TrinityCore
Loading...
Searching...
No Matches
pet_hunter.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18/*
19 * Ordered alphabetically using scriptname.
20 * Scriptnames of files in this file should be prefixed with "npc_pet_hun_".
21 */
22
23#include "ScriptMgr.h"
24#include "Containers.h"
25#include "CreatureAIImpl.h"
26#include "ScriptedCreature.h"
27#include "SpellScript.h"
28#include "SpellAuraEffects.h"
29#include "TemporarySummon.h"
30
32{
34 SPELL_HUNTER_DEADLY_POISON_PASSIVE = 34657, // Venomous Snake
36};
37
42
57
59{
60 npc_pet_hunter_snake_trap(Creature* creature) : ScriptedAI(creature), _isViper(false), _spellTimer(0) { }
61
62 void JustEngagedWith(Unit* /*who*/) override { }
63
64 void JustAppeared() override
65 {
66 _isViper = me->GetEntry() == NPC_HUNTER_VIPER ? true : false;
67
68 me->SetMaxHealth(uint32(107 * (me->GetLevel() - 40) * 0.025f));
69 // Add delta to make them not all hit the same time
71
74 }
75
76 // Redefined for random target selection:
77 void MoveInLineOfSight(Unit* /*who*/) override { }
78
79 void UpdateAI(uint32 diff) override
80 {
82 { // don't break cc
85 me->AttackStop();
86 return;
87 }
88
90 { // find new target
91 Unit* summoner = me->ToTempSummon()->GetSummonerUnit();
92
93 std::vector<Unit*> targets;
94
95 auto addTargetIfValid = [this, &targets, summoner](CombatReference* ref) mutable
96 {
97 Unit* enemy = ref->GetOther(summoner);
99 targets.push_back(enemy);
100 };
101
102 for (std::pair<ObjectGuid const, PvPCombatReference*> const& pair : summoner->GetCombatManager().GetPvPCombatRefs())
103 addTargetIfValid(pair.second);
104
105 if (targets.empty())
106 for (std::pair<ObjectGuid const, CombatReference*> const& pair : summoner->GetCombatManager().GetPvECombatRefs())
107 addTargetIfValid(pair.second);
108
109 for (Unit* target : targets)
110 me->EngageWithTarget(target);
111
112 if (!targets.empty())
113 {
116 }
117 }
118
119 if (!UpdateVictim())
120 return;
121
122 // Viper
123 if (_isViper)
124 {
125 if (_spellTimer <= diff)
126 {
127 if (!urand(0, 2)) // 33% chance to cast
129
130 _spellTimer = 3000;
131 }
132 else
133 _spellTimer -= diff;
134 }
135
137 }
138
139private:
142};
143
144// 57627 - Charge
146{
148
149 bool Validate(SpellInfo const* /*spellInfo*/) override
150 {
151 return ValidateSpellInfo(
152 {
155 });
156 }
157
158 void HandleDummy(AuraEffect const* /*aurEff*/, ProcEventInfo& eventInfo)
159 {
161
162 // Remove +% AP aura
163 Unit* pet = eventInfo.GetActor();
164 Aura* aura = pet->GetAura(SPELL_PET_SWOOP, pet->GetGUID());
165 if (!aura)
166 aura = pet->GetAura(SPELL_PET_CHARGE, pet->GetGUID());
167
168 if (!aura)
169 return;
170
172 }
173
178};
179
180// -53178 - Guard Dog
182{
184
185 bool Validate(SpellInfo const* /*spellInfo*/) override
186 {
188 }
189
190 bool CheckProc(ProcEventInfo& eventInfo)
191 {
192 // Growl shares family flags with other spells
193 // filter by spellIcon instead
194 SpellInfo const* spellInfo = eventInfo.GetSpellInfo();
195 if (!spellInfo || spellInfo->SpellIconID != PET_ICON_ID_GROWL)
196 return false;
197
198 return true;
199 }
200
201 void HandleProc(AuraEffect const* aurEff, ProcEventInfo& eventInfo)
202 {
204
205 Unit* caster = eventInfo.GetActor();
206 caster->CastSpell(nullptr, SPELL_PET_GUARD_DOG_HAPPINESS, aurEff);
207
208 Unit* target = eventInfo.GetActionTarget();
209 if (!target->CanHaveThreatList())
210 return;
211 float addThreat = CalculatePct(ASSERT_NOTNULL(eventInfo.GetSpellInfo())->GetEffect(EFFECT_0).CalcValue(caster), aurEff->GetAmount());
212 target->GetThreatManager().AddThreat(caster, addThreat, GetSpellInfo(), false, true);
213 }
214
220};
221
222// -62764 - Silverback
224{
226
227 bool Validate(SpellInfo const* /*spellInfo*/) override
228 {
230 }
231
232 bool CheckProc(ProcEventInfo& eventInfo)
233 {
234 // Growl shares family flags with other spells
235 // filter by spellIcon instead
236 SpellInfo const* spellInfo = eventInfo.GetSpellInfo();
237 if (!spellInfo || spellInfo->SpellIconID != PET_ICON_ID_GROWL)
238 return false;
239
240 return true;
241 }
242
243 void HandleProc(AuraEffect const* aurEff, ProcEventInfo& eventInfo)
244 {
245 static uint32 const triggerSpell[2] = { SPELL_PET_SILVERBACK_RANK_1, SPELL_PET_SILVERBACK_RANK_2 };
246
248
249 uint32 spellId = triggerSpell[GetSpellInfo()->GetRank() - 1];
250 eventInfo.GetActor()->CastSpell(nullptr, spellId, aurEff);
251 }
252
258};
259
260// -61680 - Culling the Herd
262{
264
265 bool CheckProc(ProcEventInfo& eventInfo)
266 {
267 // Claw, Bite and Smack share FamilyFlags with other spells
268 // filter by spellIcon instead
269 SpellInfo const* spellInfo = eventInfo.GetSpellInfo();
270 if (!spellInfo)
271 return false;
272
273 switch (spellInfo->SpellIconID)
274 {
275 case PET_ICON_ID_CLAW:
276 case PET_ICON_ID_BITE:
278 break;
279 default:
280 return false;
281 }
282
283 return true;
284 }
285
290};
291
First const & RAND(First const &first, Second const &second, Rest const &... rest)
uint32_t uint32
Definition Define.h:133
#define ASSERT_NOTNULL(pointer)
Definition Errors.h:84
uint32 urand(uint32 min, uint32 max)
Definition Random.cpp:42
uint32 urandms(uint32 min, uint32 max)
Definition Random.cpp:49
#define RegisterCreatureAI(ai_name)
Definition ScriptMgr.h:1139
#define RegisterSpellScript(spell_script)
Definition ScriptMgr.h:1128
@ EFFECT_0
@ BASE_ATTACK
@ AURA_REMOVE_BY_EXPIRE
@ SPELL_AURA_DUMMY
#define AuraEffectProcFn(F, I, N)
#define AuraCheckProcFn(F)
T CalculatePct(T base, U pct)
Definition Util.h:71
int32 GetAmount() const
void PreventDefaultAction()
SpellInfo const * GetSpellInfo() const
HookList< CheckProcHandler > DoCheckProc
HookList< EffectProcHandler > OnEffectProc
bool DropCharge(AuraRemoveMode removeMode=AURA_REMOVE_BY_DEFAULT)
Definition SpellAuras.h:160
std::unordered_map< ObjectGuid, PvPCombatReference * > const & GetPvPCombatRefs() const
std::unordered_map< ObjectGuid, CombatReference * > const & GetPvECombatRefs() const
bool UpdateVictim()
Creature *const me
Definition CreatureAI.h:82
float GetAttackDistance(Unit const *player) const
bool CanCreatureAttack(Unit const *victim, bool force=true) const
uint32 GetEntry() const
Definition Object.h:81
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:78
Unit * GetActionTarget() const
Definition Unit.h:509
SpellInfo const * GetSpellInfo() const
Definition Unit.cpp:268
Unit * GetActor()
Definition Unit.h:508
uint8 GetRank() const
uint32 SpellIconID
Definition SpellInfo.h:349
Unit * GetSummonerUnit() const
void FixateTarget(Unit *target)
void AddThreat(Unit *target, float amount, SpellInfo const *spell=nullptr, bool ignoreModifiers=false, bool ignoreRedirects=false)
== AFFECT MY THREAT LIST ==
Unit * GetFixateTarget() const
void DoMeleeAttackIfReady()
Definition UnitAI.cpp:54
SpellCastResult DoCastVictim(uint32 spellId, CastSpellExtraArgs const &args={})
Definition UnitAI.cpp:166
SpellCastResult DoCast(uint32 spellId)
Definition UnitAI.cpp:106
Definition Unit.h:769
Aura * GetAura(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, ObjectGuid itemCasterGUID=ObjectGuid::Empty, uint8 reqEffMask=0) const
Definition Unit.cpp:4439
bool CanHaveThreatList() const
====================== THREAT & COMBAT ====================
Definition Unit.h:1122
ThreatManager & GetThreatManager()
Definition Unit.h:1155
bool HasBreakableByDamageCrowdControlAura(Unit *excludeCasterChannel=nullptr) const
Definition Unit.cpp:693
void InterruptNonMeleeSpells(bool withDelayed, uint32 spellid=0, bool withInstant=true)
Definition Unit.cpp:3093
TempSummon * ToTempSummon()
Definition Unit.h:1794
bool HasAura(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, ObjectGuid itemCasterGUID=ObjectGuid::Empty, uint8 reqEffMask=0) const
Definition Unit.cpp:4535
bool IsSummon() const
Definition Unit.h:882
void EngageWithTarget(Unit *who)
Definition Unit.cpp:8292
uint32 GetAttackTime(WeaponAttackType att) const
Definition Unit.cpp:8471
Unit * GetVictim() const
Definition Unit.h:859
void SetMaxHealth(uint32 val)
Definition Unit.cpp:9393
CombatManager & GetCombatManager()
Definition Unit.h:1130
void SetAttackTime(WeaponAttackType att, uint32 val)
Definition Unit.h:946
bool AttackStop()
Definition Unit.cpp:5645
uint8 GetLevel() const
Definition Unit.h:889
SpellCastResult CastSpell(CastSpellTargetArg const &targets, uint32 spellId, CastSpellExtraArgs const &args={ })
Definition Object.cpp:2832
bool IsWithinDistInMap(WorldObject const *obj, float dist2compare, bool is3D=true, bool incOwnRadius=true, bool incTargetRadius=true) const
Definition Object.cpp:1192
static bool ValidateSpellInfo(std::initializer_list< uint32 > spellIds)
PrepareAuraScript(spell_pet_charge)
void Register() override
void HandleDummy(AuraEffect const *, ProcEventInfo &eventInfo)
bool Validate(SpellInfo const *) override
bool CheckProc(ProcEventInfo &eventInfo)
PrepareAuraScript(spell_pet_culling_the_herd)
bool Validate(SpellInfo const *) override
void Register() override
PrepareAuraScript(spell_pet_guard_dog)
bool CheckProc(ProcEventInfo &eventInfo)
void HandleProc(AuraEffect const *aurEff, ProcEventInfo &eventInfo)
PrepareAuraScript(spell_pet_silverback)
bool CheckProc(ProcEventInfo &eventInfo)
bool Validate(SpellInfo const *) override
void HandleProc(AuraEffect const *aurEff, ProcEventInfo &eventInfo)
void Register() override
auto SelectRandomContainerElement(C const &container) -> typename std::add_const< decltype(*std::begin(container))>::type &
Definition Containers.h:108
@ SPELL_HUNTER_CRIPPLING_POISON
@ SPELL_HUNTER_DEADLY_POISON_PASSIVE
@ SPELL_HUNTER_MIND_NUMBING_POISON
HunterCreatures
@ NPC_HUNTER_VIPER
void AddSC_hunter_pet_scripts()
PetSpellsMisc
@ SPELL_PET_GUARD_DOG_HAPPINESS
@ PET_ICON_ID_BITE
@ PET_ICON_ID_GROWL
@ SPELL_PET_CHARGE
@ SPELL_PET_SILVERBACK_RANK_2
@ SPELL_PET_SWOOP
@ PET_ICON_ID_CLAW
@ PET_ICON_ID_SMACK
@ SPELL_PET_SILVERBACK_RANK_1
void MoveInLineOfSight(Unit *) override
void UpdateAI(uint32 diff) override
void JustEngagedWith(Unit *) override
void JustAppeared() override
npc_pet_hunter_snake_trap(Creature *creature)