[8449] Deprecate healing/damage item mods and merge internal data in to spell power.
[getmangos.git] / src / game / TemporarySummon.cpp
bloba93bdd925ca2787a35b9b7d0a3589b64c951979b
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
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.
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.
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
19 #include "TemporarySummon.h"
20 #include "Log.h"
21 #include "ObjectAccessor.h"
22 #include "CreatureAI.h"
24 TemporarySummon::TemporarySummon( uint64 summoner ) :
25 Creature(), m_type(TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN), m_timer(0), m_lifetime(0), m_summoner(summoner)
29 void TemporarySummon::Update( uint32 diff )
31 switch(m_type)
33 case TEMPSUMMON_MANUAL_DESPAWN:
34 break;
35 case TEMPSUMMON_TIMED_DESPAWN:
37 if (m_timer <= diff)
39 UnSummon();
40 return;
43 m_timer -= diff;
44 break;
46 case TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT:
48 if (!isInCombat())
50 if (m_timer <= diff)
52 UnSummon();
53 return;
56 m_timer -= diff;
58 else if (m_timer != m_lifetime)
59 m_timer = m_lifetime;
61 break;
64 case TEMPSUMMON_CORPSE_TIMED_DESPAWN:
66 if ( m_deathState == CORPSE)
68 if (m_timer <= diff)
70 UnSummon();
71 return;
74 m_timer -= diff;
76 break;
78 case TEMPSUMMON_CORPSE_DESPAWN:
80 // if m_deathState is DEAD, CORPSE was skipped
81 if ( m_deathState == CORPSE || m_deathState == DEAD)
83 UnSummon();
84 return;
87 break;
89 case TEMPSUMMON_DEAD_DESPAWN:
91 if ( m_deathState == DEAD )
93 UnSummon();
94 return;
96 break;
98 case TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN:
100 // if m_deathState is DEAD, CORPSE was skipped
101 if ( m_deathState == CORPSE || m_deathState == DEAD)
103 UnSummon();
104 return;
107 if (!isInCombat())
109 if (m_timer <= diff)
111 UnSummon();
112 return;
114 else
115 m_timer -= diff;
117 else if (m_timer != m_lifetime)
118 m_timer = m_lifetime;
119 break;
121 case TEMPSUMMON_TIMED_OR_DEAD_DESPAWN:
123 // if m_deathState is DEAD, CORPSE was skipped
124 if (m_deathState == DEAD)
126 UnSummon();
127 return;
130 if (!isInCombat() && isAlive() )
132 if (m_timer <= diff)
134 UnSummon();
135 return;
137 else
138 m_timer -= diff;
140 else if (m_timer != m_lifetime)
141 m_timer = m_lifetime;
142 break;
144 default:
145 UnSummon();
146 sLog.outError("Temporary summoned creature (entry: %u) have unknown type %u of ",GetEntry(),m_type);
147 break;
150 Creature::Update( diff );
153 void TemporarySummon::Summon(TempSummonType type, uint32 lifetime)
155 m_type = type;
156 m_timer = lifetime;
157 m_lifetime = lifetime;
159 GetMap()->Add((Creature*)this);
161 AIM_Initialize();
164 void TemporarySummon::UnSummon()
166 CombatStop();
168 Unit* sum = m_summoner ? ObjectAccessor::GetUnit(*this, m_summoner) : NULL;
169 if (sum && sum->GetTypeId() == TYPEID_UNIT && ((Creature*)sum)->AI())
171 ((Creature*)sum)->AI()->SummonedCreatureDespawn(this);
174 AddObjectToRemoveList();
177 void TemporarySummon::SaveToDB()