1 | /* |
---|
2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
3 | * |
---|
4 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or modify |
---|
7 | * it under the terms of the GNU General Public License as published by |
---|
8 | * the Free Software Foundation; either version 2 of the License, or |
---|
9 | * (at your option) any later version. |
---|
10 | * |
---|
11 | * This program is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * GNU General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public License |
---|
17 | * along with this program; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
19 | */ |
---|
20 | |
---|
21 | #include "TemporarySummon.h" |
---|
22 | #include "WorldPacket.h" |
---|
23 | #include "MapManager.h" |
---|
24 | #include "Log.h" |
---|
25 | #include "ObjectAccessor.h" |
---|
26 | #include "CreatureAI.h" |
---|
27 | |
---|
28 | TemporarySummon::TemporarySummon( uint64 summoner ) : |
---|
29 | Creature(), m_type(TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN), m_timer(0), m_lifetime(0), m_summoner(summoner) |
---|
30 | { |
---|
31 | } |
---|
32 | |
---|
33 | void TemporarySummon::Update( uint32 diff ) |
---|
34 | { |
---|
35 | if (m_deathState == DEAD) |
---|
36 | { |
---|
37 | UnSummon(); |
---|
38 | return; |
---|
39 | } |
---|
40 | switch(m_type) |
---|
41 | { |
---|
42 | case TEMPSUMMON_MANUAL_DESPAWN: |
---|
43 | break; |
---|
44 | case TEMPSUMMON_TIMED_DESPAWN: |
---|
45 | { |
---|
46 | if (m_timer <= diff) |
---|
47 | { |
---|
48 | UnSummon(); |
---|
49 | return; |
---|
50 | } |
---|
51 | |
---|
52 | m_timer -= diff; |
---|
53 | break; |
---|
54 | } |
---|
55 | case TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT: |
---|
56 | { |
---|
57 | if (!isInCombat()) |
---|
58 | { |
---|
59 | if (m_timer <= diff) |
---|
60 | { |
---|
61 | UnSummon(); |
---|
62 | return; |
---|
63 | } |
---|
64 | |
---|
65 | m_timer -= diff; |
---|
66 | } |
---|
67 | else if (m_timer != m_lifetime) |
---|
68 | m_timer = m_lifetime; |
---|
69 | |
---|
70 | break; |
---|
71 | } |
---|
72 | |
---|
73 | case TEMPSUMMON_CORPSE_TIMED_DESPAWN: |
---|
74 | { |
---|
75 | if ( m_deathState == CORPSE) |
---|
76 | { |
---|
77 | if (m_timer <= diff) |
---|
78 | { |
---|
79 | UnSummon(); |
---|
80 | return; |
---|
81 | } |
---|
82 | |
---|
83 | m_timer -= diff; |
---|
84 | } |
---|
85 | break; |
---|
86 | } |
---|
87 | case TEMPSUMMON_CORPSE_DESPAWN: |
---|
88 | { |
---|
89 | // if m_deathState is DEAD, CORPSE was skipped |
---|
90 | if ( m_deathState == CORPSE || m_deathState == DEAD) |
---|
91 | { |
---|
92 | UnSummon(); |
---|
93 | return; |
---|
94 | } |
---|
95 | |
---|
96 | break; |
---|
97 | } |
---|
98 | case TEMPSUMMON_DEAD_DESPAWN: |
---|
99 | { |
---|
100 | if ( m_deathState == DEAD ) |
---|
101 | { |
---|
102 | UnSummon(); |
---|
103 | return; |
---|
104 | } |
---|
105 | break; |
---|
106 | } |
---|
107 | case TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN: |
---|
108 | { |
---|
109 | // if m_deathState is DEAD, CORPSE was skipped |
---|
110 | if ( m_deathState == CORPSE || m_deathState == DEAD) |
---|
111 | { |
---|
112 | UnSummon(); |
---|
113 | return; |
---|
114 | } |
---|
115 | |
---|
116 | if (!isInCombat()) |
---|
117 | { |
---|
118 | if (m_timer <= diff) |
---|
119 | { |
---|
120 | UnSummon(); |
---|
121 | return; |
---|
122 | } |
---|
123 | else |
---|
124 | m_timer -= diff; |
---|
125 | } |
---|
126 | else if (m_timer != m_lifetime) |
---|
127 | m_timer = m_lifetime; |
---|
128 | break; |
---|
129 | } |
---|
130 | case TEMPSUMMON_TIMED_OR_DEAD_DESPAWN: |
---|
131 | { |
---|
132 | // if m_deathState is DEAD, CORPSE was skipped |
---|
133 | if (m_deathState == DEAD) |
---|
134 | { |
---|
135 | UnSummon(); |
---|
136 | return; |
---|
137 | } |
---|
138 | |
---|
139 | if (!isInCombat() && isAlive() ) |
---|
140 | { |
---|
141 | if (m_timer <= diff) |
---|
142 | { |
---|
143 | UnSummon(); |
---|
144 | return; |
---|
145 | } |
---|
146 | else |
---|
147 | m_timer -= diff; |
---|
148 | } |
---|
149 | else if (m_timer != m_lifetime) |
---|
150 | m_timer = m_lifetime; |
---|
151 | break; |
---|
152 | } |
---|
153 | default: |
---|
154 | UnSummon(); |
---|
155 | sLog.outError("Temporary summoned creature (entry: %u) have unknown type %u of ",GetEntry(),m_type); |
---|
156 | break; |
---|
157 | } |
---|
158 | |
---|
159 | Creature::Update( diff ); |
---|
160 | } |
---|
161 | |
---|
162 | void TemporarySummon::Summon(TempSummonType type, uint32 lifetime) |
---|
163 | { |
---|
164 | m_type = type; |
---|
165 | m_timer = lifetime; |
---|
166 | m_lifetime = lifetime; |
---|
167 | |
---|
168 | MapManager::Instance().GetMap(GetMapId(), this)->Add((Creature*)this); |
---|
169 | |
---|
170 | AIM_Initialize(); |
---|
171 | } |
---|
172 | |
---|
173 | void TemporarySummon::UnSummon() |
---|
174 | { |
---|
175 | CombatStop(); |
---|
176 | |
---|
177 | UnpossessSelf(false); |
---|
178 | |
---|
179 | CleanupsBeforeDelete(); |
---|
180 | AddObjectToRemoveList(); |
---|
181 | |
---|
182 | Unit* sum = m_summoner ? ObjectAccessor::GetUnit(*this, m_summoner) : NULL; |
---|
183 | if (sum && sum->GetTypeId() == TYPEID_UNIT && ((Creature*)sum)->AI()) |
---|
184 | { |
---|
185 | ((Creature*)sum)->AI()->SummonedCreatureDespawn(this); |
---|
186 | } |
---|
187 | } |
---|
188 | |
---|
189 | void TemporarySummon::SaveToDB() |
---|
190 | { |
---|
191 | } |
---|