TrinityCore
Loading...
Searching...
No Matches
instance_the_black_morass.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 "Containers.h"
22#include "EventMap.h"
23#include "InstanceScript.h"
24#include "Player.h"
25#include "the_black_morass.h"
26
27static constexpr ObjectData creatureData[] =
28{
31};
32
33static Position const PortalPosition1 = { -2030.832f, 7024.944f, 23.07182f, 3.141593f };
34static Position const PortalPosition2 = { -1961.734f, 7029.528f, 21.8114f, 2.129302f };
35static Position const PortalPosition3 = { -1887.695f, 7106.557f, 22.0495f, 4.956735f };
36static Position const PortalPosition4 = { -1930.911f, 7183.597f, 23.00764f, 3.595378f };
37
39{
40public:
42
47
49 {
57
72
73 bool SetBossState(uint32 type, EncounterState state) override
74 {
75 if (!InstanceScript::SetBossState(type, state))
76 return false;
77
78 switch (type)
79 {
80 case DATA_DEJA:
81 case DATA_TEMPORUS:
82 if (state == DONE)
84 break;
85 case DATA_AEONUS:
86 if (state == DONE)
87 {
92 }
93 break;
94 default:
95 break;
96 }
97
98 return true;
99 }
100
101 void SetData(uint32 type, uint32 data) override
102 {
103 switch (type)
104 {
105 case DATA_EVENT:
106 EventState = data;
107 switch (data)
108 {
109 case IN_PROGRESS:
112 if (Creature* saat = GetCreature(DATA_SAAT))
113 saat->RemoveNpcFlag(UNIT_NPC_FLAG_QUESTGIVER);
114 break;
115 case DONE:
116 if (Creature* medivh = GetCreature(DATA_MEDIVH))
117 medivh->AI()->DoAction(ACTION_EPILOGUE);
118 if (Creature* saat = GetCreature(DATA_SAAT))
119 saat->SetNpcFlag(UNIT_NPC_FLAG_QUESTGIVER);
120 break;
121 case FAIL:
122 DoResetEvent();
123 if (Creature* saat = GetCreature(DATA_SAAT))
124 saat->SetNpcFlag(UNIT_NPC_FLAG_QUESTGIVER);
125 break;
126 default:
127 break;
128 }
129 break;
130 case DATA_SHIELD_PCT:
131 if (data == SPECIAL && GetData(DATA_EVENT) == IN_PROGRESS)
132 {
134
136
137 switch (ShieldPercent)
138 {
139 case 75:
140 if (Creature* medivh = GetCreature(DATA_MEDIVH))
141 medivh->AI()->DoAction(ACTION_SHIELD_75);
142 break;
143 case 50:
144 if (Creature* medivh = GetCreature(DATA_MEDIVH))
145 medivh->AI()->DoAction(ACTION_SHIELD_50);
146 break;
147 case 25:
148 if (Creature* medivh = GetCreature(DATA_MEDIVH))
149 medivh->AI()->DoAction(ACTION_SHIELD_25);
150 break;
151 case 0:
152 if (Creature* medivh = GetCreature(DATA_MEDIVH))
153 medivh->AI()->DoAction(ACTION_SHIELD_0);
155 break;
156 default:
157 break;
158 }
159 }
160 break;
161 case DATA_RIFT:
162 switch (data)
163 {
164 case DONE:
167 break;
168 case SPECIAL:
172 break;
173 default:
174 break;
175 }
176 break;
177 default:
178 break;
179 }
180 }
181
182 uint32 GetData(uint32 type) const override
183 {
184 switch (type)
185 {
186 case DATA_EVENT:
187 return EventState;
188 case DATA_RIFT_COUNT:
189 return RiftPortalCount;
190 case DATA_SHIELD_PCT:
191 return ShieldPercent;
192 }
193
194 return 0;
195 }
196
197 void OnUnitDeath(Unit* unit) override
198 {
199 switch (unit->GetEntry())
200 {
201 case NPC_RIFT_LORD:
203 case NPC_RIFT_KEEPER:
206 break;
210 break;
211 default:
212 break;
213 }
214 }
215
217 {
218 // Spells are guessed
219 if (Creature* medivh = GetCreature(DATA_MEDIVH))
220 {
221 std::vector<uint32> availableSummonRiftSpells =
222 {
227 };
228
230 std::erase(availableSummonRiftSpells, LastSummonRiftSpell);
231
232 uint32 selectedSpell = Trinity::Containers::SelectRandomContainerElement(availableSummonRiftSpells);
233
234 LastSummonRiftSpell = selectedSpell;
235
236 medivh->CastSpell(nullptr, selectedSpell, true);
237
239 }
240 }
241
242 void ProcessEvent(WorldObject* /*gameObject*/, uint32 eventId, WorldObject* /*invoker*/) override
243 {
244 // Positions are sniffed but the way they are linked to events is guessed
245 switch (eventId)
246 {
248 if (Creature* medivh = GetCreature(DATA_MEDIVH))
250 break;
252 if (Creature* medivh = GetCreature(DATA_MEDIVH))
254 break;
256 if (Creature* medivh = GetCreature(DATA_MEDIVH))
258 break;
260 if (Creature* medivh = GetCreature(DATA_MEDIVH))
262 break;
263 default:
264 break;
265 }
266 }
267
268 void Update(uint32 diff) override
269 {
270 Events.Update(diff);
271
272 if (Events.ExecuteEvent() == EVENT_SUMMON_PORTAL)
273 {
277 if (RiftPortalCount != 6 && RiftPortalCount != 12 && RiftPortalCount != 18)
278 ScheduleEventNextPortal(RiftPortalCount > 12 ? 90s : 120s);
279 }
280 }
281
283 {
284 Events.RescheduleEvent(EVENT_SUMMON_PORTAL, nextPortalTime);
285 }
286
287 protected:
294 };
295
296};
297
uint32_t uint32
Definition Define.h:154
std::chrono::milliseconds Milliseconds
Milliseconds shorthand typedef.
Definition Duration.h:24
EncounterState
@ IN_PROGRESS
@ FAIL
@ DONE
@ SPECIAL
@ NOT_STARTED
@ TEMPSUMMON_MANUAL_DESPAWN
Milliseconds randtime(Milliseconds min, Milliseconds max)
Definition Random.cpp:63
@ UNIT_NPC_FLAG_QUESTGIVER
#define DataHeader
uint32 const EncounterCount
@ DATA_EVENT
void SetBossNumber(uint32 number)
virtual bool SetBossState(uint32 id, EncounterState state)
void DoCastSpellOnPlayers(uint32 spell, bool includePets=false, bool includeControlled=false)
Creature * GetCreature(uint32 type)
void DoUpdateWorldState(int32 worldStateId, int32 value)
void LoadObjectData(std::span< ObjectData const > creatureData, std::span< ObjectData const > gameObjectData)
void SetHeaders(std::string_view dataHeaders)
uint32 GetEntry() const
Definition Object.h:89
Definition Unit.h:647
InstanceScript * GetInstanceScript(InstanceMap *map) const override
static constexpr ObjectData creatureData[]
static Position const PortalPosition4
static Position const PortalPosition1
static Position const PortalPosition3
void AddSC_instance_the_black_morass()
static Position const PortalPosition2
auto SelectRandomContainerElement(C const &container) -> std::add_const_t< decltype(*std::ranges::begin(container))> &
Definition Containers.h:110
void ProcessEvent(WorldObject *, uint32 eventId, WorldObject *) override
@ WORLD_STATE_BM_SHIELD
@ WORLD_STATE_BM_RIFT
@ WORLD_STATE_BM
@ ACTION_SHIELD_25
@ ACTION_EPILOGUE
@ ACTION_SHIELD_0
@ ACTION_SHIELD_75
@ ACTION_SHIELD_50
@ NPC_INFINITE_TIMEREAVER
@ NPC_SAAT
@ NPC_RIFT_LORD_ALT
@ NPC_INFINITE_CHRONO_LORD
@ NPC_RIFT_KEEPER
@ NPC_MEDIVH
@ NPC_RIFT_LORD
@ NPC_RIFT_KEEPER_ALT
@ DATA_MEDIVH
@ DATA_TEMPORUS
@ DATA_RIFT
@ DATA_SAAT
@ DATA_RIFT_COUNT
@ DATA_SHIELD_PCT
@ DATA_DEJA
@ DATA_AEONUS
#define TBMScriptName
@ SPELL_THE_MASTERS_TOUCH_COMPLETE
@ SPELL_SUMMON_TIME_RIFT_EFFECT_1
@ SPELL_SUMMON_TIME_RIFT_EFFECT_2
@ SPELL_SUMMON_TIME_RIFT_EFFECT_4
@ SPELL_THE_BLACK_MORASS_COMPLETE
@ SPELL_SUMMON_TIME_RIFT_EFFECT_3
@ EVENT_SUMMON_TIME_RIFT_3
@ EVENT_SUMMON_TIME_RIFT_1
@ EVENT_SUMMON_TIME_RIFT_2
@ EVENT_SUMMON_PORTAL
@ EVENT_SUMMON_TIME_RIFT_4