Core/SAI: Add 'playerOnly' parameters to SMART_TARGET_CLOSEST_ENEMY and SMART_TARGET_CLOSEST_FRIENDLY. Wiki is updated accordingly.
This commit is contained in:
@@ -2551,7 +2551,7 @@ ObjectList* SmartScript::GetTargets(SmartScriptHolder const& e, Unit* invoker /*
|
||||
case SMART_TARGET_CLOSEST_ENEMY:
|
||||
{
|
||||
if (me)
|
||||
if (Unit* target = me->SelectNearestTarget(e.target.closestAttackable.maxDist))
|
||||
if (Unit* target = me->SelectNearestTarget(e.target.closestAttackable.maxDist, e.target.closestAttackable.playerOnly))
|
||||
l->push_back(target);
|
||||
|
||||
break;
|
||||
@@ -2559,7 +2559,7 @@ ObjectList* SmartScript::GetTargets(SmartScriptHolder const& e, Unit* invoker /*
|
||||
case SMART_TARGET_CLOSEST_FRIENDLY:
|
||||
{
|
||||
if (me)
|
||||
if (Unit* target = DoFindClosestFriendlyInRange(e.target.closestFriendly.maxDist))
|
||||
if (Unit* target = DoFindClosestFriendlyInRange(e.target.closestFriendly.maxDist, e.target.closestFriendly.playerOnly))
|
||||
l->push_back(target);
|
||||
|
||||
break;
|
||||
@@ -3443,13 +3443,13 @@ void SmartScript::DoFindFriendlyMissingBuff(std::list<Creature*>& list, float ra
|
||||
cell.Visit(p, grid_creature_searcher, *me->GetMap(), *me, range);
|
||||
}
|
||||
|
||||
Unit* SmartScript::DoFindClosestFriendlyInRange(float range)
|
||||
Unit* SmartScript::DoFindClosestFriendlyInRange(float range, bool playerOnly)
|
||||
{
|
||||
if (!me)
|
||||
return NULL;
|
||||
|
||||
Unit* unit = NULL;
|
||||
Trinity::AnyFriendlyUnitInObjectRangeCheck u_check(me, me, range);
|
||||
Trinity::AnyFriendlyUnitInObjectRangeCheck u_check(me, me, range, playerOnly);
|
||||
Trinity::UnitLastSearcher<Trinity::AnyFriendlyUnitInObjectRangeCheck> searcher(me, unit, u_check);
|
||||
me->VisitNearbyObject(range, searcher);
|
||||
return unit;
|
||||
|
||||
@@ -89,7 +89,7 @@ class SmartScript
|
||||
Unit* DoSelectLowestHpFriendly(float range, uint32 MinHPDiff);
|
||||
void DoFindFriendlyCC(std::list<Creature*>& _list, float range);
|
||||
void DoFindFriendlyMissingBuff(std::list<Creature*>& list, float range, uint32 spellid);
|
||||
Unit* DoFindClosestFriendlyInRange(float range);
|
||||
Unit* DoFindClosestFriendlyInRange(float range, bool playerOnly);
|
||||
|
||||
void StoreTargetList(ObjectList* targets, uint32 id)
|
||||
{
|
||||
|
||||
@@ -1021,8 +1021,8 @@ enum SMARTAI_TARGETS
|
||||
SMART_TARGET_ACTION_INVOKER_VEHICLE = 22, // Unit's vehicle who caused this Event to occur
|
||||
SMART_TARGET_OWNER_OR_SUMMONER = 23, // Unit's owner or summoner
|
||||
SMART_TARGET_THREAT_LIST = 24, // All units on creature's threat list
|
||||
SMART_TARGET_CLOSEST_ENEMY = 25, // maxDist
|
||||
SMART_TARGET_CLOSEST_FRIENDLY = 26, // maxDist
|
||||
SMART_TARGET_CLOSEST_ENEMY = 25, // maxDist, playerOnly
|
||||
SMART_TARGET_CLOSEST_FRIENDLY = 26, // maxDist, playerOnly
|
||||
|
||||
SMART_TARGET_END = 27
|
||||
};
|
||||
@@ -1109,11 +1109,13 @@ struct SmartTarget
|
||||
struct
|
||||
{
|
||||
uint32 maxDist;
|
||||
uint32 playerOnly;
|
||||
} closestAttackable;
|
||||
|
||||
struct
|
||||
{
|
||||
uint32 maxDist;
|
||||
uint32 playerOnly;
|
||||
} closestFriendly;
|
||||
|
||||
struct
|
||||
|
||||
@@ -1709,7 +1709,7 @@ SpellInfo const* Creature::reachWithSpellCure(Unit* victim)
|
||||
}
|
||||
|
||||
// select nearest hostile unit within the given distance (regardless of threat list).
|
||||
Unit* Creature::SelectNearestTarget(float dist) const
|
||||
Unit* Creature::SelectNearestTarget(float dist, bool playerOnly /* = false */) const
|
||||
{
|
||||
CellCoord p(Trinity::ComputeCellCoord(GetPositionX(), GetPositionY()));
|
||||
Cell cell(p);
|
||||
@@ -1721,7 +1721,7 @@ Unit* Creature::SelectNearestTarget(float dist) const
|
||||
if (dist == 0.0f)
|
||||
dist = MAX_VISIBILITY_DISTANCE;
|
||||
|
||||
Trinity::NearestHostileUnitCheck u_check(this, dist);
|
||||
Trinity::NearestHostileUnitCheck u_check(this, dist, playerOnly);
|
||||
Trinity::UnitLastSearcher<Trinity::NearestHostileUnitCheck> searcher(this, target, u_check);
|
||||
|
||||
TypeContainerVisitor<Trinity::UnitLastSearcher<Trinity::NearestHostileUnitCheck>, WorldTypeMapContainer > world_unit_searcher(searcher);
|
||||
|
||||
@@ -609,7 +609,7 @@ class Creature : public Unit, public GridObject<Creature>, public MapCreature
|
||||
|
||||
void SendAIReaction(AiReaction reactionType);
|
||||
|
||||
Unit* SelectNearestTarget(float dist = 0) const;
|
||||
Unit* SelectNearestTarget(float dist = 0, bool playerOnly = false) const;
|
||||
Unit* SelectNearestTargetInAttackDistance(float dist = 0) const;
|
||||
Player* SelectNearestPlayer(float distance = 0) const;
|
||||
Unit* SelectNearestHostileUnitInAggroRange(bool useLOS = false) const;
|
||||
|
||||
@@ -871,10 +871,10 @@ namespace Trinity
|
||||
class AnyFriendlyUnitInObjectRangeCheck
|
||||
{
|
||||
public:
|
||||
AnyFriendlyUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range) : i_obj(obj), i_funit(funit), i_range(range) {}
|
||||
AnyFriendlyUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range, bool playerOnly = false) : i_obj(obj), i_funit(funit), i_range(range), i_playerOnly(playerOnly) {}
|
||||
bool operator()(Unit* u)
|
||||
{
|
||||
if (u->IsAlive() && i_obj->IsWithinDistInMap(u, i_range) && i_funit->IsFriendlyTo(u))
|
||||
if (u->IsAlive() && i_obj->IsWithinDistInMap(u, i_range) && i_funit->IsFriendlyTo(u) && (!i_playerOnly || u->GetTypeId() == TYPEID_PLAYER))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
@@ -883,6 +883,7 @@ namespace Trinity
|
||||
WorldObject const* i_obj;
|
||||
Unit const* i_funit;
|
||||
float i_range;
|
||||
bool i_playerOnly;
|
||||
};
|
||||
|
||||
class AnyGroupedUnitInObjectRangeCheck
|
||||
@@ -1035,7 +1036,7 @@ namespace Trinity
|
||||
class NearestHostileUnitCheck
|
||||
{
|
||||
public:
|
||||
explicit NearestHostileUnitCheck(Creature const* creature, float dist = 0) : me(creature)
|
||||
explicit NearestHostileUnitCheck(Creature const* creature, float dist = 0, bool playerOnly = false) : me(creature), i_playerOnly(playerOnly)
|
||||
{
|
||||
m_range = (dist == 0 ? 9999 : dist);
|
||||
}
|
||||
@@ -1047,6 +1048,9 @@ namespace Trinity
|
||||
if (!me->IsValidAttackTarget(u))
|
||||
return false;
|
||||
|
||||
if (i_playerOnly && u->GetTypeId() != TYPEID_PLAYER)
|
||||
return false;
|
||||
|
||||
m_range = me->GetDistance(u); // use found unit range as new range limit for next check
|
||||
return true;
|
||||
}
|
||||
@@ -1054,6 +1058,7 @@ namespace Trinity
|
||||
private:
|
||||
Creature const* me;
|
||||
float m_range;
|
||||
bool i_playerOnly;
|
||||
NearestHostileUnitCheck(NearestHostileUnitCheck const&);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user