TrinityCore
Loading...
Searching...
No Matches
instance_uldaman.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 "Creature.h"
20#include "CreatureAI.h"
21#include "GameObject.h"
22#include "InstanceScript.h"
23#include "Map.h"
24#include "uldaman.h"
25#include <algorithm>
26
35
36static constexpr ObjectData creatureData[] =
37{
39 { 0, 0 } // END
40};
41
42static constexpr ObjectData gameObjectData[] =
43{
45 { 0, 0 } // END
46};
47
49{
50 public:
52
54 {
64
65 void OnCreatureCreate(Creature* creature) override
66 {
68
69 switch (creature->GetEntry())
70 {
72 {
73 static constexpr std::array<std::string_view, 4> KeeperStringId = {{ "StoneKeeper1", "StoneKeeper2", "StoneKeeper3", "StoneKeeper4" }};
74 auto stringId = std::ranges::find_if(KeeperStringId, [creature](std::string_view stringId) { return creature->HasStringId(stringId); });
75 if (stringId != KeeperStringId.end())
76 StoneKeeperGuid[std::ranges::distance(KeeperStringId.begin(), stringId)] = creature->GetGUID();
77 break;
78 }
83 ArchaedasMinionsGuidSet.insert(creature->GetGUID());
84 break;
85 default:
86 break;
87 }
88 }
89
90 void OnCreatureRemove(Creature* creature) override
91 {
93
94 switch (creature->GetEntry())
95 {
100 ArchaedasMinionsGuidSet.erase(creature->GetGUID());
101 break;
102 default:
103 break;
104 }
105 }
106
108 {
110
111 switch (go->GetEntry())
112 {
116 break;
117 case GO_KEYSTONE:
119 {
122 }
123 break;
124 default:
125 break;
126 }
127 }
128
129 void OnUnitDeath(Unit* unit) override
130 {
132
133 Creature* creature = unit->ToCreature();
134 if (!creature)
135 return;
136
137 switch (creature->GetEntry())
138 {
139 case NPC_STONE_KEEPER:
140 {
141 for (std::size_t i = 0; i < StoneKeeperGuid.size() - 1; ++i)
142 {
143 if (creature->GetGUID() == StoneKeeperGuid[i])
144 {
145 if (Creature* keeper = instance->GetCreature(StoneKeeperGuid[i + 1]))
146 {
148 break;
149 }
150 }
151 }
152
153 if (creature->GetGUID() == StoneKeeperGuid[3])
155 break;
156 }
157 default:
158 break;
159 }
160 }
161
162 bool SetBossState(uint32 bossId, EncounterState state) override
163 {
164 if (!InstanceScript::SetBossState(bossId, state))
165 return false;
166
167 switch (bossId)
168 {
169 case DATA_ARCHAEDAS:
170 if (state == FAIL)
171 {
173 if (Creature* minion = instance->GetCreature(guid))
174 {
175 if (minion->isDead())
176 minion->Respawn();
177 }
178 }
179 break;
181 if (state == FAIL)
182 {
183 for (std::size_t i = 0; i < StoneKeeperGuid.size() - 1; ++i)
184 {
185 if (Creature* keeper = instance->GetCreature(StoneKeeperGuid[i]))
186 {
187 if (!keeper->IsAlive())
188 {
189 StoneKeeperGuid[i].Clear();
190 keeper->Respawn();
191 }
192 }
193 }
194
196 }
197 break;
198 default:
199 break;
200 }
201
202 return true;
203 }
204
205 void SetData(uint32 type, uint32 data) override
206 {
207 switch (type)
208 {
210 IronayaIntroState = data;
211 switch (data)
212 {
213 case IN_PROGRESS:
215 break;
216 case DONE:
218 SaveToDB();
219 break;
220 default:
221 break;
222 }
223 break;
224 }
225 }
226
227 void ProcessEvent(WorldObject* /*gameObject*/, uint32 eventId) override
228 {
229 switch (eventId)
230 {
232 if (Creature* keeper = instance->GetCreature(StoneKeeperGuid[0]))
233 keeper->AI()->DoAction(ACTION_KEEPER_ACTIVATED);
234 break;
235 case EVENT_BOSS_AGGRO:
236 if (Creature* archaedas = GetCreature(DATA_ARCHAEDAS))
237 archaedas->AI()->DoAction(ACTION_ARCHAEDAS_AWAKEN);
238 break;
239 default:
240 break;
241 }
242 }
243
244 void WriteSaveDataMore(std::ostringstream& stream) override
245 {
246 stream << IronayaIntroState;
247 }
248
249 void ReadSaveDataMore(std::istringstream& stream) override
250 {
251 stream >> IronayaIntroState;
252 }
253
254 uint32 GetData(uint32 type) const override
255 {
256 switch (type)
257 {
259 return IronayaIntroState;
260 }
261 return 0;
262 }
263
264 protected:
265 std::array<ObjectGuid, 4> StoneKeeperGuid;
268 };
269
271 {
273 }
274};
275
277{
278 new instance_uldaman();
279}
uint32_t uint32
Definition Define.h:133
EncounterState
@ IN_PROGRESS
@ FAIL
@ DONE
@ NOT_STARTED
@ DOOR_TYPE_ROOM
@ DOOR_TYPE_PASSAGE
std::set< ObjectGuid > GuidSet
Definition ObjectGuid.h:260
@ GO_FLAG_INTERACT_COND
#define DataHeader
uint32 const EncounterCount
bool HasStringId(std::string_view id) const
CreatureAI * AI() const
Definition Creature.h:154
void SetFlag(GameObjectFlags flags)
Definition GameObject.h:171
void SetBossNumber(uint32 number)
virtual bool SetBossState(uint32 id, EncounterState state)
virtual void OnCreatureCreate(Creature *creature) override
Creature * GetCreature(uint32 type)
void HandleGameObject(ObjectGuid guid, bool open, GameObject *go=nullptr)
virtual void OnCreatureRemove(Creature *creature) override
InstanceMap * instance
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:4397
static ObjectGuid const Empty
Definition ObjectGuid.h:140
static Creature * ToCreature(Object *o)
Definition Object.h:186
uint32 GetEntry() const
Definition Object.h:81
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:78
virtual void DoAction(int32)
Definition UnitAI.h:154
Definition Unit.h:769
virtual void OnUnitDeath(Unit *)
Definition ZoneScript.h:45
InstanceScript * GetInstanceScript(InstanceMap *map) const override
static constexpr ObjectData creatureData[]
void AddSC_instance_uldaman()
static constexpr DoorData doorData[]
static constexpr ObjectData gameObjectData[]
void ReadSaveDataMore(std::istringstream &stream) override
void SetData(uint32 type, uint32 data) override
void WriteSaveDataMore(std::ostringstream &stream) override
bool SetBossState(uint32 bossId, EncounterState state) override
void ProcessEvent(WorldObject *, uint32 eventId) override
@ ACTION_ARCHAEDAS_AWAKEN
Definition uldaman.h:66
@ ACTION_KEEPER_ACTIVATED
Definition uldaman.h:65
@ EVENT_SUB_BOSS_AGGRO
Definition uldaman.h:71
@ EVENT_BOSS_AGGRO
Definition uldaman.h:72
@ DATA_IRONAYA_SEAL_DOOR
Definition uldaman.h:35
@ DATA_ARCHAEDAS
Definition uldaman.h:32
@ DATA_STONE_KEEPERS
Definition uldaman.h:31
@ DATA_IRONAYA_INTRO
Definition uldaman.h:34
#define UldamanScriptName
Definition uldaman.h:23
@ NPC_EARTHEN_CUSTODIAN
Definition uldaman.h:44
@ NPC_VAULT_WARDER
Definition uldaman.h:45
@ NPC_STONE_KEEPER
Definition uldaman.h:41
@ NPC_EARTHEN_GUARDIAN
Definition uldaman.h:42
@ NPC_EARTHEN_HALLSHAPER
Definition uldaman.h:43
@ NPC_ARCHAEDAS
Definition uldaman.h:40
@ GO_ANCIENT_VAULT_DOOR
Definition uldaman.h:55
@ GO_TEMPLE_DOOR_ARCHAEDAS
Definition uldaman.h:54
@ GO_TEMPLE_DOOR_TO_ARCHAEDAS
Definition uldaman.h:53
@ GO_TEMPLE_DOOR_TO_KEEPERS
Definition uldaman.h:52
@ GO_KEYSTONE
Definition uldaman.h:51
@ GO_IRONAYA_SEAL_DOOR
Definition uldaman.h:50
@ SPAWN_GROUP_IRONAYA
Definition uldaman.h:60