[2] | 1 | /* |
---|
| 2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
| 3 | * |
---|
| 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. |
---|
| 8 | * |
---|
| 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. |
---|
| 13 | * |
---|
| 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 |
---|
| 17 | */ |
---|
| 18 | |
---|
| 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" |
---|
| 27 | |
---|
| 28 | Totem::Totem() : Creature() |
---|
| 29 | { |
---|
| 30 | m_isTotem = true; |
---|
| 31 | m_duration = 0; |
---|
| 32 | m_type = TOTEM_PASSIVE; |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | void Totem::Update( uint32 time ) |
---|
| 36 | { |
---|
| 37 | Unit *owner = GetOwner(); |
---|
| 38 | if (!owner || !owner->isAlive() || !this->isAlive()) |
---|
| 39 | { |
---|
| 40 | UnSummon(); // remove self |
---|
| 41 | return; |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | if (m_duration <= time) |
---|
| 45 | { |
---|
| 46 | UnSummon(); // remove self |
---|
| 47 | return; |
---|
| 48 | } |
---|
| 49 | else |
---|
| 50 | m_duration -= time; |
---|
| 51 | |
---|
| 52 | Creature::Update( time ); |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | void Totem::Summon(Unit* owner) |
---|
| 56 | { |
---|
| 57 | sLog.outDebug("AddObject at Totem.cpp line 49"); |
---|
| 58 | |
---|
| 59 | SetInstanceId(owner->GetInstanceId()); |
---|
| 60 | owner->GetMap()->Add((Creature*)this); |
---|
| 61 | |
---|
| 62 | // select totem model in dependent from owner team |
---|
| 63 | CreatureInfo const *cinfo = GetCreatureInfo(); |
---|
| 64 | if(owner->GetTypeId()==TYPEID_PLAYER && cinfo) |
---|
| 65 | { |
---|
| 66 | if(((Player*)owner)->GetTeam()==HORDE) |
---|
| 67 | SetDisplayId(cinfo->DisplayID_H); |
---|
| 68 | else |
---|
| 69 | SetDisplayId(cinfo->DisplayID_A); |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | WorldPacket data(SMSG_GAMEOBJECT_SPAWN_ANIM_OBSOLETE, 8); |
---|
| 73 | data << GetGUID(); |
---|
| 74 | SendMessageToSet(&data,true); |
---|
| 75 | |
---|
| 76 | AIM_Initialize(); |
---|
| 77 | |
---|
| 78 | switch(m_type) |
---|
| 79 | { |
---|
| 80 | case TOTEM_PASSIVE: CastSpell(this, GetSpell(), true); break; |
---|
| 81 | case TOTEM_STATUE: CastSpell(GetOwner(), GetSpell(), true); break; |
---|
| 82 | default: break; |
---|
| 83 | } |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | void Totem::UnSummon() |
---|
| 87 | { |
---|
| 88 | SendObjectDeSpawnAnim(GetGUID()); |
---|
| 89 | |
---|
| 90 | CombatStop(); |
---|
| 91 | RemoveAurasDueToSpell(GetSpell()); |
---|
| 92 | Unit *owner = this->GetOwner(); |
---|
| 93 | if (owner) |
---|
| 94 | { |
---|
| 95 | // clear owenr's totem slot |
---|
| 96 | for(int i = 0; i < MAX_TOTEM; ++i) |
---|
| 97 | { |
---|
| 98 | if(owner->m_TotemSlot[i]==GetGUID()) |
---|
| 99 | { |
---|
| 100 | owner->m_TotemSlot[i] = 0; |
---|
| 101 | break; |
---|
| 102 | } |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | owner->RemoveAurasDueToSpell(GetSpell()); |
---|
| 106 | |
---|
| 107 | //remove aura all party members too |
---|
| 108 | Group *pGroup = NULL; |
---|
| 109 | if (owner->GetTypeId() == TYPEID_PLAYER) |
---|
| 110 | { |
---|
| 111 | // Not only the player can summon the totem (scripted AI) |
---|
| 112 | pGroup = ((Player*)owner)->GetGroup(); |
---|
| 113 | if (pGroup) |
---|
| 114 | { |
---|
| 115 | for(GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next()) |
---|
| 116 | { |
---|
| 117 | Player* Target = itr->getSource(); |
---|
| 118 | if(Target && pGroup->SameSubGroup((Player*)owner, Target)) |
---|
| 119 | Target->RemoveAurasDueToSpell(GetSpell()); |
---|
| 120 | } |
---|
| 121 | } |
---|
| 122 | } |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | CleanupsBeforeDelete(); |
---|
| 126 | AddObjectToRemoveList(); |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | void Totem::SetOwner(uint64 guid) |
---|
| 130 | { |
---|
| 131 | SetUInt64Value(UNIT_FIELD_SUMMONEDBY, guid); |
---|
| 132 | SetUInt64Value(UNIT_FIELD_CREATEDBY, guid); |
---|
| 133 | Unit *owner = this->GetOwner(); |
---|
| 134 | if (owner) |
---|
| 135 | { |
---|
| 136 | this->setFaction(owner->getFaction()); |
---|
| 137 | this->SetLevel(owner->getLevel()); |
---|
| 138 | } |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | Unit *Totem::GetOwner() |
---|
| 142 | { |
---|
| 143 | uint64 ownerid = GetOwnerGUID(); |
---|
| 144 | if(!ownerid) |
---|
| 145 | return NULL; |
---|
| 146 | return ObjectAccessor::GetUnit(*this, ownerid); |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | void Totem::SetTypeBySummonSpell(SpellEntry const * spellProto) |
---|
| 150 | { |
---|
| 151 | // Get spell casted by totem |
---|
| 152 | SpellEntry const * totemSpell = sSpellStore.LookupEntry(GetSpell()); |
---|
| 153 | if (totemSpell) |
---|
| 154 | { |
---|
| 155 | // If spell have cast time -> so its active totem |
---|
| 156 | if (GetSpellCastTime(totemSpell)) |
---|
| 157 | m_type = TOTEM_ACTIVE; |
---|
| 158 | } |
---|
| 159 | if(spellProto->SpellIconID==2056) |
---|
| 160 | m_type = TOTEM_STATUE; //Jewelery statue |
---|
| 161 | } |
---|