From 8673e7218d5ec5bbf57cd25c60613752ff9df855 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Wed, 25 Jul 2018 14:08:35 -0400 Subject: [PATCH] Core/Spells: Fixed travel form --- Source/Game/Entities/Player/Player.cs | 2 +- Source/Game/Entities/Unit/Unit.Spells.cs | 2 +- Source/Game/Entities/Unit/Unit.cs | 2 +- Source/Game/Spells/SpellManager.cs | 3 + .../AzjolNerub/AzjolNerub/BossNadronox.cs | 2 +- Source/Scripts/Spells/Druid.cs | 148 ++++++++++++++++++ Source/Scripts/Spells/Hunter.cs | 2 +- .../world/master/2018_07_22_00_world.sql | 11 ++ 8 files changed, 167 insertions(+), 5 deletions(-) create mode 100644 sql/updates/world/master/2018_07_22_00_world.sql diff --git a/Source/Game/Entities/Player/Player.cs b/Source/Game/Entities/Player/Player.cs index 8d7c6d0d5..e2aa65916 100644 --- a/Source/Game/Entities/Player/Player.cs +++ b/Source/Game/Entities/Player/Player.cs @@ -6699,7 +6699,7 @@ namespace Game.Entities if (GetDisplayId() != GetNativeDisplayId()) RestoreDisplayId(true); - if (IsDisallowedMountForm(getTransForm(), FORM_NONE, GetDisplayId())) + if (IsDisallowedMountForm(getTransForm(), ShapeShiftForm.None, GetDisplayId())) { GetSession().SendActivateTaxiReply(ActivateTaxiReply.PlayerShapeshifted); return false; diff --git a/Source/Game/Entities/Unit/Unit.Spells.cs b/Source/Game/Entities/Unit/Unit.Spells.cs index f16aca044..9e9b097c4 100644 --- a/Source/Game/Entities/Unit/Unit.Spells.cs +++ b/Source/Game/Entities/Unit/Unit.Spells.cs @@ -2160,7 +2160,7 @@ namespace Game.Entities } } - uint getTransForm() { return m_transform; } + public uint getTransForm() { return m_transform; } public bool HasStealthAura() { return HasAuraType(AuraType.ModStealth); } public bool HasInvisibilityAura() { return HasAuraType(AuraType.ModInvisibility); } diff --git a/Source/Game/Entities/Unit/Unit.cs b/Source/Game/Entities/Unit/Unit.cs index 3ed6bd864..d25abd2dc 100644 --- a/Source/Game/Entities/Unit/Unit.cs +++ b/Source/Game/Entities/Unit/Unit.cs @@ -256,7 +256,7 @@ namespace Game.Entities return IsDisallowedMountForm(getTransForm(), GetShapeshiftForm(), GetDisplayId()); } - bool IsDisallowedMountForm(uint spellId, ShapeShiftForm form, uint displayId) + public bool IsDisallowedMountForm(uint spellId, ShapeShiftForm form, uint displayId) { SpellInfo transformSpellInfo = Global.SpellMgr.GetSpellInfo(getTransForm()); if (transformSpellInfo != null) diff --git a/Source/Game/Spells/SpellManager.cs b/Source/Game/Spells/SpellManager.cs index ceec78c7a..fc7f9e786 100644 --- a/Source/Game/Spells/SpellManager.cs +++ b/Source/Game/Spells/SpellManager.cs @@ -2750,6 +2750,9 @@ namespace Game.Entities case 24314: // Threatening Gaze spellInfo.AuraInterruptFlags[0] |= (uint)(SpellAuraInterruptFlags.Cast | SpellAuraInterruptFlags.Move | SpellAuraInterruptFlags.Jump); break; + case 783: // Travel Form (dummy) - cannot be cast indoors. + spellInfo.Attributes |= SpellAttr0.OutdoorsOnly; + break; case 5420: // Tree of Life (Passive) spellInfo.Stances = 1 << ((int)ShapeShiftForm.TreeOfLife - 1); break; diff --git a/Source/Scripts/Northrend/AzjolNerub/AzjolNerub/BossNadronox.cs b/Source/Scripts/Northrend/AzjolNerub/AzjolNerub/BossNadronox.cs index b6c033d3d..8c67c9069 100644 --- a/Source/Scripts/Northrend/AzjolNerub/AzjolNerub/BossNadronox.cs +++ b/Source/Scripts/Northrend/AzjolNerub/AzjolNerub/BossNadronox.cs @@ -880,7 +880,7 @@ namespace Scripts.Northrend.AzjolNerub.AzjolNerub.Nadronox void HandleEffectRemove(AuraEffect aurEff, AuraEffectHandleModes mode) { - if (GetTargetApplication().GetRemoveMode() != AuraRemoveMode.ByDeath) + if (GetTargetApplication().GetRemoveMode() != AuraRemoveMode.Death) return; if (GetTarget().IsGuardian()) diff --git a/Source/Scripts/Spells/Druid.cs b/Source/Scripts/Spells/Druid.cs index c8f30680c..700fe6859 100644 --- a/Source/Scripts/Spells/Druid.cs +++ b/Source/Scripts/Spells/Druid.cs @@ -36,6 +36,10 @@ namespace Scripts.Spells.Druid public const uint Exhilarate = 28742; public const uint FeralChargeBear = 16979; public const uint FeralChargeCat = 49376; + public const uint FormAquatic = 1066; + public const uint FormFlight = 33943; + public const uint FormStag = 165961; + public const uint FormSwiftFlight = 40120; public const uint FormsTrinketBear = 37340; public const uint FormsTrinketCat = 37341; public const uint FormsTrinketMoonkin = 37343; @@ -57,6 +61,7 @@ namespace Scripts.Spells.Druid public const uint StampedeCatState = 109881; public const uint SunfireDamage = 164815; public const uint SurvivalInstincts = 50322; + public const uint TravelForm = 783; } [Script] // 1850 - Dash @@ -684,6 +689,149 @@ namespace Scripts.Spells.Druid } } + [Script] // 783 - Travel Form (dummy) + class spell_dru_travel_form_dummy_SpellScript : SpellScript + { + SpellCastResult CheckCast() + { + Player player = GetCaster().ToPlayer(); + if (!player) + return SpellCastResult.CustomError; + + if (player.GetSkillValue(SkillType.Riding) < 75) + return SpellCastResult.ApprenticeRidingRequirement; + + SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(player.IsInWater() ? SpellIds.FormAquatic : SpellIds.FormStag); + return spellInfo.CheckLocation(player.GetMapId(), player.GetZoneId(), player.GetAreaId(), player); + } + + public override void Register() + { + OnCheckCast.Add(new CheckCastHandler(CheckCast)); + } + } + + [Script] + class spell_dru_travel_form_dummy_AuraScript : AuraScript + { + public override bool Validate(SpellInfo spellInfo) + { + return ValidateSpellInfo(SpellIds.FormStag, SpellIds.FormAquatic, SpellIds.FormFlight, SpellIds.FormSwiftFlight); + } + + public override bool Load() + { + return GetCaster().GetTypeId() == TypeId.Player; + } + + void OnApply(AuraEffect aurEff, AuraEffectHandleModes mode) + { + uint triggeredSpellId; + + Player player = GetTarget().ToPlayer(); + if (player.IsInWater()) // Aquatic form + triggeredSpellId = SpellIds.FormAquatic; + else if (player.GetSkillValue(SkillType.Riding) >= 225 && CheckLocationForForm(SpellIds.FormFlight) == SpellCastResult.SpellCastOk) // Flight form + triggeredSpellId = player.getLevel() >= 71 ? SpellIds.FormSwiftFlight : SpellIds.FormFlight; + else // Stag form (riding skill already checked in CheckCast) + triggeredSpellId = SpellIds.FormStag; + + player.AddAura(triggeredSpellId, player); + } + + void AfterRemove(AuraEffect aurEff, AuraEffectHandleModes mode) + { + // No need to check remove mode, it's safe for auras to remove each other in AfterRemove hook. + GetTarget().RemoveAura(SpellIds.FormStag); + GetTarget().RemoveAura(SpellIds.FormAquatic); + GetTarget().RemoveAura(SpellIds.FormFlight); + GetTarget().RemoveAura(SpellIds.FormSwiftFlight); + } + + public override void Register() + { + OnEffectApply.Add(new EffectApplyHandler(OnApply, 0, AuraType.Dummy, AuraEffectHandleModes.Real)); + AfterEffectRemove.Add(new EffectApplyHandler(AfterRemove, 0, AuraType.Dummy, AuraEffectHandleModes.Real)); + } + + // Outdoor check already passed - Travel Form (dummy) has SPELL_ATTR0_OUTDOORS_ONLY attribute. + SpellCastResult CheckLocationForForm(uint spell) + { + Player player = GetTarget().ToPlayer(); + SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(spell); + return spellInfo.CheckLocation(player.GetMapId(), player.GetZoneId(), player.GetAreaId(), player); + } + } + + // 1066 - Aquatic Form + // 33943 - Flight Form + // 40120 - Swift Flight Form + [Script] // 165961 - Stag Form + class spell_dru_travel_form_AuraScript : AuraScript + { + public override bool Validate(SpellInfo spellInfo) + { + return ValidateSpellInfo(SpellIds.FormStag, SpellIds.FormAquatic, SpellIds.FormFlight, SpellIds.FormSwiftFlight); + } + + public override bool Load() + { + return GetCaster().GetTypeId() == TypeId.Player; + } + + void OnRemove(AuraEffect aurEff, AuraEffectHandleModes mode) + { + // If it stays 0, it removes Travel Form dummy in AfterRemove. + triggeredSpellId = 0; + + // We should only handle aura interrupts. + if (GetTargetApplication().GetRemoveMode() != AuraRemoveMode.Interrupt) + return; + + // Check what form is appropriate + Player player = GetTarget().ToPlayer(); + if (player.IsInWater()) // Aquatic form + triggeredSpellId = SpellIds.FormAquatic; + else if (player.GetSkillValue(SkillType.Riding) >= 225 && CheckLocationForForm(SpellIds.FormFlight) == SpellCastResult.SpellCastOk) // Flight form + triggeredSpellId = player.GetSkillValue(SkillType.Riding) >= 300 ? SpellIds.FormSwiftFlight : SpellIds.FormFlight; + else if (CheckLocationForForm(SpellIds.FormStag) == SpellCastResult.SpellCastOk) // Stag form + triggeredSpellId = SpellIds.FormStag; + + // If chosen form is current aura, just don't remove it. + if (triggeredSpellId == m_scriptSpellId) + PreventDefaultAction(); + } + + void AfterRemove(AuraEffect aurEff, AuraEffectHandleModes mode) + { + Player player = GetTarget().ToPlayer(); + + if (triggeredSpellId != 0) // Apply new form + player.AddAura(triggeredSpellId, player); + else // If not set, simply remove Travel Form dummy + player.RemoveAura(SpellIds.TravelForm); + } + + public override void Register() + { + OnEffectRemove.Add(new EffectApplyHandler(OnRemove, 0, AuraType.ModShapeshift, AuraEffectHandleModes.Real)); + AfterEffectRemove.Add(new EffectApplyHandler(AfterRemove, 0, AuraType.ModShapeshift, AuraEffectHandleModes.Real)); + } + + SpellCastResult CheckLocationForForm(uint spell_id) + { + Player player = GetTarget().ToPlayer(); + SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(spell_id); + + if (!player.GetMap().IsOutdoors(player.GetPhaseShift(), player.GetPositionX(), player.GetPositionY(), player.GetPositionZ())) + return SpellCastResult.OnlyOutdoors; + + return spellInfo.CheckLocation(player.GetMapId(), player.GetZoneId(), player.GetAreaId(), player); + } + + uint triggeredSpellId; + } + [Script] // 40442 - Druid Tier 6 Trinket class spell_dru_item_t6_trinket : AuraScript { diff --git a/Source/Scripts/Spells/Hunter.cs b/Source/Scripts/Spells/Hunter.cs index c659d02e7..77d25608e 100644 --- a/Source/Scripts/Spells/Hunter.cs +++ b/Source/Scripts/Spells/Hunter.cs @@ -298,7 +298,7 @@ namespace Scripts.Spells.Hunter void OnRemove(AuraEffect aurEff, AuraEffectHandleModes mode) { - if (GetTargetApplication().GetRemoveMode() = AuraRemoveMode.Default || GetTargetApplication().GetRemoveMode() == AuraRemoveMode.Interrupt) + if (GetTargetApplication().GetRemoveMode() == AuraRemoveMode.Default || GetTargetApplication().GetRemoveMode() == AuraRemoveMode.Interrupt) return; if (!GetTarget().HasAura(SpellIds.MisdirectionProc)) diff --git a/sql/updates/world/master/2018_07_22_00_world.sql b/sql/updates/world/master/2018_07_22_00_world.sql new file mode 100644 index 000000000..0242f0a6a --- /dev/null +++ b/sql/updates/world/master/2018_07_22_00_world.sql @@ -0,0 +1,11 @@ +DELETE FROM `spell_script_names` WHERE `ScriptName` IN ('spell_dru_travel_form_dummy', 'spell_dru_travel_form'); +INSERT INTO `spell_script_names` (`spell_id`, `ScriptName`) VALUES +(783, 'spell_dru_travel_form_dummy'), +(1066, 'spell_dru_travel_form'), +(33943, 'spell_dru_travel_form'), +(40120, 'spell_dru_travel_form'), +(165961, 'spell_dru_travel_form'); + +DELETE FROM `spell_linked_spell` WHERE `spell_trigger` = 165961 AND spell_effect = 126056; +INSERT INTO `spell_linked_spell` (`spell_trigger`, `spell_effect`, `type`, `comment`) VALUES +(165961, 126056, 1, 'Stag Form - Sound Effect: Stag Form');