mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-24 02:46:33 +01:00
Scripts/Pets: Some cleanup for Snake Trap. Tagging #21847, though this doesn't address it (yet).
This commit is contained in:
@@ -56,81 +56,74 @@ class npc_pet_hunter_snake_trap : public CreatureScript
|
||||
|
||||
struct npc_pet_hunter_snake_trapAI : public ScriptedAI
|
||||
{
|
||||
npc_pet_hunter_snake_trapAI(Creature* creature) : ScriptedAI(creature)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
_spellTimer = 0;
|
||||
_isViper = false;
|
||||
}
|
||||
npc_pet_hunter_snake_trapAI(Creature* creature) : ScriptedAI(creature), _isViper(false), _spellTimer(0) { }
|
||||
|
||||
void JustEngagedWith(Unit* /*who*/) override { }
|
||||
|
||||
void Reset() override
|
||||
{
|
||||
Initialize();
|
||||
|
||||
CreatureTemplate const* Info = me->GetCreatureTemplate();
|
||||
|
||||
_isViper = Info->Entry == NPC_HUNTER_VIPER ? true : false;
|
||||
_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
|
||||
uint32 delta = (rand32() % 7) * 100;
|
||||
me->SetAttackTime(BASE_ATTACK, Info->BaseAttackTime + delta);
|
||||
//me->SetStatFloatValue(UNIT_FIELD_RANGED_ATTACK_POWER, float(Info->attackpower));
|
||||
me->SetAttackTime(BASE_ATTACK, me->GetAttackTime(BASE_ATTACK) + urandms(0,6));
|
||||
|
||||
// Start attacking attacker of owner on first ai update after spawn - move in line of sight may choose better target
|
||||
if (!me->GetVictim() && me->IsSummon())
|
||||
if (Unit* Owner = me->ToTempSummon()->GetSummoner())
|
||||
if (Owner->getAttackerForHelper())
|
||||
AttackStart(Owner->getAttackerForHelper());
|
||||
|
||||
if (!_isViper)
|
||||
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
|
||||
{
|
||||
if (!me->GetVictim() && me->CanCreatureAttack(who))
|
||||
{
|
||||
if (me->GetDistanceZ(who) > CREATURE_Z_ATTACK_RANGE)
|
||||
return;
|
||||
|
||||
float attackRadius = me->GetAttackDistance(who);
|
||||
if (me->IsWithinDistInMap(who, attackRadius) && me->IsWithinLOSInMap(who))
|
||||
{
|
||||
if (!(rand32() % 5))
|
||||
{
|
||||
me->setAttackTimer(BASE_ATTACK, (rand32() % 10) * 100);
|
||||
_spellTimer = (rand32() % 10) * 100;
|
||||
AttackStart(who);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void MoveInLineOfSight(Unit* who) override { }
|
||||
|
||||
void UpdateAI(uint32 diff) override
|
||||
{
|
||||
if (!UpdateVictim() || !me->GetVictim())
|
||||
return;
|
||||
|
||||
if (me->EnsureVictim()->HasBreakableByDamageCrowdControlAura(me))
|
||||
{
|
||||
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()->GetSummoner();
|
||||
|
||||
std::vector<Unit*> targets;
|
||||
for (std::pair<ObjectGuid const, PvPCombatReference*> const& pair : summoner->GetCombatManager().GetPvPCombatRefs())
|
||||
{
|
||||
Unit* enemy = pair.second->GetOther(summoner);
|
||||
if (!enemy->HasBreakableByDamageCrowdControlAura() && me->CanCreatureAttack(enemy) && me->IsWithinDistInMap(enemy, me->GetAttackDistance(enemy)))
|
||||
targets.push_back(enemy);
|
||||
}
|
||||
|
||||
if (targets.empty())
|
||||
for (std::pair<ObjectGuid const, CombatReference*> const& pair : summoner->GetCombatManager().GetPvECombatRefs())
|
||||
{
|
||||
Unit* enemy = pair.second->GetOther(summoner);
|
||||
if (!enemy->HasBreakableByDamageCrowdControlAura() && me->CanCreatureAttack(enemy) && me->IsWithinDistInMap(enemy, me->GetAttackDistance(enemy)))
|
||||
targets.push_back(enemy);
|
||||
}
|
||||
|
||||
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) == 0) // 33% chance to cast
|
||||
if (!urand(0, 2)) // 33% chance to cast
|
||||
DoCastVictim(RAND(SPELL_HUNTER_MIND_NUMBING_POISON, SPELL_HUNTER_CRIPPLING_POISON));
|
||||
|
||||
_spellTimer = 3000;
|
||||
|
||||
Reference in New Issue
Block a user