Scripts/Pet: Update pet scripts to new register model (1/2) (#26661)

(cherry picked from commit 51c94fed9a87652b6c0372b20a54ecd51beb1a06)
This commit is contained in:
offl
2022-03-11 15:25:17 +01:00
committed by Shauren
parent 779053ab90
commit 72ea274df8
3 changed files with 215 additions and 259 deletions
+77 -88
View File
@@ -37,104 +37,93 @@ enum HunterCreatures
NPC_HUNTER_VIPER = 19921
};
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), _isViper(false), _spellTimer(0) { }
struct npc_pet_hunter_snake_trapAI : public ScriptedAI
{
npc_pet_hunter_snake_trapAI(Creature* creature) : ScriptedAI(creature), _isViper(false), _spellTimer(0) { }
void JustEngagedWith(Unit* /*who*/) override { }
void JustEngagedWith(Unit* /*who*/) override { }
void JustAppeared() override
{
_isViper = me->GetEntry() == NPC_HUNTER_VIPER ? true : false;
void JustAppeared() override
{
_isViper = me->GetEntry() == NPC_HUNTER_VIPER ? true : false;
me->SetMaxHealth(uint32(107 * (me->GetLevel() - 40) * 0.025f));
// Add delta to make them not all hit the same time
me->SetBaseAttackTime(BASE_ATTACK, me->GetBaseAttackTime(BASE_ATTACK) + urandms(0,6));
me->SetMaxHealth(uint32(107 * (me->GetLevel() - 40) * 0.025f));
// Add delta to make them not all hit the same time
me->SetBaseAttackTime(BASE_ATTACK, me->GetBaseAttackTime(BASE_ATTACK) + urandms(0,6));
if (!_isViper && !me->HasAura(SPELL_HUNTER_DEADLY_POISON_PASSIVE))
DoCast(me, SPELL_HUNTER_DEADLY_POISON_PASSIVE, true);
}
if (!_isViper && !me->HasAura(SPELL_HUNTER_DEADLY_POISON_PASSIVE))
DoCast(me, SPELL_HUNTER_DEADLY_POISON_PASSIVE, true);
}
// Redefined for random target selection:
void MoveInLineOfSight(Unit* /*who*/) override { }
// Redefined for random target selection:
void MoveInLineOfSight(Unit* /*who*/) override { }
void UpdateAI(uint32 diff) override
{
if (me->GetVictim() && me->GetVictim()->HasBreakableByDamageCrowdControlAura())
{ // don't break cc
me->GetThreatManager().ClearFixate();
me->InterruptNonMeleeSpells(false);
me->AttackStop();
return;
}
if (me->IsSummon() && !me->GetThreatManager().GetFixateTarget())
{ // find new target
Unit* summoner = me->ToTempSummon()->GetSummonerUnit();
std::vector<Unit*> targets;
auto addTargetIfValid = [this, &targets, summoner](CombatReference* ref) mutable
{
Unit* enemy = ref->GetOther(summoner);
if (!enemy->HasBreakableByDamageCrowdControlAura() && me->CanCreatureAttack(enemy) && me->IsWithinDistInMap(enemy, me->GetAttackDistance(enemy)))
targets.push_back(enemy);
};
for (std::pair<ObjectGuid const, PvPCombatReference*> const& pair : summoner->GetCombatManager().GetPvPCombatRefs())
addTargetIfValid(pair.second);
if (targets.empty())
for (std::pair<ObjectGuid const, CombatReference*> const& pair : summoner->GetCombatManager().GetPvECombatRefs())
addTargetIfValid(pair.second);
for (Unit* target : targets)
me->EngageWithTarget(target);
if (!targets.empty())
{
Unit* target = Trinity::Containers::SelectRandomContainerElement(targets);
me->GetThreatManager().FixateTarget(target);
}
}
if (!UpdateVictim())
return;
// Viper
if (_isViper)
{
if (_spellTimer <= diff)
{
if (!urand(0, 2)) // 33% chance to cast
DoCastVictim(RAND(SPELL_HUNTER_MIND_NUMBING_POISON, SPELL_HUNTER_CRIPPLING_POISON));
_spellTimer = 3000;
}
else
_spellTimer -= diff;
}
DoMeleeAttackIfReady();
}
private:
bool _isViper;
uint32 _spellTimer;
};
CreatureAI* GetAI(Creature* creature) const override
{
return new npc_pet_hunter_snake_trapAI(creature);
void UpdateAI(uint32 diff) override
{
if (me->GetVictim() && me->GetVictim()->HasBreakableByDamageCrowdControlAura())
{ // don't break cc
me->GetThreatManager().ClearFixate();
me->InterruptNonMeleeSpells(false);
me->AttackStop();
return;
}
if (me->IsSummon() && !me->GetThreatManager().GetFixateTarget())
{ // find new target
Unit* summoner = me->ToTempSummon()->GetSummonerUnit();
std::vector<Unit*> targets;
auto addTargetIfValid = [this, &targets, summoner](CombatReference* ref) mutable
{
Unit* enemy = ref->GetOther(summoner);
if (!enemy->HasBreakableByDamageCrowdControlAura() && me->CanCreatureAttack(enemy) && me->IsWithinDistInMap(enemy, me->GetAttackDistance(enemy)))
targets.push_back(enemy);
};
for (std::pair<ObjectGuid const, PvPCombatReference*> const& pair : summoner->GetCombatManager().GetPvPCombatRefs())
addTargetIfValid(pair.second);
if (targets.empty())
for (std::pair<ObjectGuid const, CombatReference*> const& pair : summoner->GetCombatManager().GetPvECombatRefs())
addTargetIfValid(pair.second);
for (Unit* target : targets)
me->EngageWithTarget(target);
if (!targets.empty())
{
Unit* target = Trinity::Containers::SelectRandomContainerElement(targets);
me->GetThreatManager().FixateTarget(target);
}
}
if (!UpdateVictim())
return;
// Viper
if (_isViper)
{
if (_spellTimer <= diff)
{
if (!urand(0, 2)) // 33% chance to cast
DoCastVictim(RAND(SPELL_HUNTER_MIND_NUMBING_POISON, SPELL_HUNTER_CRIPPLING_POISON));
_spellTimer = 3000;
}
else
_spellTimer -= diff;
}
DoMeleeAttackIfReady();
}
private:
bool _isViper;
uint32 _spellTimer;
};
void AddSC_hunter_pet_scripts()
{
new npc_pet_hunter_snake_trap();
RegisterCreatureAI(npc_pet_hunter_snake_trap);
}