[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / src / game / Totem.cpp
blobc5043a4725896f9c6002508c47848188646b4694
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 "MapManager.h"
22 #include "Log.h"
23 #include "Group.h"
24 #include "Player.h"
25 #include "ObjectMgr.h"
26 #include "SpellMgr.h"
28 Totem::Totem() : Creature()
30 m_isTotem = true;
31 m_duration = 0;
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
41 return;
44 if (m_duration <= time)
46 UnSummon(); // remove self
47 return;
49 else
50 m_duration -= time;
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);
68 else
69 SetDisplayId(cinfo->DisplayID_A);
72 WorldPacket data(SMSG_GAMEOBJECT_SPAWN_ANIM_OBSOLETE, 8);
73 data << GetGUID();
74 SendMessageToSet(&data,true);
76 AIM_Initialize();
78 switch(m_type)
80 case TOTEM_PASSIVE: CastSpell(this, GetSpell(), true); break;
81 case TOTEM_STATUE: CastSpell(GetOwner(), GetSpell(), true); break;
82 default: break;
86 void Totem::UnSummon()
88 SendObjectDeSpawnAnim(GetGUID());
90 CombatStop();
91 RemoveAurasDueToSpell(GetSpell());
92 Unit *owner = GetOwner();
93 if (owner)
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;
101 break;
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();
113 if (pGroup)
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);
132 SetOwnerGUID(guid);
133 if (Unit *owner = GetOwner())
135 setFaction(owner->getFaction());
136 SetLevel(owner->getLevel());
140 Unit *Totem::GetOwner()
142 uint64 ownerid = GetOwnerGUID();
143 if(!ownerid)
144 return NULL;
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());
152 if (totemSpell)
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::IsImmunedToSpellEffect(SpellEntry const* spellInfo, uint32 index) const
164 // TODO: possibly all negative auras immuned?
165 switch(spellInfo->EffectApplyAuraName[index])
167 case SPELL_AURA_PERIODIC_DAMAGE:
168 case SPELL_AURA_PERIODIC_LEECH:
169 case SPELL_AURA_MOD_FEAR:
170 case SPELL_AURA_TRANSFORM:
171 return true;
172 default:
173 break;
175 return Creature::IsImmunedToSpellEffect(spellInfo, index);