TrinityCore
Loading...
Searching...
No Matches
instance_zulaman.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18/* ScriptData
19SDName: instance_zulaman
20SD%Complete: 80
21SDComment:
22SDCategory: Zul'Aman
23EndScriptData */
24
25#include "ScriptMgr.h"
26#include "CreatureAI.h"
27#include "GameObject.h"
28#include "InstanceScript.h"
29#include "Log.h"
30#include "Map.h"
31#include "Player.h"
32#include "TemporarySummon.h"
33#include "zulaman.h"
34#include <algorithm>
35
42
49{
50 { .StringId = "NalorakkWave1", .CreatureCount = 3, .ActionId = ACTION_WAVE_DONE_1 },
51 { .StringId = "NalorakkWave2", .CreatureCount = 4, .ActionId = ACTION_WAVE_DONE_2 },
52 { .StringId = "NalorakkWave3", .CreatureCount = 2, .ActionId = ACTION_WAVE_DONE_3 },
53 { .StringId = "NalorakkWave4", .CreatureCount = 4, .ActionId = ACTION_WAVE_DONE_4 },
54};
55
56// Chests spawn at bear/eagle/dragonhawk/lynx bosses
57// The loots depend on how many bosses have been killed, but not the entries of the chests
58// But we cannot add loots to gameobject, so we have to use the fixed loot_template
60{
61 uint32 npc, go; // FIXME go Not used
63};
64
65static SHostageInfo const HostageInfo[] =
66{
67 { 23790, 186648, { -57.f, 1343.f, 40.77f, 3.2f } }, // bear
68 { 23999, 187021, { 400.f, 1414.f, 74.36f, 3.3f } }, // eagle
69 { 24001, 186672, { -35.f, 1134.f, 18.71f, 1.9f } }, // dragonhawk
70 { 24024, 186667, { 413.f, 1117.f, 6.32f, 3.1f } } // lynx
71};
72
73Position const HarrisonJonesLoc = { 120.687f, 1674.0f, 42.0217f, 1.59044f };
74
89
106
117
119{
120 public:
122
124 {
141
145
148
154
156 {
158
159 switch (go->GetEntry())
160 {
161 case GO_MASSIVE_GATE:
162 if (GongEvent == DONE)
164 break;
165 default:
166 break;
167 }
168 }
169
170 void OnUnitDeath(Unit* unit) override
171 {
173
174 Creature* creature = unit->ToCreature();
175 if (!creature)
176 return;
177
178 auto nalorakkEventWave = std::ranges::find_if(NalorakkEventWaves,
179 [creature](std::string_view stringId) { return creature->HasStringId(stringId); }, &NalorakkWaveDefinition::StringId);
180 if (nalorakkEventWave != std::ranges::end(NalorakkEventWaves))
181 {
182 std::ptrdiff_t waveIndex = std::ranges::distance(std::ranges::begin(NalorakkEventWaves), nalorakkEventWave);
183 ++killedUnitInWaveCounter[waveIndex];
184
185 if (killedUnitInWaveCounter[waveIndex] == nalorakkEventWave->CreatureCount)
186 if (Creature* nalorakk = GetCreature(BOSS_NALORAKK))
187 nalorakk->AI()->DoAction(nalorakkEventWave->ActionId);
188 }
189 }
190
192 {
193 if (!QuestMinute)
194 return;
195
196 Map::PlayerList const& playerList = instance->GetPlayers();
197 if (playerList.isEmpty())
198 return;
199
200 if (Player* player = playerList.getFirst()->GetSource())
201 {
202 if (Unit* hostage = player->SummonCreature(HostageInfo[num].npc, HostageInfo[num].pos, TEMPSUMMON_DEAD_DESPAWN))
203 {
204 hostage->SetUnitFlag(UNIT_FLAG_NON_ATTACKABLE);
205 hostage->SetNpcFlag(UNIT_NPC_FLAG_GOSSIP);
206 }
207 }
208 }
209
210 void WriteSaveDataMore(std::ostringstream& oss) override
211 {
212 oss << "S " << uint32(GongEvent) << ' '
213 << uint32(ChestLooted) << ' '
214 << uint32(QuestMinute) << ' ';
215 }
216
217 void ReadSaveDataMore(std::istringstream& iss) override
218 {
219 char dataHead; // S
220 uint32 data1, data2, data3;
221 iss >> dataHead >> data1 >> data2 >> data3;
222
223 if (dataHead == 'S')
224 {
225 GongEvent = EncounterState(data1);
226 ChestLooted = data2;
227 QuestMinute = data3;
228 }
229 else
230 {
231 TC_LOG_ERROR("scripts", "Zul'aman: corrupted save data.");
232 return;
233 }
234
235 if (GongEvent == IN_PROGRESS)
237 }
238
239 void SetData(uint32 type, uint32 data) override
240 {
241 switch (type)
242 {
243 case DATA_GONGEVENT:
245 if (GongEvent == IN_PROGRESS)
246 SaveToDB();
247 else if (GongEvent == DONE)
248 QuestMinute = 21;
249 break;
250 case DATA_CHESTLOOTED:
251 ++ChestLooted;
252 SaveToDB();
253 break;
257 break;
258 }
259 }
260
261 bool SetBossState(uint32 id, EncounterState state) override
262 {
263 if (!InstanceScript::SetBossState(id, state))
264 return false;
265
266 switch (id)
267 {
268 case BOSS_NALORAKK:
269 if (state == DONE)
270 {
271 if (QuestMinute)
272 {
273 QuestMinute += 15;
275 }
276 SummonHostage(0);
277 }
278 break;
279 case BOSS_AKILZON:
280 if (state == DONE)
281 {
282 if (QuestMinute)
283 {
284 QuestMinute += 10;
286 }
287 SummonHostage(1);
288 }
289 break;
290 case BOSS_JANALAI:
291 if (state == DONE)
292 SummonHostage(2);
293 break;
294 case BOSS_HALAZZI:
295 if (state == DONE)
296 SummonHostage(3);
297 break;
298 }
299
300 if (state == DONE)
301 {
302 if (QuestMinute && id == BOSS_HALAZZI)
303 {
304 QuestMinute = 0;
306 }
307 SaveToDB();
308 }
309
310 return true;
311 }
312
313 uint32 GetData(uint32 type) const override
314 {
315 switch (type)
316 {
317 case DATA_GONGEVENT:
318 return uint32(GongEvent);
319 case DATA_CHESTLOOTED:
320 return ChestLooted;
323 return RandVendor[type - TYPE_RAND_VENDOR_1];
324 }
325
326 return 0;
327 }
328
329 void Update(uint32 diff) override
330 {
331 if (QuestMinute)
332 {
333 if (QuestTimer <= diff)
334 {
335 QuestMinute--;
336 SaveToDB();
338 if (QuestMinute)
339 {
342 }
343 else
345 }
346 QuestTimer -= diff;
347 }
348 }
349
350 protected:
351 std::array<uint8, 4> killedUnitInWaveCounter = { };
352 };
353
355 {
357 }
358};
359
361{
362 new instance_zulaman();
363}
@ IN_MILLISECONDS
Definition Common.h:35
@ MINUTE
Definition Common.h:29
uint8_t uint8
Definition Define.h:135
uint32_t uint32
Definition Define.h:133
EncounterState
@ IN_PROGRESS
@ DONE
@ NOT_STARTED
@ DOOR_TYPE_ROOM
@ DOOR_TYPE_PASSAGE
#define TC_LOG_ERROR(filterType__,...)
Definition Log.h:165
@ TEMPSUMMON_DEAD_DESPAWN
@ GO_STATE_ACTIVE
@ UNIT_NPC_FLAG_GOSSIP
@ UNIT_FLAG_NON_ATTACKABLE
#define DataHeader
bool HasStringId(std::string_view id) const
void SetGoState(GOState state)
void SetBossNumber(uint32 number)
virtual bool SetBossState(uint32 id, EncounterState state)
Creature * GetCreature(uint32 type)
virtual ObjectGuid GetGuidData(uint32 type) const override
InstanceMap * instance
virtual void OnGameObjectCreate(GameObject *go) override
void LoadDoorData(DoorData const *data)
void DoUpdateWorldState(uint32 worldstateId, uint32 worldstateValue)
void SetHeaders(std::string const &dataHeaders)
void LoadObjectData(ObjectData const *creatureData, ObjectData const *gameObjectData)
bool isEmpty() const
Definition LinkedList.h:108
MapReference * getFirst()
TempSummon * SummonCreature(uint32 entry, Position const &pos, SummonPropertiesEntry const *properties=nullptr, uint32 duration=0, WorldObject *summoner=nullptr, uint32 spellId=0, uint32 vehId=0, ObjectGuid privateObjectOwner=ObjectGuid::Empty)
Definition Object.cpp:1852
PlayerList const & GetPlayers() const
Definition Map.h:448
static Creature * ToCreature(Object *o)
Definition Object.h:186
uint32 GetEntry() const
Definition Object.h:81
FROM * GetSource() const
Definition Reference.h:96
Definition Unit.h:769
TempSummon * SummonCreature(uint32 entry, Position const &pos, TempSummonType despawnType=TEMPSUMMON_MANUAL_DESPAWN, Milliseconds despawnTime=0s, uint32 vehId=0, uint32 spellId=0, ObjectGuid privateObjectOwner=ObjectGuid::Empty)
Definition Object.cpp:1992
virtual void OnUnitDeath(Unit *)
Definition ZoneScript.h:45
InstanceScript * GetInstanceScript(InstanceMap *map) const override
#define MAX_ENCOUNTER
static ObjectData const gameObjectData[]
static SHostageInfo const HostageInfo[]
void AddSC_instance_zulaman()
@ WORLDSTATE_TIME_TO_SACRIFICE
@ RAND_VENDOR
@ WORLDSTATE_SHOW_TIMER
static ObjectData const creatureData[]
static DoorData const doorData[]
Position const HarrisonJonesLoc
struct NalorakkWaveDefinition NalorakkEventWaves[]
void ReadSaveDataMore(std::istringstream &iss) override
void SetData(uint32 type, uint32 data) override
void WriteSaveDataMore(std::ostringstream &oss) override
bool SetBossState(uint32 id, EncounterState state) override
@ NPC_EAGLE_SPIRIT
Definition zulaman.h:59
@ NPC_AKILZON
Definition zulaman.h:51
@ NPC_JANALAI
Definition zulaman.h:52
@ NPC_NALORAKK
Definition zulaman.h:50
@ NPC_DRAGONHAWK_SPIRIT
Definition zulaman.h:61
@ NPC_HALAZZI
Definition zulaman.h:53
@ NPC_BEAR_SPIRIT
Definition zulaman.h:58
@ NPC_ZULJIN
Definition zulaman.h:55
@ NPC_HARRISON_JONES
Definition zulaman.h:49
@ NPC_LYNX_SPIRIT
Definition zulaman.h:60
@ NPC_HEXLORD
Definition zulaman.h:54
#define ZulamanScriptName
Definition zulaman.h:23
@ BOSS_HEXLORD
Definition zulaman.h:32
@ DATA_CHESTLOOTED
Definition zulaman.h:37
@ BOSS_ZULJIN
Definition zulaman.h:33
@ DATA_GONGEVENT
Definition zulaman.h:36
@ TYPE_RAND_VENDOR_1
Definition zulaman.h:38
@ TYPE_RAND_VENDOR_2
Definition zulaman.h:39
@ DATA_EAGLE_SPIRIT
Definition zulaman.h:42
@ DATA_BEAR_SPIRIT
Definition zulaman.h:41
@ DATA_DRAGONHAWK_SPIRIT
Definition zulaman.h:44
@ BOSS_NALORAKK
Definition zulaman.h:28
@ BOSS_HALAZZI
Definition zulaman.h:31
@ DATA_LYNX_SPIRIT
Definition zulaman.h:43
@ BOSS_AKILZON
Definition zulaman.h:29
@ BOSS_JANALAI
Definition zulaman.h:30
@ GO_STRANGE_GONG
Definition zulaman.h:77
@ GO_KRAZS_PACKAGE
Definition zulaman.h:76
@ GO_ASHLIS_BAG
Definition zulaman.h:75
@ GO_DOOR_ZULJIN
Definition zulaman.h:72
@ GO_LYNX_TEMPLE_EXIT
Definition zulaman.h:66
@ GO_MASSIVE_GATE
Definition zulaman.h:70
@ GO_WOODEN_DOOR
Definition zulaman.h:69
@ GO_HEXLORD_ENTRANCE
Definition zulaman.h:68
@ GO_LYNX_TEMPLE_ENTRANCE
Definition zulaman.h:67
@ GO_DOOR_AKILZON
Definition zulaman.h:71
@ GO_HARKORS_SATCHEL
Definition zulaman.h:73
@ GO_TANZARS_TRUNK
Definition zulaman.h:74
ZAActionIds
Definition zulaman.h:81
@ ACTION_WAVE_DONE_2
Definition zulaman.h:83
@ ACTION_WAVE_DONE_4
Definition zulaman.h:85
@ ACTION_WAVE_DONE_1
Definition zulaman.h:82
@ ACTION_WAVE_DONE_3
Definition zulaman.h:84