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"
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
)
33 case TEMPSUMMON_MANUAL_DESPAWN
:
35 case TEMPSUMMON_TIMED_DESPAWN
:
46 case TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT
:
58 else if (m_timer
!= m_lifetime
)
64 case TEMPSUMMON_CORPSE_TIMED_DESPAWN
:
66 if ( m_deathState
== CORPSE
)
78 case TEMPSUMMON_CORPSE_DESPAWN
:
80 // if m_deathState is DEAD, CORPSE was skipped
81 if ( m_deathState
== CORPSE
|| m_deathState
== DEAD
)
89 case TEMPSUMMON_DEAD_DESPAWN
:
91 if ( m_deathState
== DEAD
)
98 case TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN
:
100 // if m_deathState is DEAD, CORPSE was skipped
101 if ( m_deathState
== CORPSE
|| m_deathState
== DEAD
)
117 else if (m_timer
!= m_lifetime
)
118 m_timer
= m_lifetime
;
121 case TEMPSUMMON_TIMED_OR_DEAD_DESPAWN
:
123 // if m_deathState is DEAD, CORPSE was skipped
124 if (m_deathState
== DEAD
)
130 if (!isInCombat() && isAlive() )
140 else if (m_timer
!= m_lifetime
)
141 m_timer
= m_lifetime
;
146 sLog
.outError("Temporary summoned creature (entry: %u) have unknown type %u of ",GetEntry(),m_type
);
150 Creature::Update( diff
);
153 void TemporarySummon::Summon(TempSummonType type
, uint32 lifetime
)
157 m_lifetime
= lifetime
;
159 GetMap()->Add((Creature
*)this);
164 void TemporarySummon::UnSummon()
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()