| 1 | /* |
|---|
| 2 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
|---|
| 3 | * |
|---|
| 4 | * Thanks to the original authors: MaNGOS <http://www.mangosproject.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 "TemporarySummon.h" |
|---|
| 22 | #include "WorldPacket.h" |
|---|
| 23 | #include "MapManager.h" |
|---|
| 24 | #include "Log.h" |
|---|
| 25 | #include "ObjectAccessor.h" |
|---|
| 26 | #include "CreatureAI.h" |
|---|
| 27 | |
|---|
| 28 | TemporarySummon::TemporarySummon( uint64 summoner ) : |
|---|
| 29 | Creature(), m_type(TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN), m_timer(0), m_lifetime(0), m_summoner(summoner) |
|---|
| 30 | { |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | void TemporarySummon::Update( uint32 diff ) |
|---|
| 34 | { |
|---|
| 35 | switch(m_type) |
|---|
| 36 | { |
|---|
| 37 | case TEMPSUMMON_MANUAL_DESPAWN: |
|---|
| 38 | break; |
|---|
| 39 | case TEMPSUMMON_TIMED_DESPAWN: |
|---|
| 40 | { |
|---|
| 41 | if (m_timer <= diff) |
|---|
| 42 | { |
|---|
| 43 | UnSummon(); |
|---|
| 44 | return; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | m_timer -= diff; |
|---|
| 48 | break; |
|---|
| 49 | } |
|---|
| 50 | case TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT: |
|---|
| 51 | { |
|---|
| 52 | if (!isInCombat()) |
|---|
| 53 | { |
|---|
| 54 | if (m_timer <= diff) |
|---|
| 55 | { |
|---|
| 56 | UnSummon(); |
|---|
| 57 | return; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | m_timer -= diff; |
|---|
| 61 | } |
|---|
| 62 | else if (m_timer != m_lifetime) |
|---|
| 63 | m_timer = m_lifetime; |
|---|
| 64 | |
|---|
| 65 | break; |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | case TEMPSUMMON_CORPSE_TIMED_DESPAWN: |
|---|
| 69 | { |
|---|
| 70 | if ( m_deathState == CORPSE) |
|---|
| 71 | { |
|---|
| 72 | if (m_timer <= diff) |
|---|
| 73 | { |
|---|
| 74 | UnSummon(); |
|---|
| 75 | return; |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | m_timer -= diff; |
|---|
| 79 | } |
|---|
| 80 | break; |
|---|
| 81 | } |
|---|
| 82 | case TEMPSUMMON_CORPSE_DESPAWN: |
|---|
| 83 | { |
|---|
| 84 | // if m_deathState is DEAD, CORPSE was skipped |
|---|
| 85 | if ( m_deathState == CORPSE || m_deathState == DEAD) |
|---|
| 86 | { |
|---|
| 87 | UnSummon(); |
|---|
| 88 | return; |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | break; |
|---|
| 92 | } |
|---|
| 93 | case TEMPSUMMON_DEAD_DESPAWN: |
|---|
| 94 | { |
|---|
| 95 | if ( m_deathState == DEAD ) |
|---|
| 96 | { |
|---|
| 97 | UnSummon(); |
|---|
| 98 | return; |
|---|
| 99 | } |
|---|
| 100 | break; |
|---|
| 101 | } |
|---|
| 102 | case TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN: |
|---|
| 103 | { |
|---|
| 104 | // if m_deathState is DEAD, CORPSE was skipped |
|---|
| 105 | if ( m_deathState == CORPSE || m_deathState == DEAD) |
|---|
| 106 | { |
|---|
| 107 | UnSummon(); |
|---|
| 108 | return; |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | if (!isInCombat()) |
|---|
| 112 | { |
|---|
| 113 | if (m_timer <= diff) |
|---|
| 114 | { |
|---|
| 115 | UnSummon(); |
|---|
| 116 | return; |
|---|
| 117 | } |
|---|
| 118 | else |
|---|
| 119 | m_timer -= diff; |
|---|
| 120 | } |
|---|
| 121 | else if (m_timer != m_lifetime) |
|---|
| 122 | m_timer = m_lifetime; |
|---|
| 123 | break; |
|---|
| 124 | } |
|---|
| 125 | case TEMPSUMMON_TIMED_OR_DEAD_DESPAWN: |
|---|
| 126 | { |
|---|
| 127 | // if m_deathState is DEAD, CORPSE was skipped |
|---|
| 128 | if (m_deathState == DEAD) |
|---|
| 129 | { |
|---|
| 130 | UnSummon(); |
|---|
| 131 | return; |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | if (!isInCombat() && isAlive() ) |
|---|
| 135 | { |
|---|
| 136 | if (m_timer <= diff) |
|---|
| 137 | { |
|---|
| 138 | UnSummon(); |
|---|
| 139 | return; |
|---|
| 140 | } |
|---|
| 141 | else |
|---|
| 142 | m_timer -= diff; |
|---|
| 143 | } |
|---|
| 144 | else if (m_timer != m_lifetime) |
|---|
| 145 | m_timer = m_lifetime; |
|---|
| 146 | break; |
|---|
| 147 | } |
|---|
| 148 | default: |
|---|
| 149 | UnSummon(); |
|---|
| 150 | sLog.outError("Temporary summoned creature (entry: %u) have unknown type %u of ",GetEntry(),m_type); |
|---|
| 151 | break; |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | Creature::Update( diff ); |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | void TemporarySummon::Summon(TempSummonType type, uint32 lifetime) |
|---|
| 158 | { |
|---|
| 159 | m_type = type; |
|---|
| 160 | m_timer = lifetime; |
|---|
| 161 | m_lifetime = lifetime; |
|---|
| 162 | |
|---|
| 163 | MapManager::Instance().GetMap(GetMapId(), this)->Add((Creature*)this); |
|---|
| 164 | |
|---|
| 165 | AIM_Initialize(); |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | void TemporarySummon::UnSummon() |
|---|
| 169 | { |
|---|
| 170 | CombatStop(); |
|---|
| 171 | |
|---|
| 172 | CleanupsBeforeDelete(); |
|---|
| 173 | AddObjectToRemoveList(); |
|---|
| 174 | |
|---|
| 175 | Unit* sum = m_summoner ? ObjectAccessor::GetUnit(*this, m_summoner) : NULL; |
|---|
| 176 | if (sum && sum->GetTypeId() == TYPEID_UNIT && ((Creature*)sum)->AI()) |
|---|
| 177 | { |
|---|
| 178 | ((Creature*)sum)->AI()->SummonedCreatureDespawn(this); |
|---|
| 179 | } |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | void TemporarySummon::SaveToDB() |
|---|
| 183 | { |
|---|
| 184 | } |
|---|