2 * Copyright (C) 2005-2008 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
20 #include "WorldPacket.h"
21 #include "MapManager.h"
25 #include "ObjectMgr.h"
28 Totem::Totem() : Creature()
32 m_type
= TOTEM_PASSIVE
;
35 void Totem::Update( uint32 time
)
37 Unit
*owner
= GetOwner();
38 if (!owner
|| !owner
->isAlive() || !isAlive())
40 UnSummon(); // remove self
44 if (m_duration
<= time
)
46 UnSummon(); // remove self
52 Creature::Update( time
);
55 void Totem::Summon(Unit
* owner
)
57 sLog
.outDebug("AddObject at Totem.cpp line 49");
59 SetInstanceId(owner
->GetInstanceId());
60 owner
->GetMap()->Add((Creature
*)this);
62 // select totem model in dependent from owner team
63 CreatureInfo
const *cinfo
= GetCreatureInfo();
64 if(owner
->GetTypeId()==TYPEID_PLAYER
&& cinfo
)
66 if(((Player
*)owner
)->GetTeam()==HORDE
)
67 SetDisplayId(cinfo
->DisplayID_H
);
69 SetDisplayId(cinfo
->DisplayID_A
);
72 WorldPacket
data(SMSG_GAMEOBJECT_SPAWN_ANIM_OBSOLETE
, 8);
74 SendMessageToSet(&data
,true);
80 case TOTEM_PASSIVE
: CastSpell(this, GetSpell(), true); break;
81 case TOTEM_STATUE
: CastSpell(GetOwner(), GetSpell(), true); break;
86 void Totem::UnSummon()
88 SendObjectDeSpawnAnim(GetGUID());
91 RemoveAurasDueToSpell(GetSpell());
92 Unit
*owner
= GetOwner();
95 // clear owenr's totem slot
96 for(int i
= 0; i
< MAX_TOTEM
; ++i
)
98 if(owner
->m_TotemSlot
[i
]==GetGUID())
100 owner
->m_TotemSlot
[i
] = 0;
105 owner
->RemoveAurasDueToSpell(GetSpell());
107 //remove aura all party members too
108 Group
*pGroup
= NULL
;
109 if (owner
->GetTypeId() == TYPEID_PLAYER
)
111 // Not only the player can summon the totem (scripted AI)
112 pGroup
= ((Player
*)owner
)->GetGroup();
115 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
117 Player
* Target
= itr
->getSource();
118 if(Target
&& pGroup
->SameSubGroup((Player
*)owner
, Target
))
119 Target
->RemoveAurasDueToSpell(GetSpell());
125 CleanupsBeforeDelete();
126 AddObjectToRemoveList();
129 void Totem::SetOwner(uint64 guid
)
131 SetCreatorGUID(guid
);
133 if (Unit
*owner
= GetOwner())
135 setFaction(owner
->getFaction());
136 SetLevel(owner
->getLevel());
140 Unit
*Totem::GetOwner()
142 uint64 ownerid
= GetOwnerGUID();
145 return ObjectAccessor::GetUnit(*this, ownerid
);
148 void Totem::SetTypeBySummonSpell(SpellEntry
const * spellProto
)
150 // Get spell casted by totem
151 SpellEntry
const * totemSpell
= sSpellStore
.LookupEntry(GetSpell());
154 // If spell have cast time -> so its active totem
155 if (GetSpellCastTime(totemSpell
))
156 m_type
= TOTEM_ACTIVE
;
158 if(spellProto
->SpellIconID
==2056)
159 m_type
= TOTEM_STATUE
; //Jewelery statue
162 bool Totem::IsImmunedToSpell(SpellEntry
const* spellInfo
, bool useCharges
)
164 for (int i
=0;i
<3;i
++)
166 switch(spellInfo
->EffectApplyAuraName
[i
])
168 case SPELL_AURA_PERIODIC_DAMAGE
:
169 case SPELL_AURA_PERIODIC_LEECH
:
175 return Creature::IsImmunedToSpell(spellInfo
, useCharges
);