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

Revision 123, 4.9 kB (checked in by yumileroy, 17 years ago)

[svn] * Changed modelid_a/h(2) values to modelid1..4, display ids are no longer incorrectly chosen based on player faction. Patch provided by WarHead?.

Original author: w12x
Date: 2008-10-27 11:48:45-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    CreatureInfo const *cinfo = GetCreatureInfo();
60    if (owner->GetTypeId()==TYPEID_PLAYER && cinfo)
61    {
62        if (uint32 modelid = cinfo->GetRandomValidModelId()) 
63            SetDisplayId(modelid);
64        else
65        {
66            sLog.outErrorDb("No displayid found for the totem with the entry %u! Can't summon it!", GetEntry());
67            return;
68        }
69    }
70
71    // Only add if a display exists.
72    sLog.outDebug("AddObject at Totem.cpp line 49");
73    SetInstanceId(owner->GetInstanceId());
74    owner->GetMap()->Add((Creature*)this);
75
76    WorldPacket data(SMSG_GAMEOBJECT_SPAWN_ANIM_OBSOLETE, 8);
77    data << GetGUID();
78    SendMessageToSet(&data,true);
79
80    AIM_Initialize();
81
82    switch(m_type)
83    {
84        case TOTEM_PASSIVE: CastSpell(this, GetSpell(), true); break;
85        case TOTEM_STATUE:  CastSpell(GetOwner(), GetSpell(), true); break;
86        default: break;
87    }
88}
89
90void Totem::UnSummon()
91{
92    SendObjectDeSpawnAnim(GetGUID());
93
94    CombatStop();
95    RemoveAurasDueToSpell(GetSpell());
96    Unit *owner = this->GetOwner();
97    if (owner)
98    {
99        // clear owenr's totem slot
100        for(int i = 0; i < MAX_TOTEM; ++i)
101        {
102            if(owner->m_TotemSlot[i]==GetGUID())
103            {
104                owner->m_TotemSlot[i] = 0;
105                break;
106            }
107        }
108
109        owner->RemoveAurasDueToSpell(GetSpell());
110
111        //remove aura all party members too
112        Group *pGroup = NULL;
113        if (owner->GetTypeId() == TYPEID_PLAYER)
114        {
115            // Not only the player can summon the totem (scripted AI)
116            pGroup = ((Player*)owner)->GetGroup();
117            if (pGroup)
118            {
119                for(GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next())
120                {
121                    Player* Target = itr->getSource();
122                    if(Target && pGroup->SameSubGroup((Player*)owner, Target))
123                        Target->RemoveAurasDueToSpell(GetSpell());
124                }
125            }
126        }
127    }
128
129    CleanupsBeforeDelete();
130    AddObjectToRemoveList();
131}
132
133void Totem::SetOwner(uint64 guid)
134{
135    SetUInt64Value(UNIT_FIELD_SUMMONEDBY, guid);
136    SetUInt64Value(UNIT_FIELD_CREATEDBY, guid);
137    Unit *owner = this->GetOwner();
138    if (owner)
139    {
140        this->setFaction(owner->getFaction());
141        this->SetLevel(owner->getLevel());
142    }
143}
144
145Unit *Totem::GetOwner()
146{
147    uint64 ownerid = GetOwnerGUID();
148    if(!ownerid)
149        return NULL;
150    return ObjectAccessor::GetUnit(*this, ownerid);
151}
152
153void Totem::SetTypeBySummonSpell(SpellEntry const * spellProto)
154{
155    // Get spell casted by totem
156    SpellEntry const * totemSpell = sSpellStore.LookupEntry(GetSpell());
157    if (totemSpell)
158    {
159        // If spell have cast time -> so its active totem
160        if (GetSpellCastTime(totemSpell))
161            m_type = TOTEM_ACTIVE;
162    }
163    if(spellProto->SpellIconID==2056)
164        m_type = TOTEM_STATUE;                              //Jewelery statue
165}
166
167bool Totem::IsImmunedToSpell(SpellEntry const* spellInfo, bool useCharges)
168{
169    for (int i=0;i<3;i++)
170    {
171        switch(spellInfo->EffectApplyAuraName[i])
172        {
173            case SPELL_AURA_PERIODIC_DAMAGE:
174            case SPELL_AURA_PERIODIC_LEECH:
175                return true;
176            default:
177                continue;
178        }
179    }
180    return Creature::IsImmunedToSpell(spellInfo, useCharges);
181}
Note: See TracBrowser for help on using the browser.