root/trunk/src/game/Totem.cpp @ 102

Revision 102, 4.8 kB (checked in by yumileroy, 17 years ago)

[svn] Fixed copyright notices to comply with GPL.

Original author: w12x
Date: 2008-10-23 03:29:52-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include "Totem.h"
22#include "WorldPacket.h"
23#include "MapManager.h"
24#include "Log.h"
25#include "Group.h"
26#include "Player.h"
27#include "ObjectMgr.h"
28#include "SpellMgr.h"
29
30Totem::Totem() : Creature()
31{
32    m_isTotem = true;
33    m_duration = 0;
34    m_type = TOTEM_PASSIVE;
35}
36
37void Totem::Update( uint32 time )
38{
39    Unit *owner = GetOwner();
40    if (!owner || !owner->isAlive() || !this->isAlive())
41    {
42        UnSummon();                                         // remove self
43        return;
44    }
45
46    if (m_duration <= time)
47    {
48        UnSummon();                                         // remove self
49        return;
50    }
51    else
52        m_duration -= time;
53
54    Creature::Update( time );
55}
56
57void Totem::Summon(Unit* owner)
58{
59    sLog.outDebug("AddObject at Totem.cpp line 49");
60
61    SetInstanceId(owner->GetInstanceId());
62    owner->GetMap()->Add((Creature*)this);
63
64    // select totem model in dependent from owner team
65    CreatureInfo const *cinfo = GetCreatureInfo();
66    if(owner->GetTypeId()==TYPEID_PLAYER && cinfo)
67    {
68        if(((Player*)owner)->GetTeam()==HORDE)
69            SetDisplayId(cinfo->DisplayID_H);
70        else
71            SetDisplayId(cinfo->DisplayID_A);
72    }
73
74    WorldPacket data(SMSG_GAMEOBJECT_SPAWN_ANIM_OBSOLETE, 8);
75    data << GetGUID();
76    SendMessageToSet(&data,true);
77
78    AIM_Initialize();
79
80    switch(m_type)
81    {
82        case TOTEM_PASSIVE: CastSpell(this, GetSpell(), true); break;
83        case TOTEM_STATUE:  CastSpell(GetOwner(), GetSpell(), true); break;
84        default: break;
85    }
86}
87
88void Totem::UnSummon()
89{
90    SendObjectDeSpawnAnim(GetGUID());
91
92    CombatStop();
93    RemoveAurasDueToSpell(GetSpell());
94    Unit *owner = this->GetOwner();
95    if (owner)
96    {
97        // clear owenr's totem slot
98        for(int i = 0; i < MAX_TOTEM; ++i)
99        {
100            if(owner->m_TotemSlot[i]==GetGUID())
101            {
102                owner->m_TotemSlot[i] = 0;
103                break;
104            }
105        }
106
107        owner->RemoveAurasDueToSpell(GetSpell());
108
109        //remove aura all party members too
110        Group *pGroup = NULL;
111        if (owner->GetTypeId() == TYPEID_PLAYER)
112        {
113            // Not only the player can summon the totem (scripted AI)
114            pGroup = ((Player*)owner)->GetGroup();
115            if (pGroup)
116            {
117                for(GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next())
118                {
119                    Player* Target = itr->getSource();
120                    if(Target && pGroup->SameSubGroup((Player*)owner, Target))
121                        Target->RemoveAurasDueToSpell(GetSpell());
122                }
123            }
124        }
125    }
126
127    CleanupsBeforeDelete();
128    AddObjectToRemoveList();
129}
130
131void Totem::SetOwner(uint64 guid)
132{
133    SetUInt64Value(UNIT_FIELD_SUMMONEDBY, guid);
134    SetUInt64Value(UNIT_FIELD_CREATEDBY, guid);
135    Unit *owner = this->GetOwner();
136    if (owner)
137    {
138        this->setFaction(owner->getFaction());
139        this->SetLevel(owner->getLevel());
140    }
141}
142
143Unit *Totem::GetOwner()
144{
145    uint64 ownerid = GetOwnerGUID();
146    if(!ownerid)
147        return NULL;
148    return ObjectAccessor::GetUnit(*this, ownerid);
149}
150
151void Totem::SetTypeBySummonSpell(SpellEntry const * spellProto)
152{
153    // Get spell casted by totem
154    SpellEntry const * totemSpell = sSpellStore.LookupEntry(GetSpell());
155    if (totemSpell)
156    {
157        // If spell have cast time -> so its active totem
158        if (GetSpellCastTime(totemSpell))
159            m_type = TOTEM_ACTIVE;
160    }
161    if(spellProto->SpellIconID==2056)
162        m_type = TOTEM_STATUE;                              //Jewelery statue
163}
164
165bool Totem::IsImmunedToSpell(SpellEntry const* spellInfo, bool useCharges)
166{
167    for (int i=0;i<3;i++)
168    {
169        switch(spellInfo->EffectApplyAuraName[i])
170        {
171            case SPELL_AURA_PERIODIC_DAMAGE:
172            case SPELL_AURA_PERIODIC_LEECH:
173                return true;
174            default:
175                continue;
176        }
177    }
178    return Creature::IsImmunedToSpell(spellInfo, useCharges);
179}
Note: See TracBrowser for help on using the browser.