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#include "ScriptMgr.h"
19#include "CreatureAI.h"
20#include "GameObject.h"
21#include "InstanceScript.h"
22#include "Map.h"
23#include "Player.h"
24#include "ScriptedCreature.h"
25#include "TemporarySummon.h"
26#include "zulaman.h"
27#include <algorithm>
28
35{
36 { .StringId = "NalorakkWave1", .CreatureCount = 3, .ActionId = ACTION_WAVE_DONE_1 },
37 { .StringId = "NalorakkWave2", .CreatureCount = 4, .ActionId = ACTION_WAVE_DONE_2 },
38 { .StringId = "NalorakkWave3", .CreatureCount = 2, .ActionId = ACTION_WAVE_DONE_3 },
39 { .StringId = "NalorakkWave4", .CreatureCount = 4, .ActionId = ACTION_WAVE_DONE_4 },
40};
41
42// Chests spawn at bear/eagle/dragonhawk/lynx bosses
43// The loots depend on how many bosses have been killed, but not the entries of the chests
44// But we cannot add loots to gameobject, so we have to use the fixed loot_template
46{
47 uint32 npc, go; // FIXME go Not used
49};
50
51static SHostageInfo const HostageInfo[] =
52{
53 { 23790, 186648, { -57.f, 1343.f, 40.77f, 3.2f } }, // bear
54 { 23999, 187021, { 400.f, 1414.f, 74.36f, 3.3f } }, // eagle
55 { 24001, 186672, { -35.f, 1134.f, 18.71f, 1.9f } }, // dragonhawk
56 { 24024, 186667, { 413.f, 1117.f, 6.32f, 3.1f } } // lynx
57};
58
72
87
97
98static constexpr DungeonEncounterData encounters[] =
99{
100 { BOSS_AKILZON, {{ 1189 }} },
101 { BOSS_NALORAKK, {{ 1190 }} },
102 { BOSS_JANALAI, {{ 1191 }} },
103 { BOSS_HALAZZI, {{ 1192 }} },
104 { BOSS_HEXLORD, {{ 1193 }} },
105 { BOSS_DAAKARA, {{ 1194 }} }
106};
107
109{
110 public:
112
114 {
127
128 void OnCreatureCreate(Creature* creature) override
129 {
131
132 switch (creature->GetEntry())
133 {
134 case NPC_VOLJIN:
135 VoljinGUID = creature->GetGUID();
136 break;
137 default:
138 break;
139 }
140 }
141
143 {
145
146 switch (go->GetEntry())
147 {
148 case GO_MASSIVE_GATE:
151 break;
152 default:
153 break;
154 }
155 }
156
157 void OnUnitDeath(Unit* unit) override
158 {
160
161 Creature* creature = unit->ToCreature();
162 if (!creature)
163 return;
164
165 auto nalorakkEventWave = std::ranges::find_if(NalorakkEventWaves,
166 [creature](std::string_view stringId) { return creature->HasStringId(stringId); }, &NalorakkWaveDefinition::StringId);
167 if (nalorakkEventWave != std::ranges::end(NalorakkEventWaves))
168 {
169 std::ptrdiff_t waveIndex = std::ranges::distance(std::ranges::begin(NalorakkEventWaves), nalorakkEventWave);
170 ++killedUnitInWaveCounter[waveIndex];
171
172 if (killedUnitInWaveCounter[waveIndex] == nalorakkEventWave->CreatureCount)
173 if (Creature* nalorakk = GetCreature(BOSS_NALORAKK))
174 nalorakk->AI()->DoAction(nalorakkEventWave->ActionId);
175 }
176 }
177
179 {
181 return;
182
183 Map::PlayerList const& playerList = instance->GetPlayers();
184 if (playerList.empty())
185 return;
186
187 if (Player* player = playerList.front()->GetSource())
188 {
189 if (Unit* hostage = player->SummonCreature(HostageInfo[num].npc, HostageInfo[num].pos, TEMPSUMMON_DEAD_DESPAWN))
190 {
191 hostage->SetUnitFlag(UNIT_FLAG_NON_ATTACKABLE);
192 hostage->SetNpcFlag(UNIT_NPC_FLAG_GOSSIP);
193 }
194 }
195 }
196
197 void SetData(uint32 type, uint32 data) override
198 {
199 switch (type)
200 {
202 {
203 if (data == IN_PROGRESS)
204 {
208 SpeedRunTimer = 15;
209 ZulAmanState = data;
210 }
211 break;
212 }
213 default:
214 break;
215 }
216 }
217
218 uint32 GetData(uint32 type) const override
219 {
220 switch (type)
221 {
223 return ZulAmanState;
224 default:
225 break;
226 }
227
228 return 0;
229 }
230
231 bool SetBossState(uint32 type, EncounterState state) override
232 {
233 if (!InstanceScript::SetBossState(type, state))
234 return false;
235
236 if (state == DONE)
237 {
239 {
241
242 if (ZulAmanBossCount < 2)
243 {
246 }
247 else if (ZulAmanBossCount == 4)
248 {
252 }
253 }
254 }
255
256 switch (type)
257 {
258 case BOSS_NALORAKK:
259 if (state == DONE)
260 SummonHostage(0);
261 break;
262 case BOSS_AKILZON:
263 if (state == DONE)
264 SummonHostage(1);
265 break;
266 case BOSS_JANALAI:
267 if (state == DONE)
268 SummonHostage(2);
269 break;
270 case BOSS_HALAZZI:
271 if (state == DONE)
272 SummonHostage(3);
273 break;
274 case BOSS_HEXLORD:
275 case BOSS_DAAKARA:
276 default:
277 break;
278 }
279
280 return true;
281 }
282
283 void ProcessEvent(WorldObject* /*obj*/, uint32 eventId, WorldObject* /*invoker*/) override
284 {
285 switch (eventId)
286 {
288 if (Creature* voljin = instance->GetCreature(VoljinGUID))
289 {
290 if (voljin->IsAIEnabled())
291 voljin->AI()->DoAction(ACTION_START_ZULAMAN);
292 }
293 break;
294 default:
295 break;
296 }
297 }
298
299 void Update(uint32 diff) override
300 {
301 if (events.Empty())
302 return;
303
304 events.Update(diff);
305
306 while (uint32 eventId = events.ExecuteEvent())
307 {
308 switch (eventId)
309 {
312 if (SpeedRunTimer)
314 else
315 {
319 }
320 break;
321 default:
322 break;
323 }
324 }
325 }
326
327 void AfterDataLoad() override
328 {
329 // Speed run cannot be resumed after reset/crash
331 {
332 SpeedRunTimer = 0;
334 }
335 }
336
337 protected:
343 std::array<uint8, 4> killedUnitInWaveCounter = { };
344 };
345
347 {
348 return new instance_zulaman_InstanceScript(map);
349 }
350};
351
353{
354 new instance_zulaman();
355}
uint8_t uint8
Definition Define.h:156
uint32_t uint32
Definition Define.h:154
EncounterState
@ IN_PROGRESS
@ FAIL
@ DONE
@ NOT_STARTED
@ TEMPSUMMON_DEAD_DESPAWN
@ GO_STATE_ACTIVE
@ UNIT_NPC_FLAG_GOSSIP
@ UNIT_FLAG_NON_ATTACKABLE
#define DataHeader
ObjectGuid const & GetGUID() const
Definition BaseEntity.h:163
bool HasStringId(std::string_view id) const
void Update(uint32 time)
Definition EventMap.h:77
bool Empty() const
Definition EventMap.h:105
EventId ExecuteEvent()
Definition EventMap.cpp:77
void CancelEvent(EventId eventId)
Definition EventMap.cpp:156
void ScheduleEvent(EventId eventId, Milliseconds time, GroupIndex group=0u, PhaseIndex phase=0u)
Definition EventMap.cpp:40
void SetGoState(GOState state)
void SetBossNumber(uint32 number)
virtual bool SetBossState(uint32 id, EncounterState state)
virtual void OnCreatureCreate(Creature *creature) override
Creature * GetCreature(uint32 type)
void DoUpdateWorldState(int32 worldStateId, int32 value)
void LoadObjectData(std::span< ObjectData const > creatureData, std::span< ObjectData const > gameObjectData)
InstanceMap * instance
void SetHeaders(std::string_view dataHeaders)
void LoadDungeonEncounterData(std::span< DungeonEncounterData const > encounters)
virtual void OnGameObjectCreate(GameObject *go) override
void LoadDoorData(std::span< DoorData const > data)
bool empty() const
Definition LinkedList.h:107
PlayerList const & GetPlayers() const
Definition Map.h:408
Creature * GetCreature(ObjectGuid const &guid)
Definition Map.cpp:3578
uint32 GetEntry() const
Definition Object.h:89
Creature * ToCreature()
Definition Object.h:121
ReferenceType * front()
Definition RefManager.h:32
FROM * GetSource() const
Definition Reference.h:87
Definition Unit.h:647
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:1403
virtual void OnUnitDeath(Unit *unit)
Definition ZoneScript.h:85
InstanceScript * GetInstanceScript(InstanceMap *map) const override
#define MAX_ENCOUNTER
static constexpr ObjectData creatureData[]
static SHostageInfo const HostageInfo[]
void AddSC_instance_zulaman()
static constexpr DoorData doorData[]
static constexpr ObjectData gameObjectData[]
static constexpr DungeonEncounterData encounters[]
struct NalorakkWaveDefinition NalorakkEventWaves[]
void OnCreatureCreate(Creature *creature) override
void SetData(uint32 type, uint32 data) override
void ProcessEvent(WorldObject *, uint32 eventId, WorldObject *) override
PersistentInstanceScriptValue< uint32 > ZulAmanState
bool SetBossState(uint32 type, EncounterState state) override
@ WORLD_STATE_ZULAMAN_TIMER_ENABLED
Definition zulaman.h:96
@ WORLD_STATE_ZULAMAN_TIMER
Definition zulaman.h:97
@ NPC_EAGLE_SPIRIT
Definition zulaman.h:62
@ NPC_HEXLORD_TRIGGER
Definition zulaman.h:58
@ NPC_AKILZON
Definition zulaman.h:50
@ NPC_JANALAI
Definition zulaman.h:52
@ NPC_NALORAKK
Definition zulaman.h:51
@ NPC_DAAKARA
Definition zulaman.h:55
@ NPC_DRAGONHAWK_SPIRIT
Definition zulaman.h:64
@ NPC_HALAZZI
Definition zulaman.h:53
@ NPC_BEAR_SPIRIT
Definition zulaman.h:61
@ NPC_VOLJIN
Definition zulaman.h:57
@ NPC_LYNX_SPIRIT
Definition zulaman.h:63
@ NPC_HEXLORD
Definition zulaman.h:54
#define ZulamanScriptName
Definition zulaman.h:23
@ BOSS_HEXLORD
Definition zulaman.h:32
@ DATA_ZULAMAN_STATE
Definition zulaman.h:40
@ DATA_EAGLE_SPIRIT
Definition zulaman.h:43
@ DATA_BEAR_SPIRIT
Definition zulaman.h:42
@ DATA_DRAGONHAWK_SPIRIT
Definition zulaman.h:45
@ BOSS_DAAKARA
Definition zulaman.h:33
@ BOSS_NALORAKK
Definition zulaman.h:29
@ BOSS_HALAZZI
Definition zulaman.h:31
@ DATA_LYNX_SPIRIT
Definition zulaman.h:44
@ BOSS_AKILZON
Definition zulaman.h:28
@ BOSS_JANALAI
Definition zulaman.h:30
@ DATA_HEXLORD_TRIGGER
Definition zulaman.h:37
@ ACTION_START_ZULAMAN
Definition zulaman.h:91
@ GO_HAZLEKS_TRUNK
Definition zulaman.h:77
@ GO_STRANGE_GONG
Definition zulaman.h:80
@ GO_DOOR_DAAKARA
Definition zulaman.h:75
@ GO_BAKKALZUS_SATCHEL
Definition zulaman.h:76
@ GO_LYNX_TEMPLE_EXIT
Definition zulaman.h:69
@ GO_MASSIVE_GATE
Definition zulaman.h:73
@ GO_WOODEN_DOOR
Definition zulaman.h:72
@ GO_HEXLORD_ENTRANCE
Definition zulaman.h:71
@ GO_LYNX_TEMPLE_ENTRANCE
Definition zulaman.h:70
@ GO_DOOR_AKILZON
Definition zulaman.h:74
@ GO_NORKANIS_PACKAGE
Definition zulaman.h:79
@ GO_KASHAS_BAG
Definition zulaman.h:78
@ EVENT_UPDATE_ZULAMAN_TIMER
Definition zulaman.h:86
@ EVENT_START_ZULAMAN
Definition zulaman.h:85
ZAActionIds
Definition zulaman.h:101
@ ACTION_WAVE_DONE_2
Definition zulaman.h:103
@ ACTION_WAVE_DONE_4
Definition zulaman.h:105
@ ACTION_WAVE_DONE_1
Definition zulaman.h:102
@ ACTION_WAVE_DONE_3
Definition zulaman.h:104