Core/AI: 06443e3 followup

This commit is contained in:
ccrs
2019-10-22 13:36:23 +02:00
parent fe7c2c3772
commit bb9af06cd4
2 changed files with 39 additions and 24 deletions

View File

@@ -243,6 +243,41 @@ float ScriptedAI::GetThreat(Unit const* victim, Unit const* who)
return who->GetThreatManager().GetThreat(victim);
}
void ScriptedAI::ForceCombatStop(Creature* who, bool reset /*= true*/)
{
if (!who || !who->IsInCombat())
return;
who->CombatStop(true);
who->DoNotReacquireSpellFocusTarget();
who->GetMotionMaster()->Clear(MOTION_PRIORITY_NORMAL);
if (reset) {
who->LoadCreaturesAddon();
who->SetLootRecipient(nullptr);
who->ResetPlayerDamageReq();
who->SetLastDamagedTime(0);
who->SetCannotReachTarget(false);
}
}
void ScriptedAI::ForceCombatStopForCreatureEntry(uint32 entry, float maxSearchRange /*= 250.0f*/, bool samePhase /*= true*/, bool reset /*= true*/)
{
TC_LOG_DEBUG("scripts.ai", "ScriptedAI::ForceCombatStopForCreatureEntry: called on '%s'. Debug info: %s", me->GetGUID().ToString().c_str(), me->GetDebugInfo().c_str());
std::list<Creature*> creatures;
Trinity::AllCreaturesOfEntryInRange check(me, entry, maxSearchRange);
Trinity::CreatureListSearcher<Trinity::AllCreaturesOfEntryInRange> searcher(me, creatures, check);
if (!samePhase)
searcher.i_phaseMask = PHASEMASK_ANYWHERE;
Cell::VisitGridObjects(me, searcher, maxSearchRange);
for (Creature* creature : creatures)
ForceCombatStop(creature, reset);
}
Creature* ScriptedAI::DoSpawnCreature(uint32 entry, float offsetX, float offsetY, float offsetZ, float angle, uint32 type, uint32 despawntime)
{
return me->SummonCreature(entry, me->GetPositionX() + offsetX, me->GetPositionY() + offsetY, me->GetPositionZ() + offsetZ, angle, TempSummonType(type), despawntime);
@@ -517,28 +552,6 @@ void BossAI::TeleportCheaters()
}
}
void BossAI::ForceCombatStopForCreatureEntry(uint32 entry, float maxSearchRange /*= 250.0f*/, bool reset /*= true*/)
{
TC_LOG_DEBUG("scripts.ai", "BossAI::ForceCombatStopForCreatureEntry: called on '%s'. Debug info: %s", me->GetGUID().ToString().c_str(), me->GetDebugInfo().c_str());
std::list<Creature*> creatures;
me->GetCreatureListWithEntryInGrid(creatures, entry, maxSearchRange);
for (Creature* creature : creatures) {
creature->CombatStop(true);
creature->DoNotReacquireSpellFocusTarget();
creature->GetMotionMaster()->Clear(MOTION_PRIORITY_NORMAL);
if (reset) {
creature->LoadCreaturesAddon();
creature->SetLootRecipient(nullptr);
creature->ResetPlayerDamageReq();
creature->SetLastDamagedTime(0);
creature->SetCannotReachTarget(false);
}
}
}
void BossAI::JustSummoned(Creature* summon)
{
summons.Summon(summon);

View File

@@ -186,6 +186,10 @@ struct TC_GAME_API ScriptedAI : public CreatureAI
void ResetThreatList(Unit* who = nullptr);
// Returns the threat level of victim towards who (or me if not specified)
float GetThreat(Unit const* victim, Unit const* who = nullptr);
// Stops combat, ignoring restrictions, for the given creature
void ForceCombatStop(Creature* who, bool reset = true);
// Stops combat, ignoring restrictions, for the found creatures
void ForceCombatStopForCreatureEntry(uint32 entry, float maxSearchRange = 250.0f, bool samePhase = true, bool reset = true);
void DoTeleportTo(float x, float y, float z, uint32 time = 0);
void DoTeleportTo(float const pos[4]);
@@ -337,8 +341,6 @@ class TC_GAME_API BossAI : public ScriptedAI
void TeleportCheaters();
void ForceCombatStopForCreatureEntry(uint32 entry, float maxSearchRange = 250.0f, bool reset = true);
EventMap events;
SummonList summons;
TaskScheduler scheduler;