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
20 #include "WorldPacket.h"
24 #include "ObjectMgr.h"
27 Totem::Totem() : Creature(CREATURE_SUBTYPE_TOTEM
)
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
42 if (m_duration
<= time
)
44 UnSummon(); // remove self
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
);
64 display_id
= minfo
->modelid
;
65 SetDisplayId(display_id
);
70 // there are some totems, which exist just for their visual appeareance
77 CastSpell(this, GetSpell(), true);
80 CastSpell(GetOwner(), GetSpell(), true);
86 void Totem::UnSummon()
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;
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
);
130 if (Unit
*owner
= GetOwner())
132 setFaction(owner
->getFaction());
133 SetLevel(owner
->getLevel());
137 Unit
*Totem::GetOwner()
139 uint64 ownerid
= GetOwnerGUID();
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());
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
:
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
:
180 return Creature::IsImmunedToSpellEffect(spellInfo
, index
);