refactor(Scripts/TempleOfAhnQiraj): Clean up script files (#17718)

* refactor(Scripts/TempleOfAhnQiraj): Clean up script files

* Update src/server/scripts/Kalimdor/TempleOfAhnQiraj/boss_fankriss.cpp

Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com>

* Update src/server/scripts/Kalimdor/TempleOfAhnQiraj/boss_ouro.cpp

Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com>

---------

Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com>
This commit is contained in:
Andrew
2023-11-15 14:17:29 -03:00
committed by GitHub
parent 590c2d7ea1
commit 03612e8bff
7 changed files with 131 additions and 238 deletions

View File

@@ -19,7 +19,6 @@
#include "ScriptedCreature.h" #include "ScriptedCreature.h"
#include "SpellScript.h" #include "SpellScript.h"
#include "temple_of_ahnqiraj.h" #include "temple_of_ahnqiraj.h"
#include "TaskScheduler.h"
enum Spells enum Spells
{ {

View File

@@ -168,8 +168,6 @@ struct boss_eye_of_cthun : public BossAI
if (pPortal) if (pPortal)
pPortal->SetReactState(REACT_PASSIVE); pPortal->SetReactState(REACT_PASSIVE);
scheduler.CancelAll();
BossAI::Reset(); BossAI::Reset();
} }
@@ -330,15 +328,6 @@ struct boss_eye_of_cthun : public BossAI
}); });
} }
void UpdateAI(uint32 diff) override
{
//Check if we have a target
if (!UpdateVictim())
return;
scheduler.Update(diff);
}
void DamageTaken(Unit*, uint32& damage, DamageEffectType, SpellSchoolMask) override void DamageTaken(Unit*, uint32& damage, DamageEffectType, SpellSchoolMask) override
{ {
//Only if it will kill //Only if it will kill
@@ -402,7 +391,6 @@ 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();
} }
void JustEngagedWith(Unit* /*who*/) override void JustEngagedWith(Unit* /*who*/) override
@@ -622,7 +610,7 @@ struct npc_eye_tentacle : public ScriptedAI
void Reset() override void Reset() override
{ {
DoZoneInCombat(); DoZoneInCombat();
_scheduler.Schedule(500ms, [this](TaskContext /*task*/) scheduler.Schedule(500ms, [this](TaskContext /*task*/)
{ {
DoCastAOE(SPELL_GROUND_RUPTURE); DoCastAOE(SPELL_GROUND_RUPTURE);
}) })
@@ -634,7 +622,7 @@ struct npc_eye_tentacle : public ScriptedAI
void JustEngagedWith(Unit* /*who*/) override void JustEngagedWith(Unit* /*who*/) override
{ {
_scheduler.Schedule(1s, 5s, [this](TaskContext context) scheduler.Schedule(1s, 5s, [this](TaskContext context)
{ {
if (Unit* target = SelectTarget(SelectTargetMethod::Random, 0, NotInStomachSelector())) if (Unit* target = SelectTarget(SelectTargetMethod::Random, 0, NotInStomachSelector()))
{ {
@@ -651,11 +639,10 @@ struct npc_eye_tentacle : public ScriptedAI
if (!UpdateVictim()) if (!UpdateVictim())
return; return;
_scheduler.Update(diff); scheduler.Update(diff);
} }
private: private:
TaskScheduler _scheduler;
ObjectGuid _portalGUID; ObjectGuid _portalGUID;
}; };
@@ -693,24 +680,24 @@ struct npc_claw_tentacle : public ScriptedAI
void Reset() override void Reset() override
{ {
_scheduler.Schedule(Milliseconds(500), [this](TaskContext /*task*/) scheduler.Schedule(Milliseconds(500), [this](TaskContext /*task*/)
{ {
DoCastAOE(SPELL_GROUND_RUPTURE); DoCastAOE(SPELL_GROUND_RUPTURE);
}).Schedule(Minutes(5), [this](TaskContext /*task*/) }).Schedule(Minutes(5), [this](TaskContext /*task*/)
{ {
me->DespawnOrUnsummon(); me->DespawnOrUnsummon();
}); });
} }
void JustEngagedWith(Unit* /*who*/) override void JustEngagedWith(Unit* /*who*/) override
{ {
DoZoneInCombat(); DoZoneInCombat();
_scheduler.Schedule(2s, [this](TaskContext context) scheduler.Schedule(2s, [this](TaskContext context)
{ {
DoCastVictim(SPELL_HAMSTRING); DoCastVictim(SPELL_HAMSTRING);
context.Repeat(5s); context.Repeat(5s);
}); });
} }
void UpdateAI(uint32 diff) override void UpdateAI(uint32 diff) override
@@ -719,13 +706,12 @@ struct npc_claw_tentacle : public ScriptedAI
if (!UpdateVictim()) if (!UpdateVictim())
return; return;
_scheduler.Update(diff); scheduler.Update(diff);
DoMeleeAttackIfReady(); DoMeleeAttackIfReady();
} }
private: private:
TaskScheduler _scheduler;
ObjectGuid _portalGUID; ObjectGuid _portalGUID;
}; };
@@ -765,10 +751,10 @@ struct npc_giant_claw_tentacle : public ScriptedAI
void Reset() override void Reset() override
{ {
_scheduler.Schedule(500ms, [this](TaskContext /*task*/) scheduler.Schedule(500ms, [this](TaskContext /*task*/)
{ {
DoCastAOE(SPELL_MASSIVE_GROUND_RUPTURE); DoCastAOE(SPELL_MASSIVE_GROUND_RUPTURE);
}); });
} }
void JustEngagedWith(Unit* /*who*/) override void JustEngagedWith(Unit* /*who*/) override
@@ -780,7 +766,7 @@ struct npc_giant_claw_tentacle : public ScriptedAI
void ScheduleTasks() void ScheduleTasks()
{ {
// Check if a target is in melee range // Check if a target is in melee range
_scheduler.Schedule(10s, [this](TaskContext task) scheduler.Schedule(10s, [this](TaskContext task)
{ {
if (Unit* target = me->GetVictim()) if (Unit* target = me->GetVictim())
{ {
@@ -830,13 +816,13 @@ struct npc_giant_claw_tentacle : public ScriptedAI
me->SetHealth(me->GetMaxHealth()); me->SetHealth(me->GetMaxHealth());
me->SetUnitFlag(UNIT_FLAG_NOT_SELECTABLE | UNIT_FLAG_NON_ATTACKABLE); me->SetUnitFlag(UNIT_FLAG_NOT_SELECTABLE | UNIT_FLAG_NON_ATTACKABLE);
_scheduler.CancelAll(); scheduler.CancelAll();
_canAttack = false; _canAttack = false;
_scheduler.Schedule(5s, [this](TaskContext /*task*/) scheduler.Schedule(5s, [this](TaskContext /*task*/)
{ {
Emerge(); Emerge();
}); });
} }
void Emerge() void Emerge()
@@ -866,7 +852,7 @@ struct npc_giant_claw_tentacle : public ScriptedAI
if (!UpdateVictim()) if (!UpdateVictim())
return; return;
_scheduler.Update(diff); scheduler.Update(diff);
if (_canAttack) if (_canAttack)
{ {
@@ -875,7 +861,6 @@ struct npc_giant_claw_tentacle : public ScriptedAI
} }
private: private:
TaskScheduler _scheduler;
ObjectGuid _portalGUID; ObjectGuid _portalGUID;
bool _canAttack; bool _canAttack;
}; };
@@ -914,18 +899,18 @@ struct npc_giant_eye_tentacle : public ScriptedAI
void Reset() override void Reset() override
{ {
_scheduler.Schedule(500ms, [this](TaskContext /*task*/) scheduler.Schedule(500ms, [this](TaskContext /*task*/)
{
DoCastAOE(SPELL_MASSIVE_GROUND_RUPTURE);
}).Schedule(1s, 5s, [this](TaskContext context)
{
if (Unit* target = SelectTarget(SelectTargetMethod::Random, 0, NotInStomachSelector()))
{ {
DoCastAOE(SPELL_MASSIVE_GROUND_RUPTURE); DoCast(target, SPELL_GREEN_BEAM);
}).Schedule(1s, 5s, [this](TaskContext context) }
{
if (Unit* target = SelectTarget(SelectTargetMethod::Random, 0, NotInStomachSelector()))
{
DoCast(target, SPELL_GREEN_BEAM);
}
context.Repeat(2100ms); context.Repeat(2100ms);
}); });
} }
void JustEngagedWith(Unit* /*who*/) override void JustEngagedWith(Unit* /*who*/) override
@@ -939,11 +924,10 @@ struct npc_giant_eye_tentacle : public ScriptedAI
if (!UpdateVictim()) if (!UpdateVictim())
return; return;
_scheduler.Update(diff); scheduler.Update(diff);
} }
private: private:
TaskScheduler _scheduler;
ObjectGuid _portalGUID; ObjectGuid _portalGUID;
}; };

View File

@@ -17,7 +17,6 @@
#include "ScriptMgr.h" #include "ScriptMgr.h"
#include "ScriptedCreature.h" #include "ScriptedCreature.h"
#include "TaskScheduler.h"
#include "temple_of_ahnqiraj.h" #include "temple_of_ahnqiraj.h"
enum Spells enum Spells
@@ -58,9 +57,7 @@ struct boss_fankriss : public BossAI
void Reset() override void Reset() override
{ {
_scheduler.CancelAll();
summonWormSpells = { SPELL_SUMMON_WORM_1, SPELL_SUMMON_WORM_2, SPELL_SUMMON_WORM_3}; summonWormSpells = { SPELL_SUMMON_WORM_1, SPELL_SUMMON_WORM_2, SPELL_SUMMON_WORM_3};
BossAI::Reset(); BossAI::Reset();
} }
@@ -87,11 +84,9 @@ struct boss_fankriss : public BossAI
void JustEngagedWith(Unit* who) override void JustEngagedWith(Unit* who) override
{ {
_scheduler.CancelAll();
BossAI::JustEngagedWith(who); BossAI::JustEngagedWith(who);
_scheduler scheduler.Schedule(7s, 14s, [this](TaskContext context)
.Schedule(7s, 14s, [this](TaskContext context)
{ {
DoCastVictim(SPELL_MORTAL_WOUND); DoCastVictim(SPELL_MORTAL_WOUND);
context.Repeat(); context.Repeat();
@@ -114,18 +109,7 @@ struct boss_fankriss : public BossAI
}); });
} }
void UpdateAI(uint32 diff) override
{
//Return since we have no target
if (!UpdateVictim())
return;
_scheduler.Update(diff,
std::bind(&ScriptedAI::DoMeleeAttackIfReady, this));
}
private: private:
TaskScheduler _scheduler;
std::vector<uint32> summonWormSpells; std::vector<uint32> summonWormSpells;
}; };

View File

@@ -22,7 +22,6 @@
#include "Player.h" #include "Player.h"
#include "ScriptMgr.h" #include "ScriptMgr.h"
#include "ScriptedCreature.h" #include "ScriptedCreature.h"
#include "TaskScheduler.h"
#include "temple_of_ahnqiraj.h" #include "temple_of_ahnqiraj.h"
enum Spells enum Spells
@@ -109,7 +108,6 @@ struct boss_ouro : public BossAI
{ {
SetCombatMovement(false); SetCombatMovement(false);
me->SetControlled(true, UNIT_STATE_ROOT); me->SetControlled(true, UNIT_STATE_ROOT);
_scheduler.SetValidator([this] { return !me->HasUnitState(UNIT_STATE_CASTING); });
} }
bool CanAIAttack(Unit const* victim) const override bool CanAIAttack(Unit const* victim) const override
@@ -123,8 +121,8 @@ struct boss_ouro : public BossAI
{ {
DoCastSelf(SPELL_BERSERK, true); DoCastSelf(SPELL_BERSERK, true);
_enraged = true; _enraged = true;
_scheduler.CancelGroup(GROUP_PHASE_TRANSITION); scheduler.CancelGroup(GROUP_PHASE_TRANSITION);
_scheduler.Schedule(1s, [this](TaskContext context) scheduler.Schedule(1s, [this](TaskContext context)
{ {
if (!IsPlayerWithinMeleeRange()) if (!IsPlayerWithinMeleeRange())
DoSpellAttackToRandomTargetIfReady(SPELL_BOULDER); DoSpellAttackToRandomTargetIfReady(SPELL_BOULDER);
@@ -150,8 +148,8 @@ struct boss_ouro : public BossAI
_submergeMelee = 0; _submergeMelee = 0;
_submerged = true; _submerged = true;
DoCastSelf(SPELL_OURO_SUBMERGE_VISUAL); DoCastSelf(SPELL_OURO_SUBMERGE_VISUAL);
_scheduler.CancelGroup(GROUP_EMERGED); scheduler.CancelGroup(GROUP_EMERGED);
_scheduler.CancelGroup(GROUP_PHASE_TRANSITION); scheduler.CancelGroup(GROUP_PHASE_TRANSITION);
if (GameObject* base = me->FindNearestGameObject(GO_SANDWORM_BASE, 10.f)) if (GameObject* base = me->FindNearestGameObject(GO_SANDWORM_BASE, 10.f))
{ {
@@ -206,8 +204,7 @@ struct boss_ouro : public BossAI
DoCastSelf(SPELL_SUMMON_SANDWORM_BASE, true); DoCastSelf(SPELL_SUMMON_SANDWORM_BASE, true);
me->SetReactState(REACT_AGGRESSIVE); me->SetReactState(REACT_AGGRESSIVE);
CastGroundRupture(); CastGroundRupture();
_scheduler scheduler.Schedule(20s, GROUP_EMERGED, [this](TaskContext context)
.Schedule(20s, GROUP_EMERGED, [this](TaskContext context)
{ {
if (Unit* target = SelectTarget(SelectTargetMethod::MaxThreat, 0, 0.0f, true)) if (Unit* target = SelectTarget(SelectTargetMethod::MaxThreat, 0, 0.0f, true))
{ {
@@ -265,7 +262,7 @@ struct boss_ouro : public BossAI
void Reset() override void Reset() override
{ {
instance->SetBossState(DATA_OURO, NOT_STARTED); instance->SetBossState(DATA_OURO, NOT_STARTED);
_scheduler.CancelAll(); scheduler.CancelAll();
_submergeMelee = 0; _submergeMelee = 0;
_submerged = false; _submerged = false;
_enraged = false; _enraged = false;
@@ -286,7 +283,6 @@ struct boss_ouro : public BossAI
void JustEngagedWith(Unit* who) override void JustEngagedWith(Unit* who) override
{ {
Emerge(); Emerge();
BossAI::JustEngagedWith(who); BossAI::JustEngagedWith(who);
} }
@@ -294,14 +290,11 @@ struct boss_ouro : public BossAI
{ {
UpdateVictim(); UpdateVictim();
_scheduler.Update(diff, [this] scheduler.Update(diff,
{ std::bind(&ScriptedAI::DoMeleeAttackIfReady, this));
DoMeleeAttackIfReady();
});
} }
protected: protected:
TaskScheduler _scheduler;
bool _enraged; bool _enraged;
uint8 _submergeMelee; uint8 _submergeMelee;
bool _submerged; bool _submerged;
@@ -338,16 +331,16 @@ struct npc_dirt_mound : ScriptedAI
void JustEngagedWith(Unit* /*who*/) override void JustEngagedWith(Unit* /*who*/) override
{ {
DoZoneInCombat(); DoZoneInCombat();
_scheduler.Schedule(30s, [this](TaskContext /*context*/) scheduler.Schedule(30s, [this](TaskContext /*context*/)
{ {
DoCastSelf(SPELL_SUMMON_SCARABS, true); DoCastSelf(SPELL_SUMMON_SCARABS, true);
me->DespawnOrUnsummon(1000); me->DespawnOrUnsummon(1000);
}) })
.Schedule(100ms, [this](TaskContext context) .Schedule(100ms, [this](TaskContext context)
{ {
ChaseNewTarget(); ChaseNewTarget();
context.Repeat(5s, 10s); context.Repeat(5s, 10s);
}); });
} }
void ChaseNewTarget() void ChaseNewTarget()
@@ -365,7 +358,7 @@ struct npc_dirt_mound : ScriptedAI
if (!UpdateVictim()) if (!UpdateVictim())
return; return;
_scheduler.Update(diff); scheduler.Update(diff);
} }
void Reset() override void Reset() override
@@ -389,7 +382,6 @@ struct npc_dirt_mound : ScriptedAI
} }
protected: protected:
TaskScheduler _scheduler;
uint32 _ouroHealth; uint32 _ouroHealth;
InstanceScript* _instance; InstanceScript* _instance;
}; };

View File

@@ -19,7 +19,6 @@
#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
@@ -88,11 +87,6 @@ struct boss_twinemperorsAI : public BossAI
boss_twinemperorsAI(Creature* creature): BossAI(creature, DATA_TWIN_EMPERORS), _introDone(false) boss_twinemperorsAI(Creature* creature): BossAI(creature, DATA_TWIN_EMPERORS), _introDone(false)
{ {
me->SetStandState(UNIT_STAND_STATE_KNEEL); me->SetStandState(UNIT_STAND_STATE_KNEEL);
_scheduler.SetValidator([this]
{
return !me->HasUnitState(UNIT_STATE_CASTING);
});
} }
Creature* GetTwin() Creature* GetTwin()
@@ -132,8 +126,6 @@ struct boss_twinemperorsAI : public BossAI
if (Creature* twin = GetTwin()) if (Creature* twin = GetTwin())
if (!twin->IsInEvadeMode()) if (!twin->IsInEvadeMode())
twin->AI()->EnterEvadeMode(why); twin->AI()->EnterEvadeMode(why);
_scheduler.CancelAll();
} }
void JustDied(Unit* killer) override void JustDied(Unit* killer) override
@@ -152,7 +144,7 @@ struct boss_twinemperorsAI : public BossAI
if (action == ACTION_CANCEL_INTRO) if (action == ACTION_CANCEL_INTRO)
{ {
_introDone = true; _introDone = true;
_scheduler.CancelGroup(GROUP_INTRO); scheduler.CancelGroup(GROUP_INTRO);
return; return;
} }
@@ -161,32 +153,31 @@ struct boss_twinemperorsAI : public BossAI
DoResetThreatList(); DoResetThreatList();
me->SetReactState(REACT_PASSIVE); me->SetReactState(REACT_PASSIVE);
DoCastSelf(SPELL_TWIN_TELEPORT_VISUAL, true); DoCastSelf(SPELL_TWIN_TELEPORT_VISUAL, true);
_scheduler.DelayAll(2300ms); scheduler.DelayAll(2300ms);
_scheduler.Schedule(2s, [this](TaskContext /*context*/) scheduler.Schedule(2s, [this](TaskContext /*context*/)
{
me->SetReactState(REACT_AGGRESSIVE);
me->SetControlled(false, UNIT_STATE_ROOT);
if (Unit* victim = me->SelectNearestTarget())
{ {
me->SetReactState(REACT_AGGRESSIVE); me->AddThreat(victim, 2000.f);
me->SetControlled(false, UNIT_STATE_ROOT); AttackStart(victim);
if (Unit* victim = me->SelectNearestTarget()) }
{ });
me->AddThreat(victim, 2000.f);
AttackStart(victim);
}
});
} }
if (action != ACTION_START_INTRO) if (action != ACTION_START_INTRO)
return; return;
_scheduler.Schedule(5s, [this](TaskContext /*context*/) scheduler.Schedule(5s, [this](TaskContext /*context*/)
{ {
me->SetStandState(UNIT_STAND_STATE_STAND); me->SetStandState(UNIT_STAND_STATE_STAND);
me->LoadEquipment(1, true); me->LoadEquipment(1, true);
}); });
if (IAmVeklor()) if (IAmVeklor())
{ {
_scheduler scheduler.Schedule(12s, GROUP_INTRO, [this](TaskContext /*context*/)
.Schedule(12s, GROUP_INTRO, [this](TaskContext /*context*/)
{ {
Talk(SAY_INTRO_0); Talk(SAY_INTRO_0);
}) })
@@ -211,8 +202,7 @@ struct boss_twinemperorsAI : public BossAI
} }
else else
{ {
_scheduler scheduler.Schedule(17s, GROUP_INTRO, [this](TaskContext /*context*/)
.Schedule(17s, GROUP_INTRO, [this](TaskContext /*context*/)
{ {
Talk(SAY_INTRO_0); Talk(SAY_INTRO_0);
}) })
@@ -252,8 +242,7 @@ struct boss_twinemperorsAI : public BossAI
if (!twin->IsInCombat()) if (!twin->IsInCombat())
twin->AI()->AttackStart(who); twin->AI()->AttackStart(who);
_scheduler scheduler.Schedule(15min, [this](TaskContext /*context*/)
.Schedule(15min, [this](TaskContext /*context*/)
{ {
if (IAmVeklor()) if (IAmVeklor())
{ {
@@ -280,17 +269,16 @@ struct boss_twinemperorsAI : public BossAI
if (!UpdateVictim() && _introDone) if (!UpdateVictim() && _introDone)
return; return;
_scheduler.Update(diff, [this] scheduler.Update(diff, [this]
{ {
if (!IAmVeklor()) if (!IAmVeklor())
DoMeleeAttackIfReady(); DoMeleeAttackIfReady();
}); });
} }
virtual bool IAmVeklor() = 0; virtual bool IAmVeklor() = 0;
protected: protected:
TaskScheduler _scheduler;
bool _introDone; bool _introDone;
}; };
@@ -306,8 +294,7 @@ struct boss_veknilash : public boss_twinemperorsAI
DoPlaySoundToSet(me, SOUND_VN_AGGRO); DoPlaySoundToSet(me, SOUND_VN_AGGRO);
_scheduler scheduler.Schedule(14s, [this](TaskContext context)
.Schedule(14s, [this](TaskContext context)
{ {
DoCastRandomTarget(SPELL_UPPERCUT, 0, me->GetMeleeReach(), true); DoCastRandomTarget(SPELL_UPPERCUT, 0, me->GetMeleeReach(), true);
context.Repeat(4s, 15s); context.Repeat(4s, 15s);
@@ -337,8 +324,7 @@ struct boss_veklor : public boss_twinemperorsAI
DoPlaySoundToSet(me, SOUND_VK_AGGRO); DoPlaySoundToSet(me, SOUND_VK_AGGRO);
_scheduler scheduler.Schedule(4s, [this](TaskContext context)
.Schedule(4s, [this](TaskContext context)
{ {
if (me->GetVictim()) if (me->GetVictim())
{ {

View File

@@ -19,7 +19,6 @@
#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
@@ -118,9 +117,7 @@ struct boss_viscidus : public BossAI
void Reset() override void Reset() override
{ {
BossAI::Reset(); BossAI::Reset();
events.Reset();
SoftReset(); SoftReset();
_scheduler.CancelAll();
me->RemoveAurasDueToSpell(SPELL_VISCIDUS_SHRINKS); me->RemoveAurasDueToSpell(SPELL_VISCIDUS_SHRINKS);
} }
@@ -133,17 +130,6 @@ struct boss_viscidus : public BossAI
me->RemoveAurasDueToSpell(SPELL_INVIS_SELF); me->RemoveAurasDueToSpell(SPELL_INVIS_SELF);
} }
void JustDied(Unit* /*killer*/) override
{
events.Reset();
summons.DespawnAll(10 * IN_MILLISECONDS);
if (instance)
{
instance->SetBossState(DATA_VISCIDUS, DONE);
instance->SaveToDB();
}
}
void DamageTaken(Unit* attacker, uint32& damage, DamageEffectType effType, SpellSchoolMask spellSchoolMask) override void DamageTaken(Unit* attacker, uint32& damage, DamageEffectType effType, SpellSchoolMask spellSchoolMask) override
{ {
if (me->HealthBelowPct(5)) if (me->HealthBelowPct(5))
@@ -184,8 +170,7 @@ struct boss_viscidus : public BossAI
me->AttackStop(); me->AttackStop();
me->CastStop(); me->CastStop();
me->HandleEmoteCommand(EMOTE_ONESHOT_FLYDEATH); // not found in sniff, this is the best one I found me->HandleEmoteCommand(EMOTE_ONESHOT_FLYDEATH); // not found in sniff, this is the best one I found
_scheduler scheduler.Schedule(2500ms, [this](TaskContext /*context*/)
.Schedule(2500ms, [this](TaskContext /*context*/)
{ {
DoCastSelf(SPELL_EXPLODE_TRIGGER, true); DoCastSelf(SPELL_EXPLODE_TRIGGER, true);
}) })
@@ -295,7 +280,7 @@ struct boss_viscidus : public BossAI
return; return;
events.Update(diff); events.Update(diff);
_scheduler.Update(diff); scheduler.Update(diff);
while (uint32 eventId = events.ExecuteEvent()) while (uint32 eventId = events.ExecuteEvent())
{ {
@@ -330,7 +315,6 @@ struct boss_viscidus : public BossAI
private: private:
uint8 _hitcounter; uint8 _hitcounter;
uint8 _phase; uint8 _phase;
TaskScheduler _scheduler;
}; };
struct boss_glob_of_viscidus : public ScriptedAI struct boss_glob_of_viscidus : public ScriptedAI
@@ -343,8 +327,8 @@ struct boss_glob_of_viscidus : public ScriptedAI
void InitializeAI() override void InitializeAI() override
{ {
me->SetInCombatWithZone(); me->SetInCombatWithZone();
_scheduler.CancelAll(); scheduler.CancelAll();
_scheduler.Schedule(2400ms, [this](TaskContext context) scheduler.Schedule(2400ms, [this](TaskContext context)
{ {
me->GetMotionMaster()->MovePoint(ROOM_CENTER, roomCenter); me->GetMotionMaster()->MovePoint(ROOM_CENTER, roomCenter);
float topSpeed = me->GetSpeedRate(MOVE_RUN) + 0.2142855f * 4; float topSpeed = me->GetSpeedRate(MOVE_RUN) + 0.2142855f * 4;
@@ -368,11 +352,8 @@ struct boss_glob_of_viscidus : public ScriptedAI
void UpdateAI(uint32 diff) override void UpdateAI(uint32 diff) override
{ {
_scheduler.Update(diff); scheduler.Update(diff);
} }
protected:
TaskScheduler _scheduler;
}; };
struct npc_toxic_slime : public ScriptedAI struct npc_toxic_slime : public ScriptedAI

View File

@@ -21,7 +21,6 @@
#include "ScriptedCreature.h" #include "ScriptedCreature.h"
#include "SpellScript.h" #include "SpellScript.h"
#include "temple_of_ahnqiraj.h" #include "temple_of_ahnqiraj.h"
#include "TaskScheduler.h"
enum Spells enum Spells
{ {
@@ -72,13 +71,11 @@ enum Spells
struct npc_anubisath_defender : public ScriptedAI struct npc_anubisath_defender : public ScriptedAI
{ {
npc_anubisath_defender(Creature* creature) : ScriptedAI(creature) npc_anubisath_defender(Creature* creature) : ScriptedAI(creature) { }
{
}
void Reset() override void Reset() override
{ {
_scheduler.CancelAll(); scheduler.CancelAll();
_enraged = false; _enraged = false;
} }
@@ -88,7 +85,7 @@ struct npc_anubisath_defender : public ScriptedAI
if (urand(0, 1)) if (urand(0, 1))
{ {
_scheduler.Schedule(6s, 10s, [this](TaskContext context) scheduler.Schedule(6s, 10s, [this](TaskContext context)
{ {
if (Unit* target = SelectTarget(SelectTargetMethod::MaxThreat, 1)) if (Unit* target = SelectTarget(SelectTargetMethod::MaxThreat, 1))
DoCast(target, SPELL_METEOR, true); DoCast(target, SPELL_METEOR, true);
@@ -97,7 +94,7 @@ struct npc_anubisath_defender : public ScriptedAI
} }
else else
{ {
_scheduler.Schedule(6s, 10s, [this](TaskContext context) scheduler.Schedule(6s, 10s, [this](TaskContext context)
{ {
if (Unit* target = SelectTarget(SelectTargetMethod::MaxThreat, 1)) if (Unit* target = SelectTarget(SelectTargetMethod::MaxThreat, 1))
DoCast(target, SPELL_PLAGUE, true); DoCast(target, SPELL_PLAGUE, true);
@@ -107,7 +104,7 @@ struct npc_anubisath_defender : public ScriptedAI
if (urand(0, 1)) if (urand(0, 1))
{ {
_scheduler.Schedule(5s, 8s, [this](TaskContext context) scheduler.Schedule(5s, 8s, [this](TaskContext context)
{ {
DoCastAOE(SPELL_THUNDERCLAP, true); DoCastAOE(SPELL_THUNDERCLAP, true);
context.Repeat(5s, 8s); context.Repeat(5s, 8s);
@@ -115,7 +112,7 @@ struct npc_anubisath_defender : public ScriptedAI
} }
else else
{ {
_scheduler.Schedule(5s, 8s, [this](TaskContext context) scheduler.Schedule(5s, 8s, [this](TaskContext context)
{ {
DoCastAOE(SPELL_SHADOW_STORM, true); DoCastAOE(SPELL_SHADOW_STORM, true);
context.Repeat(5s, 8s); context.Repeat(5s, 8s);
@@ -124,7 +121,7 @@ struct npc_anubisath_defender : public ScriptedAI
if (urand(0, 1)) if (urand(0, 1))
{ {
_scheduler.Schedule(3s, 5s, [this](TaskContext context) scheduler.Schedule(3s, 5s, [this](TaskContext context)
{ {
DoCastSelf(SPELL_SUMMON_WARRIOR, true); DoCastSelf(SPELL_SUMMON_WARRIOR, true);
context.Repeat(12s, 16s); context.Repeat(12s, 16s);
@@ -132,7 +129,7 @@ struct npc_anubisath_defender : public ScriptedAI
} }
else else
{ {
_scheduler.Schedule(3s, 5s, [this](TaskContext context) scheduler.Schedule(3s, 5s, [this](TaskContext context)
{ {
DoCastAOE(SPELL_SUMMON_SWARMGUARD, true); DoCastAOE(SPELL_SUMMON_SWARMGUARD, true);
context.Repeat(12s, 16s); context.Repeat(12s, 16s);
@@ -171,31 +168,28 @@ struct npc_anubisath_defender : public ScriptedAI
return; return;
} }
_scheduler.Update(diff, scheduler.Update(diff,
std::bind(&ScriptedAI::DoMeleeAttackIfReady, this)); std::bind(&ScriptedAI::DoMeleeAttackIfReady, this));
} }
private: private:
TaskScheduler _scheduler;
bool _enraged; bool _enraged;
}; };
struct npc_vekniss_stinger : public ScriptedAI struct npc_vekniss_stinger : public ScriptedAI
{ {
npc_vekniss_stinger(Creature* creature) : ScriptedAI(creature) npc_vekniss_stinger(Creature* creature) : ScriptedAI(creature) { }
{
}
void Reset() override void Reset() override
{ {
_scheduler.CancelAll(); scheduler.CancelAll();
} }
void JustEngagedWith(Unit* who) override void JustEngagedWith(Unit* who) override
{ {
DoCast(who ,who->HasAura(SPELL_VEKNISS_CATALYST) ? SPELL_STINGER_CHARGE_BUFFED : SPELL_STINGER_CHARGE_NORMAL, true); DoCast(who ,who->HasAura(SPELL_VEKNISS_CATALYST) ? SPELL_STINGER_CHARGE_BUFFED : SPELL_STINGER_CHARGE_NORMAL, true);
_scheduler.Schedule(6s, [this](TaskContext context) scheduler.Schedule(6s, [this](TaskContext context)
{ {
Unit* target = SelectTarget(SelectTargetMethod::Random, 0, [&](Unit* u) Unit* target = SelectTarget(SelectTargetMethod::Random, 0, [&](Unit* u)
{ {
@@ -225,44 +219,35 @@ struct npc_vekniss_stinger : public ScriptedAI
return; return;
} }
_scheduler.Update(diff, scheduler.Update(diff,
std::bind(&ScriptedAI::DoMeleeAttackIfReady, this)); std::bind(&ScriptedAI::DoMeleeAttackIfReady, this));
} }
private:
TaskScheduler _scheduler;
}; };
struct npc_obsidian_eradicator : public ScriptedAI struct npc_obsidian_eradicator : public ScriptedAI
{ {
npc_obsidian_eradicator(Creature* creature) : ScriptedAI(creature) npc_obsidian_eradicator(Creature* creature) : ScriptedAI(creature) { }
{
}
void Reset() override void Reset() override
{ {
_scheduler.CancelAll(); scheduler.CancelAll();
me->SetPower(POWER_MANA, 0); me->SetPower(POWER_MANA, 0);
_targetGUIDs.clear(); _targetGUIDs.clear();
} }
void JustEngagedWith(Unit* /*who*/) override void JustEngagedWith(Unit* /*who*/) override
{ {
_scheduler.Schedule(3500ms, [this](TaskContext context) scheduler.Schedule(3500ms, [this](TaskContext context)
{ {
if (_targetGUIDs.empty()) if (_targetGUIDs.empty())
{ {
Map::PlayerList const& players = me->GetMap()->GetPlayers(); me->GetMap()->DoForAllPlayers([&](Player* player)
for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
{ {
if (Player* player = itr->GetSource()) if (player->IsAlive() && !player->IsGameMaster() && !player->IsSpectator() && player->GetPower(POWER_MANA) > 0)
{ {
if (player->IsAlive() && !player->IsGameMaster() && !player->IsSpectator() && player->GetPower(POWER_MANA) > 0) _targetGUIDs.push_back(player->GetGUID());
{
_targetGUIDs.push_back(player->GetGUID());
}
} }
} });
Acore::Containers::RandomResize(_targetGUIDs, 10); Acore::Containers::RandomResize(_targetGUIDs, 10);
} }
@@ -291,31 +276,28 @@ struct npc_obsidian_eradicator : public ScriptedAI
return; return;
} }
_scheduler.Update(diff, scheduler.Update(diff,
std::bind(&ScriptedAI::DoMeleeAttackIfReady, this)); std::bind(&ScriptedAI::DoMeleeAttackIfReady, this));
} }
private: private:
TaskScheduler _scheduler;
GuidList _targetGUIDs; GuidList _targetGUIDs;
}; };
struct npc_anubisath_warder : public ScriptedAI struct npc_anubisath_warder : public ScriptedAI
{ {
npc_anubisath_warder(Creature* creature) : ScriptedAI(creature) npc_anubisath_warder(Creature* creature) : ScriptedAI(creature) { }
{
}
void Reset() override void Reset() override
{ {
_scheduler.CancelAll(); scheduler.CancelAll();
} }
void JustEngagedWith(Unit* /*who*/) override void JustEngagedWith(Unit* /*who*/) override
{ {
if (urand(0, 1)) if (urand(0, 1))
{ {
_scheduler.Schedule(5s, 5s, [this](TaskContext context) scheduler.Schedule(5s, 5s, [this](TaskContext context)
{ {
DoCastAOE(SPELL_FEAR, true); DoCastAOE(SPELL_FEAR, true);
context.Repeat(20s, 20s); context.Repeat(20s, 20s);
@@ -323,7 +305,7 @@ struct npc_anubisath_warder : public ScriptedAI
} }
else else
{ {
_scheduler.Schedule(5s, 5s, [this](TaskContext context) scheduler.Schedule(5s, 5s, [this](TaskContext context)
{ {
DoCastAOE(SPELL_ENTAGLING_ROOTS, true); DoCastAOE(SPELL_ENTAGLING_ROOTS, true);
context.Repeat(20s, 20s); context.Repeat(20s, 20s);
@@ -332,7 +314,7 @@ struct npc_anubisath_warder : public ScriptedAI
if (urand(0, 1)) if (urand(0, 1))
{ {
_scheduler.Schedule(4s, 4s, [this](TaskContext context) scheduler.Schedule(4s, 4s, [this](TaskContext context)
{ {
DoCastAOE(SPELL_SILENCE, true); DoCastAOE(SPELL_SILENCE, true);
context.Repeat(15s, 15s); context.Repeat(15s, 15s);
@@ -340,14 +322,14 @@ struct npc_anubisath_warder : public ScriptedAI
} }
else else
{ {
_scheduler.Schedule(4s, 4s, [this](TaskContext context) scheduler.Schedule(4s, 4s, [this](TaskContext context)
{ {
DoCastAOE(SPELL_DUST_CLOUD, true); DoCastAOE(SPELL_DUST_CLOUD, true);
context.Repeat(15s, 15s); context.Repeat(15s, 15s);
}); });
} }
_scheduler.Schedule(2s, 2s, [this](TaskContext context) scheduler.Schedule(2s, 2s, [this](TaskContext context)
{ {
DoCastAOE(SPELL_FIRE_NOVA, true); DoCastAOE(SPELL_FIRE_NOVA, true);
context.Repeat(8s, 15s); context.Repeat(8s, 15s);
@@ -361,44 +343,35 @@ struct npc_anubisath_warder : public ScriptedAI
return; return;
} }
_scheduler.Update(diff, scheduler.Update(diff,
std::bind(&ScriptedAI::DoMeleeAttackIfReady, this)); std::bind(&ScriptedAI::DoMeleeAttackIfReady, this));
} }
private:
TaskScheduler _scheduler;
}; };
struct npc_obsidian_nullifier : public ScriptedAI struct npc_obsidian_nullifier : public ScriptedAI
{ {
npc_obsidian_nullifier(Creature* creature) : ScriptedAI(creature) npc_obsidian_nullifier(Creature* creature) : ScriptedAI(creature) { }
{
}
void Reset() override void Reset() override
{ {
_scheduler.CancelAll(); scheduler.CancelAll();
me->SetPower(POWER_MANA, 0); me->SetPower(POWER_MANA, 0);
_targetGUIDs.clear(); _targetGUIDs.clear();
} }
void JustEngagedWith(Unit* /*who*/) override void JustEngagedWith(Unit* /*who*/) override
{ {
_scheduler.Schedule(6s, [this](TaskContext context) scheduler.Schedule(6s, [this](TaskContext context)
{ {
if (_targetGUIDs.empty()) if (_targetGUIDs.empty())
{ {
Map::PlayerList const& players = me->GetMap()->GetPlayers(); me->GetMap()->DoForAllPlayers([&](Player* player)
for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
{ {
if (Player* player = itr->GetSource()) if (player->IsAlive() && !player->IsGameMaster() && !player->IsSpectator() && player->GetPower(POWER_MANA) > 0)
{ {
if (player->IsAlive() && !player->IsGameMaster() && !player->IsSpectator() && player->GetPower(POWER_MANA) > 0) _targetGUIDs.push_back(player->GetGUID());
{
_targetGUIDs.push_back(player->GetGUID());
}
} }
} });
Acore::Containers::RandomResize(_targetGUIDs, 11); Acore::Containers::RandomResize(_targetGUIDs, 11);
} }
@@ -432,26 +405,23 @@ struct npc_obsidian_nullifier : public ScriptedAI
return; return;
} }
_scheduler.Update(diff, scheduler.Update(diff,
std::bind(&ScriptedAI::DoMeleeAttackIfReady, this)); std::bind(&ScriptedAI::DoMeleeAttackIfReady, this));
} }
private: private:
TaskScheduler _scheduler;
GuidList _targetGUIDs; GuidList _targetGUIDs;
}; };
struct npc_ahnqiraji_critter : public ScriptedAI struct npc_ahnqiraji_critter : public ScriptedAI
{ {
npc_ahnqiraji_critter(Creature* creature) : ScriptedAI(creature) npc_ahnqiraji_critter(Creature* creature) : ScriptedAI(creature) { }
{
}
void Reset() override void Reset() override
{ {
me->RestoreFaction(); me->RestoreFaction();
_scheduler.CancelAll(); scheduler.CancelAll();
// Don't attack nearby players randomly if they are the Twin's pet bugs. // Don't attack nearby players randomly if they are the Twin's pet bugs.
if (CreatureData const* crData = me->GetCreatureData()) if (CreatureData const* crData = me->GetCreatureData())
@@ -465,7 +435,7 @@ struct npc_ahnqiraji_critter : public ScriptedAI
} }
} }
_scheduler.Schedule(100ms, [this](TaskContext context) scheduler.Schedule(100ms, [this](TaskContext context)
{ {
if (Player* player = me->SelectNearestPlayer(10.f)) if (Player* player = me->SelectNearestPlayer(10.f))
{ {
@@ -481,11 +451,11 @@ struct npc_ahnqiraji_critter : public ScriptedAI
void JustEngagedWith(Unit* /*who*/) override void JustEngagedWith(Unit* /*who*/) override
{ {
_scheduler.CancelAll(); scheduler.CancelAll();
if (me->GetEntry() == NPC_QIRAJI_SCORPION) if (me->GetEntry() == NPC_QIRAJI_SCORPION)
{ {
_scheduler.Schedule(2s, 5s, [this](TaskContext context) scheduler.Schedule(2s, 5s, [this](TaskContext context)
{ {
DoCastVictim(SPELL_PIERCE_ARMOR, true); DoCastVictim(SPELL_PIERCE_ARMOR, true);
context.Repeat(5s, 9s); context.Repeat(5s, 9s);
@@ -508,7 +478,7 @@ struct npc_ahnqiraji_critter : public ScriptedAI
void UpdateAI(uint32 diff) override void UpdateAI(uint32 diff) override
{ {
_scheduler.Update(diff); scheduler.Update(diff);
if (!UpdateVictim()) if (!UpdateVictim())
{ {
@@ -517,9 +487,6 @@ struct npc_ahnqiraji_critter : public ScriptedAI
DoMeleeAttackIfReady(); DoMeleeAttackIfReady();
} }
private:
TaskScheduler _scheduler;
}; };
enum NPCs enum NPCs