[3137] - Applied MaNGOS coding style (see trunk/bcpp.cfg).
[mangos-git.git] / src / game / Totem.cpp
blob7b777948e5271bb1aa8df473993de889cc0a88fd
1 /*
2 * Copyright (C) 2005,2006,2007 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"
24 #include "Group.h"
25 #include "Player.h"
26 #include "ObjectMgr.h"
28 Totem::Totem()
30 m_isTotem = true;
31 m_spell = 0;
32 m_duration = 0;
33 m_type = TOTEM_PASSIVE;
36 void Totem::Update( uint32 time )
38 Unit *owner = GetOwner();
39 if (!owner || !owner->isAlive() || !this->isAlive())
41 UnSummon(); // remove self
42 return;
45 if (m_duration <= time)
47 UnSummon(); // remove self
48 return;
50 else
51 m_duration -= time;
53 Creature::Update( time );
56 void Totem::Summon()
58 sLog.outDebug("AddObject at Totem.cpp line 49");
59 MapManager::Instance().GetMap(GetMapId())->Add((Creature*)this);
61 WorldPacket data(SMSG_GAMEOBJECT_SPAWN_ANIM, 8);
62 data << GetGUID();
63 SendMessageToSet(&data,true);
65 AIM_Initialize();
67 if (m_type == TOTEM_PASSIVE)
68 this->CastSpell(this, m_spell, true);
71 void Totem::UnSummon()
73 if (m_type == TOTEM_LAST_BURST)
74 this->CastSpell(this, m_spell, true);
76 SendObjectDeSpawnAnim(GetGUID());
77 SendDestroyObject(GetGUID());
79 CombatStop();
80 RemoveAurasDueToSpell(m_spell);
81 Unit *owner = this->GetOwner();
82 if (owner)
84 owner->RemoveAurasDueToSpell(m_spell);
86 //remove aura all party members too
87 Group *pGroup = NULL;
88 pGroup = ((Player*)owner)->groupInfo.group;
89 if (pGroup)
91 for(uint32 p=0;p<pGroup->GetMembersCount();p++)
93 if(!pGroup->SameSubGroup(owner->GetGUID(), pGroup->GetMemberGUID(p)))
94 continue;
96 Unit* Target = objmgr.GetPlayer(pGroup->GetMemberGUID(p));
97 if (Target) Target->RemoveAurasDueToSpell(m_spell);
102 ObjectAccessor::Instance().AddObjectToRemoveList(this);
105 void Totem::SetOwner(uint64 guid)
107 SetUInt64Value(UNIT_FIELD_SUMMONEDBY, guid);
108 Unit *owner = this->GetOwner();
109 if (owner)
111 this->setFaction(owner->getFaction());
112 this->SetLevel(owner->getLevel());
116 Unit *Totem::GetOwner()
118 uint64 ownerid = GetOwnerGUID();
119 if(!ownerid)
120 return NULL;
121 return ObjectAccessor::Instance().GetUnit(*this, ownerid);
124 void Totem::SetSpell(uint32 spellId)
126 //now, spellId is the spell of EffectSummonTotem , not the spell1 of totem!
127 m_spell = this->GetCreatureInfo()->spell1;
128 if (GetDuration(sSpellStore.LookupEntry(m_spell)) != -1)
129 m_type = TOTEM_ACTIVE;
131 if(spellId)
133 SpellEntry const *spellinfo = sSpellStore.LookupEntry(spellId);
134 if ( spellinfo && spellinfo->SpellFamilyFlags == 0x28000000 )
135 m_type = TOTEM_LAST_BURST; //For Fire Nova Totem and Corrupted Fire Nova Totem