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

Revision 265, 5.4 kB (checked in by yumileroy, 17 years ago)

*Add m_isAggressive. Only aggressive creatures will call AttackStart? and MoveInLineOfSight?.
*Set melee dmg school for summoned creatures.
*Fix some compiling errors.

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