Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
instance_the_black_morass.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6/*
7Name: Instance_The_Black_Morass
8%Complete: 50
9Comment: Quest support: 9836, 10297. Currently in progress.
10Category: Caverns of Time, The Black Morass
11*/
12
13#include "ScriptMgr.h"
14#include "InstanceScript.h"
15#include "the_black_morass.h"
16#include "Player.h"
17#include "TemporarySummon.h"
18#include "SpellInfo.h"
19#include "ScriptedCreature.h"
20
21enum Misc
22{
25};
26
27inline uint32 RandRiftBoss() { return ((rand()%2) ? NPC_RIFT_KEEPER : NPC_RIFT_LORD); }
28
29float PortalLocation[4][4]=
30{
31 {-2041.06f, 7042.08f, 29.99f, 1.30f},
32 {-1968.18f, 7042.11f, 21.93f, 2.12f},
33 {-1885.82f, 7107.36f, 22.32f, 3.07f},
34 {-1928.11f, 7175.95f, 22.11f, 3.44f}
35};
36
37struct Wave
38{
39 uint32 PortalBoss; //protector of current portal
40 uint32 NextPortalTime; //time to next portal, or 0 if portal boss need to be killed
41};
42
43static Wave RiftWaves[]=
44{
45 { RIFT_BOSS, 0 },
47 { RIFT_BOSS, 120000 },
48 { NPC_TEMPORUS, 140000 },
49 { RIFT_BOSS, 120000 },
50 { NPC_AEONUS, 0 }
51};
52
57
59{
60public:
61 instance_the_black_morass() : InstanceMapScript("instance_the_black_morass", 269) { }
62
67
69 {
71
73
78
81
83 {
84 _medivhGUID = 0;
85 Clear();
86 }
87
88 void Clear()
89 {
90 memset(&m_auiEncounter, 0, sizeof(m_auiEncounter));
91
93 mShieldPercent = 100;
95 mRiftWaveId = 0;
96
98 }
99
100 void InitWorldState(bool Enable = true)
101 {
102 DoUpdateWorldState(WORLD_STATE_BM, Enable ? 1 : 0);
105 }
106
108 {
110 return true;
111
112 return false;
113 }
114
116 {
118 return;
119
120 player->SendUpdateWorldState(WORLD_STATE_BM, 0);
121 }
122
124 {
125 if (creature->GetEntry() == NPC_MEDIVH)
126 _medivhGUID = creature->GetGUID();
127 }
128
129 //what other conditions to check?
131 {
132 if (instance->GetPlayers().isEmpty())
133 return false;
134
135 return true;
136 }
137
139 {
140 switch (mRiftPortalCount)
141 {
142 case 6:
143 mRiftWaveId = 2;
144 return 1;
145 case 12:
146 mRiftWaveId = 4;
147 return 3;
148 case 18:
149 return 5;
150 default:
151 return mRiftWaveId;
152 }
153 }
154
155 void SetData(uint32 type, uint32 data) OVERRIDE
156 {
157 switch (type)
158 {
159 case TYPE_MEDIVH:
160 if (data == SPECIAL && m_auiEncounter[0] == IN_PROGRESS)
161 {
163
165
166 if (!mShieldPercent)
167 {
168 if (Creature* medivh = instance->GetCreature(_medivhGUID))
169 {
170 if (medivh->IsAlive())
171 {
172 medivh->DealDamage(medivh, medivh->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
173 m_auiEncounter[0] = FAIL;
175 }
176 }
177 }
178 }
179 else
180 {
181 if (data == IN_PROGRESS)
182 {
183 SF_LOG_DEBUG("scripts", "Instance The Black Morass: Starting event.");
187 }
188
189 if (data == DONE)
190 {
191 //this may be completed further out in the post-event
192 SF_LOG_DEBUG("scripts", "Instance The Black Morass: Event completed.");
193 Map::PlayerList const& players = instance->GetPlayers();
194
195 if (!players.isEmpty())
196 {
197 for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
198 {
199 if (Player* player = itr->GetSource())
200 {
201 if (player->GetQuestStatus(QUEST_OPENING_PORTAL) == QUEST_STATUS_INCOMPLETE)
202 player->AreaExploredOrEventHappens(QUEST_OPENING_PORTAL);
203
204 if (player->GetQuestStatus(QUEST_MASTER_TOUCH) == QUEST_STATUS_INCOMPLETE)
205 player->AreaExploredOrEventHappens(QUEST_MASTER_TOUCH);
206 }
207 }
208 }
209 }
210
211 m_auiEncounter[0] = data;
212 }
213 break;
214 case TYPE_RIFT:
215 if (data == SPECIAL)
216 {
217 if (mRiftPortalCount < 7)
219 }
220 else
221 m_auiEncounter[1] = data;
222 break;
223 }
224 }
225
227 {
228 switch (type)
229 {
230 case TYPE_MEDIVH:
231 return m_auiEncounter[0];
232 case TYPE_RIFT:
233 return m_auiEncounter[1];
235 return mRiftPortalCount;
236 case DATA_SHIELD:
237 return mShieldPercent;
238 }
239 return 0;
240 }
241
243 {
244 if (data == DATA_MEDIVH)
245 return _medivhGUID;
246
247 return 0;
248 }
249
251 {
252 uint32 entry = RiftWaves[GetRiftWaveId()].PortalBoss;
253
254 if (entry == RIFT_BOSS)
255 entry = RandRiftBoss();
256
257 SF_LOG_DEBUG("scripts", "Instance The Black Morass: Summoning rift boss entry %u.", entry);
258
259 Position pos;
260 me->GetRandomNearPosition(pos, 10.0f);
261
262 //normalize Z-level if we can, if rift is not at ground level.
263 pos.m_positionZ = std::max(me->GetMap()->GetHeight(pos.m_positionX, pos.m_positionY, MAX_HEIGHT), me->GetMap()->GetWaterLevel(pos.m_positionX, pos.m_positionY));
264
265 if (Creature* summon = me->SummonCreature(entry, pos, TempSummonType::TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, 600000))
266 return summon;
267
268 SF_LOG_DEBUG("scripts", "Instance The Black Morass: What just happened there? No boss, no loot, no fun...");
269 return NULL;
270 }
271
273 {
274 if (Creature* medivh = instance->GetCreature(_medivhGUID))
275 {
276 uint8 tmp = std::rand() % 2;
277
278 if (tmp >= _currentRiftId)
279 ++tmp;
280
281 SF_LOG_DEBUG("scripts", "Instance The Black Morass: Creating Time Rift at locationId %i (old locationId was %u).", tmp, _currentRiftId);
282
283 _currentRiftId = tmp;
284
285 Creature* temp = medivh->SummonCreature(NPC_TIME_RIFT,
286 PortalLocation[tmp][0], PortalLocation[tmp][1], PortalLocation[tmp][2], PortalLocation[tmp][3],
288 if (temp)
289 {
292
293 if (Creature* boss = SummonedPortalBoss(temp))
294 {
295 if (boss->GetEntry() == NPC_AEONUS)
296 boss->AddThreat(medivh, 0.0f);
297 else
298 {
299 boss->AddThreat(temp, 0.0f);
300 temp->CastSpell(boss, SPELL_RIFT_CHANNEL, false);
301 }
302 }
303 }
304 }
305 }
306
308 {
309 if (m_auiEncounter[1] != IN_PROGRESS)
310 return;
311
312 //add delay timer?
313 if (!CanProgressEvent())
314 {
315 Clear();
316 return;
317 }
318
319 Events.Update(diff);
320
321 if (Events.ExecuteEvent() == EVENT_NEXT_PORTAL)
322 {
327 }
328 }
329
330 void ScheduleEventNextPortal(uint32 nextPortalTime)
331 {
332 if (nextPortalTime > 0)
333 Events.RescheduleEvent(EVENT_NEXT_PORTAL, nextPortalTime);
334 }
335
336 protected:
338 };
339};
340
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
#define OVERRIDE
Definition Define.h:60
std::uint64_t uint64
Definition Define.h:76
@ IN_PROGRESS
@ FAIL
@ DONE
@ SPECIAL
@ NOT_STARTED
#define SF_LOG_DEBUG(filterType__,...)
Definition Log.h:134
#define MAX_HEIGHT
Definition Map.h:141
@ TEMPSUMMON_CORPSE_DESPAWN
Definition Object.h:72
@ TEMPSUMMON_TIMED_OR_DEAD_DESPAWN
Definition Object.h:68
@ QUEST_STATUS_INCOMPLETE
Definition QuestDef.h:89
@ SPELL_SCHOOL_MASK_NORMAL
@ UNIT_FLAG_NON_ATTACKABLE
Definition Unit.h:626
@ UNIT_FLAG_NOT_SELECTABLE
Definition Unit.h:650
@ DIRECT_DAMAGE
Definition Unit.h:614
@ UNIT_FIELD_FLAGS
uint32 const EncounterCount
InstanceMapScript(const char *name, uint32 mapId)
InstanceScript(Map *map)
void DoUpdateWorldState(uint32 worldstateId, uint32 worldstateValue)
bool isEmpty() const
Definition LinkedList.h:86
Definition Map.h:238
float GetWaterLevel(float x, float y) const
Definition Map.cpp:2195
float GetHeight(float x, float y, float z, bool checkVMap=true, float maxSearchDist=DEFAULT_HEIGHT_SEARCH) const
Definition Map.cpp:1959
MapRefManager PlayerList
Definition Map.h:406
iterator end()
iterator begin()
LinkedListHead::Iterator< MapReference const > const_iterator
void SetFlag(uint16 index, uint32 newFlag)
Definition Object.cpp:1261
void CastSpell(SpellCastTargets const &targets, SpellInfo const *spellInfo, CustomSpellValues const *value, TriggerCastFlags triggerFlags=TRIGGERED_NONE, Item *castItem=NULL, AuraEffect const *triggeredByAura=NULL, uint64 originalCaster=0)
Map * GetMap() const
Definition Object.h:740
void GetRandomNearPosition(Position &pos, float radius)
Definition Object.cpp:3088
TempSummon * SummonCreature(uint32 id, Position const &pos, TempSummonType spwtype=TempSummonType::TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime=0, uint32 vehId=0) const
Definition Object.cpp:2703
InstanceScript * GetInstanceScript(InstanceMap *map) const OVERRIDE
float PortalLocation[4][4]
void AddSC_instance_the_black_morass()
uint32 RandRiftBoss()
static Wave RiftWaves[]
float m_positionZ
Definition Object.h:289
float m_positionX
Definition Object.h:287
float m_positionY
Definition Object.h:288
Definition hyjalAI.h:31
@ WORLD_STATE_BM_SHIELD
@ WORLD_STATE_BM_RIFT
@ WORLD_STATE_BM
@ QUEST_MASTER_TOUCH
@ QUEST_OPENING_PORTAL
@ NPC_AEONUS
@ NPC_RIFT_KEEPER
@ NPC_MEDIVH
@ NPC_RIFT_LORD
@ NPC_TEMPORUS
@ NPC_CRONO_LORD_DEJA
@ DATA_MEDIVH
@ DATA_PORTAL_COUNT
@ TYPE_MEDIVH
@ TYPE_RIFT
@ DATA_SHIELD