[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / src / game / TemporarySummon.cpp
blobd24e3ba83455a65365460182c576aedd9d4565f4
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 "WorldPacket.h"
21 #include "MapManager.h"
22 #include "Log.h"
23 #include "ObjectAccessor.h"
24 #include "CreatureAI.h"
26 TemporarySummon::TemporarySummon( uint64 summoner ) :
27 Creature(), m_type(TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN), m_timer(0), m_lifetime(0), m_summoner(summoner)
31 void TemporarySummon::Update( uint32 diff )
33 switch(m_type)
35 case TEMPSUMMON_MANUAL_DESPAWN:
36 break;
37 case TEMPSUMMON_TIMED_DESPAWN:
39 if (m_timer <= diff)
41 UnSummon();
42 return;
45 m_timer -= diff;
46 break;
48 case TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT:
50 if (!isInCombat())
52 if (m_timer <= diff)
54 UnSummon();
55 return;
58 m_timer -= diff;
60 else if (m_timer != m_lifetime)
61 m_timer = m_lifetime;
63 break;
66 case TEMPSUMMON_CORPSE_TIMED_DESPAWN:
68 if ( m_deathState == CORPSE)
70 if (m_timer <= diff)
72 UnSummon();
73 return;
76 m_timer -= diff;
78 break;
80 case TEMPSUMMON_CORPSE_DESPAWN:
82 // if m_deathState is DEAD, CORPSE was skipped
83 if ( m_deathState == CORPSE || m_deathState == DEAD)
85 UnSummon();
86 return;
89 break;
91 case TEMPSUMMON_DEAD_DESPAWN:
93 if ( m_deathState == DEAD )
95 UnSummon();
96 return;
98 break;
100 case TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN:
102 // if m_deathState is DEAD, CORPSE was skipped
103 if ( m_deathState == CORPSE || m_deathState == DEAD)
105 UnSummon();
106 return;
109 if (!isInCombat())
111 if (m_timer <= diff)
113 UnSummon();
114 return;
116 else
117 m_timer -= diff;
119 else if (m_timer != m_lifetime)
120 m_timer = m_lifetime;
121 break;
123 case TEMPSUMMON_TIMED_OR_DEAD_DESPAWN:
125 // if m_deathState is DEAD, CORPSE was skipped
126 if (m_deathState == DEAD)
128 UnSummon();
129 return;
132 if (!isInCombat() && isAlive() )
134 if (m_timer <= diff)
136 UnSummon();
137 return;
139 else
140 m_timer -= diff;
142 else if (m_timer != m_lifetime)
143 m_timer = m_lifetime;
144 break;
146 default:
147 UnSummon();
148 sLog.outError("Temporary summoned creature (entry: %u) have unknown type %u of ",GetEntry(),m_type);
149 break;
152 Creature::Update( diff );
155 void TemporarySummon::Summon(TempSummonType type, uint32 lifetime)
157 m_type = type;
158 m_timer = lifetime;
159 m_lifetime = lifetime;
161 GetMap()->Add((Creature*)this);
163 AIM_Initialize();
166 void TemporarySummon::UnSummon()
168 CombatStop();
170 CleanupsBeforeDelete();
171 AddObjectToRemoveList();
173 Unit* sum = m_summoner ? ObjectAccessor::GetUnit(*this, m_summoner) : NULL;
174 if (sum && sum->GetTypeId() == TYPEID_UNIT && ((Creature*)sum)->AI())
176 ((Creature*)sum)->AI()->SummonedCreatureDespawn(this);
180 void TemporarySummon::SaveToDB()