From 87df85cac7b96301f66cdde1d4a28d127c6fec52 Mon Sep 17 00:00:00 2001 From: Hondacrx Date: Mon, 19 May 2025 11:08:47 -0400 Subject: [PATCH] Core/Objects: Allow more specific checks to include or exclude feign death units in CreatureWithOptionsInObjectRangeCheck::IsAlive check (#30361) * this also extends SMART_TARGET_CLOSEST_CREATURE dead param Port From (https://github.com/TrinityCore/TrinityCore/commit/92efc2523b75e4ca01be7d0894ed8bc979cb3049) --- Source/Framework/Constants/ObjectConst.cs | 10 ++++++ Source/Framework/Constants/SmartAIConst.cs | 2 +- Source/Game/AI/SmartScripts/SmartAIManager.cs | 8 +++-- Source/Game/AI/SmartScripts/SmartScript.cs | 2 +- Source/Game/Entities/Object/WorldObject.cs | 4 +-- Source/Game/Maps/GridNotifiers.cs | 34 +++++++++++++++++-- 6 files changed, 52 insertions(+), 8 deletions(-) diff --git a/Source/Framework/Constants/ObjectConst.cs b/Source/Framework/Constants/ObjectConst.cs index 4974eeb08..38f0de2ca 100644 --- a/Source/Framework/Constants/ObjectConst.cs +++ b/Source/Framework/Constants/ObjectConst.cs @@ -258,4 +258,14 @@ namespace Framework.Constants FromRedirect = 0x01, HasRedirected = 0x02 } + + public enum FindCreatureAliveState + { + Alive = 0, // includes feign death + Dead = 1, // excludes feign death + EffectivelyAlive = 2, // excludes feign death + EffectivelyDead = 3, // includes feign death + + Max + } } diff --git a/Source/Framework/Constants/SmartAIConst.cs b/Source/Framework/Constants/SmartAIConst.cs index f2eeb2b14..3fbb58574 100644 --- a/Source/Framework/Constants/SmartAIConst.cs +++ b/Source/Framework/Constants/SmartAIConst.cs @@ -415,7 +415,7 @@ namespace Framework.Constants InvokerParty = 16, // Invoker'S Party Members PlayerRange = 17, // Min, Max PlayerDistance = 18, // Maxdist - ClosestCreature = 19, // Creatureentry(0any), Maxdist, Dead?, StringId + ClosestCreature = 19, // Creatureentry(0any), Maxdist, findCreatureAliveState, StringId ClosestGameobject = 20, // Entry(0any), Maxdist, StringId ClosestPlayer = 21, // Maxdist ActionInvokerVehicle = 22, // Unit'S Vehicle Who Caused This Event To Occur diff --git a/Source/Game/AI/SmartScripts/SmartAIManager.cs b/Source/Game/AI/SmartScripts/SmartAIManager.cs index e09a3263a..5fb076d67 100644 --- a/Source/Game/AI/SmartScripts/SmartAIManager.cs +++ b/Source/Game/AI/SmartScripts/SmartAIManager.cs @@ -497,7 +497,11 @@ namespace Game.AI TC_SAI_IS_BOOLEAN_VALID(e, e.Target.farthest.isInLos); break; case SmartTargets.ClosestCreature: - TC_SAI_IS_BOOLEAN_VALID(e, e.Target.unitClosest.dead); + if (e.Target.unitClosest.findCreatureAliveState < (uint)FindCreatureAliveState.Alive || e.Target.unitClosest.findCreatureAliveState >= (uint)FindCreatureAliveState.Max) + { + Log.outError(LogFilter.Sql, $"SmartAIMgr: {e} has invalid alive state {e.Target.unitClosest.findCreatureAliveState}"); + return false; + } break; case SmartTargets.ClosestEnemy: TC_SAI_IS_BOOLEAN_VALID(e, e.Target.closestAttackable.playerOnly); @@ -3969,7 +3973,7 @@ namespace Game.AI { public uint entry; public uint dist; - public uint dead; + public uint findCreatureAliveState; } public struct GoClosest { diff --git a/Source/Game/AI/SmartScripts/SmartScript.cs b/Source/Game/AI/SmartScripts/SmartScript.cs index e3952a4c5..291c82fc2 100644 --- a/Source/Game/AI/SmartScripts/SmartScript.cs +++ b/Source/Game/AI/SmartScripts/SmartScript.cs @@ -2918,7 +2918,7 @@ namespace Game.AI } Creature target = refObj.FindNearestCreatureWithOptions(e.Target.unitClosest.dist != 0 ? e.Target.unitClosest.dist : 100, - new FindCreatureOptions() { CreatureId = e.Target.unitClosest.entry, StringId = !e.Target.param_string.IsEmpty() ? e.Target.param_string : null, IsAlive = e.Target.unitClosest.dead == 0 }); + new FindCreatureOptions() { CreatureId = e.Target.unitClosest.entry, StringId = !e.Target.param_string.IsEmpty() ? e.Target.param_string : null, IsAlive = (FindCreatureAliveState)e.Target.unitClosest.findCreatureAliveState }); if (target != null) targets.Add(target); diff --git a/Source/Game/Entities/Object/WorldObject.cs b/Source/Game/Entities/Object/WorldObject.cs index 1d05b5f38..26a61a585 100644 --- a/Source/Game/Entities/Object/WorldObject.cs +++ b/Source/Game/Entities/Object/WorldObject.cs @@ -4181,7 +4181,7 @@ namespace Game.Entities public FindCreatureOptions SetCreatureId(uint creatureId) { CreatureId = creatureId; return this; } public FindCreatureOptions SetStringId(string stringId) { StringId = stringId; return this; } - public FindCreatureOptions SetIsAlive(bool isAlive) { IsAlive = isAlive; return this; } + public FindCreatureOptions SetIsAlive(FindCreatureAliveState isAlive) { IsAlive = isAlive; return this; } public FindCreatureOptions SetIsInCombat(bool isInCombat) { IsInCombat = isInCombat; return this; } public FindCreatureOptions SetIsSummon(bool isSummon) { IsSummon = isSummon; return this; } @@ -4199,7 +4199,7 @@ namespace Game.Entities public uint? CreatureId; public string StringId; - public bool? IsAlive; + public FindCreatureAliveState? IsAlive; public bool? IsInCombat; public bool? IsSummon; diff --git a/Source/Game/Maps/GridNotifiers.cs b/Source/Game/Maps/GridNotifiers.cs index 963fbecd4..7e8aa34c2 100644 --- a/Source/Game/Maps/GridNotifiers.cs +++ b/Source/Game/Maps/GridNotifiers.cs @@ -2468,8 +2468,38 @@ namespace Game.Maps if (i_args.StringId != null && !u.HasStringId(i_args.StringId)) return false; - if (i_args.IsAlive.HasValue && u.IsAlive() != i_args.IsAlive) - return false; + if (i_args.IsAlive.HasValue) + { + switch (i_args.IsAlive.Value) + { + case FindCreatureAliveState.Alive: + { + if (!u.IsAlive()) + return false; + break; + } + case FindCreatureAliveState.Dead: + { + if (u.IsAlive()) + return false; + break; + } + case FindCreatureAliveState.EffectivelyAlive: + { + if (!u.IsAlive() || u.HasUnitFlag2(UnitFlags2.FeignDeath)) + return false; + break; + } + case FindCreatureAliveState.EffectivelyDead: + { + if (u.IsAlive() && !u.HasUnitFlag2(UnitFlags2.FeignDeath)) + return false; + break; + } + default: + break; + } + } if (i_args.IsSummon.HasValue && u.IsSummon() != i_args.IsSummon) return false;