2 * Copyright (C) 2005-2008 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"
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
)
35 case TEMPSUMMON_MANUAL_DESPAWN
:
37 case TEMPSUMMON_TIMED_DESPAWN
:
48 case TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT
:
60 else if (m_timer
!= m_lifetime
)
66 case TEMPSUMMON_CORPSE_TIMED_DESPAWN
:
68 if ( m_deathState
== CORPSE
)
80 case TEMPSUMMON_CORPSE_DESPAWN
:
82 // if m_deathState is DEAD, CORPSE was skipped
83 if ( m_deathState
== CORPSE
|| m_deathState
== DEAD
)
91 case TEMPSUMMON_DEAD_DESPAWN
:
93 if ( m_deathState
== DEAD
)
100 case TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN
:
102 // if m_deathState is DEAD, CORPSE was skipped
103 if ( m_deathState
== CORPSE
|| m_deathState
== DEAD
)
119 else if (m_timer
!= m_lifetime
)
120 m_timer
= m_lifetime
;
123 case TEMPSUMMON_TIMED_OR_DEAD_DESPAWN
:
125 // if m_deathState is DEAD, CORPSE was skipped
126 if (m_deathState
== DEAD
)
132 if (!isInCombat() && isAlive() )
142 else if (m_timer
!= m_lifetime
)
143 m_timer
= m_lifetime
;
148 sLog
.outError("Temporary summoned creature (entry: %u) have unknown type %u of ",GetEntry(),m_type
);
152 Creature::Update( diff
);
155 void TemporarySummon::Summon(TempSummonType type
, uint32 lifetime
)
159 m_lifetime
= lifetime
;
161 GetMap()->Add((Creature
*)this);
166 void TemporarySummon::UnSummon()
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()