3037{
3038 Unit* scriptTrigger =
nullptr;
3039 if (invoker)
3040 scriptTrigger = invoker;
3042 scriptTrigger = tempLastInvoker;
3043
3045
3046 switch (e.GetTargetType())
3047 {
3049 if (baseObject)
3050 targets.push_back(baseObject);
3051 break;
3055 targets.push_back(victim);
3056 break;
3059 {
3060 if (e.target.hostileRandom.powerType)
3061 {
3063 targets.push_back(u);
3064 }
3065 else if (
Unit* u =
me->
AI()->
SelectTarget(SelectTargetMethod::MaxThreat, 1, (
float)e.target.hostileRandom.maxDist, e.target.hostileRandom.playerOnly))
3066 targets.push_back(u);
3067 }
3068 break;
3071 {
3072 if (e.target.hostileRandom.powerType)
3073 {
3075 targets.push_back(u);
3076 }
3077 else if (
Unit* u =
me->
AI()->
SelectTarget(SelectTargetMethod::MinThreat, 0, (
float)e.target.hostileRandom.maxDist, e.target.hostileRandom.playerOnly))
3078 targets.push_back(u);
3079 }
3080 break;
3083 {
3084 if (e.target.hostileRandom.powerType)
3085 {
3087 targets.push_back(u);
3088 }
3089 else if (
Unit* u =
me->
AI()->
SelectTarget(SelectTargetMethod::Random, 0, (
float)e.target.hostileRandom.maxDist, e.target.hostileRandom.playerOnly))
3090 targets.push_back(u);
3091 }
3092 break;
3095 {
3096 if (e.target.hostileRandom.powerType)
3097 {
3099 targets.push_back(u);
3100 }
3101 else if (
Unit* u =
me->
AI()->
SelectTarget(SelectTargetMethod::Random, 1, (
float)e.target.hostileRandom.maxDist, e.target.hostileRandom.playerOnly))
3102 targets.push_back(u);
3103 }
3104 break;
3107 {
3109 targets.push_back(u);
3110 }
3111 break;
3113 if (scriptTrigger)
3114 targets.push_back(scriptTrigger);
3115 break;
3119 break;
3121 if (scriptTrigger)
3122 {
3124 {
3125 if (
Group* group = player->GetGroup())
3126 {
3127 for (
GroupReference* groupRef = group->GetFirstMember(); groupRef !=
nullptr; groupRef = groupRef->
next())
3128 if (
Player* member = groupRef->GetSource())
3129 if (member->IsInMap(player))
3130 targets.push_back(member);
3131 }
3132
3133
3134
3135 else
3136 targets.push_back(scriptTrigger);
3137 }
3138 }
3139 break;
3141 {
3143 if (!ref)
3144 ref = scriptTrigger;
3145
3146 if (!ref)
3147 {
3148 LOG_ERROR(
"scripts.ai.sai",
"SMART_TARGET_CREATURE_RANGE: Entry {} SourceType {} Event {} Action {} Target {} is missing base object or invoker",
3149 e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.GetTargetType());
3150 break;
3151 }
3152
3155
3157 {
3159 continue;
3160
3162 continue;
3163
3164
3165 if (
uint32 state = e.target.unitRange.livingState)
3166 {
3167 if (unit->ToCreature()->IsAlive() && state == 2)
3168 continue;
3169 if (!unit->ToCreature()->IsAlive() && state == 1)
3170 continue;
3171 }
3172
3173 if (((e.target.unitRange.creature && unit->ToCreature()->GetEntry() == e.target.unitRange.creature) || !e.target.unitRange.creature) && ref->
IsInRange(unit, (
float)e.target.unitRange.minDist, (
float)e.target.unitRange.maxDist))
3174 targets.push_back(unit);
3175 }
3176
3177 break;
3178 }
3180 {
3183
3185 {
3187 continue;
3188
3190 continue;
3191
3192
3193 if (
uint32 state = e.target.unitDistance.livingState)
3194 {
3195 if (unit->ToCreature()->IsAlive() && state == 2)
3196 continue;
3197 if (!unit->ToCreature()->IsAlive() && state == 1)
3198 continue;
3199 }
3200
3201 if ((e.target.unitDistance.creature && unit->ToCreature()->GetEntry() == e.target.unitDistance.creature) || !e.target.unitDistance.creature)
3202 targets.push_back(unit);
3203 }
3204
3205 break;
3206 }
3208 {
3211
3213 {
3215 continue;
3216
3218 continue;
3219
3220 if ((e.target.goDistance.entry && unit->ToGameObject()->GetEntry() == e.target.goDistance.entry) || !e.target.goDistance.entry)
3221 targets.push_back(unit);
3222 }
3223
3224 break;
3225 }
3227 {
3228
3230 if (!ref)
3231 ref = scriptTrigger;
3232
3233 if (!ref)
3234 {
3235 LOG_ERROR(
"scripts.ai.sai",
"SMART_TARGET_GAMEOBJECT_RANGE: Entry: {} SourceType {} Event {} Action {} Target {} is missing base object or invoker.",
3236 e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.GetTargetType());
3237 break;
3238 }
3239
3242
3244 {
3246 continue;
3247
3249 continue;
3250
3251 if (((e.target.goRange.entry &&
IsGameObject(unit) && unit->ToGameObject()->GetEntry() == e.target.goRange.entry) || !e.target.goRange.entry) && ref->
IsInRange((unit), (
float)e.target.goRange.minDist, (
float)e.target.goRange.maxDist))
3252 targets.push_back(unit);
3253 }
3254
3255 break;
3256 }
3258 {
3259 if (!scriptTrigger && !baseObject)
3260 {
3261 LOG_ERROR(
"scripts.ai.sai",
"SMART_TARGET_CREATURE_GUID: Entry {} SourceType {} Event {} Action {} Target {} is missing base object or invoker.",
3262 e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.GetTargetType());
3263 break;
3264 }
3265
3267 if (target && (!e.target.unitGUID.entry || target->
GetEntry() == e.target.unitGUID.entry))
3268 targets.push_back(target);
3269 break;
3270 }
3272 {
3274 {
3275 LOG_ERROR(
"scripts.ai.sai",
"SMART_TARGET_GAMEOBJECT_GUID: Entry {} SourceType {} Event {} Action {} Target {} is missing base object or invoker.",
3276 e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.GetTargetType());
3277 break;
3278 }
3279
3281 if (target && (!e.target.goGUID.entry || target->
GetEntry() == e.target.goGUID.entry))
3282 targets.push_back(target);
3283 break;
3284 }
3286 {
3289
3290 if (!units.empty() && baseObject)
3292 if (
IsPlayer(unit) && baseObject->
IsInRange(unit,
float(e.target.playerRange.minDist),
float(e.target.playerRange.maxDist)))
3293 targets.push_back(unit);
3294 break;
3295 }
3297 {
3300
3303 targets.push_back(unit);
3304 break;
3305 }
3307 {
3309 if (!ref)
3310 ref = scriptTrigger;
3311
3312 if (!ref)
3313 {
3314 LOG_ERROR(
"scripts.ai.sai",
"SMART_TARGET_STORED: Entry {} SourceType {} Event {} Action {} Target {} is missing base object or invoker.",
3315 e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.GetTargetType());
3316 break;
3317 }
3318
3320 targets.assign(stored->begin(), stored->end());
3321 break;
3322 }
3324 {
3326
3327 if (!ref)
3328 ref = scriptTrigger;
3329
3330 if (!ref)
3331 {
3332 LOG_ERROR(
"scripts.ai.sai",
"SMART_TARGET_CLOSEST_CREATURE: Entry {} SourceType {} Event {} Action {} Target {} is missing base object or invoker.",
3333 e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.GetTargetType());
3334 break;
3335 }
3336
3337 Creature* target =
GetClosestCreatureWithEntry(ref, e.target.unitClosest.entry, (
float)(e.target.unitClosest.dist ? e.target.unitClosest.dist : 100), !e.target.unitClosest.dead);
3338 if (target)
3339 targets.push_back(target);
3340 break;
3341 }
3343 {
3345
3346 if (!ref)
3347 ref = scriptTrigger;
3348
3349 if (!ref)
3350 {
3351 LOG_ERROR(
"scripts.ai.sai",
"SMART_TARGET_CLOSEST_GAMEOBJECT: Entry {} SourceType {} Event {} Action {} Target {} is missing base object or invoker.",
3352 e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.GetTargetType());
3353 break;
3354 }
3355
3357 if (target)
3358 targets.push_back(target);
3359 break;
3360 }
3362 {
3364
3365 if (!ref)
3366 ref = scriptTrigger;
3367
3368 if (!ref)
3369 {
3370 LOG_ERROR(
"scripts.ai.sai",
"SMART_TARGET_CLOSEST_PLAYER: Entry {} SourceType {} Event {} Action {} Target {} is missing base object or invoker.",
3371 e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.GetTargetType());
3372 break;
3373 }
3374
3376 targets.push_back(target);
3377 break;
3378 }
3380
3381
3382
3383
3384
3385 {
3387 {
3389 {
3390 targets.push_back(owner);
3391 }
3393 {
3395 }
3396 }
3398 {
3400 {
3401 targets.push_back(owner);
3402 }
3403 }
3404
3405
3406 if (e.target.owner.useCharmerOrOwner && !targets.empty())
3407 {
3409 {
3410 targets.clear();
3411
3412 if (owner->ToCreature())
3413 {
3415 {
3416 targets.push_back(base);
3417 }
3418 }
3419 else
3420 {
3422 {
3423 targets.push_back(base);
3424 }
3425 }
3426 }
3427 }
3428 break;
3429 }
3431 {
3433 {
3435 for (ThreatContainer::StorageType::const_iterator i = threatList.begin(); i != threatList.end(); ++i)
3437
3438 if (e.target.threatList.maxDist == 0 ||
me->
IsWithinCombatRange(temp, (
float)e.target.threatList.maxDist))
3439 targets.push_back(temp);
3440 }
3441 break;
3442 }
3444 {
3447 targets.push_back(target);
3448
3449 break;
3450 }
3452 {
3455 targets.push_back(target);
3456
3457 break;
3458 }
3460 {
3463
3465 if (
IsPlayer(unit) && unit->ToPlayer()->IsAlive() && !unit->ToPlayer()->IsGameMaster())
3466 if (
GetBaseObject()->IsInRange(unit, (
float)e.target.playerWithAura.distMin, (
float)e.target.playerWithAura.distMax))
3467 if (bool(e.target.playerWithAura.negation) != unit->ToPlayer()->HasAura(e.target.playerWithAura.spellId))
3468 targets.push_back(unit);
3469
3470 if (e.target.o > 0)
3472
3473 break;
3474 }
3476 {
3479
3480 uint32 roleMask = e.target.roleSelection.roleMask;
3483 if (targetPlayer->IsAlive() && !targetPlayer->IsGameMaster())
3484 {
3486 {
3487 if (targetPlayer->HasTankSpec())
3488 {
3489 targets.push_back(unit);
3490 continue;
3491 }
3492 }
3494 {
3495 if (targetPlayer->HasHealSpec())
3496 {
3497 targets.push_back(unit);
3498 continue;
3499 }
3500 }
3502 {
3503 if (targetPlayer->HasCasterSpec() || targetPlayer->HasMeleeSpec())
3504 {
3505 targets.push_back(unit);
3506 continue;
3507 }
3508 }
3509 }
3510
3511 if (e.target.roleSelection.resize > 0)
3513
3514 break;
3515 }
3517 {
3519 {
3521 {
3522 targets.push_back(target);
3523 }
3524 }
3525 break;
3526 }
3528 {
3530 {
3532 {
3533 for (
GroupReference* it = lootGroup->GetFirstMember(); it !=
nullptr; it = it->
next())
3534 {
3535 if (
Player* recipient = it->GetSource())
3536 {
3537 targets.push_back(recipient);
3538 }
3539 }
3540 }
3541 else
3542 {
3544 {
3545 targets.push_back(recipient);
3546 }
3547 }
3548 }
3549 break;
3550 }
3552 {
3554 {
3556 {
3557 if (!e.target.summonedCreatures.entry || guid.GetEntry() == e.target.summonedCreatures.entry)
3558 {
3560 {
3561 targets.push_back(creature);
3562 }
3563 }
3564 }
3565 }
3566 break;
3567 }
3569 {
3571 {
3572 if (e.target.instanceStorage.type == 1)
3573 {
3574 if (
Creature* creature = instance->GetCreature(e.target.instanceStorage.index))
3575 {
3576 targets.push_back(creature);
3577 }
3578 }
3579 else if (e.target.instanceStorage.type == 2)
3580 {
3581 if (
GameObject*
go = instance->GetGameObject(e.target.instanceStorage.index))
3582 {
3583 targets.push_back(
go);
3584 }
3585 }
3586 }
3587 else
3588 {
3589 LOG_ERROR(
"scripts.ai.sai",
"SMART_TARGET_INSTANCE_STORAGE: Entry {} SourceType {} Event {} Action {} Target {} called outside an instance map.",
3590 e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.GetTargetType());
3591 }
3592
3593 break;
3594 }
3597 default:
3598 break;
3599 }
3600}
std::uint32_t uint32
Definition: Define.h:108
#define LOG_ERROR(filterType__,...)
Definition: Log.h:159
Creature * GetClosestCreatureWithEntry(WorldObject *source, uint32 entry, float maxSearchRange, bool alive)
Definition: ScriptedCreature.cpp:773
GameObject * GetClosestGameObjectWithEntry(WorldObject *source, uint32 entry, float maxSearchRange, bool onlySpawned)
Definition: ScriptedCreature.cpp:778
@ SMART_TARGET_ROLE_FLAG_HEALERS
Definition: SmartScriptMgr.h:1699
@ SMART_TARGET_ROLE_FLAG_TANKS
Definition: SmartScriptMgr.h:1698
@ SMART_TARGET_ROLE_FLAG_DAMAGERS
Definition: SmartScriptMgr.h:1700
@ SMART_TARGET_LOOT_RECIPIENTS
Definition: SmartScriptMgr.h:1503
@ SMART_TARGET_CLOSEST_CREATURE
Definition: SmartScriptMgr.h:1495
@ SMART_TARGET_CREATURE_DISTANCE
Definition: SmartScriptMgr.h:1487
@ SMART_TARGET_HOSTILE_RANDOM_NOT_TOP
Definition: SmartScriptMgr.h:1482
@ SMART_TARGET_INVOKER_PARTY
Definition: SmartScriptMgr.h:1492
@ SMART_TARGET_CLOSEST_FRIENDLY
Definition: SmartScriptMgr.h:1502
@ SMART_TARGET_CLOSEST_GAMEOBJECT
Definition: SmartScriptMgr.h:1496
@ SMART_TARGET_VEHICLE_PASSENGER
Definition: SmartScriptMgr.h:1505
@ SMART_TARGET_GAMEOBJECT_RANGE
Definition: SmartScriptMgr.h:1489
@ SMART_TARGET_CREATURE_GUID
Definition: SmartScriptMgr.h:1486
@ SMART_TARGET_PLAYER_RANGE
Definition: SmartScriptMgr.h:1493
@ SMART_TARGET_SUMMONED_CREATURES
Definition: SmartScriptMgr.h:1516
@ SMART_TARGET_VICTIM
Definition: SmartScriptMgr.h:1478
@ SMART_TARGET_GAMEOBJECT_DISTANCE
Definition: SmartScriptMgr.h:1491
@ SMART_TARGET_CREATURE_RANGE
Definition: SmartScriptMgr.h:1485
@ SMART_TARGET_CLOSEST_PLAYER
Definition: SmartScriptMgr.h:1497
@ SMART_TARGET_HOSTILE_RANDOM
Definition: SmartScriptMgr.h:1481
@ SMART_TARGET_GAMEOBJECT_GUID
Definition: SmartScriptMgr.h:1490
@ SMART_TARGET_HOSTILE_SECOND_AGGRO
Definition: SmartScriptMgr.h:1479
@ SMART_TARGET_OWNER_OR_SUMMONER
Definition: SmartScriptMgr.h:1499
@ SMART_TARGET_SELF
Definition: SmartScriptMgr.h:1477
@ SMART_TARGET_PLAYER_WITH_AURA
Definition: SmartScriptMgr.h:1513
@ SMART_TARGET_ROLE_SELECTION
Definition: SmartScriptMgr.h:1515
@ SMART_TARGET_ACTION_INVOKER
Definition: SmartScriptMgr.h:1483
@ SMART_TARGET_POSITION
Definition: SmartScriptMgr.h:1484
@ SMART_TARGET_HOSTILE_LAST_AGGRO
Definition: SmartScriptMgr.h:1480
@ SMART_TARGET_ACTION_INVOKER_VEHICLE
Definition: SmartScriptMgr.h:1498
@ SMART_TARGET_INSTANCE_STORAGE
Definition: SmartScriptMgr.h:1517
@ SMART_TARGET_FARTHEST
Definition: SmartScriptMgr.h:1504
@ SMART_TARGET_THREAT_LIST
Definition: SmartScriptMgr.h:1500
@ SMART_TARGET_CLOSEST_ENEMY
Definition: SmartScriptMgr.h:1501
@ SMART_TARGET_NONE
Definition: SmartScriptMgr.h:1476
@ SMART_TARGET_PLAYER_DISTANCE
Definition: SmartScriptMgr.h:1494
@ SMART_TARGET_STORED
Definition: SmartScriptMgr.h:1488
std::vector< WorldObject * > ObjectVector
Definition: SmartScriptMgr.h:1916
Powers
Definition: SharedDefines.h:240
void RandomResize(C &container, std::size_t requestedSize)
Definition: Containers.h:81
WorldObject * GetWorldObject(WorldObject const &, ObjectGuid const guid)
Definition: ObjectAccessor.cpp:120
Unit * SelectTarget(SelectTargetMethod targetType, uint32 position=0, float dist=0.0f, bool playerOnly=false, bool withTank=true, int32 aura=0)
Definition: UnitAI.cpp:111
static bool IsPlayer(WorldObject *obj)
Definition: SmartScript.cpp:4905
Unit * GetLastInvoker(Unit *invoker=nullptr) const
Definition: SmartScript.cpp:4889
static bool IsCreature(WorldObject *obj)
Definition: SmartScript.cpp:4910
void GetWorldObjectsInDist(ObjectVector &objects, float dist) const
Definition: SmartScript.cpp:3602
Creature * FindCreatureNear(WorldObject *searchObject, ObjectGuid::LowType guid) const
Definition: SmartScript.h:166
static bool IsGameObject(WorldObject *obj)
Definition: SmartScript.cpp:4926
ObjectVector const * GetStoredTargetVector(uint32 id, WorldObject const &ref) const
Definition: SmartScript.h:115
Unit * DoFindClosestFriendlyInRange(float range, bool playerOnly) const
Definition: SmartScript.cpp:4842
GameObject * FindGameObjectNear(WorldObject *searchObject, ObjectGuid::LowType guid) const
Definition: SmartScript.h:157
std::list< HostileReference * > StorageType
Definition: ThreatMgr.h:148
ThreatContainer::StorageType const & GetThreatList() const
Definition: ThreatMgr.h:274
Definition: Creature.h:46
Player * GetLootRecipient() const
Definition: Creature.cpp:1278
Group * GetLootRecipientGroup() const
Definition: Creature.cpp:1285
Unit * SelectNearestTarget(float dist=0, bool playerOnly=false) const
Definition: Creature.cpp:2314
CreatureAI * AI() const
Definition: Creature.h:135
Unit * GetSummonerUnit() const
Definition: TemporarySummon.cpp:45
Definition: GameObject.h:122
ObjectGuid GetOwnerGUID() const
Definition: GameObject.h:175
Player * ToPlayer()
Definition: Object.h:195
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:106
Player * SelectNearestPlayer(float distance=0) const
Definition: Object.cpp:2461
bool IsInRange(WorldObject const *obj, float minRange, float maxRange, bool is3D=true) const
Definition: Object.cpp:1404
Definition: ObjectGuid.h:120
Definition: Player.h:1056
bool IsVehicle() const
Definition: Unit.h:1428
Vehicle * GetVehicle() const
Definition: Unit.h:2366
bool IsWithinCombatRange(Unit const *obj, float dist2compare) const
Definition: Unit.cpp:667
TempSummon * ToTempSummon()
Definition: Unit.h:2412
bool IsSummon() const
Definition: Unit.h:1422
Unit * GetVictim() const
Definition: Unit.h:1398
ThreatMgr & GetThreatMgr()
Definition: Unit.h:2157
Vehicle * GetVehicleKit() const
Definition: Unit.h:2365
ObjectGuid GetCharmerOrOwnerGUID() const
Definition: Unit.h:1842
Unit * GetBase() const
May be called from scripts.
Definition: Vehicle.h:39
Unit * GetPassenger(int8 seatId) const
Definition: Vehicle.cpp:226
Definition: GroupReference.h:27
GroupReference * next()
Definition: GroupReference.h:36
Definition: InstanceScript.h:140
Creature * GetCreature(ObjectGuid const guid)
Definition: Map.cpp:3304