refactor(Scripts/Creature): convert pets into new system (#9046)

This commit is contained in:
Kitzunu
2021-11-09 11:44:09 +01:00
committed by GitHub
parent 6654b98312
commit 47c44d74c3
5 changed files with 867 additions and 1076 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -32,124 +32,113 @@ enum HunterSpells
SPELL_HUNTER_PET_SCALING = 62915
};
class npc_pet_hunter_snake_trap : public CreatureScript
struct npc_pet_hunter_snake_trap : public ScriptedAI
{
public:
npc_pet_hunter_snake_trap() : CreatureScript("npc_pet_hunter_snake_trap") { }
npc_pet_hunter_snake_trap(Creature* creature) : ScriptedAI(creature) { _init = false; }
struct npc_pet_hunter_snake_trapAI : public ScriptedAI
void Reset() override
{
npc_pet_hunter_snake_trapAI(Creature* creature) : ScriptedAI(creature) { _init = false; }
_spellTimer = urand(1500, 3000);
void Reset() override
{
_spellTimer = urand(1500, 3000);
// Start attacking attacker of owner on first ai update after spawn - move in line of sight may choose better target
if (!me->GetVictim())
if (Unit* tgt = me->SelectNearestTarget(10.0f))
{
me->AddThreat(tgt, 100000.0f);
AttackStart(tgt);
}
}
void EnterEvadeMode() override
{
// _EnterEvadeMode();
me->DeleteThreatList();
me->CombatStop(true);
me->LoadCreaturesAddon(true);
me->SetLootRecipient(nullptr);
me->ResetPlayerDamageReq();
me->SetLastDamagedTime(0);
me->AddUnitState(UNIT_STATE_EVADE);
me->GetMotionMaster()->MoveTargetedHome();
Reset();
}
//Redefined for random target selection:
void MoveInLineOfSight(Unit* who) override
{
if (!me->GetVictim() && who->isTargetableForAttack() && (me->IsHostileTo(who)) && who->isInAccessiblePlaceFor(me))
// Start attacking attacker of owner on first ai update after spawn - move in line of sight may choose better target
if (!me->GetVictim())
if (Unit* tgt = me->SelectNearestTarget(10.0f))
{
if (me->GetDistanceZ(who) > CREATURE_Z_ATTACK_RANGE)
return;
if (me->IsWithinDistInMap(who, 10.0f))
{
me->AddThreat(who, 100000.0f);
AttackStart(who);
}
me->AddThreat(tgt, 100000.0f);
AttackStart(tgt);
}
}
void UpdateAI(uint32 diff) override
{
if (!UpdateVictim())
return;
if (me->GetVictim()->HasBreakableByDamageCrowdControlAura(me))
{
me->InterruptNonMeleeSpells(false);
return;
}
if (!_init)
{
_init = true;
CreatureTemplate const* Info = me->GetCreatureTemplate();
CreatureBaseStats const* stats = sObjectMgr->GetCreatureBaseStats(me->getLevel(), Info->unit_class);
uint32 health = uint32(107 * (me->getLevel() - 40) * 0.025f);
me->SetCreateHealth(health);
for (uint8 stat = 0; stat < MAX_STATS; ++stat)
{
me->SetStat(Stats(stat), 0);
me->SetCreateStat(Stats(stat), 0);
}
me->SetModifierValue(UNIT_MOD_HEALTH, BASE_VALUE, (float)health);
me->SetMaxHealth(health);
//Add delta to make them not all hit the same time
uint32 delta = urand(0, 700);
me->SetAttackTime(BASE_ATTACK, Info->BaseAttackTime + delta);
me->SetStatFloatValue(UNIT_FIELD_RANGED_ATTACK_POWER, float(stats->AttackPower));
me->CastSpell(me, SPELL_HUNTER_DEADLY_POISON_PASSIVE, true);
// Glyph of Snake Trap
if (Unit* owner = me->GetOwner())
if (owner->GetAuraEffectDummy(SPELL_HUNTER_GLYPH_OF_SNAKE_TRAP))
me->CastSpell(me, SPELL_HUNTER_PET_SCALING, true);
}
_spellTimer += diff;
if (_spellTimer >= 3000)
{
if (urand(0, 2) == 0) // 33% chance to cast
DoCastVictim(RAND(SPELL_HUNTER_MIND_NUMBING_POISON, SPELL_HUNTER_CRIPPLING_POISON));
_spellTimer = 0;
}
DoMeleeAttackIfReady();
}
private:
bool _init;
uint32 _spellTimer;
};
CreatureAI* GetAI(Creature* creature) const override
{
return new npc_pet_hunter_snake_trapAI(creature);
}
void EnterEvadeMode() override
{
// _EnterEvadeMode();
me->DeleteThreatList();
me->CombatStop(true);
me->LoadCreaturesAddon(true);
me->SetLootRecipient(nullptr);
me->ResetPlayerDamageReq();
me->SetLastDamagedTime(0);
me->AddUnitState(UNIT_STATE_EVADE);
me->GetMotionMaster()->MoveTargetedHome();
Reset();
}
//Redefined for random target selection:
void MoveInLineOfSight(Unit* who) override
{
if (!me->GetVictim() && who->isTargetableForAttack() && (me->IsHostileTo(who)) && who->isInAccessiblePlaceFor(me))
{
if (me->GetDistanceZ(who) > CREATURE_Z_ATTACK_RANGE)
return;
if (me->IsWithinDistInMap(who, 10.0f))
{
me->AddThreat(who, 100000.0f);
AttackStart(who);
}
}
}
void UpdateAI(uint32 diff) override
{
if (!UpdateVictim())
return;
if (me->GetVictim()->HasBreakableByDamageCrowdControlAura(me))
{
me->InterruptNonMeleeSpells(false);
return;
}
if (!_init)
{
_init = true;
CreatureTemplate const* Info = me->GetCreatureTemplate();
CreatureBaseStats const* stats = sObjectMgr->GetCreatureBaseStats(me->getLevel(), Info->unit_class);
uint32 health = uint32(107 * (me->getLevel() - 40) * 0.025f);
me->SetCreateHealth(health);
for (uint8 stat = 0; stat < MAX_STATS; ++stat)
{
me->SetStat(Stats(stat), 0);
me->SetCreateStat(Stats(stat), 0);
}
me->SetModifierValue(UNIT_MOD_HEALTH, BASE_VALUE, (float)health);
me->SetMaxHealth(health);
//Add delta to make them not all hit the same time
uint32 delta = urand(0, 700);
me->SetAttackTime(BASE_ATTACK, Info->BaseAttackTime + delta);
me->SetStatFloatValue(UNIT_FIELD_RANGED_ATTACK_POWER, float(stats->AttackPower));
me->CastSpell(me, SPELL_HUNTER_DEADLY_POISON_PASSIVE, true);
// Glyph of Snake Trap
if (Unit* owner = me->GetOwner())
if (owner->GetAuraEffectDummy(SPELL_HUNTER_GLYPH_OF_SNAKE_TRAP))
me->CastSpell(me, SPELL_HUNTER_PET_SCALING, true);
}
_spellTimer += diff;
if (_spellTimer >= 3000)
{
if (urand(0, 2) == 0) // 33% chance to cast
DoCastVictim(RAND(SPELL_HUNTER_MIND_NUMBING_POISON, SPELL_HUNTER_CRIPPLING_POISON));
_spellTimer = 0;
}
DoMeleeAttackIfReady();
}
private:
bool _init;
uint32 _spellTimer;
};
void AddSC_hunter_pet_scripts()
{
new npc_pet_hunter_snake_trap();
RegisterCreatureAI(npc_pet_hunter_snake_trap);
}

View File

@@ -53,182 +53,171 @@ private:
Creature& _owner;
};
class npc_pet_mage_mirror_image : public CreatureScript
struct npc_pet_mage_mirror_image : CasterAI
{
public:
npc_pet_mage_mirror_image() : CreatureScript("npc_pet_mage_mirror_image") { }
npc_pet_mage_mirror_image(Creature* creature) : CasterAI(creature) { }
struct npc_pet_mage_mirror_imageAI : CasterAI
uint32 selectionTimer;
ObjectGuid _ebonGargoyleGUID;
uint32 checktarget;
uint32 dist = urand(1, 5);
void InitializeAI() override
{
npc_pet_mage_mirror_imageAI(Creature* creature) : CasterAI(creature) { }
CasterAI::InitializeAI();
Unit* owner = me->GetOwner();
if (!owner)
return;
uint32 selectionTimer;
ObjectGuid _ebonGargoyleGUID;
uint32 checktarget;
uint32 dist = urand(1, 5);
// Clone Me!
owner->CastSpell(me, SPELL_MAGE_CLONE_ME, true);
void InitializeAI() override
// xinef: Glyph of Mirror Image (4th copy)
float angle = 0.0f;
switch (me->GetUInt32Value(UNIT_CREATED_BY_SPELL))
{
CasterAI::InitializeAI();
Unit* owner = me->GetOwner();
if (!owner)
return;
case SPELL_SUMMON_MIRROR_IMAGE1:
angle = 0.5f * M_PI;
break;
case SPELL_SUMMON_MIRROR_IMAGE2:
angle = M_PI;
break;
case SPELL_SUMMON_MIRROR_IMAGE3:
angle = 1.5f * M_PI;
break;
}
// Clone Me!
owner->CastSpell(me, SPELL_MAGE_CLONE_ME, true);
((Minion*)me)->SetFollowAngle(angle);
if (owner->IsInCombat())
me->NearTeleportTo(me->GetPositionX() + cos(angle)*dist, me->GetPositionY() + sin(angle)*dist, me->GetPositionZ(), me->GetOrientation(), false, false, false, false);
else
me->GetMotionMaster()->MoveFollow(owner, PET_FOLLOW_DIST, me->GetFollowAngle(), MOTION_SLOT_ACTIVE);
// xinef: Glyph of Mirror Image (4th copy)
float angle = 0.0f;
switch (me->GetUInt32Value(UNIT_CREATED_BY_SPELL))
me->SetReactState(REACT_DEFENSIVE);
// Xinef: Inherit Master's Threat List (not yet implemented)
//owner->CastSpell((Unit*)nullptr, SPELL_MAGE_MASTERS_THREAT_LIST, true);
HostileReference* ref = owner->getHostileRefMgr().getFirst();
while (ref)
{
if (Unit* unit = ref->GetSource()->GetOwner())
unit->AddThreat(me, ref->getThreat() - ref->getTempThreatModifier());
ref = ref->next();
}
_ebonGargoyleGUID.Clear();
// Xinef: copy caster auras
Unit::VisibleAuraMap const* visibleAuraMap = owner->GetVisibleAuras();
for (Unit::VisibleAuraMap::const_iterator itr = visibleAuraMap->begin(); itr != visibleAuraMap->end(); ++itr)
if (Aura* visAura = itr->second->GetBase())
{
case SPELL_SUMMON_MIRROR_IMAGE1:
angle = 0.5f * M_PI;
break;
case SPELL_SUMMON_MIRROR_IMAGE2:
angle = M_PI;
break;
case SPELL_SUMMON_MIRROR_IMAGE3:
angle = 1.5f * M_PI;
break;
// Ebon Gargoyle
if (visAura->GetId() == 49206 && me->GetUInt32Value(UNIT_CREATED_BY_SPELL) == SPELL_SUMMON_MIRROR_IMAGE1)
{
if (Unit* gargoyle = visAura->GetCaster())
_ebonGargoyleGUID = gargoyle->GetGUID();
continue;
}
SpellScriptsBounds bounds = sObjectMgr->GetSpellScriptsBounds(visAura->GetId());
if (bounds.first != bounds.second)
continue;
std::vector<int32> const* spellTriggered = sSpellMgr->GetSpellLinked(visAura->GetId() + SPELL_LINK_AURA);
if (!spellTriggered || !spellTriggered->empty())
continue;
if (Aura* newAura = me->AddAura(visAura->GetId(), me))
newAura->SetDuration(visAura->GetDuration());
}
((Minion*)me)->SetFollowAngle(angle);
if (owner->IsInCombat())
me->NearTeleportTo(me->GetPositionX() + cos(angle)*dist, me->GetPositionY() + sin(angle)*dist, me->GetPositionZ(), me->GetOrientation(), false, false, false, false);
else
me->GetMotionMaster()->MoveFollow(owner, PET_FOLLOW_DIST, me->GetFollowAngle(), MOTION_SLOT_ACTIVE);
me->m_Events.AddEvent(new DeathEvent(*me), me->m_Events.CalculateTime(29500));
}
me->SetReactState(REACT_DEFENSIVE);
// Do not reload Creature templates on evade mode enter - prevent visual lost
void EnterEvadeMode() override
{
if (me->IsInEvadeMode() || !me->IsAlive())
return;
// Xinef: Inherit Master's Threat List (not yet implemented)
//owner->CastSpell((Unit*)nullptr, SPELL_MAGE_MASTERS_THREAT_LIST, true);
HostileReference* ref = owner->getHostileRefMgr().getFirst();
while (ref)
{
if (Unit* unit = ref->GetSource()->GetOwner())
unit->AddThreat(me, ref->getThreat() - ref->getTempThreatModifier());
ref = ref->next();
}
Unit* owner = me->GetCharmerOrOwner();
me->CombatStop(true);
if (owner && !me->HasUnitState(UNIT_STATE_FOLLOW))
{
me->GetMotionMaster()->Clear(false);
me->GetMotionMaster()->MoveFollow(owner, PET_FOLLOW_DIST, me->GetFollowAngle(), MOTION_SLOT_ACTIVE);
}
}
void MySelectNextTarget()
{
if (_ebonGargoyleGUID)
{
Unit* gargoyle = ObjectAccessor::GetUnit(*me, _ebonGargoyleGUID);
if (gargoyle && gargoyle->GetAI())
gargoyle->GetAI()->AttackStart(me);
_ebonGargoyleGUID.Clear();
// Xinef: copy caster auras
Unit::VisibleAuraMap const* visibleAuraMap = owner->GetVisibleAuras();
for (Unit::VisibleAuraMap::const_iterator itr = visibleAuraMap->begin(); itr != visibleAuraMap->end(); ++itr)
if (Aura* visAura = itr->second->GetBase())
{
// Ebon Gargoyle
if (visAura->GetId() == 49206 && me->GetUInt32Value(UNIT_CREATED_BY_SPELL) == SPELL_SUMMON_MIRROR_IMAGE1)
{
if (Unit* gargoyle = visAura->GetCaster())
_ebonGargoyleGUID = gargoyle->GetGUID();
continue;
}
SpellScriptsBounds bounds = sObjectMgr->GetSpellScriptsBounds(visAura->GetId());
if (bounds.first != bounds.second)
continue;
std::vector<int32> const* spellTriggered = sSpellMgr->GetSpellLinked(visAura->GetId() + SPELL_LINK_AURA);
if (!spellTriggered || !spellTriggered->empty())
continue;
if (Aura* newAura = me->AddAura(visAura->GetId(), me))
newAura->SetDuration(visAura->GetDuration());
}
me->m_Events.AddEvent(new DeathEvent(*me), me->m_Events.CalculateTime(29500));
}
// Do not reload Creature templates on evade mode enter - prevent visual lost
void EnterEvadeMode() override
Unit* owner = me->GetOwner();
if (owner && owner->GetTypeId() == TYPEID_PLAYER)
{
if (me->IsInEvadeMode() || !me->IsAlive())
return;
Unit* selection = owner->ToPlayer()->GetSelectedUnit();
Unit* owner = me->GetCharmerOrOwner();
me->CombatStop(true);
if (owner && !me->HasUnitState(UNIT_STATE_FOLLOW))
if (selection)
{
me->GetMotionMaster()->Clear(false);
me->GetMotionMaster()->MoveFollow(owner, PET_FOLLOW_DIST, me->GetFollowAngle(), MOTION_SLOT_ACTIVE);
me->getThreatMgr().resetAllAggro();
me->AddThreat(selection, 1000000.0f);
if (owner->IsInCombat())
AttackStart(selection);
}
if (!owner->IsInCombat() && !me->GetVictim())
EnterEvadeMode();
}
}
void Reset() override
{
selectionTimer = 0;
checktarget = 0;
}
void UpdateAI(uint32 diff) override
{
events.Update(diff);
if (events.GetTimer() < 1200)
return;
if (!me->IsInCombat() || !me->GetVictim())
{
MySelectNextTarget();
return;
}
void MySelectNextTarget()
checktarget += diff;
if (checktarget >= 1000)
{
if (_ebonGargoyleGUID)
{
Unit* gargoyle = ObjectAccessor::GetUnit(*me, _ebonGargoyleGUID);
if (gargoyle && gargoyle->GetAI())
gargoyle->GetAI()->AttackStart(me);
_ebonGargoyleGUID.Clear();
}
Unit* owner = me->GetOwner();
if (owner && owner->GetTypeId() == TYPEID_PLAYER)
{
Unit* selection = owner->ToPlayer()->GetSelectedUnit();
if (selection)
{
me->getThreatMgr().resetAllAggro();
me->AddThreat(selection, 1000000.0f);
if (owner->IsInCombat())
AttackStart(selection);
}
if (!owner->IsInCombat() && !me->GetVictim())
EnterEvadeMode();
}
}
void Reset() override
{
selectionTimer = 0;
checktarget = 0;
}
void UpdateAI(uint32 diff) override
{
events.Update(diff);
if (events.GetTimer() < 1200)
return;
if (!me->IsInCombat() || !me->GetVictim())
if (me->GetVictim()->HasBreakableByDamageCrowdControlAura() || !me->GetVictim()->IsAlive())
{
MySelectNextTarget();
me->InterruptNonMeleeSpells(true); // Stop casting if target is CC or not Alive.
return;
}
checktarget += diff;
if (checktarget >= 1000)
{
if (me->GetVictim()->HasBreakableByDamageCrowdControlAura() || !me->GetVictim()->IsAlive())
{
MySelectNextTarget();
me->InterruptNonMeleeSpells(true); // Stop casting if target is CC or not Alive.
return;
}
}
if (me->HasUnitState(UNIT_STATE_CASTING))
return;
if (uint32 spellId = events.ExecuteEvent())
{
events.RescheduleEvent(spellId, spellId == 59637 ? 6500 : 2500);
me->CastSpell(me->GetVictim(), spellId, false);
}
}
};
CreatureAI* GetAI(Creature* creature) const override
{
return new npc_pet_mage_mirror_imageAI(creature);
if (me->HasUnitState(UNIT_STATE_CASTING))
return;
if (uint32 spellId = events.ExecuteEvent())
{
events.RescheduleEvent(spellId, spellId == 59637 ? 6500 : 2500);
me->CastSpell(me->GetVictim(), spellId, false);
}
}
};
void AddSC_mage_pet_scripts()
{
new npc_pet_mage_mirror_image();
RegisterCreatureAI(npc_pet_mage_mirror_image);
}

View File

@@ -34,72 +34,50 @@ enum PriestSpells
SPELL_PRIEST_LIGHTWELL_CHARGES = 59907
};
class npc_pet_pri_lightwell : public CreatureScript
struct npc_pet_pri_lightwell : public TotemAI
{
public:
npc_pet_pri_lightwell() : CreatureScript("npc_pet_pri_lightwell") { }
npc_pet_pri_lightwell(Creature* creature) : TotemAI(creature) { }
struct npc_pet_pri_lightwellAI : public TotemAI
void InitializeAI() override
{
npc_pet_pri_lightwellAI(Creature* creature) : TotemAI(creature) { }
void InitializeAI() override
if (Unit* owner = me->ToTempSummon()->GetSummonerUnit())
{
if (Unit* owner = me->ToTempSummon()->GetSummonerUnit())
{
uint32 hp = uint32(owner->GetMaxHealth() * 0.3f);
me->SetMaxHealth(hp);
me->SetHealth(hp);
me->SetLevel(owner->getLevel());
}
me->CastSpell(me, SPELL_PRIEST_LIGHTWELL_CHARGES, false); // Spell for Lightwell Charges
TotemAI::InitializeAI();
uint32 hp = uint32(owner->GetMaxHealth() * 0.3f);
me->SetMaxHealth(hp);
me->SetHealth(hp);
me->SetLevel(owner->getLevel());
}
};
CreatureAI* GetAI(Creature* creature) const override
{
return new npc_pet_pri_lightwellAI(creature);
me->CastSpell(me, SPELL_PRIEST_LIGHTWELL_CHARGES, false); // Spell for Lightwell Charges
TotemAI::InitializeAI();
}
};
class npc_pet_pri_shadowfiend : public CreatureScript
struct npc_pet_pri_shadowfiend : public PetAI
{
public:
npc_pet_pri_shadowfiend() : CreatureScript("npc_pet_pri_shadowfiend") { }
npc_pet_pri_shadowfiend(Creature* creature) : PetAI(creature) { }
struct npc_pet_pri_shadowfiendAI : public PetAI
void Reset() override
{
npc_pet_pri_shadowfiendAI(Creature* creature) : PetAI(creature) { }
PetAI::Reset();
if (!me->HasAura(SPELL_PRIEST_SHADOWFIEND_DODGE))
me->AddAura(SPELL_PRIEST_SHADOWFIEND_DODGE, me);
void Reset() override
{
PetAI::Reset();
if (!me->HasAura(SPELL_PRIEST_SHADOWFIEND_DODGE))
me->AddAura(SPELL_PRIEST_SHADOWFIEND_DODGE, me);
if (Unit* target = me->SelectNearestTarget(15.0f))
AttackStart(target);
}
if (Unit* target = me->SelectNearestTarget(15.0f))
AttackStart(target);
}
void JustDied(Unit* /*killer*/) override
{
if (me->IsSummon())
if (Unit* owner = me->ToTempSummon()->GetSummonerUnit())
if (owner->HasAura(SPELL_PRIEST_GLYPH_OF_SHADOWFIEND))
owner->CastSpell(owner, SPELL_PRIEST_GLYPH_OF_SHADOWFIEND_MANA, true);
}
};
CreatureAI* GetAI(Creature* creature) const override
void JustDied(Unit* /*killer*/) override
{
return new npc_pet_pri_shadowfiendAI(creature);
if (me->IsSummon())
if (Unit* owner = me->ToTempSummon()->GetSummonerUnit())
if (owner->HasAura(SPELL_PRIEST_GLYPH_OF_SHADOWFIEND))
owner->CastSpell(owner, SPELL_PRIEST_GLYPH_OF_SHADOWFIEND_MANA, true);
}
};
void AddSC_priest_pet_scripts()
{
new npc_pet_pri_lightwell();
new npc_pet_pri_shadowfiend();
RegisterCreatureAI(npc_pet_pri_lightwell);
RegisterCreatureAI(npc_pet_pri_shadowfiend);
}

View File

@@ -42,131 +42,109 @@ enum ShamanEvents
EVENT_SHAMAN_FIREBLAST = 3
};
class npc_pet_shaman_earth_elemental : public CreatureScript
struct npc_pet_shaman_earth_elemental : public ScriptedAI
{
public:
npc_pet_shaman_earth_elemental() : CreatureScript("npc_pet_shaman_earth_elemental") { }
npc_pet_shaman_earth_elemental(Creature* creature) : ScriptedAI(creature), _initAttack(true) { }
struct npc_pet_shaman_earth_elementalAI : public ScriptedAI
void EnterCombat(Unit*) override
{
npc_pet_shaman_earth_elementalAI(Creature* creature) : ScriptedAI(creature), _initAttack(true) { }
void EnterCombat(Unit*) override
{
_events.Reset();
_events.ScheduleEvent(EVENT_SHAMAN_ANGEREDEARTH, 0);
}
void InitializeAI() override { }
void UpdateAI(uint32 diff) override
{
if (_initAttack)
{
if (!me->IsInCombat())
if (Player* owner = me->GetCharmerOrOwnerPlayerOrPlayerItself())
if (Unit* target = owner->GetSelectedUnit())
if (me->_CanDetectFeignDeathOf(target) && me->CanCreatureAttack(target))
AttackStart(target);
_initAttack = false;
}
if (!UpdateVictim())
return;
_events.Update(diff);
if (_events.ExecuteEvent() == EVENT_SHAMAN_ANGEREDEARTH)
{
DoCastVictim(SPELL_SHAMAN_ANGEREDEARTH);
_events.ScheduleEvent(EVENT_SHAMAN_ANGEREDEARTH, urand(5000, 20000));
}
DoMeleeAttackIfReady();
}
private:
EventMap _events;
bool _initAttack;
};
CreatureAI* GetAI(Creature* creature) const override
{
return new npc_pet_shaman_earth_elementalAI(creature);
_events.Reset();
_events.ScheduleEvent(EVENT_SHAMAN_ANGEREDEARTH, 0);
}
void InitializeAI() override { }
void UpdateAI(uint32 diff) override
{
if (_initAttack)
{
if (!me->IsInCombat())
if (Player* owner = me->GetCharmerOrOwnerPlayerOrPlayerItself())
if (Unit* target = owner->GetSelectedUnit())
if (me->_CanDetectFeignDeathOf(target) && me->CanCreatureAttack(target))
AttackStart(target);
_initAttack = false;
}
if (!UpdateVictim())
return;
_events.Update(diff);
if (_events.ExecuteEvent() == EVENT_SHAMAN_ANGEREDEARTH)
{
DoCastVictim(SPELL_SHAMAN_ANGEREDEARTH);
_events.ScheduleEvent(EVENT_SHAMAN_ANGEREDEARTH, urand(5000, 20000));
}
DoMeleeAttackIfReady();
}
private:
EventMap _events;
bool _initAttack;
};
class npc_pet_shaman_fire_elemental : public CreatureScript
struct npc_pet_shaman_fire_elemental : public ScriptedAI
{
public:
npc_pet_shaman_fire_elemental() : CreatureScript("npc_pet_shaman_fire_elemental") { }
npc_pet_shaman_fire_elemental(Creature* creature) : ScriptedAI(creature), _initAttack(true) { }
struct npc_pet_shaman_fire_elementalAI : public ScriptedAI
void InitializeAI() override { }
void EnterCombat(Unit*) override
{
npc_pet_shaman_fire_elementalAI(Creature* creature) : ScriptedAI(creature), _initAttack(true) { }
_events.Reset();
_events.ScheduleEvent(EVENT_SHAMAN_FIRENOVA, urand(5000, 20000));
_events.ScheduleEvent(EVENT_SHAMAN_FIREBLAST, urand(5000, 20000));
//_events.ScheduleEvent(EVENT_SHAMAN_FIRESHIELD, 0);
void InitializeAI() override { }
void EnterCombat(Unit*) override
{
_events.Reset();
_events.ScheduleEvent(EVENT_SHAMAN_FIRENOVA, urand(5000, 20000));
_events.ScheduleEvent(EVENT_SHAMAN_FIREBLAST, urand(5000, 20000));
//_events.ScheduleEvent(EVENT_SHAMAN_FIRESHIELD, 0);
me->RemoveAurasDueToSpell(SPELL_SHAMAN_FIRESHIELD);
me->CastSpell(me, SPELL_SHAMAN_FIRESHIELD, true);
}
void UpdateAI(uint32 diff) override
{
if (_initAttack)
{
if (!me->IsInCombat())
if (Player* owner = me->GetCharmerOrOwnerPlayerOrPlayerItself())
if (Unit* target = owner->GetSelectedUnit())
if (me->_CanDetectFeignDeathOf(target) && me->CanCreatureAttack(target))
AttackStart(target);
_initAttack = false;
}
if (!UpdateVictim())
return;
_events.Update(diff);
while (uint32 eventId = _events.ExecuteEvent())
{
switch (eventId)
{
case EVENT_SHAMAN_FIRENOVA:
me->CastSpell(me, SPELL_SHAMAN_FIRENOVA, false);
_events.ScheduleEvent(EVENT_SHAMAN_FIRENOVA, urand(8000, 15000));
break;
case EVENT_SHAMAN_FIREBLAST:
me->CastSpell(me->GetVictim(), SPELL_SHAMAN_FIREBLAST, false);
_events.ScheduleEvent(EVENT_SHAMAN_FIREBLAST, urand(4000, 8000));
break;
default:
break;
}
}
DoMeleeAttackIfReady();
}
private:
EventMap _events;
bool _initAttack;
};
CreatureAI* GetAI(Creature* creature) const override
{
return new npc_pet_shaman_fire_elementalAI(creature);
me->RemoveAurasDueToSpell(SPELL_SHAMAN_FIRESHIELD);
me->CastSpell(me, SPELL_SHAMAN_FIRESHIELD, true);
}
void UpdateAI(uint32 diff) override
{
if (_initAttack)
{
if (!me->IsInCombat())
if (Player* owner = me->GetCharmerOrOwnerPlayerOrPlayerItself())
if (Unit* target = owner->GetSelectedUnit())
if (me->_CanDetectFeignDeathOf(target) && me->CanCreatureAttack(target))
AttackStart(target);
_initAttack = false;
}
if (!UpdateVictim())
return;
_events.Update(diff);
while (uint32 eventId = _events.ExecuteEvent())
{
switch (eventId)
{
case EVENT_SHAMAN_FIRENOVA:
me->CastSpell(me, SPELL_SHAMAN_FIRENOVA, false);
_events.ScheduleEvent(EVENT_SHAMAN_FIRENOVA, urand(8000, 15000));
break;
case EVENT_SHAMAN_FIREBLAST:
me->CastSpell(me->GetVictim(), SPELL_SHAMAN_FIREBLAST, false);
_events.ScheduleEvent(EVENT_SHAMAN_FIREBLAST, urand(4000, 8000));
break;
default:
break;
}
}
DoMeleeAttackIfReady();
}
private:
EventMap _events;
bool _initAttack;
};
void AddSC_shaman_pet_scripts()
{
new npc_pet_shaman_earth_elemental();
new npc_pet_shaman_fire_elemental();
RegisterCreatureAI(npc_pet_shaman_earth_elemental);
RegisterCreatureAI(npc_pet_shaman_fire_elemental);
}