TrinityCore
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 "TemporarySummon.h"
28
30{
32 SPELL_HUNTER_DEADLY_POISON_PASSIVE = 34657, // Venomous Snake
34};
35
37{
38 NPC_HUNTER_VIPER = 19921
39};
40
42{
43 npc_pet_hunter_snake_trap(Creature* creature) : ScriptedAI(creature), _isViper(false), _spellTimer(0) { }
44
45 void JustEngagedWith(Unit* /*who*/) override { }
46
47 void JustAppeared() override
48 {
49 _isViper = me->GetEntry() == NPC_HUNTER_VIPER ? true : false;
50
51 me->SetMaxHealth(uint32(107 * (me->GetLevel() - 40) * 0.025f));
52 // Add delta to make them not all hit the same time
54
57 }
58
59 // Redefined for random target selection:
60 void MoveInLineOfSight(Unit* /*who*/) override { }
61
62 void UpdateAI(uint32 diff) override
63 {
65 { // don't break cc
68 me->AttackStop();
69 return;
70 }
71
73 { // find new target
74 Unit* summoner = me->ToTempSummon()->GetSummonerUnit();
75
76 std::vector<Unit*> targets;
77
78 auto addTargetIfValid = [this, &targets, summoner](CombatReference* ref) mutable
79 {
80 Unit* enemy = ref->GetOther(summoner);
82 targets.push_back(enemy);
83 };
84
85 for (std::pair<ObjectGuid const, PvPCombatReference*> const& pair : summoner->GetCombatManager().GetPvPCombatRefs())
86 addTargetIfValid(pair.second);
87
88 if (targets.empty())
89 for (std::pair<ObjectGuid const, CombatReference*> const& pair : summoner->GetCombatManager().GetPvECombatRefs())
90 addTargetIfValid(pair.second);
91
92 for (Unit* target : targets)
93 me->EngageWithTarget(target);
94
95 if (!targets.empty())
96 {
99 }
100 }
101
102 if (!UpdateVictim())
103 return;
104
105 // Viper
106 if (_isViper)
107 {
108 if (_spellTimer <= diff)
109 {
110 if (!urand(0, 2)) // 33% chance to cast
112
113 _spellTimer = 3000;
114 }
115 else
116 _spellTimer -= diff;
117 }
118 }
119
120private:
123};
124
126{
128}
First const & RAND(First const &first, Second const &second, Rest const &... rest)
uint32_t uint32
Definition: Define.h:142
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:1380
@ BASE_ATTACK
std::unordered_map< ObjectGuid, PvPCombatReference * > const & GetPvPCombatRefs() const
std::unordered_map< ObjectGuid, CombatReference * > const & GetPvECombatRefs() const
bool UpdateVictim()
Definition: CreatureAI.cpp:245
Creature *const me
Definition: CreatureAI.h:61
float GetAttackDistance(Unit const *player) const
Definition: Creature.cpp:2153
bool CanCreatureAttack(Unit const *victim, bool force=true) const
Definition: Creature.cpp:2686
uint32 GetEntry() const
Definition: Object.h:161
Unit * GetSummonerUnit() const
void ClearFixate()
void FixateTarget(Unit *target)
Unit * GetFixateTarget() const
SpellCastResult DoCastVictim(uint32 spellId, CastSpellExtraArgs const &args={})
Definition: UnitAI.cpp:180
SpellCastResult DoCast(uint32 spellId)
Definition: UnitAI.cpp:89
Definition: Unit.h:627
ThreatManager & GetThreatManager()
Definition: Unit.h:1063
bool HasBreakableByDamageCrowdControlAura(Unit *excludeCasterChannel=nullptr) const
Definition: Unit.cpp:734
void InterruptNonMeleeSpells(bool withDelayed, uint32 spellid=0, bool withInstant=true)
Definition: Unit.cpp:3089
uint32 GetBaseAttackTime(WeaponAttackType att) const
Definition: Unit.cpp:10303
TempSummon * ToTempSummon()
Definition: Unit.h:1756
void SetBaseAttackTime(WeaponAttackType att, uint32 val)
Definition: Unit.cpp:10308
bool IsSummon() const
Definition: Unit.h:738
void EngageWithTarget(Unit *who)
Definition: Unit.cpp:8077
void SetMaxHealth(uint64 val)
Definition: Unit.cpp:9377
Unit * GetVictim() const
Definition: Unit.h:715
bool HasAura(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, ObjectGuid itemCasterGUID=ObjectGuid::Empty, uint32 reqEffMask=0) const
Definition: Unit.cpp:4664
CombatManager & GetCombatManager()
Definition: Unit.h:1023
bool AttackStop()
Definition: Unit.cpp:5781
uint8 GetLevel() const
Definition: Unit.h:746
bool IsWithinDistInMap(WorldObject const *obj, float dist2compare, bool is3D=true, bool incOwnRadius=true, bool incTargetRadius=true) const
Definition: Object.cpp:1147
auto SelectRandomContainerElement(C const &container) -> typename std::add_const< decltype(*std::begin(container))>::type &
Definition: Containers.h:109
@ SPELL_HUNTER_CRIPPLING_POISON
Definition: pet_hunter.cpp:31
@ SPELL_HUNTER_DEADLY_POISON_PASSIVE
Definition: pet_hunter.cpp:32
@ SPELL_HUNTER_MIND_NUMBING_POISON
Definition: pet_hunter.cpp:33
HunterCreatures
Definition: pet_hunter.cpp:37
@ NPC_HUNTER_VIPER
Definition: pet_hunter.cpp:38
void AddSC_hunter_pet_scripts()
Definition: pet_hunter.cpp:125
void MoveInLineOfSight(Unit *) override
Definition: pet_hunter.cpp:60
void UpdateAI(uint32 diff) override
Definition: pet_hunter.cpp:62
void JustEngagedWith(Unit *) override
Definition: pet_hunter.cpp:45
void JustAppeared() override
Definition: pet_hunter.cpp:47
npc_pet_hunter_snake_trap(Creature *creature)
Definition: pet_hunter.cpp:43