fix(Core/SmartScripts): Implemented new target type: SMART_TARGET_SUM… (#13880)

* fix(Core/SmartScripts): Implemented new target type: SMART_TARGET_SUMMONED_CREATURES.

Fixes #13787

* Update.

* Update.
This commit is contained in:
UltraNix
2022-12-06 13:41:05 +01:00
committed by GitHub
parent ac65434f3f
commit 95652e14d5
6 changed files with 56 additions and 1 deletions

View File

@@ -810,6 +810,7 @@ void SmartAI::KilledUnit(Unit* victim)
void SmartAI::JustSummoned(Creature* creature)
{
GetScript()->ProcessEventsFor(SMART_EVENT_SUMMONED_UNIT, creature);
GetScript()->AddCreatureSummon(creature->GetGUID());
}
void SmartAI::SummonedCreatureDies(Creature* summon, Unit* /*killer*/)
@@ -890,6 +891,7 @@ void SmartAI::DamageDealt(Unit* doneTo, uint32& damage, DamageEffectType /*damag
void SmartAI::SummonedCreatureDespawn(Creature* unit)
{
GetScript()->ProcessEventsFor(SMART_EVENT_SUMMON_DESPAWNED, unit);
GetScript()->RemoveCreatureSummon(unit->GetGUID());
}
void SmartAI::CorpseRemoved(uint32& respawnDelay)

View File

@@ -3334,6 +3334,24 @@ void SmartScript::GetTargets(ObjectVector& targets, SmartScriptHolder const& e,
}
}
}
break;
}
case SMART_TARGET_SUMMONED_CREATURES:
{
if (me)
{
for (ObjectGuid const& guid : _summonList)
{
if (!e.target.summonedCreatures.entry || guid.GetEntry() == e.target.summonedCreatures.entry)
{
if (Creature* creature = me->GetMap()->GetCreature(guid))
{
targets.push_back(creature);
}
}
}
}
break;
}
case SMART_TARGET_NONE:
case SMART_TARGET_POSITION:
@@ -4560,3 +4578,13 @@ bool SmartScript::IsInPhase(uint32 p) const
return ((1 << (mEventPhase - 1)) & p) != 0;
}
void SmartScript::AddCreatureSummon(ObjectGuid const& guid)
{
_summonList.insert(guid);
}
void SmartScript::RemoveCreatureSummon(ObjectGuid const& guid)
{
_summonList.erase(guid);
}

View File

@@ -232,6 +232,9 @@ public:
bool AllowPhaseReset() const { return _allowPhaseReset; }
void SetPhaseReset(bool allow) { _allowPhaseReset = allow; }
void AddCreatureSummon(ObjectGuid const& guid);
void RemoveCreatureSummon(ObjectGuid const& guid);
private:
void IncPhase(uint32 p);
void DecPhase(uint32 p);
@@ -306,6 +309,8 @@ private:
SmartScriptHolder s;
return s;
}
GuidUnorderedSet _summonList;
};
#endif

View File

@@ -413,6 +413,14 @@ bool SmartAIMgr::IsTargetValid(SmartScriptHolder const& e)
return false;
}
break;
case SMART_TARGET_SUMMONED_CREATURES:
{
if (e.target.summonedCreatures.entry && !IsCreatureValid(e, e.target.summonedCreatures.entry))
{
return false;
}
break;
}
case SMART_TARGET_HOSTILE_SECOND_AGGRO:
case SMART_TARGET_HOSTILE_LAST_AGGRO:
case SMART_TARGET_HOSTILE_RANDOM:

View File

@@ -1407,8 +1407,9 @@ enum SMARTAI_TARGETS
SMART_TARGET_PLAYER_WITH_AURA = 201, // spellId, negation, MaxDist, MinDist, set target.o to a number to random resize the list
SMART_TARGET_RANDOM_POINT = 202, // range, amount (for summoning creature), self als middle (0/1) else use xyz
SMART_TARGET_ROLE_SELECTION = 203, // Range Max, TargetMask (Tanks (1), Healer (2) Damage (4)), resize list
SMART_TARGET_SUMMONED_CREATURES = 204, // Entry
SMART_TARGET_AC_END = 204 // placeholder
SMART_TARGET_AC_END = 205 // placeholder
};
struct SmartTarget
@@ -1564,6 +1565,11 @@ struct SmartTarget
uint32 distMin;
} playerWithAura;
struct
{
uint32 entry;
} summonedCreatures;
struct
{
uint32 param1;