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
37
38static constexpr ObjectData creatureData[] =
39{
43 { 0, 0 } // END
44};
45
57
64
65static constexpr std::array<PrisonersWave, 4> PrisonersWaves =
66{{
67 { "BroggokPrisonerCell1", DATA_PRISON_CELL_DOOR_6, 0 },
68 { "BroggokPrisonerCell2", DATA_PRISON_CELL_DOOR_7, 0 },
69 { "BroggokPrisonerCell3", DATA_PRISON_CELL_DOOR_8, 0 },
70 { "BroggokPrisonerCell4", DATA_PRISON_DOOR_04, ACTION_RELEASE_BROGGOK }
71}};
72
80
88
90{
91 public:
93
95 {
106
107 void OnPlayerEnter(Player* /*player*/) override
108 {
110 {
111 for (uint32 group : PrisonersSpawnGroupsData)
112 instance->SpawnGroupSpawn(group, true);
113
114 ShouldResetPrisoners = false;
115 }
116 }
117
118 void OnCreatureCreate(Creature* creature) override
119 {
121
122 auto prisonerWave = std::ranges::find_if(PrisonersWaves, [creature](std::string_view stringId) { return creature->HasStringId(stringId); }, &PrisonersWave::StringId);
123 if (prisonerWave != PrisonersWaves.end())
124 WaveGuidList[std::ranges::distance(PrisonersWaves.begin(), prisonerWave)].insert(creature->GetGUID());
125 }
126
127 void OnUnitDeath(Unit* unit) override
128 {
130
131 if (unit->GetTypeId() != TYPEID_UNIT)
132 return;
133
134 auto prisonerWave = std::ranges::find_if(PrisonersWaves, [creature = unit->ToCreature()](std::string_view stringId) { return creature->HasStringId(stringId); }, &PrisonersWave::StringId);
135 if (prisonerWave != PrisonersWaves.end())
136 {
137 std::ptrdiff_t waveIndex = std::ranges::distance(PrisonersWaves.begin(), prisonerWave);
138 if (WaveGuidList[waveIndex].erase(unit->GetGUID()) && WaveGuidList[waveIndex].empty())
139 {
140 if (prisonerWave->CellOrDoorToOpen)
141 if (GameObject* go = GetGameObject(prisonerWave->CellOrDoorToOpen))
143
144 if (waveIndex + 1 < std::ranges::ssize(WaveGuidList))
145 for (ObjectGuid guid : WaveGuidList[waveIndex + 1])
146 if (Creature* creature = instance->GetCreature(guid))
147 creature->AI()->DoAction(ACTION_PRISONER_ENGAGE);
148
149 if (prisonerWave->BossActionIdOnClear)
150 if (Creature* broggok = GetCreature(DATA_BROGGOK))
151 broggok->AI()->DoAction(prisonerWave->BossActionIdOnClear);
152 }
153 }
154 }
155
157 {
159
160 if (go->GetEntry() == GO_PRISON_DOOR_04)
163 }
164
165 void SetData(uint32 type, uint32 data) override
166 {
167 // This have to be done without boss state since encounter starts when Broggok is engaged, not when prisoners event starts
168 if (type == DATA_PRISONERS_EVENT)
169 {
170 // Do not set data to current - don't trigger events more than once
171 if (PrisonersEventState == data)
172 return;
173
174 PrisonersEventState = data;
175
176 switch (data)
177 {
178 case IN_PROGRESS:
179 {
180 if (Creature* broggok = GetCreature(DATA_BROGGOK))
181 broggok->AI()->DoAction(ACTION_PERFORM_INTRO);
182
185
188
189 for (ObjectGuid guid : WaveGuidList[0])
190 if (Creature* creature = instance->GetCreature(guid))
191 creature->AI()->DoAction(ACTION_PRISONER_ENGAGE);
192
193 break;
194 }
195 case FAIL:
196 {
198 lever->ActivateObject(GameObjectActions::MakeActive);
199
200 if (Creature* broggok = GetCreature(DATA_BROGGOK))
201 broggok->AI()->DoAction(ACTION_DESPAWN_TRIGGER);
202
205
206 for (uint32 prisonCellId : PrisonCellDoorsData)
207 if (GameObject* go = GetGameObject(prisonCellId))
209
210 for (uint32 group : PrisonersSpawnGroupsData)
211 instance->SpawnGroupSpawn(group, true);
212
213 break;
214 }
215 default:
216 break;
217 }
218 }
219 }
220
221 void ReadSaveDataMore(std::istringstream& /*data*/) override
222 {
224 }
225
226 protected:
230 };
231
233 {
235 }
236};
237
uint8_t uint8
Definition Define.h:135
int32_t int32
Definition Define.h:129
uint32_t uint32
Definition Define.h:133
@ IN_PROGRESS
@ FAIL
@ DONE
@ NOT_STARTED
@ DOOR_TYPE_ROOM
@ DOOR_TYPE_PASSAGE
@ TYPEID_UNIT
Definition ObjectGuid.h:38
std::set< ObjectGuid > GuidSet
Definition ObjectGuid.h:260
#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
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)
InstanceMap * instance
EncounterState GetBossState(uint32 id) const
virtual void OnGameObjectCreate(GameObject *go) override
void LoadDoorData(DoorData const *data)
GameObject * GetGameObject(uint32 type)
void SetHeaders(std::string const &dataHeaders)
void LoadObjectData(ObjectData const *creatureData, ObjectData const *gameObjectData)
bool SpawnGroupSpawn(uint32 groupId, bool ignoreRespawn=false, bool force=false, std::vector< WorldObject * > *spawnedObjects=nullptr)
Definition Map.cpp:3382
Creature * GetCreature(ObjectGuid const &guid)
Definition Map.cpp:4392
static ObjectGuid const Empty
Definition ObjectGuid.h:140
static Creature * ToCreature(Object *o)
Definition Object.h:189
TypeID GetTypeId() const
Definition Object.h:93
uint32 GetEntry() const
Definition Object.h:81
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:78
Definition Unit.h:783
virtual void OnUnitDeath(Unit *)
Definition ZoneScript.h:45
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
void AddSC_instance_blood_furnace()
std::string_view StringId