2 * Copyright (C) 2005-2009 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"
24 #include "ObjectMgr.h"
27 Totem::Totem() : Creature()
31 m_type
= TOTEM_PASSIVE
;
34 void Totem::Update( uint32 time
)
36 Unit
*owner
= GetOwner();
37 if (!owner
|| !owner
->isAlive() || !isAlive())
39 UnSummon(); // remove self
43 if (m_duration
<= time
)
45 UnSummon(); // remove self
51 Creature::Update( time
);
54 void Totem::Summon(Unit
* owner
)
56 owner
->GetMap()->Add((Creature
*)this);
58 // select totem model in dependent from owner team
59 CreatureInfo
const *cinfo
= GetCreatureInfo();
60 if(owner
->GetTypeId() == TYPEID_PLAYER
&& cinfo
)
62 uint32 display_id
= sObjectMgr
.ChooseDisplayId(((Player
*)owner
)->GetTeam(), cinfo
);
63 CreatureModelInfo
const *minfo
= sObjectMgr
.GetCreatureModelRandomGender(display_id
);
65 display_id
= minfo
->modelid
;
66 SetDisplayId(display_id
);
71 // there are some totems, which exist just for their visual appeareance
78 CastSpell(this, GetSpell(), true);
81 CastSpell(GetOwner(), GetSpell(), true);
87 void Totem::UnSummon()
90 RemoveAurasDueToSpell(GetSpell());
92 if (Unit
*owner
= GetOwner())
94 // clear owner's totem slot
95 for(int i
= 0; i
< MAX_TOTEM
; ++i
)
97 if(owner
->m_TotemSlot
[i
] == GetGUID())
99 owner
->m_TotemSlot
[i
] = 0;
104 owner
->RemoveAurasDueToSpell(GetSpell());
106 //remove aura all party members too
107 if (owner
->GetTypeId() == TYPEID_PLAYER
)
109 ((Player
*)owner
)->SendAutoRepeatCancel(this);
111 // Not only the player can summon the totem (scripted AI)
112 if (Group
*pGroup
= ((Player
*)owner
)->GetGroup())
114 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
116 Player
* Target
= itr
->getSource();
117 if(Target
&& pGroup
->SameSubGroup((Player
*)owner
, Target
))
118 Target
->RemoveAurasDueToSpell(GetSpell());
124 AddObjectToRemoveList();
127 void Totem::SetOwner(uint64 guid
)
129 SetCreatorGUID(guid
);
131 if (Unit
*owner
= GetOwner())
133 setFaction(owner
->getFaction());
134 SetLevel(owner
->getLevel());
138 Unit
*Totem::GetOwner()
140 uint64 ownerid
= GetOwnerGUID();
143 return ObjectAccessor::GetUnit(*this, ownerid
);
146 void Totem::SetTypeBySummonSpell(SpellEntry
const * spellProto
)
148 // Get spell casted by totem
149 SpellEntry
const * totemSpell
= sSpellStore
.LookupEntry(GetSpell());
152 // If spell have cast time -> so its active totem
153 if (GetSpellCastTime(totemSpell
))
154 m_type
= TOTEM_ACTIVE
;
156 if(spellProto
->SpellIconID
== 2056)
157 m_type
= TOTEM_STATUE
; //Jewelery statue
160 bool Totem::IsImmunedToSpellEffect(SpellEntry
const* spellInfo
, uint32 index
) const
162 // TODO: possibly all negative auras immune?
163 switch(spellInfo
->Effect
[index
])
165 case SPELL_EFFECT_ATTACK_ME
:
170 switch(spellInfo
->EffectApplyAuraName
[index
])
172 case SPELL_AURA_PERIODIC_DAMAGE
:
173 case SPELL_AURA_PERIODIC_LEECH
:
174 case SPELL_AURA_MOD_FEAR
:
175 case SPELL_AURA_TRANSFORM
:
176 case SPELL_AURA_MOD_TAUNT
:
181 return Creature::IsImmunedToSpellEffect(spellInfo
, index
);