TrinityCore
Loading...
Searching...
No Matches
Totem.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 "Totem.h"
19#include "Group.h"
20#include "Log.h"
21#include "ObjectMgr.h"
22#include "Player.h"
23#include "SpellHistory.h"
24#include "SpellMgr.h"
25#include "SpellInfo.h"
26#include "TotemPackets.h"
27
28Totem::Totem(SummonPropertiesEntry const* properties, Unit* owner) : Minion(properties, owner, false)
29{
31 m_duration = 0;
33}
34
36{
37 if (!GetOwner()->IsAlive() || !IsAlive())
38 {
39 UnSummon(); // remove self
40 return;
41 }
42
43 if (m_duration <= time)
44 {
45 UnSummon(); // remove self
46 return;
47 }
48 else
49 m_duration -= time;
50
51 Creature::Update(time);
52}
53
55{
56 // client requires SMSG_TOTEM_CREATED to be sent before adding to world and before removing old totem
57 if (Player* owner = GetOwner()->ToPlayer())
58 {
59 uint32 slot = m_Properties->Slot;
60 if (slot >= SUMMON_SLOT_TOTEM_FIRE && slot < MAX_TOTEM_SLOT)
61 {
63 data.Totem = GetGUID();
64 data.Slot = slot - SUMMON_SLOT_TOTEM_FIRE;
65 data.Duration = duration;
67 owner->SendDirectMessage(data.Write());
68 }
69
70 // set display id depending on caster's race
71 if (uint32 totemDisplayId = sObjectMgr->GetModelForTotem(SummonSlot(slot), Races(owner->GetRace())))
72 SetDisplayId(totemDisplayId);
73 else
74 TC_LOG_DEBUG("misc", "Totem with entry {}, owned by player {} ({} {} {}) in slot {}, created by spell {}, does not have a specialized model. Set to default.",
75 GetEntry(), owner->GetGUID().ToString(), owner->GetLevel(), EnumUtils::ToTitle(Races(owner->GetRace())), EnumUtils::ToTitle(Classes(owner->GetClass())), slot, GetUInt32Value(UNIT_CREATED_BY_SPELL));
76 }
77
78 Minion::InitStats(duration);
79
80 // Get spell cast by totem
81 if (SpellInfo const* totemSpell = sSpellMgr->GetSpellInfo(GetSpell()))
82 if (totemSpell->CalcCastTime()) // If spell has cast time -> its an active totem
84
87
88 m_duration = duration;
89
91}
92
94{
95 if (m_type == TOTEM_PASSIVE && GetSpell())
96 CastSpell(this, GetSpell(), true);
97
98 // Some totems can have both instant effect and passive spell
99 if (GetSpell(1))
100 CastSpell(this, GetSpell(1), true);
101}
102
104{
105 if (msTime)
106 {
108 return;
109 }
110
111 CombatStop();
113
114 // clear owner's totem slot
116 {
117 if (GetOwner()->m_SummonSlot[i] == GetGUID())
118 {
120 break;
121 }
122 }
123
125
126 // Remove Sentry Totem Aura
129
130 // remove aura all party members too
131 if (Player* owner = GetOwner()->ToPlayer())
132 {
133 owner->SendAutoRepeatCancel(this);
134
135 if (SpellInfo const* spell = sSpellMgr->GetSpellInfo(GetUInt32Value(UNIT_CREATED_BY_SPELL)))
136 GetSpellHistory()->SendCooldownEvent(spell, 0, nullptr, false);
137
138 if (Group* group = owner->GetGroup())
139 {
140 for (GroupReference* itr = group->GetFirstMember(); itr != nullptr; itr = itr->next())
141 {
142 Player* target = itr->GetSource();
143 if (target && target->IsInMap(owner) && group->SameSubGroup(owner, target))
145 }
146 }
147 }
148
149 // any totem unsummon look like as totem kill, req. for proper animation
150 if (IsAlive())
152
154}
155
156bool Totem::IsImmunedToSpellEffect(SpellInfo const* spellInfo, SpellEffectInfo const& spellEffectInfo, WorldObject const* caster,
157 bool requireImmunityPurgesEffectAttribute /*= false*/) const
158{
159 // immune to all positive spells, except of stoneclaw totem absorb and sentry totem bind sight
160 // totems positive spells have unit_caster target
161 if (spellEffectInfo.Effect != SPELL_EFFECT_DUMMY &&
162 spellEffectInfo.Effect != SPELL_EFFECT_SCRIPT_EFFECT &&
163 spellInfo->IsPositive() && spellEffectInfo.TargetA.GetTarget() != TARGET_UNIT_CASTER &&
164 spellEffectInfo.TargetA.GetCheckType() != TARGET_CHECK_ENTRY && spellInfo->Id != SENTRY_STONECLAW_SPELLID && spellInfo->Id != SENTRY_BIND_SIGHT_SPELLID)
165 return true;
166
167 switch (spellEffectInfo.ApplyAuraName)
168 {
173 return true;
174 default:
175 break;
176 }
177
178 return Creature::IsImmunedToSpellEffect(spellInfo, spellEffectInfo, caster, requireImmunityPurgesEffectAttribute);
179}
uint8_t uint8
Definition Define.h:135
uint32_t uint32
Definition Define.h:133
std::chrono::milliseconds Milliseconds
Milliseconds shorthand typedef.
Definition Duration.h:24
#define TC_LOG_DEBUG(filterType__,...)
Definition Log.h:156
#define sObjectMgr
Definition ObjectMgr.h:1721
@ SPELL_EFFECT_DUMMY
@ SPELL_EFFECT_SCRIPT_EFFECT
@ TARGET_UNIT_CASTER
Classes
#define MAX_TOTEM_SLOT
SummonSlot
@ SUMMON_SLOT_TOTEM_FIRE
Races
@ SPELL_AURA_PERIODIC_DAMAGE
@ SPELL_AURA_MOD_FEAR
@ SPELL_AURA_TRANSFORM
@ SPELL_AURA_PERIODIC_LEECH
@ TARGET_CHECK_ENTRY
Definition SpellInfo.h:80
#define sSpellMgr
Definition SpellMgr.h:738
#define SENTRY_BIND_SIGHT_SPELLID
Definition Totem.h:36
#define SENTRY_TOTEM_ENTRY
Definition Totem.h:32
#define SENTRY_STONECLAW_SPELLID
Definition Totem.h:35
@ TOTEM_ACTIVE
Definition Totem.h:26
@ TOTEM_PASSIVE
Definition Totem.h:25
#define SENTRY_TOTEM_SPELLID
Definition Totem.h:30
@ REACT_AGGRESSIVE
@ UNIT_MASK_TOTEM
Definition Unit.h:367
@ DEAD
Definition Unit.h:214
@ UNIT_CREATED_BY_SPELL
void SetDisplayId(uint32 modelId) override
void Update(uint32 time) override
Definition Creature.cpp:670
void SetReactState(ReactStates st)
Definition Creature.h:119
bool IsImmunedToSpellEffect(SpellInfo const *spellInfo, SpellEffectInfo const &spellEffectInfo, WorldObject const *caster, bool requireImmunityPurgesEffectAttribute=false) const override
static char const * ToTitle(Enum value)
Definition SmartEnum.h:123
void AddEvent(BasicEvent *event, Milliseconds e_time, bool set_addtime=true)
Milliseconds CalculateTime(Milliseconds t_offset) const
Definition Group.h:165
void setDeathState(DeathState s) override
Unit * GetOwner() const
void InitStats(uint32 duration) override
void Clear()
Definition ObjectGuid.h:150
uint32 GetUInt32Value(uint16 index) const
Definition Object.cpp:249
Player * ToPlayer()
Definition Object.h:182
uint32 GetEntry() const
Definition Object.h:81
ObjectGuid GetGUID() const
Definition Object.h:79
AuraType ApplyAuraName
Definition SpellInfo.h:211
SpellEffects Effect
Definition SpellInfo.h:210
SpellImplicitTargetInfo TargetA
Definition SpellInfo.h:223
void SendCooldownEvent(SpellInfo const *spellInfo, uint32 itemId=0, Spell *spell=nullptr, bool startCooldown=true)
SpellTargetCheckTypes GetCheckType() const
Definition SpellInfo.cpp:89
Targets GetTarget() const
uint32 Id
Definition SpellInfo.h:289
bool IsPositive() const
SummonPropertiesEntry const *const m_Properties
void UnSummon(uint32 msTime=0) override
Definition Totem.cpp:103
uint32 m_duration
Definition Totem.h:65
uint32 GetSpell(uint8 slot=0) const
Definition Totem.h:47
void InitStats(uint32 duration) override
Definition Totem.cpp:54
TotemType m_type
Definition Totem.h:64
bool IsImmunedToSpellEffect(SpellInfo const *spellInfo, SpellEffectInfo const &spellEffectInfo, WorldObject const *caster, bool requireImmunityPurgesEffectAttribute=false) const override
Definition Totem.cpp:156
void Update(uint32 time) override
Definition Totem.cpp:35
void InitSummon() override
Definition Totem.cpp:93
Totem(SummonPropertiesEntry const *properties, Unit *owner)
Definition Totem.cpp:28
Definition Unit.h:769
bool IsAlive() const
Definition Unit.h:1234
uint32 m_unitTypeMask
Definition Unit.h:1901
void RemoveAurasDueToSpell(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, uint8 reqEffMask=0, AuraRemoveMode removeMode=AURA_REMOVE_BY_DEFAULT)
Definition Unit.cpp:3784
void SetLevel(uint8 lvl, bool sendUpdate=true)
Definition Unit.cpp:9344
SpellHistory * GetSpellHistory()
Definition Unit.h:1484
void CombatStop(bool includingCast=false, bool mutualPvP=true)
Definition Unit.cpp:5691
ObjectGuid m_SummonSlot[MAX_SUMMON_SLOT]
Definition Unit.h:1487
uint8 GetLevel() const
Definition Unit.h:889
SpellCastResult CastSpell(CastSpellTargetArg const &targets, uint32 spellId, CastSpellExtraArgs const &args={ })
Definition Object.cpp:2832
void AddObjectToRemoveList()
Definition Object.cpp:1838
EventProcessor m_Events
Definition Object.h:591
bool IsInMap(WorldObject const *obj) const
Definition Object.cpp:1160
WorldPacket const * Write() override