Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
TotemAI.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#include "Creature.h"
7#include "DBCStores.h"
8#include "ObjectAccessor.h"
9#include "SpellMgr.h"
10#include "Totem.h"
11#include "TotemAI.h"
12
13#include "CellImpl.h"
14#include "GridNotifiers.h"
15#include "GridNotifiersImpl.h"
16
17int TotemAI::Permissible(Creature const* creature)
18{
19 if (creature->IsTotem())
21
22 return PERMIT_BASE_NO;
23}
24
29
31
33{
34 me->CombatStop(true);
35}
36
38{
39 if (me->ToTotem()->GetTotemType() != TOTEM_ACTIVE)
40 return;
41
42 if (!me->IsAlive() || me->IsNonMeleeSpellCasted(false))
43 return;
44
45 // Search spell
46 SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(me->ToTotem()->GetSpell());
47 if (!spellInfo)
48 return;
49
50 // Get spell range
51 float max_range = spellInfo->GetMaxRange(false);
52
53 // SPELLMOD_RANGE not applied in this place just because not existence range mods for attacking totems
54
55 // pointer to appropriate target if found any
57
58 // Search victim if no, not attackable, or out of range, or friendly (possible in case duel end)
59 if (!victim ||
60 !victim->isTargetableForAttack() || !me->IsWithinDistInMap(victim, max_range) ||
61 me->IsFriendlyTo(victim) || !me->CanSeeOrDetect(victim))
62 {
63 victim = NULL;
66 me->VisitNearbyObject(max_range, checker);
67 }
68
69 // If have target
70 if (victim)
71 {
72 // remember
73 i_victimGuid = victim->GetGUID();
74
75 // attack
76 me->SetInFront(victim); // client change orientation by self
77 me->CastSpell(victim, me->ToTotem()->GetSpell(), false);
78 }
79 else
80 i_victimGuid = 0;
81}
82
83void TotemAI::AttackStart(Unit* /*victim*/)
84{
85}
@ PERMIT_BASE_PROACTIVE
Definition CreatureAI.h:183
@ PERMIT_BASE_NO
Definition CreatureAI.h:180
std::uint32_t uint32
Definition Define.h:77
#define ASSERT
Definition Errors.h:29
#define sSpellMgr
Definition SpellMgr.h:744
@ TOTEM_ACTIVE
Definition Totem.h:14
CreatureAI(Creature *creature)
Definition CreatureAI.h:69
Creature *const me
Definition CreatureAI.h:56
static Unit * GetUnit(WorldObject const &, uint64 guid)
uint64 GetGUID() const
Definition Object.h:119
float GetMaxRange(bool positive=false, Unit *caster=NULL, Spell *spell=NULL) const
void EnterEvadeMode() OVERRIDE
Definition TotemAI.cpp:32
void UpdateAI(uint32 diff) OVERRIDE
== Triggered Actions Requested ==================
Definition TotemAI.cpp:37
static int Permissible(Creature const *creature)
Definition TotemAI.cpp:17
void AttackStart(Unit *victim) OVERRIDE
Definition TotemAI.cpp:83
TotemAI(Creature *c)
Definition TotemAI.cpp:25
void MoveInLineOfSight(Unit *who) OVERRIDE
Definition TotemAI.cpp:30
uint64 i_victimGuid
Definition TotemAI.h:28
Definition Unit.h:1367
bool isTargetableForAttack(bool checkFakeDeath=true) const
Definition Unit.cpp:3795
bool IsTotem() const
Definition Unit.h:1519