[9290] Some cleanups in realmd, no functional changes
[getmangos.git] / src / game / Totem.cpp
blob6c07ea32c9e66eb2d508613ccb3cc07cbbe64509
1 /*
2 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "Totem.h"
20 #include "WorldPacket.h"
21 #include "Log.h"
22 #include "Group.h"
23 #include "Player.h"
24 #include "ObjectMgr.h"
25 #include "SpellMgr.h"
27 Totem::Totem() : Creature(CREATURE_SUBTYPE_TOTEM)
29 m_duration = 0;
30 m_type = TOTEM_PASSIVE;
33 void Totem::Update( uint32 time )
35 Unit *owner = GetOwner();
36 if (!owner || !owner->isAlive() || !isAlive())
38 UnSummon(); // remove self
39 return;
42 if (m_duration <= time)
44 UnSummon(); // remove self
45 return;
47 else
48 m_duration -= time;
50 Creature::Update( time );
53 void Totem::Summon(Unit* owner)
55 owner->GetMap()->Add((Creature*)this);
57 // select totem model in dependent from owner team
58 CreatureInfo const *cinfo = GetCreatureInfo();
59 if(owner->GetTypeId() == TYPEID_PLAYER && cinfo)
61 uint32 display_id = sObjectMgr.ChooseDisplayId(((Player*)owner)->GetTeam(), cinfo);
62 CreatureModelInfo const *minfo = sObjectMgr.GetCreatureModelRandomGender(display_id);
63 if (minfo)
64 display_id = minfo->modelid;
65 SetDisplayId(display_id);
68 AIM_Initialize();
70 // there are some totems, which exist just for their visual appeareance
71 if (!GetSpell())
72 return;
74 switch(m_type)
76 case TOTEM_PASSIVE:
77 CastSpell(this, GetSpell(), true);
78 break;
79 case TOTEM_STATUE:
80 CastSpell(GetOwner(), GetSpell(), true);
81 break;
82 default: break;
86 void Totem::UnSummon()
88 CombatStop();
89 RemoveAurasDueToSpell(GetSpell());
91 if (Unit *owner = GetOwner())
93 // clear owner's totem slot
94 for(int i = 0; i < MAX_TOTEM; ++i)
96 if(owner->m_TotemSlot[i] == GetGUID())
98 owner->m_TotemSlot[i] = 0;
99 break;
103 owner->RemoveAurasDueToSpell(GetSpell());
105 //remove aura all party members too
106 if (owner->GetTypeId() == TYPEID_PLAYER)
108 ((Player*)owner)->SendAutoRepeatCancel(this);
110 // Not only the player can summon the totem (scripted AI)
111 if (Group *pGroup = ((Player*)owner)->GetGroup())
113 for(GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next())
115 Player* Target = itr->getSource();
116 if(Target && pGroup->SameSubGroup((Player*)owner, Target))
117 Target->RemoveAurasDueToSpell(GetSpell());
123 AddObjectToRemoveList();
126 void Totem::SetOwner(uint64 guid)
128 SetCreatorGUID(guid);
129 SetOwnerGUID(guid);
130 if (Unit *owner = GetOwner())
132 setFaction(owner->getFaction());
133 SetLevel(owner->getLevel());
137 Unit *Totem::GetOwner()
139 uint64 ownerid = GetOwnerGUID();
140 if(!ownerid)
141 return NULL;
142 return ObjectAccessor::GetUnit(*this, ownerid);
145 void Totem::SetTypeBySummonSpell(SpellEntry const * spellProto)
147 // Get spell casted by totem
148 SpellEntry const * totemSpell = sSpellStore.LookupEntry(GetSpell());
149 if (totemSpell)
151 // If spell have cast time -> so its active totem
152 if (GetSpellCastTime(totemSpell))
153 m_type = TOTEM_ACTIVE;
155 if(spellProto->SpellIconID == 2056)
156 m_type = TOTEM_STATUE; //Jewelery statue
159 bool Totem::IsImmunedToSpellEffect(SpellEntry const* spellInfo, uint32 index) const
161 // TODO: possibly all negative auras immune?
162 switch(spellInfo->Effect[index])
164 case SPELL_EFFECT_ATTACK_ME:
165 return true;
166 default:
167 break;
169 switch(spellInfo->EffectApplyAuraName[index])
171 case SPELL_AURA_PERIODIC_DAMAGE:
172 case SPELL_AURA_PERIODIC_LEECH:
173 case SPELL_AURA_MOD_FEAR:
174 case SPELL_AURA_TRANSFORM:
175 case SPELL_AURA_MOD_TAUNT:
176 return true;
177 default:
178 break;
180 return Creature::IsImmunedToSpellEffect(spellInfo, index);