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)
This commit is contained in:
Hondacrx
2025-05-19 11:08:47 -04:00
parent c0303c2e92
commit 87df85cac7
6 changed files with 52 additions and 8 deletions
+10
View File
@@ -258,4 +258,14 @@ namespace Framework.Constants
FromRedirect = 0x01, FromRedirect = 0x01,
HasRedirected = 0x02 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
}
} }
+1 -1
View File
@@ -415,7 +415,7 @@ namespace Framework.Constants
InvokerParty = 16, // Invoker'S Party Members InvokerParty = 16, // Invoker'S Party Members
PlayerRange = 17, // Min, Max PlayerRange = 17, // Min, Max
PlayerDistance = 18, // Maxdist PlayerDistance = 18, // Maxdist
ClosestCreature = 19, // Creatureentry(0any), Maxdist, Dead?, StringId ClosestCreature = 19, // Creatureentry(0any), Maxdist, findCreatureAliveState, StringId
ClosestGameobject = 20, // Entry(0any), Maxdist, StringId ClosestGameobject = 20, // Entry(0any), Maxdist, StringId
ClosestPlayer = 21, // Maxdist ClosestPlayer = 21, // Maxdist
ActionInvokerVehicle = 22, // Unit'S Vehicle Who Caused This Event To Occur ActionInvokerVehicle = 22, // Unit'S Vehicle Who Caused This Event To Occur
@@ -497,7 +497,11 @@ namespace Game.AI
TC_SAI_IS_BOOLEAN_VALID(e, e.Target.farthest.isInLos); TC_SAI_IS_BOOLEAN_VALID(e, e.Target.farthest.isInLos);
break; break;
case SmartTargets.ClosestCreature: 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; break;
case SmartTargets.ClosestEnemy: case SmartTargets.ClosestEnemy:
TC_SAI_IS_BOOLEAN_VALID(e, e.Target.closestAttackable.playerOnly); TC_SAI_IS_BOOLEAN_VALID(e, e.Target.closestAttackable.playerOnly);
@@ -3969,7 +3973,7 @@ namespace Game.AI
{ {
public uint entry; public uint entry;
public uint dist; public uint dist;
public uint dead; public uint findCreatureAliveState;
} }
public struct GoClosest public struct GoClosest
{ {
+1 -1
View File
@@ -2918,7 +2918,7 @@ namespace Game.AI
} }
Creature target = refObj.FindNearestCreatureWithOptions(e.Target.unitClosest.dist != 0 ? e.Target.unitClosest.dist : 100, 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) if (target != null)
targets.Add(target); targets.Add(target);
+2 -2
View File
@@ -4181,7 +4181,7 @@ namespace Game.Entities
public FindCreatureOptions SetCreatureId(uint creatureId) { CreatureId = creatureId; return this; } public FindCreatureOptions SetCreatureId(uint creatureId) { CreatureId = creatureId; return this; }
public FindCreatureOptions SetStringId(string stringId) { StringId = stringId; 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 SetIsInCombat(bool isInCombat) { IsInCombat = isInCombat; return this; }
public FindCreatureOptions SetIsSummon(bool isSummon) { IsSummon = isSummon; return this; } public FindCreatureOptions SetIsSummon(bool isSummon) { IsSummon = isSummon; return this; }
@@ -4199,7 +4199,7 @@ namespace Game.Entities
public uint? CreatureId; public uint? CreatureId;
public string StringId; public string StringId;
public bool? IsAlive; public FindCreatureAliveState? IsAlive;
public bool? IsInCombat; public bool? IsInCombat;
public bool? IsSummon; public bool? IsSummon;
+31 -1
View File
@@ -2468,8 +2468,38 @@ namespace Game.Maps
if (i_args.StringId != null && !u.HasStringId(i_args.StringId)) if (i_args.StringId != null && !u.HasStringId(i_args.StringId))
return false; return false;
if (i_args.IsAlive.HasValue && u.IsAlive() != i_args.IsAlive) if (i_args.IsAlive.HasValue)
{
switch (i_args.IsAlive.Value)
{
case FindCreatureAliveState.Alive:
{
if (!u.IsAlive())
return false; 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) if (i_args.IsSummon.HasValue && u.IsSummon() != i_args.IsSummon)
return false; return false;