OregonCore  revision be9e804-git
Your Favourite TBC server
TotemAI.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore 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 <https://www.gnu.org/licenses/>.
16  */
17 
18 #include "TotemAI.h"
19 #include "Totem.h"
20 #include "Creature.h"
21 #include "Player.h"
22 #include "MapManager.h"
23 #include "ObjectAccessor.h"
24 #include "SpellMgr.h"
25 
26 #include "GridNotifiers.h"
27 #include "GridNotifiersImpl.h"
28 #include "CellImpl.h"
29 
30 int
32 {
33  if (creature->IsTotem())
34  return PERMIT_BASE_PROACTIVE;
35 
36  return PERMIT_BASE_NO;
37 }
38 
40 {
41 }
42 
43 void
45 {
46 }
47 
49 {
51 }
52 
53 void
54 TotemAI::UpdateAI(const uint32 /*diff*/)
55 {
57  return;
58 
59  if (!i_totem.IsAlive() || i_totem.IsNonMeleeSpellCast(false))
60  return;
61 
62  // Search spell
63  SpellEntry const* spellInfo = sSpellStore.LookupEntry(i_totem.GetSpell());
64  if (!spellInfo)
65  return;
66 
67  // Get spell rangy
68  SpellRangeEntry const* srange = sSpellRangeStore.LookupEntry(spellInfo->rangeIndex);
69  float max_range = GetSpellMaxRange(srange);
70 
71  // SPELLMOD_RANGE not applied in this place just because not existence range mods for attacking totems
72 
73  // pointer to appropriate target if found any
75 
76  // Search victim if no, not attackable, or out of range, or friendly (possible in case duel end)
77  if (!victim ||
78  !victim->isTargetableForAttack() || !i_totem.IsWithinDistInMap(victim, max_range) ||
79  i_totem.IsFriendlyTo(victim) || !i_totem.CanSeeOrDetect(victim))
80  {
81  victim = NULL;
82 
85  i_totem.VisitNearbyObject(max_range, checker);
86  }
87 
88  // If have target
89  if (victim)
90  {
91  // remember
92  i_victimGuid = victim->GetGUID();
93 
94  // attack
95  i_totem.SetInFront(victim); // client change orientation by self
96  i_totem.CastSpell(victim, i_totem.GetSpell(), false);
97  }
98  else
99  i_victimGuid = 0;
100 }
101 
102 bool
104 {
105  return false;
106 }
107 
108 void
110 {
111  // Sentry totem sends ping on attack
113  {
114  WorldPacket data(MSG_MINIMAP_PING, (8 + 4 + 4));
115  data << i_totem.GetGUID();
116  data << i_totem.GetPositionX();
117  data << i_totem.GetPositionY();
119  }
120 }
121 
uint32 GetSpell(uint8 slot=0) const
Definition: Totem.h:40
TotemType GetTotemType() const
Definition: Totem.h:45
void UpdateAI(const uint32)
Definition: TotemAI.cpp:54
bool IsNonMeleeSpellCast(bool withDelayed, bool skipChanneled=false, bool skipAutorepeat=false) const
Definition: Unit.cpp:3578
#define SENTRY_TOTEM_ENTRY
Definition: Totem.h:29
void SendPacket(WorldPacket const *packet)
DBCStorage< SpellEntry > sSpellStore(SpellEntryfmt)
uint32 rangeIndex
Definition: DBCStructure.h:714
bool IsWithinDistInMap(WorldObject const *obj, float dist2compare, bool is3D=true) const
Definition: Object.h:750
void VisitNearbyObject(float const &radius, NOTIFIER &notifier) const
Definition: Object.h:884
Player * ToPlayer()
Definition: Object.h:368
void SetInFront(Unit const *target)
Definition: Unit.h:1675
void EnterEvadeMode()
Definition: TotemAI.cpp:48
Totem & i_totem
Definition: TotemAI.h:42
Definition: Totem.h:31
uint64 GetGUID() const
Definition: Object.h:177
Creature *const me
Definition: CreatureAI.h:68
uint8 GetTypeId() const
Definition: Object.h:192
bool IsAlive() const
Definition: Unit.h:1336
float GetPositionY() const
Definition: Position.h:98
uint64 i_victimGuid
Definition: TotemAI.h:43
void CastSpell(Unit *Victim, uint32 spellId, bool triggered, Item *castItem=NULL, Aura *triggeredByAura=NULL, uint64 originalCaster=0)
Definition: Unit.cpp:1260
void AttackStart(Unit *)
Definition: TotemAI.cpp:109
bool IsFriendlyTo(Unit const *unit) const
Definition: Unit.cpp:7374
void CombatStop(bool cast=false)
Definition: Unit.cpp:7553
void MoveInLineOfSight(Unit *)
Definition: TotemAI.cpp:44
static int Permissible(const Creature *)
Definition: TotemAI.cpp:31
bool IsTotem() const
Definition: Unit.h:1050
static Unit * GetUnit(WorldObject const &, uint64 guid)
uint32 GetEntry() const
Definition: Object.h:186
WorldSession * GetSession() const
Definition: Player.h:1947
TotemAI(Creature *c)
Definition: TotemAI.cpp:39
bool CanSeeOrDetect(WorldObject const *obj, bool ignoreStealth=false, bool distanceCheck=false, bool checkAlert=false) const
Definition: Object.cpp:1612
ACE_UINT32 uint32
Definition: Define.h:71
float GetPositionX() const
Definition: Position.h:97
bool IsVisible(Unit *) const
Definition: TotemAI.cpp:103
Definition: Unit.h:908
bool isTargetableForAttack(bool checkFakeDeath=true) const
Definition: Unit.cpp:9530
DBCStorage< SpellRangeEntry > sSpellRangeStore(SpellRangefmt)
Unit * GetOwner()
Unit * GetCharmerOrOwnerOrSelf() const
Definition: Unit.h:1414
float GetSpellMaxRange(SpellRangeEntry const *range)
Definition: SpellMgr.h:143