From f55e8ae73ce312354578d79170c23840ef8a06d8 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Sun, 27 Feb 2022 23:36:55 -0500 Subject: [PATCH] Core/PetAI: Validate GetCharmInfo() Port From (https://github.com/TrinityCore/TrinityCore/commit/8fd7a4b6e5f6b728c4ae40cfd2080c4dae004e8f) --- Source/Game/AI/CoreAI/PetAI.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Source/Game/AI/CoreAI/PetAI.cs b/Source/Game/AI/CoreAI/PetAI.cs index e3c488129..4db093931 100644 --- a/Source/Game/AI/CoreAI/PetAI.cs +++ b/Source/Game/AI/CoreAI/PetAI.cs @@ -136,7 +136,7 @@ namespace Game.AI if (target) { - if (CanAIAttack(target) && spell.CanAutoCast(target)) + if (CanAttack(target) && spell.CanAutoCast(target)) { targetSpellStore.Add(Tuple.Create(target, spell)); spellUsed = true; @@ -174,7 +174,7 @@ namespace Game.AI if (!spellUsed) spell.Dispose(); } - else if (me.GetVictim() && CanAIAttack(me.GetVictim()) && spellInfo.CanBeUsedInCombat()) + else if (me.GetVictim() && CanAttack(me.GetVictim()) && spellInfo.CanBeUsedInCombat()) { Spell spell = new(me, spellInfo, TriggerCastFlags.None); if (spell.CanAutoCast(me.GetVictim())) @@ -248,7 +248,7 @@ namespace Game.AI public void _AttackStart(Unit target) { // Check all pet states to decide if we can attack this target - if (!CanAIAttack(target)) + if (!CanAttack(target)) return; // Only chase if not commanded to stay or if stay but commanded to attack @@ -355,6 +355,12 @@ namespace Game.AI if (me.IsCharmed()) return; + if (me.GetCharmInfo() == null) + { + Log.outWarn(LogFilter.ScriptsAi, $"me.GetCharmInfo() is NULL in PetAI::HandleReturnMovement(). Debug info: {GetDebugInfo()}"); + return; + } + if (me.GetCharmInfo().HasCommandState(CommandStates.Stay)) { if (!me.GetCharmInfo().IsAtStay() && !me.GetCharmInfo().IsReturning()) @@ -463,7 +469,7 @@ namespace Game.AI } } - public override bool CanAIAttack(Unit victim) + public bool CanAttack(Unit victim) { // Evaluates wether a pet can attack a specific target based on CommandState, ReactState and other flags // IMPORTANT: The order in which things are checked is important, be careful if you add or remove checks @@ -483,7 +489,7 @@ namespace Game.AI if (me.GetCharmInfo() == null) { - Log.outError(LogFilter.ScriptsAi, $"me.GetCharmInfo() is NULL in PetAI::CanAttack(). Debug info: {GetDebugInfo()}"); + Log.outWarn(LogFilter.ScriptsAi, $"me.GetCharmInfo() is NULL in PetAI::CanAttack(). Debug info: {GetDebugInfo()}"); return false; }