OregonCore  revision fb2a440-git
Your Favourite TBC server
Totem.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 <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "Totem.h"
19 #include "WorldPacket.h"
20 #include "MapManager.h"
21 #include "Group.h"
22 #include "Player.h"
23 #include "SpellMgr.h"
24 #include "SpellAuras.h"
25 
26 Totem::Totem(SummonPropertiesEntry const* properties, Unit* owner) : Minion(properties, owner, false)
27 {
29  m_duration = 0;
31 }
32 
34 {
35  if (!m_owner->IsAlive() || !IsAlive())
36  {
37  UnSummon(); // remove self
38  return;
39  }
40 
41  if (m_duration <= time)
42  {
43  UnSummon(); // remove self
44  return;
45  }
46  else
47  m_duration -= time;
48 
49  Creature::Update(time);
50 }
51 
52 void Totem::InitStats(uint32 duration)
53 {
57  {
58  WorldPacket data(SMSG_TOTEM_CREATED, 1 + 8 + 4 + 4);
59  data << uint8(m_Properties->Slot - 1);
60  data << uint64(GetGUID());
61  data << uint32(duration);
64 
65  CreatureInfo const* cinfo = GetCreatureTemplate();
66  if (cinfo)
67  {
68  uint32 modelid = 0;
69  if (m_owner->ToPlayer()->GetTeam() == HORDE)
70  {
71  if (cinfo->modelid3)
72  modelid = cinfo->modelid3;
73  else if (cinfo->modelid4)
74  modelid = cinfo->modelid4;
75  }
76  else
77  {
78  if (cinfo->modelid1)
79  modelid = cinfo->modelid1;
80  else if (cinfo->modelid2)
81  modelid = cinfo->modelid2;
82  }
83  if (modelid)
84  SetDisplayId(modelid);
85  else
86  sLog.outErrorDb("Totem::Summon: Missing modelid information for entry %u, team %u, totem will use default values.", GetEntry(), m_owner->ToPlayer()->GetTeam());
87  }
88  }
89 
90  Minion::InitStats(duration);
91 
92  // Get spell casted by totem
93  SpellEntry const* totemSpell = sSpellStore.LookupEntry(GetSpell());
94  if (totemSpell)
95  {
96  // If spell have cast time -> so its active totem
97  if (GetSpellCastTime(totemSpell))
99  }
100 
101  if (GetEntry() == SENTRY_TOTEM_ENTRY)
103 
104  m_duration = duration;
105 
107 }
108 
110 {
112  data << GetGUID();
113  SendMessageToSet(&data, true);
114 
115  if (m_type == TOTEM_PASSIVE && GetSpell())
116  {
117  CastSpell(this, GetSpell(), true);
118  }
119 
120  // Some totems can have both instant effect and passive spell
121  if (GetSpell(1))
122  CastSpell(this, GetSpell(1), true);
123 }
124 
126 {
128 
129  CombatStop();
131 
132  // clear owner's totem slot
133  for (int i = SUMMON_SLOT_TOTEM; i < MAX_TOTEM_SLOT; ++i)
134  {
135  if (m_owner->m_SummonSlot[i] == GetGUID())
136  {
137  m_owner->m_SummonSlot[i] = 0;
138  break;
139  }
140  }
141 
143 
144  //remove aura all party members too
145  Group* group = NULL;
146  if (m_owner->GetTypeId() == TYPEID_PLAYER)
147  {
148  // Not only the player can summon the totem (scripted AI)
149  group = m_owner->ToPlayer()->GetGroup();
150  if (group)
151  {
152  for (GroupReference* itr = group->GetFirstMember(); itr != NULL; itr = itr->next())
153  {
154  Player* target = itr->GetSource();
155  if (target && target->IsInMap(m_owner->ToPlayer()) && group->SameSubGroup(m_owner->ToPlayer(), target))
156  target->RemoveAurasDueToSpell(GetSpell());
157  }
158  }
159  }
160 
161  // any totem unsummon look like as totem kill, req. for proper animation
162  if (IsAlive())
164 
166 }
167 
168 bool Totem::IsImmuneToSpellEffect(SpellEntry const* spellInfo, uint32 index, bool castOnSelf) const
169 {
170  switch (spellInfo->Effect[index])
171  {
173  // immune to any type of regeneration effects hp/mana etc.
174  case SPELL_EFFECT_HEAL:
180  return true;
181  default:
182  break;
183  }
184 
185  // @todo possibly all negative auras immuned?
186  switch (spellInfo->EffectApplyAuraName[index])
187  {
190  case SPELL_AURA_MOD_FEAR:
192  return true;
193  default:
194  break;
195  }
196 
197  return Creature::IsImmuneToSpellEffect(spellInfo, index, castOnSelf);
198 }
199 
bool IsImmuneToSpellEffect(SpellEntry const *spellInfo, uint32 index, bool castOnSelf) const override
Definition: Creature.cpp:1737
Group * GetGroup()
Definition: Player.h:2577
Definition: Unit.h:440
const uint32 & GetUInt32Value(uint16 index) const
Definition: Object.h:234
void UnSummon()
Definition: Totem.cpp:125
bool SameSubGroup(uint64 guid1, const uint64 &guid2) const
Definition: Group.h:275
uint32 GetSpell(uint8 slot=0) const
Definition: Totem.h:40
void InitStats(uint32 duration) override
uint32 modelid4
Definition: Creature.h:137
#define SENTRY_TOTEM_ENTRY
Definition: Totem.h:29
#define sLog
Log class singleton.
Definition: Log.h:187
NULL Dbg ErrDB Arena Chat Char Map MMap false
Definition: Log.cpp:556
uint32 GetSpellCastTime(SpellEntry const *spellInfo, Spell const *spell)
Definition: SpellMgr.cpp:248
uint32 Effect[MAX_SPELL_EFFECTS]
Definition: DBCStructure.h:724
uint32 modelid1
Definition: Creature.h:134
uint64 m_SummonSlot[MAX_SUMMON_SLOT]
Definition: Unit.h:1607
DBCStorage< SpellEntry > sSpellStore(SpellEntryfmt)
virtual void SendMessageToSet(WorldPacket *data, bool self)
Definition: Object.h:789
uint32 EffectApplyAuraName[MAX_SPELL_EFFECTS]
Definition: DBCStructure.h:734
Totem(SummonPropertiesEntry const *properties, Unit *owner)
Definition: Totem.cpp:26
Player * ToPlayer()
Definition: Object.h:392
uint8 getLevel() const
Definition: Unit.h:1057
void RemoveAurasDueToSpell(uint32 spellId, Aura *except=NULL)
Definition: Unit.cpp:4371
uint8 GetTypeId() const
Definition: Object.h:210
TotemType m_type
Definition: Totem.h:68
ACE_UINT8 uint8
Definition: Define.h:73
void setDeathState(DeathState s) override
Definition: Creature.cpp:1575
void Update(uint32 time) override
Definition: Totem.cpp:33
void AddObjectToRemoveList()
Definition: Object.cpp:1990
void SetDisplayId(uint32 modelId)
Definition: Unit.cpp:11975
SummonPropertiesEntry const * m_Properties
bool IsAlive() const
Definition: Unit.h:1336
#define SUMMON_SLOT_TOTEM
Definition: Unit.h:896
void CastSpell(Unit *Victim, uint32 spellId, bool triggered, Item *castItem=NULL, Aura *triggeredByAura=NULL, uint64 originalCaster=0)
Definition: Unit.cpp:1223
void SendDirectMessage(WorldPacket *data)
Definition: Player.cpp:5724
void CombatStop(bool cast=false)
Definition: Unit.cpp:7518
GroupReference * GetFirstMember()
Definition: Group.h:304
bool IsInMap(const WorldObject *obj) const
Definition: Object.h:745
GroupReference * next()
Unit *const m_owner
uint32 modelid3
Definition: Creature.h:136
ACE_UINT64 uint64
Definition: Define.h:70
uint32 modelid2
Definition: Creature.h:135
void InitSummon() override
Definition: Totem.cpp:109
CreatureInfo const * GetCreatureTemplate() const
Definition: Creature.h:557
uint32 m_duration
Definition: Totem.h:69
void SendObjectDeSpawnAnim(uint64 guid)
Definition: Object.cpp:1939
void InitStats(uint32 duration) override
Definition: Totem.cpp:52
uint32 m_unitTypeMask
Definition: Unit.h:2049
uint32 GetTeam() const
Definition: Player.h:2063
bool IsImmuneToSpellEffect(SpellEntry const *spellInfo, uint32 index, bool castOnSelf) const override
Definition: Totem.cpp:168
void Update(uint32 time) override
Definition: Creature.cpp:472
void SetLevel(uint32 lvl)
Definition: Unit.cpp:10896
uint32 GetEntry() const
Definition: Object.h:192
ACE_UINT32 uint32
Definition: Define.h:71
Definition: Unit.h:908
void SetReactState(ReactStates st)
Definition: Creature.h:495
Definition: Player.h:922
#define MAX_TOTEM_SLOT
Definition: Unit.h:897
Definition: Group.h:154
const uint64 & GetGUID() const
Definition: Object.h:162