[8449] Deprecate healing/damage item mods and merge internal data in to spell power.
[getmangos.git] / src / game / Totem.cpp
blobcded5d44ea9a9203653fc26ecb7c96a679b6ccc0
1 /*
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
19 #include "Totem.h"
20 #include "WorldPacket.h"
21 #include "Log.h"
22 #include "Group.h"
23 #include "Player.h"
24 #include "ObjectMgr.h"
25 #include "SpellMgr.h"
27 Totem::Totem() : Creature()
29 m_isTotem = true;
30 m_duration = 0;
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
40 return;
43 if (m_duration <= time)
45 UnSummon(); // remove self
46 return;
48 else
49 m_duration -= time;
51 Creature::Update( time );
54 void Totem::Summon(Unit* owner)
56 sLog.outDebug("AddObject at Totem.cpp line 49");
57 owner->GetMap()->Add((Creature*)this);
59 // select totem model in dependent from owner team
60 CreatureInfo const *cinfo = GetCreatureInfo();
61 if(owner->GetTypeId() == TYPEID_PLAYER && cinfo)
63 uint32 display_id = objmgr.ChooseDisplayId(((Player*)owner)->GetTeam(), cinfo);
64 CreatureModelInfo const *minfo = objmgr.GetCreatureModelRandomGender(display_id);
65 if (minfo)
66 display_id = minfo->modelid;
67 SetDisplayId(display_id);
70 WorldPacket data(SMSG_GAMEOBJECT_SPAWN_ANIM_OBSOLETE, 8);
71 data << GetGUID();
72 SendMessageToSet(&data,true);
74 AIM_Initialize();
76 switch(m_type)
78 case TOTEM_PASSIVE:
79 CastSpell(this, GetSpell(), true);
80 break;
81 case TOTEM_STATUE:
82 CastSpell(GetOwner(), GetSpell(), true);
83 break;
84 default: break;
88 void Totem::UnSummon()
90 SendObjectDeSpawnAnim(GetGUID());
92 CombatStop();
93 RemoveAurasDueToSpell(GetSpell());
94 Unit *owner = GetOwner();
95 if (owner)
97 // clear owner's totem slot
98 for(int i = 0; i < MAX_TOTEM; ++i)
100 if(owner->m_TotemSlot[i] == GetGUID())
102 owner->m_TotemSlot[i] = 0;
103 break;
107 owner->RemoveAurasDueToSpell(GetSpell());
109 //remove aura all party members too
110 if (owner->GetTypeId() == TYPEID_PLAYER)
112 // Not only the player can summon the totem (scripted AI)
113 if(Group *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 AddObjectToRemoveList();
128 void Totem::SetOwner(uint64 guid)
130 SetCreatorGUID(guid);
131 SetOwnerGUID(guid);
132 if (Unit *owner = GetOwner())
134 setFaction(owner->getFaction());
135 SetLevel(owner->getLevel());
139 Unit *Totem::GetOwner()
141 uint64 ownerid = GetOwnerGUID();
142 if(!ownerid)
143 return NULL;
144 return ObjectAccessor::GetUnit(*this, ownerid);
147 void Totem::SetTypeBySummonSpell(SpellEntry const * spellProto)
149 // Get spell casted by totem
150 SpellEntry const * totemSpell = sSpellStore.LookupEntry(GetSpell());
151 if (totemSpell)
153 // If spell have cast time -> so its active totem
154 if (GetSpellCastTime(totemSpell))
155 m_type = TOTEM_ACTIVE;
157 if(spellProto->SpellIconID == 2056)
158 m_type = TOTEM_STATUE; //Jewelery statue
161 bool Totem::IsImmunedToSpellEffect(SpellEntry const* spellInfo, uint32 index) const
163 // TODO: possibly all negative auras immune?
164 switch(spellInfo->EffectApplyAuraName[index])
166 case SPELL_AURA_PERIODIC_DAMAGE:
167 case SPELL_AURA_PERIODIC_LEECH:
168 case SPELL_AURA_MOD_FEAR:
169 case SPELL_AURA_TRANSFORM:
170 return true;
171 default:
172 break;
174 return Creature::IsImmunedToSpellEffect(spellInfo, index);