Advertisement
SkullCrack

Totem.cpp

Aug 7th, 2011
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.56 KB | None | 0 0
  1. /*
  2.  * Copyright (C) 2008-2011 TrinityCore <http://www.trinitycore.org/>
  3.  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify it
  6.  * under the terms of the GNU General Public License as published by the
  7.  * Free Software Foundation; either version 2 of the License, or (at your
  8.  * option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful, but WITHOUT
  11.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12.  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13.  * more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License along
  16.  * with this program. If not, see <http://www.gnu.org/licenses/>.
  17.  */
  18.  
  19. #include "Totem.h"
  20. #include "WorldPacket.h"
  21. #include "Log.h"
  22. #include "Group.h"
  23. #include "Player.h"
  24. #include "ObjectMgr.h"
  25. #include "SpellMgr.h"
  26. #include "SpellInfo.h"
  27.  
  28. Totem::Totem(SummonPropertiesEntry const* properties, Unit* owner) : Minion(properties, owner)
  29. {
  30.     m_unitTypeMask |= UNIT_MASK_TOTEM;
  31.     m_duration = 0;
  32.     m_type = TOTEM_PASSIVE;
  33. }
  34.  
  35. void Totem::Update(uint32 time)
  36. {
  37.     if (!m_owner->isAlive() || !isAlive())
  38.     {
  39.         UnSummon();                                         // remove self
  40.         return;
  41.     }
  42.  
  43.     if (m_duration <= time)
  44.     {
  45.         UnSummon();                                         // remove self
  46.         return;
  47.     }
  48.     else
  49.         m_duration -= time;
  50.  
  51.     Creature::Update(time);
  52. }
  53.  
  54. void Totem::InitStats(uint32 duration)
  55. {
  56.     // client requires SMSG_TOTEM_CREATED to be sent before adding to world and before removing old totem
  57.     if (m_owner->GetTypeId() == TYPEID_PLAYER
  58.         && m_Properties->Slot >= SUMMON_SLOT_TOTEM
  59.         && m_Properties->Slot < MAX_TOTEM_SLOT)
  60.     {
  61.         WorldPacket data(SMSG_TOTEM_CREATED, 1 + 8 + 4 + 4);
  62.         data << uint8(m_Properties->Slot - 1);
  63.         data << uint64(GetGUID());
  64.         data << uint32(duration);
  65.         data << uint32(GetUInt32Value(UNIT_CREATED_BY_SPELL));
  66.         m_owner->ToPlayer()->SendDirectMessage(&data);
  67.  
  68.         // set display id depending on caster's race
  69.         SetDisplayId(m_owner->GetModelForTotem(PlayerTotemType(m_Properties->Id)));
  70.     }
  71.  
  72.     Minion::InitStats(duration);
  73.  
  74.     // Get spell cast by totem
  75.     if (SpellInfo const* totemSpell = sSpellMgr->GetSpellInfo(GetSpell()))
  76.         if (totemSpell->CalcCastTime())   // If spell has cast time -> its an active totem
  77.             m_type = TOTEM_ACTIVE;
  78.  
  79.     if (GetEntry() == SENTRY_TOTEM_ENTRY)
  80.         SetReactState(REACT_AGGRESSIVE);
  81.  
  82.     m_duration = duration;
  83.  
  84.     SetLevel(m_owner->getLevel());
  85. }
  86.  
  87. void Totem::InitSummon()
  88. {
  89.     if (m_type == TOTEM_PASSIVE)
  90.         CastSpell(this, GetSpell(), true);
  91.  
  92.     // Some totems can have both instant effect and passive spell
  93.     if (GetSpell(1))
  94.         CastSpell(this, GetSpell(1), true);
  95. }
  96.  
  97. void Totem::UnSummon()
  98. {
  99.     CombatStop();
  100.     RemoveAurasDueToSpell(GetSpell());
  101.  
  102.     // clear owner's totem slot
  103.     for (int i = SUMMON_SLOT_TOTEM; i < MAX_TOTEM_SLOT; ++i)
  104.     {
  105.         if (m_owner->m_SummonSlot[i] == GetGUID())
  106.         {
  107.             m_owner->m_SummonSlot[i] = 0;
  108.             break;
  109.         }
  110.     }
  111.  
  112.     m_owner->RemoveAurasDueToSpell(GetSpell());
  113.  
  114.     //remove aura all party members too
  115.     if (Player* owner = m_owner->ToPlayer())
  116.     {
  117.         owner->SendAutoRepeatCancel(this);
  118.  
  119.         if (SpellInfo const* spell = sSpellMgr->GetSpellInfo(GetUInt32Value(UNIT_CREATED_BY_SPELL)))
  120.             owner->SendCooldownEvent(spell, 0, NULL, false);
  121.  
  122.         if (Group* group = owner->GetGroup())
  123.         {
  124.             for (GroupReference* itr = group->GetFirstMember(); itr != NULL; itr = itr->next())
  125.             {
  126.                 Player* target = itr->getSource();
  127.                 if (target && group->SameSubGroup(owner, target))
  128.                     target->RemoveAurasDueToSpell(GetSpell());
  129.             }
  130.         }
  131.     }
  132.  
  133.     AddObjectToRemoveList();
  134. }
  135.  
  136. bool Totem::IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index) const
  137. {
  138.     // TODO: possibly all negative auras immune?
  139.     if (GetEntry() == 5925)
  140.         return false;
  141.  
  142.     switch (spellInfo->Effects[index].ApplyAuraName)
  143.     {
  144.         case SPELL_AURA_PERIODIC_DAMAGE:
  145.         case SPELL_AURA_PERIODIC_LEECH:
  146.         case SPELL_AURA_MOD_FEAR:
  147.         case SPELL_AURA_TRANSFORM:
  148.             return true;
  149.         default:
  150.             break;
  151.     }
  152.  
  153.     return Creature::IsImmunedToSpellEffect(spellInfo, index);
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement