Core/Object: Implement FindNearestCreatureWithAura

Port From (https://github.com/TrinityCore/TrinityCore/commit/9a3e29d416162a84dd6a11c5e248f5f65e98a604)
This commit is contained in:
hondacrx
2022-10-31 13:56:14 -04:00
parent 8acc130815
commit 1f774369f2
2 changed files with 42 additions and 0 deletions
@@ -1619,6 +1619,14 @@ namespace Game.Entities
return searcher.GetTarget();
}
public Creature FindNearestCreatureWithAura(uint entry, uint spellId, float range, bool alive = true)
{
var checker = new NearestCreatureEntryWithLiveStateAndAuraInObjectRangeCheck(this, entry, spellId, alive, range);
var searcher = new CreatureLastSearcher(this, checker);
Cell.VisitAllObjects(this, searcher, range);
return searcher.GetTarget();
}
public GameObject FindNearestGameObject(uint entry, float range, bool spawnedOnly = true)
{
var checker = new NearestGameObjectEntryInObjectRangeCheck(this, entry, range, spawnedOnly);
+34
View File
@@ -2414,6 +2414,40 @@ namespace Game.Maps
float i_range;
}
public class NearestCreatureEntryWithLiveStateAndAuraInObjectRangeCheck : ICheck<Creature>
{
WorldObject i_obj;
uint i_entry;
uint i_spellId;
bool i_alive;
float i_range;
public NearestCreatureEntryWithLiveStateAndAuraInObjectRangeCheck(WorldObject obj, uint entry, uint spellId, bool alive, float range)
{
i_obj = obj;
i_entry = entry;
i_spellId = spellId;
i_alive = alive;
i_range = range;
}
public bool Invoke(Creature u)
{
if (u.GetDeathState() != DeathState.Dead
&& u.GetEntry() == i_entry
&& u.HasAura(i_spellId)
&& u.IsAlive() == i_alive
&& u.GetGUID() != i_obj.GetGUID()
&& i_obj.IsWithinDistInMap(u, i_range)
&& u.CheckPrivateObjectOwnerVisibility(i_obj))
{
i_range = i_obj.GetDistance(u); // use found unit range as new range limit for next check
return true;
}
return false;
}
}
public class AnyPlayerInObjectRangeCheck : ICheck<Player>
{
public AnyPlayerInObjectRangeCheck(WorldObject obj, float range, bool reqAlive = true)