-
Notifications
You must be signed in to change notification settings - Fork 202
Expand file tree
/
Copy pathinstance_gundrak.cpp
More file actions
488 lines (432 loc) · 17.5 KB
/
instance_gundrak.cpp
File metadata and controls
488 lines (432 loc) · 17.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
/* This file is part of the ScriptDev2 Project. See AUTHORS file for Copyright information
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* ScriptData
SDName: instance_gundrak
SD%Complete: 80
SDComment: Reload case for bridge support is missing, achievement support is missing
SDCategory: Gundrak
EndScriptData */
#include "precompiled.h"
#include "gundrak.h"
bool GOUse_go_gundrak_altar(Player* /*pPlayer*/, GameObject* pGo)
{
ScriptedInstance* pInstance = (ScriptedInstance*)pGo->GetInstanceData();
if (!pInstance)
return false;
switch (pGo->GetEntry())
{
case GO_ALTAR_OF_SLADRAN: pInstance->SetData(TYPE_SLADRAN, SPECIAL); break;
case GO_ALTAR_OF_MOORABI: pInstance->SetData(TYPE_MOORABI, SPECIAL); break;
case GO_ALTAR_OF_COLOSSUS: pInstance->SetData(TYPE_COLOSSUS, SPECIAL); break;
}
pGo->UseDoorOrButton(0, true);
return true;
}
instance_gundrak::instance_gundrak(Map* pMap) : ScriptedInstance(pMap),
m_bLessRabi(false)
{
Initialize();
}
void instance_gundrak::Initialize()
{
memset(&m_auiEncounter, 0, sizeof(m_auiEncounter));
m_vStalkerCasterGuids.reserve(3);
m_vStalkerTargetGuids.reserve(3);
}
void instance_gundrak::OnCreatureCreate(Creature* pCreature)
{
switch (pCreature->GetEntry())
{
case NPC_SLADRAN:
case NPC_ELEMENTAL:
case NPC_COLOSSUS:
m_mNpcEntryGuidStore[pCreature->GetEntry()] = pCreature->GetObjectGuid();
break;
case NPC_INVISIBLE_STALKER:
m_luiStalkerGUIDs.push_back(pCreature->GetObjectGuid());
break;
case NPC_SLADRAN_SUMMON_T:
m_lSummonTargetsGuids.push_back(pCreature->GetObjectGuid());
break;
case NPC_LIVIN_MOJO:
// Store only the Mojos used to activate the Colossus
if (pCreature->GetPositionX() > 1650.0f)
m_sColossusMojosGuids.insert(pCreature->GetObjectGuid());
break;
}
}
/* TODO: Reload case need some love!
* Problem is to get the bridge/ collision work correct in relaod case.
* To provide correct functionality(expecting testers to activate all altars in reload case), the Keys aren't loaded, too
* TODO: When fixed, also remove the SPECIAL->DONE data translation in Load().
*
* For the Keys should be used something like this, and for bridge and collision similar
*
* if (m_auiEncounter[0] == SPECIAL && m_auiEncounter[1] == SPECIAL && m_auiEncounter[2] == SPECIAL)
* pGo->SetGoState(GO_STATE_ACTIVE_ALTERNATIVE);
* else
* pGo->SetGoState(GO_STATE_READY);
*/
void instance_gundrak::OnObjectCreate(GameObject* pGo)
{
switch (pGo->GetEntry())
{
case GO_ECK_DOOR:
if (m_auiEncounter[TYPE_MOORABI] == DONE && !instance->IsRegularDifficulty())
pGo->SetGoState(GO_STATE_ACTIVE);
break;
case GO_ECK_UNDERWATER_DOOR:
if (m_auiEncounter[TYPE_ECK] == DONE)
pGo->SetGoState(GO_STATE_ACTIVE);
break;
case GO_GALDARAH_DOOR:
pGo->SetGoState(GO_STATE_ACTIVE);
break;
case GO_EXIT_DOOR_L:
if (m_auiEncounter[TYPE_GALDARAH] == DONE)
pGo->SetGoState(GO_STATE_ACTIVE);
break;
case GO_EXIT_DOOR_R:
if (m_auiEncounter[TYPE_GALDARAH] == DONE)
pGo->SetGoState(GO_STATE_ACTIVE);
break;
case GO_ALTAR_OF_SLADRAN:
if (m_auiEncounter[TYPE_SLADRAN] == DONE)
pGo->RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_NO_INTERACT);
break;
case GO_ALTAR_OF_MOORABI:
if (m_auiEncounter[TYPE_MOORABI] == DONE)
pGo->RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_NO_INTERACT);
break;
case GO_ALTAR_OF_COLOSSUS:
if (m_auiEncounter[TYPE_COLOSSUS] == DONE)
pGo->RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_NO_INTERACT);
break;
case GO_SNAKE_KEY:
case GO_TROLL_KEY:
case GO_MAMMOTH_KEY:
case GO_RHINO_KEY:
case GO_BRIDGE:
case GO_COLLISION:
break;
default:
return;
}
m_mGoEntryGuidStore[pGo->GetEntry()] = pGo->GetObjectGuid();
}
void instance_gundrak::Load(const char* chrIn)
{
if (!chrIn)
{
OUT_LOAD_INST_DATA_FAIL;
return;
}
OUT_LOAD_INST_DATA(chrIn);
std::istringstream loadStream(chrIn);
loadStream >> m_auiEncounter[TYPE_SLADRAN] >> m_auiEncounter[TYPE_MOORABI] >> m_auiEncounter[TYPE_COLOSSUS] >> m_auiEncounter[TYPE_GALDARAH] >> m_auiEncounter[TYPE_ECK];
for (uint8 i = 0; i < MAX_ENCOUNTER; ++i)
{
if (m_auiEncounter[i] == IN_PROGRESS)
m_auiEncounter[i] = NOT_STARTED;
// TODO: REMOVE when bridge/ collision reloading correctly working
if (m_auiEncounter[i] == SPECIAL)
m_auiEncounter[i] = DONE;
}
OUT_LOAD_INST_DATA_COMPLETE;
}
void instance_gundrak::SetData(uint32 uiType, uint32 uiData)
{
debug_log("SD2: Instance Gundrak: SetData received for type %u with data %u", uiType, uiData);
switch (uiType)
{
case TYPE_SLADRAN:
m_auiEncounter[TYPE_SLADRAN] = uiData;
if (uiData == DONE)
if (GameObject* pGo = GetSingleGameObjectFromStorage(GO_ALTAR_OF_SLADRAN))
pGo->RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_NO_INTERACT);
if (uiData == FAIL)
m_uisWhySnakesAchievPlayers.clear();
if (uiData == SPECIAL)
m_mAltarInProgress.insert(TypeTimerPair(TYPE_SLADRAN, TIMER_VISUAL_ALTAR));
break;
case TYPE_MOORABI:
m_auiEncounter[TYPE_MOORABI] = uiData;
if (uiData == DONE)
{
if (!instance->IsRegularDifficulty())
DoUseDoorOrButton(GO_ECK_DOOR);
if (GameObject* pGo = GetSingleGameObjectFromStorage(GO_ALTAR_OF_MOORABI))
pGo->RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_NO_INTERACT);
}
if (uiData == IN_PROGRESS)
SetLessRabiAchievementCriteria(true);
if (uiData == SPECIAL)
m_mAltarInProgress.insert(TypeTimerPair(TYPE_MOORABI, TIMER_VISUAL_ALTAR));
break;
case TYPE_COLOSSUS:
m_auiEncounter[TYPE_COLOSSUS] = uiData;
if (uiData == DONE)
if (GameObject* pGo = GetSingleGameObjectFromStorage(GO_ALTAR_OF_COLOSSUS))
pGo->RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_NO_INTERACT);
if (uiData == FAIL)
{
for (GuidSet::const_iterator itr = m_sColossusMojosGuids.begin(); itr != m_sColossusMojosGuids.end(); ++itr)
{
if (Creature* pMojo = instance->GetCreature(*itr))
pMojo->Respawn();
}
}
if (uiData == SPECIAL)
m_mAltarInProgress.insert(TypeTimerPair(TYPE_COLOSSUS, TIMER_VISUAL_ALTAR));
break;
case TYPE_GALDARAH:
m_auiEncounter[TYPE_GALDARAH] = uiData;
DoUseDoorOrButton(GO_GALDARAH_DOOR);
if (uiData == DONE)
{
DoUseDoorOrButton(GO_EXIT_DOOR_L);
DoUseDoorOrButton(GO_EXIT_DOOR_R);
}
if (uiData == FAIL)
m_uisShareLoveAchievPlayers.clear();
break;
case TYPE_ECK:
m_auiEncounter[TYPE_ECK] = uiData;
if (uiData == DONE)
DoUseDoorOrButton(GO_ECK_UNDERWATER_DOOR);
break;
case TYPE_ACHIEV_WHY_SNAKES:
// insert the players who failed the achiev and haven't been already inserted in the set
if (m_uisWhySnakesAchievPlayers.find(uiData) == m_uisWhySnakesAchievPlayers.end())
m_uisWhySnakesAchievPlayers.insert(uiData);
break;
case TYPE_ACHIEV_SHARE_LOVE:
// insert players who got stampeled and haven't been already inserted in the set
if (m_uisShareLoveAchievPlayers.find(uiData) == m_uisShareLoveAchievPlayers.end())
m_uisShareLoveAchievPlayers.insert(uiData);
break;
default:
script_error_log("Instance Gundrak: ERROR SetData = %u for type %u does not exist/not implemented.", uiType, uiData);
return;
}
if (uiData == DONE || uiData == SPECIAL) // Save activated altars, too
{
OUT_SAVE_INST_DATA;
std::ostringstream saveStream;
saveStream << m_auiEncounter[TYPE_SLADRAN] << " " << m_auiEncounter[TYPE_MOORABI] << " " << m_auiEncounter[TYPE_COLOSSUS] << " " << m_auiEncounter[TYPE_GALDARAH] << " "
<< m_auiEncounter[TYPE_ECK];
m_strInstData = saveStream.str();
SaveToDB();
OUT_SAVE_INST_DATA_COMPLETE;
}
}
uint32 instance_gundrak::GetData(uint32 uiType) const
{
if (uiType < MAX_ENCOUNTER)
return m_auiEncounter[uiType];
return 0;
}
bool instance_gundrak::CheckAchievementCriteriaMeet(uint32 uiCriteriaId, Player const* /*pSource*/, Unit const* /*pTarget*/, uint32 /*uiMiscValue1 = 0*/) const
{
switch (uiCriteriaId)
{
case ACHIEV_CRIT_LESS_RABI:
return m_bLessRabi;
case ACHIEV_CRIT_SHARE_LOVE:
// Return true if all the players in the group got stampeled
return m_uisShareLoveAchievPlayers.size() == MIN_LOVE_SHARE_PLAYERS;
// ToDo: enable this criteria when the script will be implemented
// case ACHIEV_CRIT_WHY_SNAKES:
// // Return true if not found in the set
// return m_uisWhySnakesAchievPlayers.find(pSource->GetGUIDLow()) == m_uisWhySnakesAchievPlayers.end();
default:
return false;
}
}
void instance_gundrak::OnCreatureEnterCombat(Creature* pCreature)
{
if (pCreature->GetEntry() == NPC_LIVIN_MOJO)
{
// If not found in the set, or the event is already started, return
if (m_sColossusMojosGuids.find(pCreature->GetObjectGuid()) == m_sColossusMojosGuids.end())
return;
// Move all 4 Mojos to evade and move to the Colossus position
for (GuidSet::const_iterator itr = m_sColossusMojosGuids.begin(); itr != m_sColossusMojosGuids.end(); ++itr)
{
if (Creature* pMojo = instance->GetCreature(*itr))
pMojo->AI()->EnterEvadeMode();
}
}
}
ObjectGuid instance_gundrak::SelectRandomSladranTargetGuid()
{
if (m_lSummonTargetsGuids.empty())
return ObjectGuid();
GuidList::iterator iter = m_lSummonTargetsGuids.begin();
advance(iter, urand(0, m_lSummonTargetsGuids.size() - 1));
return *iter;
}
static bool sortFromEastToWest(Creature* pFirst, Creature* pSecond)
{
return pFirst && pSecond && pFirst->GetPositionY() < pSecond->GetPositionY();
}
void instance_gundrak::DoAltarVisualEffect(uint8 uiType)
{
// Sort the lists if not yet done
if (!m_luiStalkerGUIDs.empty())
{
float fHeight = 10.0f; // A bit higher than the altar is needed
if (GameObject* pCollusAltar = GetSingleGameObjectFromStorage(GO_ALTAR_OF_COLOSSUS))
fHeight += pCollusAltar->GetPositionZ();
std::list<Creature*> lStalkerTargets, lStalkerCasters;
for (GuidList::const_iterator itr = m_luiStalkerGUIDs.begin(); itr != m_luiStalkerGUIDs.end(); ++itr)
{
if (Creature* pStalker = instance->GetCreature(*itr))
{
if (pStalker->GetPositionZ() > fHeight)
lStalkerTargets.push_back(pStalker);
else
lStalkerCasters.push_back(pStalker);
}
}
m_luiStalkerGUIDs.clear();
lStalkerTargets.sort(sortFromEastToWest);
lStalkerCasters.sort(sortFromEastToWest);
for (std::list<Creature*>::const_iterator itr = lStalkerTargets.begin(); itr != lStalkerTargets.end(); ++itr)
m_vStalkerTargetGuids.push_back((*itr)->GetObjectGuid());
for (std::list<Creature*>::const_iterator itr = lStalkerCasters.begin(); itr != lStalkerCasters.end(); ++itr)
m_vStalkerCasterGuids.push_back((*itr)->GetObjectGuid());
}
// Verify that the DB has enough trigger spawned
if (m_vStalkerTargetGuids.size() < 3 || m_vStalkerCasterGuids.size() < 3)
return;
// Get the Index from the bosses
uint8 uiIndex = 0;
switch (uiType)
{
case TYPE_SLADRAN: uiIndex = 0; break;
case TYPE_COLOSSUS: uiIndex = 1; break;
case TYPE_MOORABI: uiIndex = 2; break;
default:
return;
}
Creature* pTarget = instance->GetCreature(m_vStalkerTargetGuids[uiIndex]);
Creature* pCaster = instance->GetCreature(m_vStalkerCasterGuids[uiIndex]);
if (!pTarget || !pCaster)
return;
uint32 auiFireBeamSpells[3] = {SPELL_BEAM_SNAKE, SPELL_BEAM_ELEMENTAL, SPELL_BEAM_MAMMOTH};
// Cast from Caster to Target
pCaster->CastSpell(pTarget, auiFireBeamSpells[uiIndex], false);
}
void instance_gundrak::Update(uint32 uiDiff)
{
// Possible multible altars used at the same time, process their timers
if (!m_mAltarInProgress.empty())
{
for (TypeTimerMap::iterator itr = m_mAltarInProgress.begin(); itr != m_mAltarInProgress.end();)
{
if (itr->second < uiDiff)
{
// Do Visual Effect
DoAltarVisualEffect(itr->first);
// Set Timer for Beam-Duration
m_mBeamInProgress.insert(TypeTimerPair(itr->first, TIMER_VISUAL_BEAM));
// Remove this timer, as processed
m_mAltarInProgress.erase(itr++);
}
else
{
itr->second -= uiDiff;
++itr;
}
}
}
// Possible multible beams used at the same time, process their timers
if (!m_mBeamInProgress.empty())
{
for (TypeTimerMap::iterator itr = m_mBeamInProgress.begin(); itr != m_mBeamInProgress.end();)
{
if (itr->second < uiDiff)
{
// Use Key
switch (itr->first)
{
case TYPE_SLADRAN: DoUseDoorOrButton(GO_SNAKE_KEY); break;
case TYPE_MOORABI: DoUseDoorOrButton(GO_MAMMOTH_KEY); break;
case TYPE_COLOSSUS: DoUseDoorOrButton(GO_TROLL_KEY); break;
}
// Set Timer for Beam-Duration
m_mKeyInProgress.insert(TypeTimerPair(itr->first, TIMER_VISUAL_KEY));
m_mBeamInProgress.erase(itr++);
}
else
{
itr->second -= uiDiff;
++itr;
}
}
}
// Activate Bridge if all Three Encounters are used
if (!m_mKeyInProgress.empty())
{
for (TypeTimerMap::iterator itr = m_mKeyInProgress.begin(); itr != m_mKeyInProgress.end();)
{
if (itr->second < uiDiff)
{
// Activate Bridge (and all other Keys) if we are on the last Key, and all other keys are already set
if (m_auiEncounter[0] == SPECIAL && m_auiEncounter[1] == SPECIAL && m_auiEncounter[2] == SPECIAL
&& m_mAltarInProgress.empty() && m_mBeamInProgress.empty() && m_mKeyInProgress.size() == 1)
{
DoUseDoorOrButton(GO_COLLISION);
DoUseDoorOrButton(GO_RHINO_KEY, 0, true);
// The already closed keys cannot be done with DoUseDoorOrButton
if (GameObject* pTrollKey = GetSingleGameObjectFromStorage(GO_TROLL_KEY))
pTrollKey->SetGoState(GO_STATE_ACTIVE_ALTERNATIVE);
if (GameObject* pMammothKey = GetSingleGameObjectFromStorage(GO_MAMMOTH_KEY))
pMammothKey->SetGoState(GO_STATE_ACTIVE_ALTERNATIVE);
if (GameObject* pSnakeKey = GetSingleGameObjectFromStorage(GO_SNAKE_KEY))
pSnakeKey->SetGoState(GO_STATE_ACTIVE_ALTERNATIVE);
// GO_BRIDGE is type 35 (TRAP_DOOR) and needs to be handled directly
// Real Use of this GO is unknown, but this change of state is expected
DoUseDoorOrButton(GO_BRIDGE);
}
// Remove this timer, as processed
m_mKeyInProgress.erase(itr++);
}
else
{
itr->second -= uiDiff;
++itr;
}
}
}
}
InstanceData* GetInstanceData_instance_gundrak(Map* pMap)
{
return new instance_gundrak(pMap);
}
void AddSC_instance_gundrak()
{
Script* pNewScript;
pNewScript = new Script;
pNewScript->Name = "go_gundrak_altar";
pNewScript->pGOUse = &GOUse_go_gundrak_altar;
pNewScript->RegisterSelf();
pNewScript = new Script;
pNewScript->Name = "instance_gundrak";
pNewScript->GetInstanceData = &GetInstanceData_instance_gundrak;
pNewScript->RegisterSelf();
}