Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
pet_hunter.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6/*
7 * Ordered alphabetically using scriptname.
8 * Scriptnames of files in this file should be prefixed with "npc_pet_hun_".
9 */
10
11#include "ScriptMgr.h"
12#include "ScriptedCreature.h"
13
15{
17 SPELL_HUNTER_DEADLY_POISON = 34655, // Venomous Snake
19};
20
25
27{
28 public:
29 npc_pet_hunter_snake_trap() : CreatureScript("npc_pet_hunter_snake_trap") { }
30
32 {
34
35 void EnterCombat(Unit* /*who*/) OVERRIDE { }
36
38 {
39 _spellTimer = 0;
40
41 CreatureTemplate const* Info = me->GetCreatureTemplate();
42
43 _isViper = Info->Entry == NPC_HUNTER_VIPER ? true : false;
44
45 me->SetMaxHealth(uint32(107 * (me->getLevel() - 40) * 0.025f));
46 // Add delta to make them not all hit the same time
47 uint32 delta = (rand() % 7) * 100;
48 me->SetStatFloatValue(UNIT_FIELD_ATTACK_ROUND_BASE_TIME, float(Info->baseattacktime + delta));
49 me->SetStatFloatValue(UNIT_FIELD_RANGED_ATTACK_POWER, float(Info->attackpower));
50
51 // Start attacking attacker of owner on first ai update after spawn - move in line of sight may choose better target
52 if (!me->GetVictim() && me->IsSummon())
53 if (Unit* Owner = me->ToTempSummon()->GetSummoner())
54 if (Owner->getAttackerForHelper())
55 AttackStart(Owner->getAttackerForHelper());
56 }
57
58 // Redefined for random target selection:
60 {
61 if (!me->GetVictim() && me->CanCreatureAttack(who))
62 {
63 if (me->GetDistanceZ(who) > CREATURE_Z_ATTACK_RANGE)
64 return;
65
66 float attackRadius = me->GetAttackDistance(who);
67 if (me->IsWithinDistInMap(who, attackRadius) && me->IsWithinLOSInMap(who))
68 {
69 if (!(rand() % 5))
70 {
71 me->setAttackTimer(WeaponAttackType::BASE_ATTACK, (rand() % 10) * 100);
72 _spellTimer = (rand() % 10) * 100;
73 AttackStart(who);
74 }
75 }
76 }
77 }
78
80 {
81 if (!UpdateVictim())
82 return;
83
84 if (me->GetVictim()->HasBreakableByDamageCrowdControlAura(me))
85 {
86 me->InterruptNonMeleeSpells(false);
87 return;
88 }
89
90 if (_spellTimer <= diff)
91 {
92 if (_isViper) // Viper
93 {
94 if ((std::rand() % 2) == 0) //33% chance to cast
95 {
96 uint32 spell;
97 if ((std::rand() % 1) == 0)
99 else
101
102 DoCastVictim(spell);
103 }
104
105 _spellTimer = 3000;
106 }
107 else // Venomous Snake
108 {
109 if ((std::rand() % 2) == 0) // 33% chance to cast
111 _spellTimer = 1500 + (rand() % 5) * 100;
112 }
113 }
114 else
115 _spellTimer -= diff;
116
118 }
119
120 private:
123 };
124
126 {
127 return new npc_pet_hunter_snake_trapAI(creature);
128 }
129};
130
#define CREATURE_Z_ATTACK_RANGE
Definition Creature.h:422
std::uint32_t uint32
Definition Define.h:77
#define OVERRIDE
Definition Define.h:60
@ UNIT_FIELD_ATTACK_ROUND_BASE_TIME
@ UNIT_FIELD_RANGED_ATTACK_POWER
bool UpdateVictim()
CreatureScript(const char *name)
void DoMeleeAttackIfReady()
Definition UnitAI.cpp:28
void DoCastVictim(uint32 spellId, bool triggered=false)
Definition UnitAI.cpp:168
Definition Unit.h:1367
CreatureAI * GetAI(Creature *creature) const OVERRIDE
@ SPELL_HUNTER_CRIPPLING_POISON
@ SPELL_HUNTER_DEADLY_POISON
@ SPELL_HUNTER_MIND_NUMBING_POISON
HunterCreatures
@ NPC_HUNTER_VIPER
void AddSC_hunter_pet_scripts()
uint32 attackpower
Definition Creature.h:89
uint32 baseattacktime
Definition Creature.h:91
Creature * me
ScriptedAI(Creature *creature)
void AttackStart(Unit *) OVERRIDE
void UpdateAI(uint32 diff) OVERRIDE
== Triggered Actions Requested ==================