[2771] Applied MaNGOS coding style (see trunk/bcpp.cfg).
[mangos-git.git] / src / game / Totem.cpp
blob044f693fb45eee6c442f273b9aa672e133f89b37
1 /*
2 * Copyright (C) 2005,2006 MaNGOS <http://www.mangosproject.org/>
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 "MapManager.h"
22 #include "Database/DBCStores.h"
23 #include "Log.h"
25 Totem::Totem()
27 m_isTotem = true;
28 m_spell = 0;
29 m_duration = 0;
30 m_type = TOTEM_PASSIVE;
33 void Totem::Update( uint32 time )
35 Unit *owner = GetOwner();
36 if (!owner || !owner->isAlive() || !this->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()
55 WorldPacket data;
56 sLog.outDebug("AddObject at Totem.cpp line 49");
57 MapManager::Instance().GetMap(GetMapId())->Add((Creature*)this);
59 data.Initialize(SMSG_GAMEOBJECT_SPAWN_ANIM);
60 data << GetGUID();
61 SendMessageToSet(&data,true);
63 AIM_Initialize();
65 if (m_type == TOTEM_PASSIVE)
66 this->CastSpell(this, m_spell, true);
69 void Totem::UnSummon()
71 if (m_type == TOTEM_LAST_BURST)
72 this->CastSpell(this, m_spell, true);
74 WorldPacket data;
75 data.Initialize(SMSG_GAMEOBJECT_DESPAWN_ANIM);
76 data << GetGUID();
77 SendMessageToSet(&data, true);
78 data.Initialize(SMSG_DESTROY_OBJECT);
79 data << GetGUID();
80 SendMessageToSet(&data, true);
82 CombatStop();
83 RemoveAurasDueToSpell(m_spell);
84 Unit *owner = this->GetOwner();
85 if (owner)
86 owner->RemoveAurasDueToSpell(m_spell);
88 ObjectAccessor::Instance().AddObjectToRemoveList(this);
91 void Totem::SetOwner(uint64 guid)
93 SetUInt64Value(UNIT_FIELD_SUMMONEDBY, guid);
94 Unit *owner = this->GetOwner();
95 if (owner)
97 this->setFaction(owner->getFaction());
98 this->SetLevel(owner->getLevel());
102 Unit *Totem::GetOwner()
104 uint64 ownerid = GetOwnerGUID();
105 if(!ownerid)
106 return NULL;
107 return ObjectAccessor::Instance().GetUnit(*this, ownerid);
110 void Totem::SetSpell(uint32 spellId)
112 //now, spellId is the spell of EffectSummonTotem , not the spell1 of totem!
113 m_spell = this->GetCreatureInfo()->spell1;
114 if (GetDuration(sSpellStore.LookupEntry(m_spell)) != -1)
115 m_type = TOTEM_ACTIVE;
117 if(spellId)
119 SpellEntry *spellinfo = sSpellStore.LookupEntry(spellId);
120 if ( spellinfo && spellinfo->SpellFamilyFlags == 0x28000000 )
121 m_type = TOTEM_LAST_BURST; //For Fire Nova Totem and Corrupted Fire Nova Totem