From aeed96f3b77145450197c74ba634db43a262d032 Mon Sep 17 00:00:00 2001 From: Skjalf <47818697+Nyeriah@users.noreply.github.com> Date: Thu, 26 Jan 2023 13:46:30 -0300 Subject: [PATCH] feat(Core/AI): Move TaskScheduler to BossAI class (#14757) --- .../game/AI/ScriptedAI/ScriptedCreature.cpp | 3 ++ .../game/AI/ScriptedAI/ScriptedCreature.h | 4 ++ .../Kalimdor/RuinsOfAhnQiraj/boss_ayamiss.cpp | 14 +++---- .../Kalimdor/TempleOfAhnQiraj/boss_cthun.cpp | 37 +++++++++---------- 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp index 0d29775e0..67df38905 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp @@ -561,6 +561,7 @@ void BossAI::_Reset() me->ResetLootMode(); events.Reset(); + scheduler.CancelAll(); summons.DespawnAll(); if (instance) instance->SetBossState(_bossId, NOT_STARTED); @@ -569,6 +570,7 @@ void BossAI::_Reset() void BossAI::_JustDied() { events.Reset(); + scheduler.CancelAll(); summons.DespawnAll(); if (instance) { @@ -581,6 +583,7 @@ void BossAI::_EnterCombat() { me->setActive(true); DoZoneInCombat(); + ScheduleTasks(); if (instance) { // bosses do not respawn, check only on enter combat diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.h b/src/server/game/AI/ScriptedAI/ScriptedCreature.h index a96834d8c..3040ede20 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.h +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.h @@ -23,6 +23,7 @@ #include "CreatureAIImpl.h" #include "InstanceScript.h" #include "EventMap.h" +#include "TaskScheduler.h" #define CAST_AI(a, b) (dynamic_cast(b)) @@ -449,6 +450,8 @@ public: // is supposed to run more than once virtual void ExecuteEvent(uint32 /*eventId*/) { } + virtual void ScheduleTasks() { } + void Reset() override { _Reset(); } void EnterCombat(Unit* /*who*/) override { _EnterCombat(); } void JustDied(Unit* /*killer*/) override { _JustDied(); } @@ -464,6 +467,7 @@ protected: EventMap events; SummonList summons; + TaskScheduler scheduler; private: uint32 const _bossId; diff --git a/src/server/scripts/Kalimdor/RuinsOfAhnQiraj/boss_ayamiss.cpp b/src/server/scripts/Kalimdor/RuinsOfAhnQiraj/boss_ayamiss.cpp index 9d4bd1367..d05c1b1e0 100644 --- a/src/server/scripts/Kalimdor/RuinsOfAhnQiraj/boss_ayamiss.cpp +++ b/src/server/scripts/Kalimdor/RuinsOfAhnQiraj/boss_ayamiss.cpp @@ -20,7 +20,6 @@ #include "ScriptedCreature.h" #include "SpellScript.h" #include "ruins_of_ahnqiraj.h" -#include "TaskScheduler.h" enum Spells { @@ -88,7 +87,7 @@ struct boss_ayamiss : public BossAI _phase = PHASE_AIR; _enraged = false; SetCombatMovement(false); - _scheduler.CancelAll(); + scheduler.CancelAll(); me->SetReactState(REACT_AGGRESSIVE); } @@ -129,7 +128,7 @@ struct boss_ayamiss : public BossAI }, 1s); - _scheduler.Schedule(5s, 8s, [this](TaskContext context) { + scheduler.Schedule(5s, 8s, [this](TaskContext context) { DoCastVictim(SPELL_LASH); context.Repeat(8s, 15s); }).Schedule(16s, [this](TaskContext context) @@ -140,9 +139,9 @@ struct boss_ayamiss : public BossAI } } - void ScheduleTasks() + void ScheduleTasks() override { - _scheduler.Schedule(20s, 30s, [this](TaskContext context) + scheduler.Schedule(20s, 30s, [this](TaskContext context) { DoCastSelf(SPELL_STINGER_SPRAY); context.Repeat(15s, 20s); @@ -222,7 +221,7 @@ struct boss_ayamiss : public BossAI me->SetDisableGravity(false); me->GetMotionMaster()->MovePath(me->GetEntry() * 10, false); DoResetThreatList(); - _scheduler.CancelGroup(PHASE_AIR); + scheduler.CancelGroup(PHASE_AIR); } if (!_enraged && me->HealthBelowPctDamaged(20, damage)) @@ -238,14 +237,13 @@ struct boss_ayamiss : public BossAI if (!UpdateVictim()) return; - _scheduler.Update(diff, + scheduler.Update(diff, std::bind(&BossAI::DoMeleeAttackIfReady, this)); } private: GuidList _swarmers; uint8 _phase; bool _enraged; - TaskScheduler _scheduler; Position homePos; }; diff --git a/src/server/scripts/Kalimdor/TempleOfAhnQiraj/boss_cthun.cpp b/src/server/scripts/Kalimdor/TempleOfAhnQiraj/boss_cthun.cpp index 01ac35f6d..b1d7bff71 100644 --- a/src/server/scripts/Kalimdor/TempleOfAhnQiraj/boss_cthun.cpp +++ b/src/server/scripts/Kalimdor/TempleOfAhnQiraj/boss_cthun.cpp @@ -26,7 +26,6 @@ EndScriptData */ #include "ScriptMgr.h" #include "ScriptedCreature.h" #include "SpellScript.h" -#include "TaskScheduler.h" #include "temple_of_ahnqiraj.h" enum Spells @@ -172,7 +171,7 @@ struct boss_eye_of_cthun : public BossAI if (pPortal) pPortal->SetReactState(REACT_PASSIVE); - _scheduler.CancelAll(); + scheduler.CancelAll(); BossAI::Reset(); } @@ -187,7 +186,7 @@ struct boss_eye_of_cthun : public BossAI void EnterCombat(Unit* who) override { - ScheduleTasks(true); + ScheduleTask(true); BossAI::EnterCombat(who); _beamTarget = who->GetGUID(); } @@ -228,9 +227,9 @@ struct boss_eye_of_cthun : public BossAI } } - void ScheduleTasks(bool onEngage = false) + void ScheduleTask(bool onEngage = false) { - _scheduler. + scheduler. Schedule(3s, [this, onEngage](TaskContext task) { if (task.GetRepeatCounter() < 3 && onEngage) @@ -244,7 +243,7 @@ struct boss_eye_of_cthun : public BossAI } else { - _scheduler.Schedule(5s, [this](TaskContext task) + scheduler.Schedule(5s, [this](TaskContext task) { DoCastRandomTarget(SPELL_GREEN_BEAM); @@ -276,7 +275,7 @@ struct boss_eye_of_cthun : public BossAI }) .Schedule(46s, [this](TaskContext /*task*/) { - _scheduler.CancelGroup(GROUP_BEAM_PHASE); + scheduler.CancelGroup(GROUP_BEAM_PHASE); me->StopMoving(); me->SetReactState(REACT_PASSIVE); @@ -286,7 +285,7 @@ struct boss_eye_of_cthun : public BossAI //Freeze animation DoCast(me, SPELL_FREEZE_ANIM, true); - _scheduler.Schedule(1s, [this](TaskContext /*task*/) + scheduler.Schedule(1s, [this](TaskContext /*task*/) { //Select random target for dark beam to start on if (Unit* target = SelectTarget(SelectTargetMethod::Random, 0, 0.0f, true)) @@ -304,7 +303,7 @@ struct boss_eye_of_cthun : public BossAI me->SetOrientation(DarkGlareAngle); } - _scheduler.Schedule(3s, [this](TaskContext tasker) + scheduler.Schedule(3s, [this](TaskContext tasker) { me->SetTarget(ObjectGuid::Empty); me->StopMoving(); @@ -319,7 +318,7 @@ struct boss_eye_of_cthun : public BossAI if (tasker.GetRepeatCounter() >= 35) { - _scheduler.CancelAll(); + scheduler.CancelAll(); me->SetReactState(REACT_AGGRESSIVE); me->RemoveAurasDueToSpell(SPELL_RED_COLORATION); me->RemoveAurasDueToSpell(SPELL_FREEZE_ANIM); @@ -339,7 +338,7 @@ struct boss_eye_of_cthun : public BossAI if (!UpdateVictim()) return; - _scheduler.Update(diff); + scheduler.Update(diff); } void DamageTaken(Unit*, uint32& damage, DamageEffectType, SpellSchoolMask) override @@ -365,7 +364,7 @@ struct boss_eye_of_cthun : public BossAI me->InterruptNonMeleeSpells(true); me->RemoveAllAuras(); - _scheduler.CancelAll(); + scheduler.CancelAll(); me->m_Events.AddEventAtOffset([this]() { @@ -384,7 +383,6 @@ private: uint32 _eyeTentacleCounter; ObjectGuid _beamTarget; - TaskScheduler _scheduler; }; struct boss_cthun : public BossAI @@ -406,7 +404,7 @@ struct boss_cthun : public BossAI me->SetUnitFlag(UNIT_FLAG_NOT_SELECTABLE | UNIT_FLAG_NON_ATTACKABLE); BossAI::Reset(); - _scheduler.CancelAll(); + scheduler.CancelAll(); } void EnterCombat(Unit* /*who*/) override @@ -439,9 +437,9 @@ struct boss_cthun : public BossAI } } - void ScheduleTasks() + void ScheduleTasks() override { - _scheduler.Schedule(13800ms, [this](TaskContext context) + scheduler.Schedule(13800ms, [this](TaskContext context) { if (Unit* target = SelectTarget(SelectTargetMethod::Random, 0, NotInStomachSelector())) { @@ -530,7 +528,7 @@ struct boss_cthun : public BossAI me->SetTarget(); - _scheduler.Update(diff); + scheduler.Update(diff); } void JustDied(Unit* killer) override @@ -560,7 +558,7 @@ struct boss_cthun : public BossAI if (_fleshTentaclesKilled > 1) { - _scheduler.CancelAll(); + scheduler.CancelAll(); _fleshTentaclesKilled = 0; @@ -569,7 +567,7 @@ struct boss_cthun : public BossAI DoCast(me, SPELL_PURPLE_COLORATION, true); me->RemoveAurasDueToSpell(SPELL_CARAPACE_CTHUN); - _scheduler.Schedule(45s, [this](TaskContext /*context*/) + scheduler.Schedule(45s, [this](TaskContext /*context*/) { ScheduleTasks(); //Remove purple coloration @@ -591,7 +589,6 @@ struct boss_cthun : public BossAI //Body Phase uint8 _fleshTentaclesKilled; - TaskScheduler _scheduler; }; struct npc_eye_tentacle : public ScriptedAI