From 77febfdee5bf5c5fd12b31d4252cdc211a317c72 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Tue, 30 May 2023 05:18:29 -0400 Subject: [PATCH] Core/Spells: Implemented spell target type 142 Port From (https://github.com/TrinityCore/TrinityCore/commit/3790c1e3dad36727279b22a33eea8e27418c4283) --- .../Framework/Constants/Spells/SpellConst.cs | 2 +- Source/Game/Spells/Spell.cs | 39 +++++++++++++++++++ Source/Game/Spells/SpellInfo.cs | 2 +- Source/Game/Spells/SpellManager.cs | 8 +++- 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/Source/Framework/Constants/Spells/SpellConst.cs b/Source/Framework/Constants/Spells/SpellConst.cs index 0c38e1bfa..d4958da56 100644 --- a/Source/Framework/Constants/Spells/SpellConst.cs +++ b/Source/Framework/Constants/Spells/SpellConst.cs @@ -2830,7 +2830,7 @@ namespace Framework.Constants Unk139 = 139, DestCasterClumpCentroid = 140, // NYI Unk141 = 141, - Unk142 = 142, + DestNearbyEntryOrDB = 142, Unk143 = 143, Unk144 = 144, Unk145 = 145, diff --git a/Source/Game/Spells/Spell.cs b/Source/Game/Spells/Spell.cs index af1f4bd6e..ed4a71ebc 100644 --- a/Source/Game/Spells/Spell.cs +++ b/Source/Game/Spells/Spell.cs @@ -631,6 +631,26 @@ namespace Game.Spells } return; } + if (targetType.GetTarget() == Targets.DestNearbyEntryOrDB) + { + SpellTargetPosition st = Global.SpellMgr.GetSpellTargetPosition(m_spellInfo.Id, spellEffectInfo.EffectIndex); + if (st != null) + { + SpellDestination dest = new(m_caster); + if (st.target_mapId == m_caster.GetMapId() && m_caster.IsInDist(st.target_X, st.target_Y, st.target_Z, range)) + dest = new SpellDestination(st.target_X, st.target_Y, st.target_Z, st.target_Orientation); + else + { + float randomRadius1 = spellEffectInfo.CalcRadius(m_caster); + if (randomRadius1 > 0.0f) + m_caster.MovePositionToFirstCollision(dest.Position, randomRadius1, targetType.CalcDirectionAngle()); + } + + CallScriptDestinationTargetSelectHandlers(ref dest, spellEffectInfo.EffectIndex, targetType); + m_targets.SetDst(dest); + return; + } + } break; default: break; @@ -638,6 +658,22 @@ namespace Game.Spells } WorldObject target = SearchNearbyTarget(range, targetType.GetObjectType(), targetType.GetCheckType(), condList); + float randomRadius = 0.0f; + switch (targetType.GetTarget()) + { + case Targets.DestNearbyEntryOrDB: + // if we are here then there was no db target + if (target == null) + { + target = m_caster; + // radius is only meant to be randomized when using caster fallback + randomRadius = spellEffectInfo.CalcRadius(m_caster); + } + break; + default: + break; + } + if (target == null) { Log.outDebug(LogFilter.Spells, "Spell.SelectImplicitNearbyTargets: cannot find nearby target for spell ID {0}, effect {1}", m_spellInfo.Id, spellEffectInfo.EffectIndex); @@ -695,6 +731,9 @@ namespace Game.Spells break; case SpellTargetObjectTypes.Dest: SpellDestination dest = new(target); + if (randomRadius > 0.0f) + target.MovePositionToFirstCollision(dest.Position, randomRadius, targetType.CalcDirectionAngle()); + if (m_spellInfo.HasAttribute(SpellAttr4.UseFacingFromSpell)) dest.Position.SetOrientation(spellEffectInfo.PositionFacing); diff --git a/Source/Game/Spells/SpellInfo.cs b/Source/Game/Spells/SpellInfo.cs index d1ebb18c8..b4f3f9f03 100644 --- a/Source/Game/Spells/SpellInfo.cs +++ b/Source/Game/Spells/SpellInfo.cs @@ -5192,7 +5192,7 @@ namespace Game.Spells new StaticData(SpellTargetObjectTypes.None, SpellTargetReferenceTypes.None, SpellTargetSelectionCategories.Nyi, SpellTargetCheckTypes.Default, SpellTargetDirectionTypes.None), // 139 new StaticData(SpellTargetObjectTypes.Dest, SpellTargetReferenceTypes.None, SpellTargetSelectionCategories.Nyi, SpellTargetCheckTypes.Default, SpellTargetDirectionTypes.None), // 140 TARGET_DEST_CASTER_CLUMP_CENTROID new StaticData(SpellTargetObjectTypes.None, SpellTargetReferenceTypes.None, SpellTargetSelectionCategories.Nyi, SpellTargetCheckTypes.Default, SpellTargetDirectionTypes.None), // 141 - new StaticData(SpellTargetObjectTypes.None, SpellTargetReferenceTypes.None, SpellTargetSelectionCategories.Nyi, SpellTargetCheckTypes.Default, SpellTargetDirectionTypes.None), // 142 + new StaticData(SpellTargetObjectTypes.Dest, SpellTargetReferenceTypes.Caster, SpellTargetSelectionCategories.Nearby, SpellTargetCheckTypes.Entry, SpellTargetDirectionTypes.FrontRight), // 142 TARGET_DEST_NEARBY_ENTRY_OR_DB new StaticData(SpellTargetObjectTypes.None, SpellTargetReferenceTypes.None, SpellTargetSelectionCategories.Nyi, SpellTargetCheckTypes.Default, SpellTargetDirectionTypes.None), // 143 new StaticData(SpellTargetObjectTypes.None, SpellTargetReferenceTypes.None, SpellTargetSelectionCategories.Nyi, SpellTargetCheckTypes.Default, SpellTargetDirectionTypes.None), // 144 new StaticData(SpellTargetObjectTypes.None, SpellTargetReferenceTypes.None, SpellTargetSelectionCategories.Nyi, SpellTargetCheckTypes.Default, SpellTargetDirectionTypes.None), // 145 diff --git a/Source/Game/Spells/SpellManager.cs b/Source/Game/Spells/SpellManager.cs index 9e8050dc1..a9b04b175 100644 --- a/Source/Game/Spells/SpellManager.cs +++ b/Source/Game/Spells/SpellManager.cs @@ -1043,7 +1043,13 @@ namespace Game.Entities else st.target_Orientation = spellInfo.GetEffect(effIndex).PositionFacing; - if (spellInfo.GetEffect(effIndex).TargetA.GetTarget() == Targets.DestDb || spellInfo.GetEffect(effIndex).TargetB.GetTarget() == Targets.DestDb) + bool hasTarget(Targets target) + { + SpellEffectInfo spellEffectInfo = spellInfo.GetEffect(effIndex); + return spellEffectInfo.TargetA.GetTarget() == target || spellEffectInfo.TargetB.GetTarget() == target; + } + + if (hasTarget(Targets.DestDb) || hasTarget(Targets.DestNearbyEntryOrDB)) { var key = new KeyValuePair(spellId, effIndex); mSpellTargetPositions[key] = st;