[2] | 1 | /* |
---|
[102] | 2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
| 3 | * |
---|
[44] | 4 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
[2] | 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 |
---|
[44] | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
[2] | 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 |
---|
[44] | 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
[2] | 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 | |
---|
| 30 | Totem::Totem() : Creature() |
---|
| 31 | { |
---|
| 32 | m_isTotem = true; |
---|
| 33 | m_duration = 0; |
---|
| 34 | m_type = TOTEM_PASSIVE; |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | void 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 | |
---|
| 57 | void Totem::Summon(Unit* owner) |
---|
| 58 | { |
---|
| 59 | CreatureInfo const *cinfo = GetCreatureInfo(); |
---|
[123] | 60 | if (owner->GetTypeId()==TYPEID_PLAYER && cinfo) |
---|
[2] | 61 | { |
---|
[126] | 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 | } |
---|
[2] | 70 | else |
---|
[123] | 71 | { |
---|
[126] | 72 | if(cinfo->Modelid1) |
---|
| 73 | modelid = cinfo->Modelid1; |
---|
| 74 | else if(cinfo->Modelid2) |
---|
| 75 | modelid = cinfo->Modelid2; |
---|
[123] | 76 | } |
---|
[126] | 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()); |
---|
[2] | 81 | } |
---|
| 82 | |
---|
[123] | 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 | |
---|
[2] | 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 | } |
---|
[265] | 100 | |
---|
| 101 | if(GetEntry() == SENTRY_TOTEM_ENTRY) |
---|
| 102 | SetAggressive(true); |
---|
[2] | 103 | } |
---|
| 104 | |
---|
| 105 | void 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 | |
---|
| 148 | void 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 | |
---|
| 160 | Unit *Totem::GetOwner() |
---|
| 161 | { |
---|
| 162 | uint64 ownerid = GetOwnerGUID(); |
---|
| 163 | if(!ownerid) |
---|
| 164 | return NULL; |
---|
| 165 | return ObjectAccessor::GetUnit(*this, ownerid); |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | void 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 | } |
---|
[72] | 181 | |
---|
| 182 | bool 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); |
---|
[111] | 196 | } |
---|