summaryrefslogtreecommitdiff
path: root/src/scripts/Pet/pet_hunter.cpp
blob: ed59a2491eb8f69bbc8ce20337cec900f90876f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
 * Copyright (C) 2016+     AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license: http://github.com/azerothcore/azerothcore-wotlk/LICENSE-GPL2
 * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
 */

/*
 * Ordered alphabetically using scriptname.
 * Scriptnames of files in this file should be prefixed with "npc_pet_hun_".
 */

#include "ScriptMgr.h"
#include "ScriptPCH.h"
#include "ScriptedCreature.h"

enum HunterSpells
{
    SPELL_HUNTER_CRIPPLING_POISON       = 30981, // Viper
    SPELL_HUNTER_DEADLY_POISON_PASSIVE  = 34657, // Venomous Snake
    SPELL_HUNTER_MIND_NUMBING_POISON    = 25810, // Viper
    SPELL_HUNTER_GLYPH_OF_SNAKE_TRAP    = 56849,
    SPELL_HUNTER_PET_SCALING            = 62915
};

enum HunterCreatures
{
    NPC_HUNTER_VIPER                    = 19921
};

class npc_pet_hunter_snake_trap : public CreatureScript
{
    public:
        npc_pet_hunter_snake_trap() : CreatureScript("npc_pet_hunter_snake_trap") { }

        struct npc_pet_hunter_snake_trapAI : public ScriptedAI
        {
            npc_pet_hunter_snake_trapAI(Creature* creature) : ScriptedAI(creature) { _init = false; }

            void Reset()
            {
                _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()
            {
                // _EnterEvadeMode();
                me->DeleteThreatList();
                me->CombatStop(true);
                me->LoadCreaturesAddon(true);
                me->SetLootRecipient(NULL);
                me->ResetPlayerDamageReq();
                me->SetLastDamagedTime(0); 
                
                me->AddUnitState(UNIT_STATE_EVADE);
                me->GetMotionMaster()->MoveTargetedHome();

                Reset();
            }

            //Redefined for random target selection:
            void MoveInLineOfSight(Unit* who)
            {
                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)
            {
                if (!UpdateVictim())
                    return;

                if (me->GetVictim()->HasBreakableByDamageCrowdControlAura(me))
                {
                    me->InterruptNonMeleeSpells(false);
                    return;
                }

                if (!_init)
                {
                    _init = true;

                    CreatureTemplate const* Info = me->GetCreatureTemplate();
                    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(Info->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
        {
            return new npc_pet_hunter_snake_trapAI(creature);
        }
};

void AddSC_hunter_pet_scripts()
{
    new npc_pet_hunter_snake_trap();
}