From addc831f0de884f92c5ab556a34a2476c75b138a Mon Sep 17 00:00:00 2001 From: hondacrx Date: Tue, 9 Feb 2021 13:02:06 -0500 Subject: [PATCH] Core/Spells: Adding SpellTargetObjectTypes to spell target checker to early-eliminate alive units Port From (https://github.com/TrinityCore/TrinityCore/commit/0cae71eac58bf37c6a2cbce2a60dd2aa1f7b4314) --- Source/Game/Maps/GridNotifiers.cs | 4 +- Source/Game/Spells/Spell.cs | 41 +++++++++++------ Source/Scripts/Spells/Generic.cs | 2 +- Source/Scripts/Spells/Hunter.cs | 45 ------------------- ...2021_02_05_00_world_remove_pet_carrion.sql | 1 + 5 files changed, 32 insertions(+), 61 deletions(-) create mode 100644 sql/updates/world/master/2021_02_05_00_world_remove_pet_carrion.sql diff --git a/Source/Game/Maps/GridNotifiers.cs b/Source/Game/Maps/GridNotifiers.cs index ab1c995c6..46e46e3f2 100644 --- a/Source/Game/Maps/GridNotifiers.cs +++ b/Source/Game/Maps/GridNotifiers.cs @@ -2742,11 +2742,11 @@ namespace Game.Maps public class AnyDeadUnitSpellTargetInRangeCheck : AnyDeadUnitObjectInRangeCheck where T : WorldObject { - public AnyDeadUnitSpellTargetInRangeCheck(Unit searchObj, float range, SpellInfo spellInfo, SpellTargetCheckTypes check) + public AnyDeadUnitSpellTargetInRangeCheck(Unit searchObj, float range, SpellInfo spellInfo, SpellTargetCheckTypes check, SpellTargetObjectTypes objectType) : base(searchObj, range) { i_spellInfo = spellInfo; - i_check = new WorldObjectSpellTargetCheck(searchObj, searchObj, spellInfo, check, null); + i_check = new WorldObjectSpellTargetCheck(searchObj, searchObj, spellInfo, check, null, objectType); } public override bool Invoke(T obj) diff --git a/Source/Game/Spells/Spell.cs b/Source/Game/Spells/Spell.cs index 702f5cfa9..940e117b0 100644 --- a/Source/Game/Spells/Spell.cs +++ b/Source/Game/Spells/Spell.cs @@ -661,7 +661,7 @@ namespace Game.Spells GridMapTypeMask containerTypeMask = GetSearcherTypeMask(objectType, condList); if (containerTypeMask != 0) { - var spellCone = new WorldObjectSpellConeTargetCheck(MathFunctions.DegToRad(m_spellInfo.ConeAngle), m_spellInfo.Width != 0 ? m_spellInfo.Width : m_caster.GetCombatReach(), radius, m_caster, m_spellInfo, selectionType, condList); + var spellCone = new WorldObjectSpellConeTargetCheck(MathFunctions.DegToRad(m_spellInfo.ConeAngle), m_spellInfo.Width != 0 ? m_spellInfo.Width : m_caster.GetCombatReach(), radius, m_caster, m_spellInfo, selectionType, condList, objectType); var searcher = new WorldObjectListSearcher(m_caster, targets, spellCone, containerTypeMask); SearchTargets(searcher, containerTypeMask, m_caster, m_caster.GetPosition(), radius); @@ -1134,7 +1134,7 @@ namespace Game.Spells SpellEffectInfo effect = m_spellInfo.GetEffect(effIndex); List targets = new List(); - var spellTraj = new WorldObjectSpellTrajTargetCheck(dist2d, srcPos, m_caster, m_spellInfo, targetType.GetCheckType(), effect.ImplicitTargetConditions); + var spellTraj = new WorldObjectSpellTrajTargetCheck(dist2d, srcPos, m_caster, m_spellInfo, targetType.GetCheckType(), effect.ImplicitTargetConditions, SpellTargetObjectTypes.None); var searcher = new WorldObjectListSearcher(m_caster, targets, spellTraj); SearchTargets(searcher, GridMapTypeMask.All, m_caster, srcPos, dist2d); if (targets.Empty()) @@ -1364,7 +1364,7 @@ namespace Game.Spells GridMapTypeMask containerTypeMask = GetSearcherTypeMask(objectType, condList); if (containerTypeMask == 0) return null; - var check = new WorldObjectSpellNearbyTargetCheck(range, m_caster, m_spellInfo, selectionType, condList); + var check = new WorldObjectSpellNearbyTargetCheck(range, m_caster, m_spellInfo, selectionType, condList, objectType); var searcher = new WorldObjectLastSearcher(m_caster, check, containerTypeMask); SearchTargets(searcher, containerTypeMask, m_caster, m_caster.GetPosition(), range); return searcher.GetTarget(); @@ -1375,7 +1375,7 @@ namespace Game.Spells var containerTypeMask = GetSearcherTypeMask(objectType, condList); if (containerTypeMask == 0) return; - var check = new WorldObjectSpellAreaTargetCheck(range, position, m_caster, referer, m_spellInfo, selectionType, condList); + var check = new WorldObjectSpellAreaTargetCheck(range, position, m_caster, referer, m_spellInfo, selectionType, condList, objectType); var searcher = new WorldObjectListSearcher(m_caster, targets, check, containerTypeMask); SearchTargets(searcher, containerTypeMask, m_caster, position, range); } @@ -7732,13 +7732,14 @@ namespace Game.Spells public class WorldObjectSpellTargetCheck : ICheck { - public WorldObjectSpellTargetCheck(Unit caster, Unit referer, SpellInfo spellInfo, SpellTargetCheckTypes selectionType, List condList) + public WorldObjectSpellTargetCheck(Unit caster, Unit referer, SpellInfo spellInfo, SpellTargetCheckTypes selectionType, List condList, SpellTargetObjectTypes objectType) { _caster = caster; _referer = referer; _spellInfo = spellInfo; _targetSelectionType = selectionType; _condList = condList; + _objectType = objectType; if (condList != null) _condSrcInfo = new ConditionSourceInfo(null, caster); @@ -7817,9 +7818,22 @@ namespace Game.Spells default: break; } + + switch (_objectType) + { + case SpellTargetObjectTypes.Corpse: + case SpellTargetObjectTypes.CorpseAlly: + case SpellTargetObjectTypes.CorpseEnemy: + if (unitTarget.IsAlive()) + return false; + break; + default: + break; + } } if (_condSrcInfo == null) return true; + _condSrcInfo.mConditionTargets[0] = obj; return Global.ConditionMgr.IsObjectMeetToConditions(_condSrcInfo, _condList); } @@ -7830,14 +7844,15 @@ namespace Game.Spells SpellTargetCheckTypes _targetSelectionType; ConditionSourceInfo _condSrcInfo; List _condList; + SpellTargetObjectTypes _objectType; } public class WorldObjectSpellNearbyTargetCheck : WorldObjectSpellTargetCheck { float _range; Position _position; - public WorldObjectSpellNearbyTargetCheck(float range, Unit caster, SpellInfo spellInfo, SpellTargetCheckTypes selectionType, List condList) - : base(caster, caster, spellInfo, selectionType, condList) + public WorldObjectSpellNearbyTargetCheck(float range, Unit caster, SpellInfo spellInfo, SpellTargetCheckTypes selectionType, List condList, SpellTargetObjectTypes objectType) + : base(caster, caster, spellInfo, selectionType, condList, objectType) { _range = range; _position = caster.GetPosition(); @@ -7859,8 +7874,8 @@ namespace Game.Spells { float _range; Position _position; - public WorldObjectSpellAreaTargetCheck(float range, Position position, Unit caster, Unit referer, SpellInfo spellInfo, SpellTargetCheckTypes selectionType, List condList) - : base(caster, referer, spellInfo, selectionType, condList) + public WorldObjectSpellAreaTargetCheck(float range, Position position, Unit caster, Unit referer, SpellInfo spellInfo, SpellTargetCheckTypes selectionType, List condList, SpellTargetObjectTypes objectType) + : base(caster, referer, spellInfo, selectionType, condList, objectType) { _range = range; _position = position; @@ -7889,8 +7904,8 @@ namespace Game.Spells public class WorldObjectSpellConeTargetCheck : WorldObjectSpellAreaTargetCheck { - public WorldObjectSpellConeTargetCheck(float coneAngle, float lineWidth, float range, Unit caster, SpellInfo spellInfo, SpellTargetCheckTypes selectionType, List condList) - : base(range, caster.GetPosition(), caster, caster, spellInfo, selectionType, condList) + public WorldObjectSpellConeTargetCheck(float coneAngle, float lineWidth, float range, Unit caster, SpellInfo spellInfo, SpellTargetCheckTypes selectionType, List condList, SpellTargetObjectTypes objectType) + : base(range, caster.GetPosition(), caster, caster, spellInfo, selectionType, condList, objectType) { _coneAngle = coneAngle; _lineWidth = lineWidth; @@ -7928,8 +7943,8 @@ namespace Game.Spells float _range; Position _position; - public WorldObjectSpellTrajTargetCheck(float range, Position position, Unit caster, SpellInfo spellInfo, SpellTargetCheckTypes selectionType, List condList) - : base(caster, caster, spellInfo, selectionType, condList) + public WorldObjectSpellTrajTargetCheck(float range, Position position, Unit caster, SpellInfo spellInfo, SpellTargetCheckTypes selectionType, List condList, SpellTargetObjectTypes objectType) + : base(caster, caster, spellInfo, selectionType, condList, objectType) { _range = range; _position = position; diff --git a/Source/Scripts/Spells/Generic.cs b/Source/Scripts/Spells/Generic.cs index e8a30d027..af2f4ba25 100644 --- a/Source/Scripts/Spells/Generic.cs +++ b/Source/Scripts/Spells/Generic.cs @@ -807,7 +807,7 @@ namespace Scripts.Spells.Generic Unit caster = GetCaster(); float max_range = GetSpellInfo().GetMaxRange(false); // search for nearby enemy corpse in range - var check = new AnyDeadUnitSpellTargetInRangeCheck(caster, max_range, GetSpellInfo(), SpellTargetCheckTypes.Enemy); + var check = new AnyDeadUnitSpellTargetInRangeCheck(caster, max_range, GetSpellInfo(), SpellTargetCheckTypes.Enemy, SpellTargetObjectTypes.CorpseEnemy); var searcher = new UnitSearcher(caster, check); Cell.VisitWorldObjects(caster, searcher, max_range); if (!searcher.GetTarget()) diff --git a/Source/Scripts/Spells/Hunter.cs b/Source/Scripts/Spells/Hunter.cs index be4f42762..9d30a372e 100644 --- a/Source/Scripts/Spells/Hunter.cs +++ b/Source/Scripts/Spells/Hunter.cs @@ -339,51 +339,6 @@ namespace Scripts.Spells.Hunter } } - // 54044 - Pet Carrion Feeder - [Script] - class spell_hun_pet_carrion_feeder : SpellScript - { - public override bool Load() - { - if (!GetCaster().IsPet()) - return false; - return true; - } - - public override bool Validate(SpellInfo spellInfo) - { - return ValidateSpellInfo(SpellIds.PetCarrionFeederTriggered); - } - - SpellCastResult CheckIfCorpseNear() - { - Unit caster = GetCaster(); - float max_range = GetSpellInfo().GetMaxRange(false); - - // search for nearby enemy corpse in range - var check = new AnyDeadUnitSpellTargetInRangeCheck(caster, max_range, GetSpellInfo(), SpellTargetCheckTypes.Enemy); - var searcher = new WorldObjectSearcher(caster, check); - Cell.VisitWorldObjects(caster, searcher, max_range); - if (!searcher.GetTarget()) - Cell.VisitGridObjects(caster, searcher, max_range); - if (!searcher.GetTarget()) - return SpellCastResult.NoEdibleCorpses; - return SpellCastResult.SpellCastOk; - } - - void HandleDummy(uint effIndex) - { - Unit caster = GetCaster(); - caster.CastSpell(caster, SpellIds.PetCarrionFeederTriggered, false); - } - - public override void Register() - { - OnEffectHit.Add(new EffectHandler(HandleDummy, 0, SpellEffectName.Dummy)); - OnCheckCast.Add(new CheckCastHandler(CheckIfCorpseNear)); - } - } - // 55709 - Pet Heart of the Phoenix [Script] class spell_hun_pet_heart_of_the_phoenix : SpellScript diff --git a/sql/updates/world/master/2021_02_05_00_world_remove_pet_carrion.sql b/sql/updates/world/master/2021_02_05_00_world_remove_pet_carrion.sql new file mode 100644 index 000000000..347ae0ef1 --- /dev/null +++ b/sql/updates/world/master/2021_02_05_00_world_remove_pet_carrion.sql @@ -0,0 +1 @@ +DELETE FROM spell_script_names WHERE ScriptName='spell_hun_pet_carrion_feeder';