TrinityCore
Loading...
Searching...
No Matches
instance_blood_furnace.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 "blood_furnace.h"
20#include "Creature.h"
21#include "CreatureAI.h"
22#include "GameObject.h"
23#include "InstanceScript.h"
24#include "Map.h"
25#include <algorithm>
26
36
43
54
55static constexpr DungeonEncounterData encounters[] =
56{
57 { DATA_THE_MAKER, {{ 1922 }} },
58 { DATA_BROGGOK, {{ 1924 }} },
59 { DATA_KELIDAN, {{ 1923 }} }
60};
61
68
69static constexpr std::array<PrisonersWave, 4> PrisonersWaves =
70{{
71 { "BroggokPrisonerCell1", DATA_PRISON_CELL_DOOR_6, 0 },
72 { "BroggokPrisonerCell2", DATA_PRISON_CELL_DOOR_7, 0 },
73 { "BroggokPrisonerCell3", DATA_PRISON_CELL_DOOR_8, 0 },
74 { "BroggokPrisonerCell4", DATA_PRISON_DOOR_04, ACTION_RELEASE_BROGGOK }
75}};
76
84
92
94{
95 public:
97
99 {
111
112 void OnPlayerEnter(Player* /*player*/) override
113 {
115 {
116 for (uint32 group : PrisonersSpawnGroupsData)
117 instance->SpawnGroupSpawn(group, true);
118
119 ShouldResetPrisoners = false;
120 }
121 }
122
123 void OnCreatureCreate(Creature* creature) override
124 {
126
127 auto prisonerWave = std::ranges::find_if(PrisonersWaves, [creature](std::string_view stringId) { return creature->HasStringId(stringId); }, &PrisonersWave::StringId);
128 if (prisonerWave != PrisonersWaves.end())
129 WaveGuidList[std::ranges::distance(PrisonersWaves.begin(), prisonerWave)].insert(creature->GetGUID());
130 }
131
132 void OnUnitDeath(Unit* unit) override
133 {
135
136 if (unit->GetTypeId() != TYPEID_UNIT)
137 return;
138
139 auto prisonerWave = std::ranges::find_if(PrisonersWaves, [creature = unit->ToCreature()](std::string_view stringId) { return creature->HasStringId(stringId); }, &PrisonersWave::StringId);
140 if (prisonerWave != PrisonersWaves.end())
141 {
142 std::ptrdiff_t waveIndex = std::ranges::distance(PrisonersWaves.begin(), prisonerWave);
143 if (WaveGuidList[waveIndex].erase(unit->GetGUID()) && WaveGuidList[waveIndex].empty())
144 {
145 if (prisonerWave->CellOrDoorToOpen)
146 if (GameObject* go = GetGameObject(prisonerWave->CellOrDoorToOpen))
148
149 if (waveIndex + 1 < std::ranges::ssize(WaveGuidList))
150 for (ObjectGuid guid : WaveGuidList[waveIndex + 1])
151 if (Creature* creature = instance->GetCreature(guid))
152 creature->AI()->DoAction(ACTION_PRISONER_ENGAGE);
153
154 if (prisonerWave->BossActionIdOnClear)
155 if (Creature* broggok = GetCreature(DATA_BROGGOK))
156 broggok->AI()->DoAction(prisonerWave->BossActionIdOnClear);
157 }
158 }
159 }
160
162 {
164
165 if (go->GetEntry() == GO_PRISON_DOOR_04)
168 }
169
170 void SetData(uint32 type, uint32 data) override
171 {
172 // This have to be done without boss state since encounter starts when Broggok is engaged, not when prisoners event starts
173 if (type == DATA_PRISONERS_EVENT)
174 {
175 // Do not set data to current - don't trigger events more than once
176 if (PrisonersEventState == data)
177 return;
178
179 PrisonersEventState = data;
180
181 switch (data)
182 {
183 case IN_PROGRESS:
184 {
185 if (Creature* broggok = GetCreature(DATA_BROGGOK))
186 broggok->AI()->DoAction(ACTION_PERFORM_INTRO);
187
190
193
194 for (ObjectGuid guid : WaveGuidList[0])
195 if (Creature* creature = instance->GetCreature(guid))
196 creature->AI()->DoAction(ACTION_PRISONER_ENGAGE);
197
198 break;
199 }
200 case FAIL:
201 {
203 lever->ActivateObject(GameObjectActions::MakeActive, 0);
204
205 if (Creature* broggok = GetCreature(DATA_BROGGOK))
206 broggok->AI()->DoAction(ACTION_DESPAWN_TRIGGER);
207
210
211 for (uint32 prisonCellId : PrisonCellDoorsData)
212 if (GameObject* go = GetGameObject(prisonCellId))
214
215 for (uint32 group : PrisonersSpawnGroupsData)
216 instance->SpawnGroupSpawn(group, true);
217
218 break;
219 }
220 default:
221 break;
222 }
223 }
224 }
225
226 void AfterDataLoad() override
227 {
229 }
230
231 protected:
235 };
236
238 {
240 }
241};
242
uint8_t uint8
Definition Define.h:156
int32_t int32
Definition Define.h:150
uint32_t uint32
Definition Define.h:154
@ IN_PROGRESS
@ FAIL
@ DONE
@ NOT_STARTED
@ TYPEID_UNIT
Definition ObjectGuid.h:43
std::set< ObjectGuid > GuidSet
Definition ObjectGuid.h:432
#define DataHeader
uint32 const EncounterCount
@ SPAWN_GROUP_PRISONERS_4
@ SPAWN_GROUP_PRISONERS_3
@ SPAWN_GROUP_PRISONERS_2
@ SPAWN_GROUP_PRISONERS_1
@ GO_PRISON_CELL_DOOR_5
@ GO_PRISON_CELL_DOOR_8
@ GO_PRISON_DOOR_05
@ GO_PRISON_DOOR_03
@ GO_SUMMON_DOOR
@ GO_PRISON_CELL_DOOR_7
@ GO_PRISON_CELL_DOOR_4
@ GO_PRISON_CELL_DOOR_6
@ GO_PRISON_DOOR_01
@ GO_PRISON_DOOR_04
@ GO_PRISON_DOOR_02
@ GO_BROGGOK_LEVER
@ NPC_BROGGOK
@ NPC_KELIDAN
@ NPC_THE_MAKER
#define BFScriptName
@ DATA_BROGGOK_LEVER
@ DATA_THE_MAKER
@ DATA_PRISON_DOOR_05
@ DATA_PRISON_CELL_DOOR_6
@ DATA_PRISON_CELL_DOOR_8
@ DATA_BROGGOK
@ DATA_PRISON_CELL_DOOR_7
@ DATA_PRISONERS_EVENT
@ DATA_KELIDAN
@ DATA_PRISON_DOOR_04
@ DATA_PRISON_CELL_DOOR_5
@ ACTION_PERFORM_INTRO
@ ACTION_DESPAWN_TRIGGER
@ ACTION_PRISONER_ENGAGE
@ ACTION_RELEASE_BROGGOK
ObjectGuid const & GetGUID() const
Definition BaseEntity.h:163
TypeID GetTypeId() const
Definition BaseEntity.h:166
bool HasStringId(std::string_view id) const
void SetBossNumber(uint32 number)
virtual void OnCreatureCreate(Creature *creature) override
Creature * GetCreature(uint32 type)
void HandleGameObject(ObjectGuid guid, bool open, GameObject *go=nullptr)
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)
EncounterState GetBossState(uint32 id) const
virtual void OnGameObjectCreate(GameObject *go) override
void LoadDoorData(std::span< DoorData const > data)
GameObject * GetGameObject(uint32 type)
bool SpawnGroupSpawn(uint32 groupId, bool ignoreRespawn=false, bool force=false, std::vector< WorldObject * > *spawnedObjects=nullptr)
Definition Map.cpp:2360
Creature * GetCreature(ObjectGuid const &guid)
Definition Map.cpp:3578
static ObjectGuid const Empty
Definition ObjectGuid.h:314
uint32 GetEntry() const
Definition Object.h:89
Creature * ToCreature()
Definition Object.h:121
Definition Unit.h:647
virtual void OnUnitDeath(Unit *unit)
Definition ZoneScript.h:85
InstanceScript * GetInstanceScript(InstanceMap *map) const override
static constexpr ObjectData creatureData[]
static constexpr std::array< PrisonersWave, 4 > PrisonersWaves
static constexpr std::array< uint32, 4 > PrisonCellDoorsData
static constexpr DoorData doorData[]
static constexpr ObjectData gameObjectData[]
static constexpr std::array< uint32, 4 > PrisonersSpawnGroupsData
static constexpr DungeonEncounterData encounters[]
void AddSC_instance_blood_furnace()
std::string_view StringId