TrinityCore
Loading...
Searching...
No Matches
TotemAI.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#include "TotemAI.h"
19#include "CellImpl.h"
20#include "Creature.h"
21#include "GridNotifiers.h"
22#include "GridNotifiersImpl.h"
23#include "ObjectAccessor.h"
24#include "SpellInfo.h"
25#include "SpellMgr.h"
26#include "Totem.h"
27
29{
30 if (creature->IsTotem())
32
33 return PERMIT_BASE_NO;
34}
35
36TotemAI::TotemAI(Creature* creature, uint32 scriptId) noexcept : NullCreatureAI(creature, scriptId), _victimGUID()
37{
38 ASSERT(creature->IsTotem(), "TotemAI: AI assigned to a non-totem creature (%s)!", creature->GetGUID().ToString().c_str());
39}
40
42{
44 return;
45
46 if (!me->IsAlive() || me->IsNonMeleeSpellCast(false))
47 return;
48
49 // Search spell
50 SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(me->ToTotem()->GetSpell(), me->GetMap()->GetDifficultyID());
51 if (!spellInfo)
52 return;
53
54 // Get spell range
55 float max_range = spellInfo->GetMaxRange(false);
56
57 // SpellModOp::Range not applied in this place just because not existence range mods for attacking totems
58
59 // pointer to appropriate target if found any
61
62 // Search victim if no, not attackable, or out of range, or friendly (possible in case duel end)
63 CanSeeOrDetectExtraArgs const& canSeeOrDetectExtraArgs = CanSeeOrDetectExtraArgs{
65 .IncludeHiddenBySpawnTracking = spellInfo->HasAttribute(SPELL_ATTR8_ALLOW_TARGETS_HIDDEN_BY_SPAWN_TRACKING),
66 .IncludeAnyPrivateObject = spellInfo->HasAttribute(SPELL_ATTR0_CU_CAN_TARGET_ANY_PRIVATE_OBJECT)
67 };
68 if (!victim || !victim->isTargetableForAttack() || !me->IsWithinDistInMap(victim, max_range) || me->IsFriendlyTo(victim) || !me->CanSeeOrDetect(victim, canSeeOrDetectExtraArgs))
69 {
70 victim = nullptr;
71 float extraSearchRadius = max_range > 0.0f ? EXTRA_CELL_SEARCH_RADIUS : 0.0f;
74 Cell::VisitAllObjects(me, checker, max_range + extraSearchRadius);
75 }
76
77 // If have target
78 if (victim)
79 {
80 // remember
81 _victimGUID = victim->GetGUID();
82
83 // attack
84 me->CastSpell(victim, me->ToTotem()->GetSpell());
85 }
86 else
88}
89
90void TotemAI::AttackStart(Unit* /*victim*/)
91{
92}
@ PERMIT_BASE_PROACTIVE
Definition CreatureAI.h:49
@ PERMIT_BASE_NO
Definition CreatureAI.h:46
int32_t int32
Definition Define.h:150
uint32_t uint32
Definition Define.h:154
#define ASSERT
Definition Errors.h:80
#define EXTRA_CELL_SEARCH_RADIUS
@ SPELL_ATTR8_ALLOW_TARGETS_HIDDEN_BY_SPAWN_TRACKING
@ SPELL_ATTR6_IGNORE_PHASE_SHIFT
@ SPELL_ATTR0_CU_CAN_TARGET_ANY_PRIVATE_OBJECT
Definition SpellInfo.h:169
#define sSpellMgr
Definition SpellMgr.h:812
@ TOTEM_ACTIVE
Definition Totem.h:26
ObjectGuid const & GetGUID() const
Definition BaseEntity.h:163
Creature *const me
Definition CreatureAI.h:63
Difficulty GetDifficultyID() const
Definition Map.h:360
bool IsEmpty() const
Definition ObjectGuid.h:362
void Clear()
Definition ObjectGuid.h:329
float GetMaxRange(bool positive=false, WorldObject const *caster=nullptr, Spell *spell=nullptr) const
bool HasAttribute(SpellAttr0 attribute) const
Definition SpellInfo.h:456
void UpdateAI(uint32 diff) override
Definition TotemAI.cpp:41
static int32 Permissible(Creature const *creature)
Definition TotemAI.cpp:28
TotemAI(Creature *creature, uint32 scriptId={}) noexcept
Definition TotemAI.cpp:36
void AttackStart(Unit *victim) override
== Triggered Actions Requested ==================
Definition TotemAI.cpp:90
ObjectGuid _victimGUID
Definition TotemAI.h:37
uint32 GetSpell(uint8 slot=0) const
Definition Totem.h:39
TotemType GetTotemType() const
Definition Totem.h:42
Definition Unit.h:635
bool isTargetableForAttack(bool checkFakeDeath=true) const
Definition Unit.cpp:8585
Totem * ToTotem()
Definition Unit.h:1825
bool IsNonMeleeSpellCast(bool withDelayed, bool skipChanneled=false, bool skipAutorepeat=false, bool isAutoshoot=false, bool skipInstant=true) const
Definition Unit.cpp:3201
bool IsAlive() const
Definition Unit.h:1185
bool IsTotem() const
Definition Unit.h:753
Map * GetMap() const
Definition Object.h:411
Unit * GetCharmerOrOwnerOrSelf() const
Definition Object.cpp:1613
SpellCastResult CastSpell(CastSpellTargetArg const &targets, uint32 spellId, CastSpellExtraArgs const &args={ })
Definition Object.cpp:2217
bool CanSeeOrDetect(WorldObject const *obj, CanSeeOrDetectExtraArgs const &args={ }) const
Definition Object.cpp:857
bool IsWithinDistInMap(WorldObject const *obj, float dist2compare, bool is3D=true, bool incOwnRadius=true, bool incTargetRadius=true) const
Definition Object.cpp:501
bool IsFriendlyTo(WorldObject const *target) const
Definition Object.cpp:2186
TC_GAME_API Unit * GetUnit(WorldObject const &, ObjectGuid const &guid)
static void VisitAllObjects(WorldObject const *obj, T &visitor, float radius, bool dont_load=true)
Definition CellImpl.h:203