mirror of
https://github.com/liyunfan1223/azerothcore-wotlk.git
synced 2026-08-08 15:58:04 +00:00
feat(Core/AI): Move TaskScheduler to BossAI class (#14757)
This commit is contained in:
@@ -561,6 +561,7 @@ void BossAI::_Reset()
|
|||||||
|
|
||||||
me->ResetLootMode();
|
me->ResetLootMode();
|
||||||
events.Reset();
|
events.Reset();
|
||||||
|
scheduler.CancelAll();
|
||||||
summons.DespawnAll();
|
summons.DespawnAll();
|
||||||
if (instance)
|
if (instance)
|
||||||
instance->SetBossState(_bossId, NOT_STARTED);
|
instance->SetBossState(_bossId, NOT_STARTED);
|
||||||
@@ -569,6 +570,7 @@ void BossAI::_Reset()
|
|||||||
void BossAI::_JustDied()
|
void BossAI::_JustDied()
|
||||||
{
|
{
|
||||||
events.Reset();
|
events.Reset();
|
||||||
|
scheduler.CancelAll();
|
||||||
summons.DespawnAll();
|
summons.DespawnAll();
|
||||||
if (instance)
|
if (instance)
|
||||||
{
|
{
|
||||||
@@ -581,6 +583,7 @@ void BossAI::_EnterCombat()
|
|||||||
{
|
{
|
||||||
me->setActive(true);
|
me->setActive(true);
|
||||||
DoZoneInCombat();
|
DoZoneInCombat();
|
||||||
|
ScheduleTasks();
|
||||||
if (instance)
|
if (instance)
|
||||||
{
|
{
|
||||||
// bosses do not respawn, check only on enter combat
|
// bosses do not respawn, check only on enter combat
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include "CreatureAIImpl.h"
|
#include "CreatureAIImpl.h"
|
||||||
#include "InstanceScript.h"
|
#include "InstanceScript.h"
|
||||||
#include "EventMap.h"
|
#include "EventMap.h"
|
||||||
|
#include "TaskScheduler.h"
|
||||||
|
|
||||||
#define CAST_AI(a, b) (dynamic_cast<a*>(b))
|
#define CAST_AI(a, b) (dynamic_cast<a*>(b))
|
||||||
|
|
||||||
@@ -449,6 +450,8 @@ public:
|
|||||||
// is supposed to run more than once
|
// is supposed to run more than once
|
||||||
virtual void ExecuteEvent(uint32 /*eventId*/) { }
|
virtual void ExecuteEvent(uint32 /*eventId*/) { }
|
||||||
|
|
||||||
|
virtual void ScheduleTasks() { }
|
||||||
|
|
||||||
void Reset() override { _Reset(); }
|
void Reset() override { _Reset(); }
|
||||||
void EnterCombat(Unit* /*who*/) override { _EnterCombat(); }
|
void EnterCombat(Unit* /*who*/) override { _EnterCombat(); }
|
||||||
void JustDied(Unit* /*killer*/) override { _JustDied(); }
|
void JustDied(Unit* /*killer*/) override { _JustDied(); }
|
||||||
@@ -464,6 +467,7 @@ protected:
|
|||||||
|
|
||||||
EventMap events;
|
EventMap events;
|
||||||
SummonList summons;
|
SummonList summons;
|
||||||
|
TaskScheduler scheduler;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32 const _bossId;
|
uint32 const _bossId;
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
#include "ScriptedCreature.h"
|
#include "ScriptedCreature.h"
|
||||||
#include "SpellScript.h"
|
#include "SpellScript.h"
|
||||||
#include "ruins_of_ahnqiraj.h"
|
#include "ruins_of_ahnqiraj.h"
|
||||||
#include "TaskScheduler.h"
|
|
||||||
|
|
||||||
enum Spells
|
enum Spells
|
||||||
{
|
{
|
||||||
@@ -88,7 +87,7 @@ struct boss_ayamiss : public BossAI
|
|||||||
_phase = PHASE_AIR;
|
_phase = PHASE_AIR;
|
||||||
_enraged = false;
|
_enraged = false;
|
||||||
SetCombatMovement(false);
|
SetCombatMovement(false);
|
||||||
_scheduler.CancelAll();
|
scheduler.CancelAll();
|
||||||
me->SetReactState(REACT_AGGRESSIVE);
|
me->SetReactState(REACT_AGGRESSIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,7 +128,7 @@ struct boss_ayamiss : public BossAI
|
|||||||
|
|
||||||
}, 1s);
|
}, 1s);
|
||||||
|
|
||||||
_scheduler.Schedule(5s, 8s, [this](TaskContext context) {
|
scheduler.Schedule(5s, 8s, [this](TaskContext context) {
|
||||||
DoCastVictim(SPELL_LASH);
|
DoCastVictim(SPELL_LASH);
|
||||||
context.Repeat(8s, 15s);
|
context.Repeat(8s, 15s);
|
||||||
}).Schedule(16s, [this](TaskContext context)
|
}).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);
|
DoCastSelf(SPELL_STINGER_SPRAY);
|
||||||
context.Repeat(15s, 20s);
|
context.Repeat(15s, 20s);
|
||||||
@@ -222,7 +221,7 @@ struct boss_ayamiss : public BossAI
|
|||||||
me->SetDisableGravity(false);
|
me->SetDisableGravity(false);
|
||||||
me->GetMotionMaster()->MovePath(me->GetEntry() * 10, false);
|
me->GetMotionMaster()->MovePath(me->GetEntry() * 10, false);
|
||||||
DoResetThreatList();
|
DoResetThreatList();
|
||||||
_scheduler.CancelGroup(PHASE_AIR);
|
scheduler.CancelGroup(PHASE_AIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_enraged && me->HealthBelowPctDamaged(20, damage))
|
if (!_enraged && me->HealthBelowPctDamaged(20, damage))
|
||||||
@@ -238,14 +237,13 @@ struct boss_ayamiss : public BossAI
|
|||||||
if (!UpdateVictim())
|
if (!UpdateVictim())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_scheduler.Update(diff,
|
scheduler.Update(diff,
|
||||||
std::bind(&BossAI::DoMeleeAttackIfReady, this));
|
std::bind(&BossAI::DoMeleeAttackIfReady, this));
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
GuidList _swarmers;
|
GuidList _swarmers;
|
||||||
uint8 _phase;
|
uint8 _phase;
|
||||||
bool _enraged;
|
bool _enraged;
|
||||||
TaskScheduler _scheduler;
|
|
||||||
Position homePos;
|
Position homePos;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ EndScriptData */
|
|||||||
#include "ScriptMgr.h"
|
#include "ScriptMgr.h"
|
||||||
#include "ScriptedCreature.h"
|
#include "ScriptedCreature.h"
|
||||||
#include "SpellScript.h"
|
#include "SpellScript.h"
|
||||||
#include "TaskScheduler.h"
|
|
||||||
#include "temple_of_ahnqiraj.h"
|
#include "temple_of_ahnqiraj.h"
|
||||||
|
|
||||||
enum Spells
|
enum Spells
|
||||||
@@ -172,7 +171,7 @@ struct boss_eye_of_cthun : public BossAI
|
|||||||
if (pPortal)
|
if (pPortal)
|
||||||
pPortal->SetReactState(REACT_PASSIVE);
|
pPortal->SetReactState(REACT_PASSIVE);
|
||||||
|
|
||||||
_scheduler.CancelAll();
|
scheduler.CancelAll();
|
||||||
|
|
||||||
BossAI::Reset();
|
BossAI::Reset();
|
||||||
}
|
}
|
||||||
@@ -187,7 +186,7 @@ struct boss_eye_of_cthun : public BossAI
|
|||||||
|
|
||||||
void EnterCombat(Unit* who) override
|
void EnterCombat(Unit* who) override
|
||||||
{
|
{
|
||||||
ScheduleTasks(true);
|
ScheduleTask(true);
|
||||||
BossAI::EnterCombat(who);
|
BossAI::EnterCombat(who);
|
||||||
_beamTarget = who->GetGUID();
|
_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)
|
Schedule(3s, [this, onEngage](TaskContext task)
|
||||||
{
|
{
|
||||||
if (task.GetRepeatCounter() < 3 && onEngage)
|
if (task.GetRepeatCounter() < 3 && onEngage)
|
||||||
@@ -244,7 +243,7 @@ struct boss_eye_of_cthun : public BossAI
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_scheduler.Schedule(5s, [this](TaskContext task)
|
scheduler.Schedule(5s, [this](TaskContext task)
|
||||||
{
|
{
|
||||||
DoCastRandomTarget(SPELL_GREEN_BEAM);
|
DoCastRandomTarget(SPELL_GREEN_BEAM);
|
||||||
|
|
||||||
@@ -276,7 +275,7 @@ struct boss_eye_of_cthun : public BossAI
|
|||||||
})
|
})
|
||||||
.Schedule(46s, [this](TaskContext /*task*/)
|
.Schedule(46s, [this](TaskContext /*task*/)
|
||||||
{
|
{
|
||||||
_scheduler.CancelGroup(GROUP_BEAM_PHASE);
|
scheduler.CancelGroup(GROUP_BEAM_PHASE);
|
||||||
|
|
||||||
me->StopMoving();
|
me->StopMoving();
|
||||||
me->SetReactState(REACT_PASSIVE);
|
me->SetReactState(REACT_PASSIVE);
|
||||||
@@ -286,7 +285,7 @@ struct boss_eye_of_cthun : public BossAI
|
|||||||
//Freeze animation
|
//Freeze animation
|
||||||
DoCast(me, SPELL_FREEZE_ANIM, true);
|
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
|
//Select random target for dark beam to start on
|
||||||
if (Unit* target = SelectTarget(SelectTargetMethod::Random, 0, 0.0f, true))
|
if (Unit* target = SelectTarget(SelectTargetMethod::Random, 0, 0.0f, true))
|
||||||
@@ -304,7 +303,7 @@ struct boss_eye_of_cthun : public BossAI
|
|||||||
me->SetOrientation(DarkGlareAngle);
|
me->SetOrientation(DarkGlareAngle);
|
||||||
}
|
}
|
||||||
|
|
||||||
_scheduler.Schedule(3s, [this](TaskContext tasker)
|
scheduler.Schedule(3s, [this](TaskContext tasker)
|
||||||
{
|
{
|
||||||
me->SetTarget(ObjectGuid::Empty);
|
me->SetTarget(ObjectGuid::Empty);
|
||||||
me->StopMoving();
|
me->StopMoving();
|
||||||
@@ -319,7 +318,7 @@ struct boss_eye_of_cthun : public BossAI
|
|||||||
|
|
||||||
if (tasker.GetRepeatCounter() >= 35)
|
if (tasker.GetRepeatCounter() >= 35)
|
||||||
{
|
{
|
||||||
_scheduler.CancelAll();
|
scheduler.CancelAll();
|
||||||
me->SetReactState(REACT_AGGRESSIVE);
|
me->SetReactState(REACT_AGGRESSIVE);
|
||||||
me->RemoveAurasDueToSpell(SPELL_RED_COLORATION);
|
me->RemoveAurasDueToSpell(SPELL_RED_COLORATION);
|
||||||
me->RemoveAurasDueToSpell(SPELL_FREEZE_ANIM);
|
me->RemoveAurasDueToSpell(SPELL_FREEZE_ANIM);
|
||||||
@@ -339,7 +338,7 @@ struct boss_eye_of_cthun : public BossAI
|
|||||||
if (!UpdateVictim())
|
if (!UpdateVictim())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_scheduler.Update(diff);
|
scheduler.Update(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DamageTaken(Unit*, uint32& damage, DamageEffectType, SpellSchoolMask) override
|
void DamageTaken(Unit*, uint32& damage, DamageEffectType, SpellSchoolMask) override
|
||||||
@@ -365,7 +364,7 @@ struct boss_eye_of_cthun : public BossAI
|
|||||||
|
|
||||||
me->InterruptNonMeleeSpells(true);
|
me->InterruptNonMeleeSpells(true);
|
||||||
me->RemoveAllAuras();
|
me->RemoveAllAuras();
|
||||||
_scheduler.CancelAll();
|
scheduler.CancelAll();
|
||||||
|
|
||||||
me->m_Events.AddEventAtOffset([this]()
|
me->m_Events.AddEventAtOffset([this]()
|
||||||
{
|
{
|
||||||
@@ -384,7 +383,6 @@ private:
|
|||||||
|
|
||||||
uint32 _eyeTentacleCounter;
|
uint32 _eyeTentacleCounter;
|
||||||
ObjectGuid _beamTarget;
|
ObjectGuid _beamTarget;
|
||||||
TaskScheduler _scheduler;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct boss_cthun : public BossAI
|
struct boss_cthun : public BossAI
|
||||||
@@ -406,7 +404,7 @@ struct boss_cthun : public BossAI
|
|||||||
me->SetUnitFlag(UNIT_FLAG_NOT_SELECTABLE | UNIT_FLAG_NON_ATTACKABLE);
|
me->SetUnitFlag(UNIT_FLAG_NOT_SELECTABLE | UNIT_FLAG_NON_ATTACKABLE);
|
||||||
|
|
||||||
BossAI::Reset();
|
BossAI::Reset();
|
||||||
_scheduler.CancelAll();
|
scheduler.CancelAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnterCombat(Unit* /*who*/) override
|
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()))
|
if (Unit* target = SelectTarget(SelectTargetMethod::Random, 0, NotInStomachSelector()))
|
||||||
{
|
{
|
||||||
@@ -530,7 +528,7 @@ struct boss_cthun : public BossAI
|
|||||||
|
|
||||||
me->SetTarget();
|
me->SetTarget();
|
||||||
|
|
||||||
_scheduler.Update(diff);
|
scheduler.Update(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JustDied(Unit* killer) override
|
void JustDied(Unit* killer) override
|
||||||
@@ -560,7 +558,7 @@ struct boss_cthun : public BossAI
|
|||||||
|
|
||||||
if (_fleshTentaclesKilled > 1)
|
if (_fleshTentaclesKilled > 1)
|
||||||
{
|
{
|
||||||
_scheduler.CancelAll();
|
scheduler.CancelAll();
|
||||||
|
|
||||||
_fleshTentaclesKilled = 0;
|
_fleshTentaclesKilled = 0;
|
||||||
|
|
||||||
@@ -569,7 +567,7 @@ struct boss_cthun : public BossAI
|
|||||||
DoCast(me, SPELL_PURPLE_COLORATION, true);
|
DoCast(me, SPELL_PURPLE_COLORATION, true);
|
||||||
me->RemoveAurasDueToSpell(SPELL_CARAPACE_CTHUN);
|
me->RemoveAurasDueToSpell(SPELL_CARAPACE_CTHUN);
|
||||||
|
|
||||||
_scheduler.Schedule(45s, [this](TaskContext /*context*/)
|
scheduler.Schedule(45s, [this](TaskContext /*context*/)
|
||||||
{
|
{
|
||||||
ScheduleTasks();
|
ScheduleTasks();
|
||||||
//Remove purple coloration
|
//Remove purple coloration
|
||||||
@@ -591,7 +589,6 @@ struct boss_cthun : public BossAI
|
|||||||
|
|
||||||
//Body Phase
|
//Body Phase
|
||||||
uint8 _fleshTentaclesKilled;
|
uint8 _fleshTentaclesKilled;
|
||||||
TaskScheduler _scheduler;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct npc_eye_tentacle : public ScriptedAI
|
struct npc_eye_tentacle : public ScriptedAI
|
||||||
|
|||||||
Reference in New Issue
Block a user