chore(Scripts/Karazhan): rework Shade of Aran using TaskScheduler and fixes (#16689)

This commit is contained in:
Dan
2023-07-18 14:56:00 +02:00
committed by GitHub
parent b55ebc186d
commit 89e7fb301a
@@ -20,6 +20,7 @@
#include "ScriptedCreature.h" #include "ScriptedCreature.h"
#include "SpellInfo.h" #include "SpellInfo.h"
#include "karazhan.h" #include "karazhan.h"
#include "TaskScheduler.h"
enum ShadeOfAran enum ShadeOfAran
{ {
@@ -58,9 +59,9 @@ enum ShadeOfAran
SPELL_SHADOW_PYRO = 29978, SPELL_SHADOW_PYRO = 29978,
//Creatures //Creatures
CREATURE_WATER_ELEMENTAL = 17167, NPC_WATER_ELEMENTAL = 17167,
CREATURE_SHADOW_OF_ARAN = 18254, NPC_SHADOW_OF_ARAN = 18254,
CREATURE_ARAN_BLIZZARD = 17161, NPC_ARAN_BLIZZARD = 17161,
}; };
enum SuperSpell enum SuperSpell
@@ -70,67 +71,56 @@ enum SuperSpell
SUPER_AE, SUPER_AE,
}; };
class boss_shade_of_aran : public CreatureScript enum Groups
{ {
public: GROUP_FLAMEWREATH = 0,
boss_shade_of_aran() : CreatureScript("boss_shade_of_aran") { } GROUP_DRINKING = 1
};
struct boss_aranAI : public BossAI Position const elementalPos[4] =
{
{-11168.1f, -1939.29f, 232.092f, 1.46f},
{-11138.2f, -1915.38f, 232.092f, 3.00f},
{-11161.7f, -1885.36f, 232.092f, 4.59f},
{-11192.4f, -1909.36f, 232.092f, 6.19f}
};
struct boss_shade_of_aran : public BossAI
{
boss_shade_of_aran(Creature* creature) : BossAI(creature, DATA_ARAN)
{ {
boss_aranAI(Creature* creature) : BossAI(creature, DATA_ARAN) scheduler.SetValidator([this]
{ {
return !me->HasUnitState(UNIT_STATE_CASTING);
});
} }
uint32 SecondarySpellTimer;
uint32 NormalCastTimer;
uint32 SuperCastTimer;
uint32 BerserkTimer;
uint32 CloseDoorTimer; // Don't close the door right on aggro in case some people are still entering.
uint8 LastSuperSpell; uint8 LastSuperSpell;
uint32 FlameWreathTimer;
uint32 FlameWreathCheckTime;
ObjectGuid FlameWreathTarget[3]; ObjectGuid FlameWreathTarget[3];
float FWTargPosX[3]; float FWTargPosX[3];
float FWTargPosY[3]; float FWTargPosY[3];
uint32 CurrentNormalSpell; uint32 CurrentNormalSpell;
uint32 ArcaneCooldown;
uint32 FireCooldown;
uint32 FrostCooldown;
uint32 DrinkInterruptTimer;
bool ElementalsSpawned;
bool Drinking; bool Drinking;
bool DrinkInturrupted;
void Reset() override void Reset() override
{ {
SecondarySpellTimer = 5000; BossAI::Reset();
NormalCastTimer = 0; drinkScheduler.CancelAll();
SuperCastTimer = 35000;
BerserkTimer = 720000;
CloseDoorTimer = 15000;
LastSuperSpell = rand() % 3; LastSuperSpell = rand() % 3;
FlameWreathTimer = 0;
FlameWreathCheckTime = 0;
for (uint8 i = 0; i < 3; ++i) for (uint8 i = 0; i < 3; ++i)
FlameWreathTarget[i].Clear(); FlameWreathTarget[i].Clear();
CurrentNormalSpell = 0; CurrentNormalSpell = 0;
ArcaneCooldown = 0;
FireCooldown = 0;
FrostCooldown = 0;
DrinkInterruptTimer = 10000; _arcaneCooledDown = true;
_fireCooledDown = true;
_frostCooledDown = true;
ElementalsSpawned = false;
Drinking = false; Drinking = false;
DrinkInturrupted = false;
// Not in progress // Not in progress
instance->SetData(DATA_ARAN, NOT_STARTED); instance->SetData(DATA_ARAN, NOT_STARTED);
@@ -140,6 +130,23 @@ public:
libraryDoor->SetGoState(GO_STATE_ACTIVE); libraryDoor->SetGoState(GO_STATE_ACTIVE);
libraryDoor->RemoveGameObjectFlag(GO_FLAG_NOT_SELECTABLE); libraryDoor->RemoveGameObjectFlag(GO_FLAG_NOT_SELECTABLE);
} }
ScheduleHealthCheckEvent(40, [&]{
Talk(SAY_ELEMENTALS);
for(Position pos : elementalPos)
{
if(Creature* elemental = me->SummonCreature(NPC_WATER_ELEMENTAL, pos, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 90000))
{
if(Unit* target = SelectTarget(SelectTargetMethod::Random, 1, 100, true))
{
DoStartNoMovement(target);
elemental->SetInCombatWithZone();
elemental->CombatStart(target);
}
}
}
});
} }
void KilledUnit(Unit* /*victim*/) override void KilledUnit(Unit* /*victim*/) override
@@ -147,6 +154,30 @@ public:
Talk(SAY_KILL); Talk(SAY_KILL);
} }
void TriggerArcaneCooldown()
{
scheduler.Schedule(5s, [this](TaskContext)
{
_arcaneCooledDown = true;
});
}
void TriggerFireCooldown()
{
scheduler.Schedule(5s, [this](TaskContext)
{
_fireCooledDown = true;
});
}
void TriggerFrostCooldown()
{
scheduler.Schedule(5s, [this](TaskContext)
{
_frostCooledDown = true;
});
}
void JustDied(Unit* /*killer*/) override void JustDied(Unit* /*killer*/) override
{ {
Talk(SAY_DEATH); Talk(SAY_DEATH);
@@ -166,13 +197,154 @@ public:
instance->SetData(DATA_ARAN, IN_PROGRESS); instance->SetData(DATA_ARAN, IN_PROGRESS);
DoZoneInCombat();
//handle timed closing door
scheduler.Schedule(15s, [this](TaskContext)
{
if (GameObject* libraryDoor = instance->instance->GetGameObject(instance->GetGuidData(DATA_GO_LIBRARY_DOOR))) if (GameObject* libraryDoor = instance->instance->GetGameObject(instance->GetGuidData(DATA_GO_LIBRARY_DOOR)))
{ {
libraryDoor->SetGoState(GO_STATE_READY); libraryDoor->SetGoState(GO_STATE_READY);
libraryDoor->SetGameObjectFlag(GO_FLAG_NOT_SELECTABLE); libraryDoor->SetGameObjectFlag(GO_FLAG_NOT_SELECTABLE);
} }
}).Schedule(1ms, [this](TaskContext context)
{
if (!me->IsNonMeleeSpellCast(false))
{
Unit* target = SelectTarget(SelectTargetMethod::Random, 0, 100, true);
if (!target)
return;
DoZoneInCombat(); uint32 Spells[3];
uint8 AvailableSpells = 0;
//Check for what spells are not on cooldown
if (_arcaneCooledDown)
{
Spells[AvailableSpells] = SPELL_ARCMISSLE;
++AvailableSpells;
}
if (_fireCooledDown)
{
Spells[AvailableSpells] = SPELL_FIREBALL;
++AvailableSpells;
}
if (_frostCooledDown)
{
Spells[AvailableSpells] = SPELL_FROSTBOLT;
++AvailableSpells;
}
//If no available spells wait 1 second and try again
if (AvailableSpells)
{
CurrentNormalSpell = Spells[rand() % AvailableSpells];
DoCast(target, CurrentNormalSpell);
}
}
context.Repeat(10s);
}).Schedule(5s, [this](TaskContext context)
{
switch (urand(0, 1))
{
case 0:
DoCastSelf(SPELL_AOE_CS);
break;
case 1:
DoCastRandomTarget(SPELL_CHAINSOFICE);
break;
}
context.Repeat(5s, 20s);
}).Schedule(35s, [this](TaskContext context)
{
uint8 Available[2];
switch (LastSuperSpell)
{
case SUPER_AE:
Available[0] = SUPER_FLAME;
Available[1] = SUPER_BLIZZARD;
break;
case SUPER_FLAME:
Available[0] = SUPER_AE;
Available[1] = SUPER_BLIZZARD;
break;
case SUPER_BLIZZARD:
Available[0] = SUPER_FLAME;
Available[1] = SUPER_AE;
break;
}
LastSuperSpell = Available[urand(0, 1)];
switch (LastSuperSpell)
{
case SUPER_AE:
Talk(SAY_EXPLOSION);
DoCastSelf(SPELL_BLINK_CENTER, true);
DoCastSelf(SPELL_PLAYERPULL, true);
DoCastSelf(SPELL_MASSSLOW, true);
DoCastSelf(SPELL_AEXPLOSION, false);
break;
case SUPER_FLAME:
Talk(SAY_FLAMEWREATH);
scheduler.Schedule(20s, GROUP_FLAMEWREATH, [this](TaskContext)
{
scheduler.CancelGroup(GROUP_FLAMEWREATH);
}).Schedule(500ms, GROUP_FLAMEWREATH, [this](TaskContext context)
{
for (uint8 i = 0; i < 3; ++i)
{
if (!FlameWreathTarget[i])
continue;
Unit* unit = ObjectAccessor::GetUnit(*me, FlameWreathTarget[i]);
if (unit && !unit->IsWithinDist2d(FWTargPosX[i], FWTargPosY[i], 3))
{
unit->CastSpell(unit, 20476, true, 0, 0, me->GetGUID());
unit->CastSpell(unit, 11027, true);
FlameWreathTarget[i].Clear();
}
}
context.Repeat(500ms);
});
FlameWreathTarget[0].Clear();
FlameWreathTarget[1].Clear();
FlameWreathTarget[2].Clear();
FlameWreathEffect();
break;
case SUPER_BLIZZARD:
Talk(SAY_BLIZZARD);
if (Creature* pSpawn = me->SummonCreature(NPC_ARAN_BLIZZARD, 0.0f, 0.0f, 0.0f, 0.0f, TEMPSUMMON_TIMED_DESPAWN, 25000))
{
pSpawn->SetFaction(me->GetFaction());
pSpawn->CastSpell(me, SPELL_CIRCULAR_BLIZZARD, false);
}
break;
}
context.Repeat(35s, 40s);
}).Schedule(12min, [this](TaskContext context)
{
for (uint32 i = 0; i < 5; ++i)
{
if (Creature* unit = me->SummonCreature(NPC_SHADOW_OF_ARAN, 0.0f, 0.0f, 0.0f, 0.0f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 5000))
{
unit->Attack(me->GetVictim(), true);
unit->SetFaction(me->GetFaction());
}
}
Talk(SAY_TIMEOVER);
context.Repeat(1min);
});
} }
void FlameWreathEffect() void FlameWreathEffect()
@@ -212,49 +384,12 @@ public:
void UpdateAI(uint32 diff) override void UpdateAI(uint32 diff) override
{ {
scheduler.Update(diff);
drinkScheduler.Update(diff);
if (!UpdateVictim()) if (!UpdateVictim())
return; return;
if (CloseDoorTimer)
{
if (CloseDoorTimer <= diff)
{
if (GameObject* libraryDoor = instance->instance->GetGameObject(instance->GetGuidData(DATA_GO_LIBRARY_DOOR)))
{
libraryDoor->SetGoState(GO_STATE_READY);
libraryDoor->SetGameObjectFlag(GO_FLAG_NOT_SELECTABLE);
}
CloseDoorTimer = 0;
}
else
CloseDoorTimer -= diff;
}
//Cooldowns for casts
if (ArcaneCooldown)
{
if (ArcaneCooldown >= diff)
ArcaneCooldown -= diff;
else
ArcaneCooldown = 0;
}
if (FireCooldown)
{
if (FireCooldown >= diff)
FireCooldown -= diff;
else
FireCooldown = 0;
}
if (FrostCooldown)
{
if (FrostCooldown >= diff)
FrostCooldown -= diff;
else
FrostCooldown = 0;
}
if (!Drinking && me->GetMaxPower(POWER_MANA) && (me->GetPower(POWER_MANA) * 100 / me->GetMaxPower(POWER_MANA)) < 20) if (!Drinking && me->GetMaxPower(POWER_MANA) && (me->GetPower(POWER_MANA) * 100 / me->GetMaxPower(POWER_MANA)) < 20)
{ {
Drinking = true; Drinking = true;
@@ -262,288 +397,56 @@ public:
Talk(SAY_DRINK); Talk(SAY_DRINK);
if (!DrinkInturrupted) scheduler.DelayAll(10s);
{ DoCastSelf(SPELL_MASS_POLY, true);
DoCast(me, SPELL_MASS_POLY, true); DoCastSelf(SPELL_CONJURE, false);
DoCast(me, SPELL_CONJURE, false); me->SetReactState(REACT_PASSIVE);
DoCast(me, SPELL_DRINK, false);
me->SetStandState(UNIT_STAND_STATE_SIT); me->SetStandState(UNIT_STAND_STATE_SIT);
DrinkInterruptTimer = 10000; DoCastSelf(SPELL_DRINK, true);
} _currentHealth = me->GetHealth();
} drinkScheduler.Schedule(500ms, GROUP_DRINKING, [this](TaskContext context)
{
//Drink Interrupt //check for damage to interrupt
if (Drinking && DrinkInturrupted) if(CheckDamageDuringDrinking(_currentHealth))
{ {
Drinking = false; Drinking = false;
me->RemoveAurasDueToSpell(SPELL_DRINK); me->RemoveAurasDueToSpell(SPELL_DRINK);
me->SetStandState(UNIT_STAND_STATE_STAND); me->SetStandState(UNIT_STAND_STATE_STAND);
me->SetReactState(REACT_AGGRESSIVE);
me->SetPower(POWER_MANA, me->GetMaxPower(POWER_MANA) - 32000); me->SetPower(POWER_MANA, me->GetMaxPower(POWER_MANA) - 32000);
DoCast(me, SPELL_POTION, false); DoCastSelf(SPELL_POTION, false);
DoCastSelf(SPELL_AOE_PYROBLAST, false);
drinkScheduler.CancelGroup(GROUP_DRINKING);
} else {
context.Repeat(500ms);
} }
}).Schedule(10s, GROUP_DRINKING, [this](TaskContext)
//Drink Interrupt Timer
if (Drinking && !DrinkInturrupted)
{
if (DrinkInterruptTimer >= diff)
DrinkInterruptTimer -= diff;
else
{ {
me->SetStandState(UNIT_STAND_STATE_STAND); me->SetStandState(UNIT_STAND_STATE_STAND);
DoCast(me, SPELL_POTION, true); me->SetReactState(REACT_AGGRESSIVE);
DoCast(me, SPELL_AOE_PYROBLAST, false); me->SetPower(POWER_MANA, me->GetMaxPower(POWER_MANA) - 32000);
DrinkInturrupted = true; DoCastSelf(SPELL_POTION, true);
DoCastSelf(SPELL_AOE_PYROBLAST, false);
Drinking = false; Drinking = false;
} drinkScheduler.CancelGroup(GROUP_DRINKING);
});
} }
//Don't execute any more code if we are drinking if (_arcaneCooledDown && _fireCooledDown && _frostCooledDown && !Drinking)
if (Drinking)
return;
//Normal casts
if (NormalCastTimer <= diff)
{
if (!me->IsNonMeleeSpellCast(false))
{
Unit* target = SelectTarget(SelectTargetMethod::Random, 0, 100, true);
if (!target)
return;
uint32 Spells[3];
uint8 AvailableSpells = 0;
//Check for what spells are not on cooldown
if (!ArcaneCooldown)
{
Spells[AvailableSpells] = SPELL_ARCMISSLE;
++AvailableSpells;
}
if (!FireCooldown)
{
Spells[AvailableSpells] = SPELL_FIREBALL;
++AvailableSpells;
}
if (!FrostCooldown)
{
Spells[AvailableSpells] = SPELL_FROSTBOLT;
++AvailableSpells;
}
//If no available spells wait 1 second and try again
if (AvailableSpells)
{
CurrentNormalSpell = Spells[rand() % AvailableSpells];
DoCast(target, CurrentNormalSpell);
}
}
NormalCastTimer = 1000;
}
else
NormalCastTimer -= diff;
if (SecondarySpellTimer <= diff)
{
switch (urand(0, 1))
{
case 0:
DoCast(me, SPELL_AOE_CS);
break;
case 1:
if (Unit* target = SelectTarget(SelectTargetMethod::Random, 0, 100, true))
DoCast(target, SPELL_CHAINSOFICE);
break;
}
SecondarySpellTimer = urand(5000, 20000);
}
else
SecondarySpellTimer -= diff;
if (SuperCastTimer <= diff)
{
uint8 Available[2];
switch (LastSuperSpell)
{
case SUPER_AE:
Available[0] = SUPER_FLAME;
Available[1] = SUPER_BLIZZARD;
break;
case SUPER_FLAME:
Available[0] = SUPER_AE;
Available[1] = SUPER_BLIZZARD;
break;
case SUPER_BLIZZARD:
Available[0] = SUPER_FLAME;
Available[1] = SUPER_AE;
break;
}
LastSuperSpell = Available[urand(0, 1)];
switch (LastSuperSpell)
{
case SUPER_AE:
Talk(SAY_EXPLOSION);
DoCast(me, SPELL_BLINK_CENTER, true);
DoCast(me, SPELL_PLAYERPULL, true);
DoCast(me, SPELL_MASSSLOW, true);
DoCast(me, SPELL_AEXPLOSION, false);
break;
case SUPER_FLAME:
Talk(SAY_FLAMEWREATH);
FlameWreathTimer = 20000;
FlameWreathCheckTime = 500;
FlameWreathTarget[0].Clear();
FlameWreathTarget[1].Clear();
FlameWreathTarget[2].Clear();
FlameWreathEffect();
break;
case SUPER_BLIZZARD:
Talk(SAY_BLIZZARD);
if (Creature* pSpawn = me->SummonCreature(CREATURE_ARAN_BLIZZARD, 0.0f, 0.0f, 0.0f, 0.0f, TEMPSUMMON_TIMED_DESPAWN, 25000))
{
pSpawn->SetFaction(me->GetFaction());
pSpawn->CastSpell(pSpawn, SPELL_CIRCULAR_BLIZZARD, false);
}
break;
}
SuperCastTimer = urand(35000, 40000);
}
else
SuperCastTimer -= diff;
if (!ElementalsSpawned && HealthBelowPct(40))
{
ElementalsSpawned = true;
Creature* ElementalOne = me->SummonCreature(CREATURE_WATER_ELEMENTAL, -11168.1f, -1939.29f, 232.092f, 1.46f, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 90000);
Creature* ElementalTwo = me->SummonCreature(CREATURE_WATER_ELEMENTAL, -11138.2f, -1915.38f, 232.092f, 3.00f, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 90000);
Creature* ElementalThree = me->SummonCreature(CREATURE_WATER_ELEMENTAL, -11161.7f, -1885.36f, 232.092f, 4.59f, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 90000);
Creature* ElementalFour = me->SummonCreature(CREATURE_WATER_ELEMENTAL, -11192.4f, -1909.36f, 232.092f, 6.19f, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 90000);
if (ElementalOne)
{
Unit* target = SelectTarget(SelectTargetMethod::Random, 1, 100, true);
if (!target)
return;
DoStartNoMovement(target);
ElementalOne->SetInCombatWithZone();
ElementalOne->CombatStart(target);
ElementalOne->SetFaction(me->GetFaction());
ElementalOne->SetUnitMovementFlags(MOVEMENTFLAG_ROOT);
ElementalOne->SetModifierValue(UNIT_MOD_RESISTANCE_FROST, BASE_VALUE, 0);
}
if (ElementalTwo)
{
Unit* target = SelectTarget(SelectTargetMethod::Random, 1, 100, true);
if (!target)
return;
DoStartNoMovement(target);
ElementalTwo->SetInCombatWithZone();
ElementalTwo->CombatStart(target);
ElementalTwo->SetFaction(me->GetFaction());
ElementalTwo->SetUnitMovementFlags(MOVEMENTFLAG_ROOT);
ElementalTwo->SetModifierValue(UNIT_MOD_RESISTANCE_FROST, BASE_VALUE, 0);
}
if (ElementalThree)
{
Unit* target = SelectTarget(SelectTargetMethod::Random, 1, 100, true);
if (!target)
return;
DoStartNoMovement(target);
ElementalThree->SetInCombatWithZone();
ElementalThree->CombatStart(target);
ElementalThree->SetFaction(me->GetFaction());
ElementalThree->SetUnitMovementFlags(MOVEMENTFLAG_ROOT);
ElementalThree->SetModifierValue(UNIT_MOD_RESISTANCE_FROST, BASE_VALUE, 0);
}
if (ElementalFour)
{
Unit* target = SelectTarget(SelectTargetMethod::Random, 1, 100, true);
if (!target)
return;
DoStartNoMovement(target);
ElementalFour->SetInCombatWithZone();
ElementalFour->CombatStart(target);
ElementalFour->SetFaction(me->GetFaction());
ElementalFour->SetUnitMovementFlags(MOVEMENTFLAG_ROOT);
ElementalFour->SetModifierValue(UNIT_MOD_RESISTANCE_FROST, BASE_VALUE, 0);
}
Talk(SAY_ELEMENTALS);
}
if (BerserkTimer <= diff)
{
for (uint32 i = 0; i < 5; ++i)
{
if (Creature* unit = me->SummonCreature(CREATURE_SHADOW_OF_ARAN, 0.0f, 0.0f, 0.0f, 0.0f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 5000))
{
unit->Attack(me->GetVictim(), true);
unit->SetFaction(me->GetFaction());
}
}
Talk(SAY_TIMEOVER);
BerserkTimer = 60000;
}
else
BerserkTimer -= diff;
//Flame Wreath check
if (FlameWreathTimer)
{
if (FlameWreathTimer >= diff)
FlameWreathTimer -= diff;
else
FlameWreathTimer = 0;
if (FlameWreathCheckTime <= diff)
{
for (uint8 i = 0; i < 3; ++i)
{
if (!FlameWreathTarget[i])
continue;
Unit* unit = ObjectAccessor::GetUnit(*me, FlameWreathTarget[i]);
if (unit && !unit->IsWithinDist2d(FWTargPosX[i], FWTargPosY[i], 3))
{
unit->CastSpell(unit, 20476, true, 0, 0, me->GetGUID());
unit->CastSpell(unit, 11027, true);
FlameWreathTarget[i].Clear();
}
}
FlameWreathCheckTime = 500;
}
else
FlameWreathCheckTime -= diff;
}
if (ArcaneCooldown && FireCooldown && FrostCooldown)
DoMeleeAttackIfReady(); DoMeleeAttackIfReady();
} }
void DamageTaken(Unit*, uint32& damage, DamageEffectType, SpellSchoolMask) override bool CheckDamageDuringDrinking(uint32 oldHealth)
{ {
if (!DrinkInturrupted && Drinking && damage) if (Drinking)
DrinkInturrupted = true; {
if (me->GetHealth() < oldHealth)
{
return true;
}
}
return false;
} }
void SpellHit(Unit* /*pAttacker*/, SpellInfo const* Spell) override void SpellHit(Unit* /*pAttacker*/, SpellInfo const* Spell) override
@@ -563,67 +466,63 @@ public:
switch (CurrentNormalSpell) switch (CurrentNormalSpell)
{ {
case SPELL_ARCMISSLE: case SPELL_ARCMISSLE:
ArcaneCooldown = 5000; TriggerArcaneCooldown();
break; break;
case SPELL_FIREBALL: case SPELL_FIREBALL:
FireCooldown = 5000; TriggerFireCooldown();
break; break;
case SPELL_FROSTBOLT: case SPELL_FROSTBOLT:
FrostCooldown = 5000; TriggerFrostCooldown();
break; break;
} }
} }
}; private:
TaskScheduler drinkScheduler;
CreatureAI* GetAI(Creature* creature) const override bool _arcaneCooledDown;
{ bool _fireCooledDown;
return GetKarazhanAI<boss_aranAI>(creature); bool _frostCooledDown;
} uint32 _currentHealth;
}; };
class npc_aran_elemental : public CreatureScript struct npc_aran_elemental : public ScriptedAI
{ {
public: npc_aran_elemental(Creature* creature) : ScriptedAI(creature)
npc_aran_elemental() : CreatureScript("npc_aran_elemental") { }
CreatureAI* GetAI(Creature* creature) const override
{ {
return new water_elementalAI(creature); SetCombatMovement(false);
_scheduler.SetValidator([this]
{
return !me->HasUnitState(UNIT_STATE_CASTING);
});
} }
struct water_elementalAI : public ScriptedAI
{
water_elementalAI(Creature* creature) : ScriptedAI(creature)
{
}
uint32 CastTimer;
void Reset() override void Reset() override
{ {
CastTimer = 2000 + (rand() % 3000); _scheduler.CancelAll();
} }
void JustEngagedWith(Unit* /*who*/) override { } void JustEngagedWith(Unit* /*who*/) override
{
_scheduler.Schedule(2s, [this](TaskContext context)
{
DoCastVictim(SPELL_WATERBOLT);
context.Repeat(2s);
});
}
void UpdateAI(uint32 diff) override void UpdateAI(uint32 diff) override
{ {
if (!UpdateVictim()) if (!UpdateVictim())
return; return;
if (CastTimer <= diff) _scheduler.Update(diff);
{
DoCastVictim(SPELL_WATERBOLT);
CastTimer = urand(2000, 5000);
} }
else private:
CastTimer -= diff; TaskScheduler _scheduler;
}
};
}; };
void AddSC_boss_shade_of_aran() void AddSC_boss_shade_of_aran()
{ {
new boss_shade_of_aran(); RegisterKarazhanCreatureAI(boss_shade_of_aran);
new npc_aran_elemental(); RegisterKarazhanCreatureAI(npc_aran_elemental);
} }