2 * Copyright (C) 2005-2013 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"
26 #include "CreatureAI.h"
27 #include "InstanceData.h"
29 Totem::Totem() : Creature(CREATURE_SUBTYPE_TOTEM
)
32 m_type
= TOTEM_PASSIVE
;
35 bool Totem::Create(uint32 guidlow
, CreatureCreatePos
& cPos
, CreatureInfo
const* cinfo
, Unit
* owner
)
37 SetMap(cPos
.GetMap());
38 SetPhaseMask(cPos
.GetPhaseMask(), false);
40 Team team
= owner
->GetTypeId() == TYPEID_PLAYER
? ((Player
*)owner
)->GetTeam() : TEAM_NONE
;
42 if (!CreateFromProto(guidlow
, cinfo
, team
))
45 // special model selection case for totems
46 if (owner
->GetTypeId() == TYPEID_PLAYER
)
48 if (uint32 modelid_race
= sObjectMgr
.GetModelForRace(GetNativeDisplayId(), owner
->getRaceMask()))
49 SetDisplayId(modelid_race
);
52 cPos
.SelectFinalPoint(this);
54 // totem must be at same Z in case swimming caster and etc.
55 if (fabs(cPos
.m_pos
.z
- owner
->GetPositionZ()) > 5.0f
)
56 cPos
.m_pos
.z
= owner
->GetPositionZ();
58 if (!cPos
.Relocate(this))
61 // Notify the map's instance data.
62 // Only works if you create the object in it, not if it is moves to that map.
63 // Normally non-players do not teleport to other maps.
64 if (InstanceData
* iData
= GetMap()->GetInstanceData())
65 iData
->OnCreatureCreate(this);
67 LoadCreatureAddon(false);
72 void Totem::Update(uint32 update_diff
, uint32 time
)
74 Unit
* owner
= GetOwner();
75 if (!owner
|| !owner
->isAlive() || !isAlive())
77 UnSummon(); // remove self
81 if (m_duration
<= update_diff
)
83 UnSummon(); // remove self
87 m_duration
-= update_diff
;
89 Creature::Update(update_diff
, time
);
92 void Totem::Summon(Unit
* owner
)
95 owner
->GetMap()->Add((Creature
*)this);
97 if (owner
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)owner
)->AI())
98 ((Creature
*)owner
)->AI()->JustSummoned((Creature
*)this);
100 // there are some totems, which exist just for their visual appeareance
107 CastSpell(this, GetSpell(), true);
110 CastSpell(GetOwner(), GetSpell(), true);
116 void Totem::UnSummon()
119 RemoveAurasDueToSpell(GetSpell());
121 if (Unit
* owner
= GetOwner())
123 owner
->_RemoveTotem(this);
124 owner
->RemoveAurasDueToSpell(GetSpell());
126 // remove aura all party members too
127 if (owner
->GetTypeId() == TYPEID_PLAYER
)
129 ((Player
*)owner
)->SendAutoRepeatCancel(this);
131 // Not only the player can summon the totem (scripted AI)
132 if (Group
* pGroup
= ((Player
*)owner
)->GetGroup())
134 for (GroupReference
* itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
136 Player
* Target
= itr
->getSource();
137 if (Target
&& pGroup
->SameSubGroup((Player
*)owner
, Target
))
138 Target
->RemoveAurasDueToSpell(GetSpell());
143 if (owner
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)owner
)->AI())
144 ((Creature
*)owner
)->AI()->SummonedCreatureDespawn((Creature
*)this);
147 // any totem unsummon look like as totem kill, req. for proper animation
151 AddObjectToRemoveList();
154 void Totem::SetOwner(Unit
* owner
)
156 SetCreatorGuid(owner
->GetObjectGuid());
157 SetOwnerGuid(owner
->GetObjectGuid());
158 setFaction(owner
->getFaction());
159 SetLevel(owner
->getLevel());
162 Unit
* Totem::GetOwner()
164 if (ObjectGuid ownerGuid
= GetOwnerGuid())
165 return ObjectAccessor::GetUnit(*this, ownerGuid
);
170 void Totem::SetTypeBySummonSpell(SpellEntry
const* spellProto
)
172 // Get spell casted by totem
173 SpellEntry
const* totemSpell
= sSpellStore
.LookupEntry(GetSpell());
176 // If spell have cast time -> so its active totem
177 if (GetSpellCastTime(totemSpell
))
178 m_type
= TOTEM_ACTIVE
;
180 if (spellProto
->SpellIconID
== 2056)
181 m_type
= TOTEM_STATUE
; // Jewelery statue
184 bool Totem::IsImmuneToSpellEffect(SpellEntry
const* spellInfo
, SpellEffectIndex index
, bool castOnSelf
) const
186 SpellEffectEntry
const* spellEffect
= spellInfo
->GetSpellEffect(index
);
189 // TODO: possibly all negative auras immune?
190 switch(spellEffect
->Effect
)
192 case SPELL_EFFECT_ATTACK_ME
:
197 switch(spellEffect
->EffectApplyAuraName
)
199 case SPELL_AURA_PERIODIC_DAMAGE
:
200 case SPELL_AURA_PERIODIC_LEECH
:
201 case SPELL_AURA_MOD_FEAR
:
202 case SPELL_AURA_TRANSFORM
:
203 case SPELL_AURA_MOD_TAUNT
:
210 return Creature::IsImmuneToSpellEffect(spellInfo
, index
, castOnSelf
);