root/trunk/src/game/TemporarySummon.cpp @ 23

Revision 2, 4.6 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

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