1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
|
/*
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "CellImpl.h"
#include "CreatureScript.h"
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
#include "PassiveAI.h"
#include "ScriptedCreature.h"
#include "SpellScript.h"
#include "SpellScriptLoader.h"
#include "zulaman.h"
enum Yells
{
SAY_AGGRO = 0,
SAY_FIRE_BOMBS = 1,
SAY_SUMMON_HATCHER = 2,
SAY_ALL_EGGS = 3,
SAY_BERSERK = 4,
SAY_SLAY = 5,
SAY_DEATH = 6,
SAY_EVENT_STRANGERS = 7,
SAY_EVENT_FRIENDS = 8
};
enum Spells
{
// Jan'alai
SPELL_FLAME_BREATH = 43140,
SPELL_FIRE_WALL = 43113,
SPELL_ENRAGE = 44779,
SPELL_SUMMON_PLAYERS_DUMMY = 43096,
SPELL_SUMMON_PLAYERS = 43097,
SPELL_TELE_TO_CENTER = 43098, // coord
SPELL_HATCH_ALL = 43144,
SPELL_BERSERK = 45078,
// Fire Bob Spells
SPELL_FIRE_BOMB_CHANNEL = 42621, // last forever
SPELL_FIRE_BOMB_THROW = 42628, // throw visual
SPELL_FIRE_BOMB_DUMMY = 42629, // bomb visual
SPELL_FIRE_BOMB_DAMAGE = 42630,
// Hatcher Spells
SPELL_HATCH_EGG_ALL = 42471,
SPELL_HATCH_EGG_SINGULAR = 43734,
SPELL_SUMMON_HATCHLING = 42493,
// Hatchling Spells
SPELL_FLAMEBUFFET = 43299
};
enum Creatures
{
NPC_AMANI_HATCHER = 23818,
NPC_EGG = 23817,
NPC_FIRE_BOMB = 23920
};
const int area_dx = 44;
const int area_dy = 51;
const Position janalainPos = {-33.93f, 1149.27f, 19.0f, 0.0f};
const Position fireWallCoords[4] =
{
{-10.13f, 1149.27f, 19, 3.1415f},
{-33.93f, 1123.90f, 19, 0.5f * 3.1415f},
{-54.80f, 1150.08f, 19, 0.0f},
{-33.93f, 1175.68f, 19, 1.5f * 3.1415f}
};
const Position hatcherway[2][5] =
{
{
{-87.46f, 1170.09f, 6.0f, 0.0f},
{-74.41f, 1154.75f, 6.0f, 0.0f},
{-52.74f, 1153.32f, 19.0f, 0.0f},
{-33.37f, 1172.46f, 19.0f, 0.0f},
{-33.09f, 1203.87f, 19.0f, 0.0f}
},
{
{-86.57f, 1132.85f, 6.0f, 0.0f},
{-73.94f, 1146.00f, 6.0f, 0.0f},
{-52.29f, 1146.51f, 19.0f, 0.0f},
{-33.57f, 1125.72f, 19.0f, 0.0f},
{-34.29f, 1095.22f, 19.0f, 0.0f}
}
};
enum HatchActions
{
HATCH_RESET = 0,
HATCH_ALL = 1
};
enum Misc
{
MAX_BOMB_COUNT = 40,
GROUP_ENRAGE = 1,
GROUP_HATCHING = 2,
DATA_ALL_EGGS_HATCHED = 0
};
struct boss_janalai : public BossAI
{
boss_janalai(Creature* creature) : BossAI(creature, DATA_JANALAI)
{
scheduler.SetValidator([this]
{
return !me->HasUnitState(UNIT_STATE_CASTING);
});
}
void Reset() override
{
BossAI::Reset();
HatchAllEggs(HATCH_RESET);
_isBombing = false;
_isFlameBreathing = false;
ScheduleHealthCheckEvent(35, [&]{
Talk(SAY_ALL_EGGS);
me->AttackStop();
me->GetMotionMaster()->Clear();
me->SetPosition(janalainPos);
me->StopMovingOnCurrentPos();
DoCastAOE(SPELL_HATCH_ALL);
});
ScheduleHealthCheckEvent(20, [&] {
if (!me->HasAura(SPELL_ENRAGE))
DoCastSelf(SPELL_ENRAGE, true);
me->m_Events.CancelEventGroup(GROUP_ENRAGE);
});
me->m_Events.KillAllEvents(false);
_sideHatched[0] = false;
_sideHatched[1] = false;
}
void JustDied(Unit* killer) override
{
Talk(SAY_DEATH);
BossAI::JustDied(killer);
}
void JustSummoned(Creature* summon) override
{
if (summon->GetEntry() == NPC_AMANI_HATCHLING)
{
if (summon->GetPositionY() > 1150)
summon->GetMotionMaster()->MovePoint(0, hatcherway[0][3].GetPositionX() + rand() % 4 - 2, 1150.0f + rand() % 4 - 2, hatcherway[0][3].GetPositionY());
else
summon->GetMotionMaster()->MovePoint(0, hatcherway[1][3].GetPositionX() + rand() % 4 - 2, 1150.0f + rand() % 4 - 2, hatcherway[1][3].GetPositionY());
}
BossAI::JustSummoned(summon);
}
void DamageDealt(Unit* target, uint32& damage, DamageEffectType /*damagetype*/, SpellSchoolMask /*damageSchoolMask*/) override
{
if (_isFlameBreathing)
{
if (!me->HasInArc(M_PI / 6, target))
damage = 0;
}
}
void JustEngagedWith(Unit* who) override
{
BossAI::JustEngagedWith(who);
Talk(SAY_AGGRO);
//schedule abilities
ScheduleTimedEvent(30s, [&]{
StartBombing();
}, 20s, 40s);
scheduler.Schedule(10s, GROUP_HATCHING, [this](TaskContext context)
{
if (_sideHatched[0] && _sideHatched[1])
return;
Talk(SAY_SUMMON_HATCHER);
if (_sideHatched[0] && !_sideHatched[1])
{
me->SummonCreature(NPC_AMANI_HATCHER, hatcherway[1][0], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 10000);
me->SummonCreature(NPC_AMANI_HATCHER, hatcherway[1][0], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 10000);
}
else if (!_sideHatched[0] && _sideHatched[1])
{
me->SummonCreature(NPC_AMANI_HATCHER, hatcherway[0][0], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 10000);
me->SummonCreature(NPC_AMANI_HATCHER, hatcherway[0][0], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 10000);
}
else
{
me->SummonCreature(NPC_AMANI_HATCHER, hatcherway[0][0], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 10000);
me->SummonCreature(NPC_AMANI_HATCHER, hatcherway[1][0], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 10000);
}
context.Repeat(90s);
});
ScheduleTimedEvent(8s, [&]{
if (Unit* target = SelectTarget(SelectTargetMethod::Random, 0))
{
me->AttackStop();
me->GetMotionMaster()->Clear();
DoCast(target, SPELL_FLAME_BREATH);
me->StopMoving();
_isFlameBreathing = true;
// placeholder time idk yet
scheduler.Schedule(2s, [this](TaskContext)
{
_isFlameBreathing = false;
});
}
}, 8s);
me->m_Events.AddEventAtOffset([&] {
DoCastSelf(SPELL_ENRAGE, true);
}, 5min, 5min, GROUP_ENRAGE);
me->m_Events.AddEventAtOffset([&] {
Talk(SAY_BERSERK);
DoCastSelf(SPELL_BERSERK);
}, 10min);
}
void SetData(uint32 index, uint32 data) override
{
if (index == DATA_ALL_EGGS_HATCHED)
_sideHatched[data] = true;
}
bool HatchAllEggs(uint32 hatchAction)
{
std::list<Creature* > eggList;
me->GetCreaturesWithEntryInRange(eggList, 100.0f, NPC_EGG);
if (eggList.empty())
return false;
if (hatchAction == HATCH_RESET)
{
for (Creature* egg : eggList)
egg->Respawn();
summons.DespawnEntry(NPC_AMANI_HATCHLING);
}
else if (hatchAction == HATCH_ALL)
DoCastSelf(SPELL_HATCH_EGG_ALL);
eggList.clear();
return true;
}
void FireWall()
{
for (uint8 i = 0; i < 4; ++i)
{
uint8 wallNum = i == 0 || i == 2 ? 3 : 2;
for (uint8 j = 0; j < wallNum; j++)
{
Creature* wall = wallNum == 3
? me->SummonCreature(NPC_FIRE_BOMB, fireWallCoords[i].GetPositionX(), fireWallCoords[i].GetPositionY() + 5 * (j - 1), fireWallCoords[i].GetPositionZ(), fireWallCoords[i].GetOrientation(), TEMPSUMMON_TIMED_DESPAWN, 15000)
: me->SummonCreature(NPC_FIRE_BOMB, fireWallCoords[i].GetPositionX() - 2 + 4 * j, fireWallCoords[i].GetPositionY(), fireWallCoords[i].GetPositionZ(), fireWallCoords[i].GetOrientation(), TEMPSUMMON_TIMED_DESPAWN, 15000);
if (wall)
wall->AI()->DoCastSelf(SPELL_FIRE_WALL, true);
}
}
}
void SpawnBombs()
{
float dx, dy;
for (int i = 0; i < MAX_BOMB_COUNT; ++i)
{
dx = float(irand(-area_dx / 2, area_dx / 2));
dy = float(irand(-area_dy / 2, area_dy / 2));
DoSpawnCreature(NPC_FIRE_BOMB, dx, dy, 0, 0, TEMPSUMMON_TIMED_DESPAWN, 15000);
}
}
void Boom()
{
summons.DoForAllSummons([&](WorldObject* summon) {
if (summon->GetEntry() == NPC_FIRE_BOMB)
{
if (Creature* bomb = summon->ToCreature())
{
bomb->AI()->DoCastSelf(SPELL_FIRE_BOMB_DAMAGE, true);
bomb->RemoveAllAuras();
}
}
});
}
void StartBombing()
{
Talk(SAY_FIRE_BOMBS);
me->AttackStop();
me->GetMotionMaster()->Clear();
me->SetPosition(janalainPos);
me->StopMovingOnCurrentPos();
DoCastSelf(SPELL_FIRE_BOMB_CHANNEL);
FireWall();
SpawnBombs();
_isBombing = true;
DoCastSelf(SPELL_TELE_TO_CENTER);
DoCastAOE(SPELL_SUMMON_PLAYERS_DUMMY, true);
//DoCast(Temp, SPELL_SUMMON_PLAYERS, true) // core bug, spell does not work if too far
ThrowBombs();
scheduler.Schedule(11s, [this](TaskContext)
{
Boom();
_isBombing = false;
me->RemoveAurasDueToSpell(SPELL_FIRE_BOMB_CHANNEL);
});
}
void ThrowBombs()
{
std::chrono::milliseconds bombTimer = 100ms;
summons.DoForAllSummons([this, &bombTimer](WorldObject* summon) {
if (summon->GetEntry() == NPC_FIRE_BOMB)
{
if (Creature* bomb = summon->ToCreature())
{
bomb->m_Events.AddEventAtOffset([this, bomb] {
bomb->RemoveUnitFlag(UNIT_FLAG_NOT_SELECTABLE);
DoCast(bomb, SPELL_FIRE_BOMB_THROW, true);
bomb->SetUnitFlag(UNIT_FLAG_NOT_SELECTABLE);
}, bombTimer);
}
bombTimer += 100ms;
}
});
}
bool CheckEvadeIfOutOfCombatArea() const override
{
return me->GetPositionZ() <= 12.0f;
}
private:
bool _isBombing;
bool _isFlameBreathing;
bool _sideHatched[2];
};
struct npc_janalai_hatcher : public ScriptedAI
{
npc_janalai_hatcher(Creature* creature) : ScriptedAI(creature) { }
void Reset() override
{
ScriptedAI::Reset();
scheduler.CancelAll();
_side = (me->GetPositionY() < 1150);
_waypoint = 0;
_repeatCount = 1;
_isHatching = false;
me->GetMotionMaster()->Clear();
me->GetMotionMaster()->MovePoint(0, hatcherway[_side][0]);
}
void MovementInform(uint32, uint32) override
{
if (_waypoint == 5)
{
_isHatching = true;
scheduler.Schedule(1500ms, [this](TaskContext context)
{
me->CastCustomSpell(SPELL_HATCH_EGG_ALL, SPELLVALUE_MAX_TARGETS, _repeatCount);
++_repeatCount;
if (me->FindNearestCreature(NPC_EGG, 100.0f))
context.Repeat(5s);
else
{
if (WorldObject* summoner = GetSummoner())
if (Creature* janalai = summoner->ToCreature())
janalai->AI()->SetData(DATA_ALL_EGGS_HATCHED, _side);
_side = _side ? 0 : 1;
_isHatching = false;
_waypoint = 3;
MoveToNewWaypoint(_waypoint);
}
});
}
else
{
MoveToNewWaypoint(_waypoint);
++_waypoint;
}
}
void MoveToNewWaypoint(uint8 waypoint)
{
if (!_isHatching)
{
scheduler.Schedule(100ms, [this, waypoint](TaskContext)
{
me->GetMotionMaster()->Clear();
me->GetMotionMaster()->MovePoint(0, hatcherway[_side][waypoint]);
});
}
}
void UpdateAI(uint32 diff) override
{
scheduler.Update(diff);
}
void JustEngagedWith(Unit* /*who*/) override { }
void AttackStart(Unit* /*who*/) override { }
void MoveInLineOfSight(Unit* /*who*/) override { }
private:
uint8 _side;
uint8 _waypoint;
uint32 _repeatCount;
bool _isHatching;
};
class spell_summon_all_players_dummy: public SpellScript
{
PrepareSpellScript(spell_summon_all_players_dummy);
bool Validate(SpellInfo const* /*spell*/) override
{
return ValidateSpellInfo({ SPELL_SUMMON_PLAYERS });
}
void FilterTargets(std::list<WorldObject*>& targets)
{
Position pos = GetCaster()->GetPosition();
targets.remove_if([&, pos](WorldObject* target) -> bool
{
return target->IsWithinBox(pos, 22.0f, 28.0f, 28.0f);
});
}
void OnHit(SpellEffIndex /*effIndex*/)
{
GetCaster()->CastSpell(GetHitUnit(), SPELL_SUMMON_PLAYERS, true);
}
void Register() override
{
OnObjectAreaTargetSelect += SpellObjectAreaTargetSelectFn(spell_summon_all_players_dummy::FilterTargets, EFFECT_0, TARGET_UNIT_SRC_AREA_ENEMY);
OnEffectHitTarget += SpellEffectFn(spell_summon_all_players_dummy::OnHit, EFFECT_0, SPELL_EFFECT_DUMMY);
}
};
void AddSC_boss_janalai()
{
RegisterZulAmanCreatureAI(boss_janalai);
RegisterZulAmanCreatureAI(npc_janalai_hatcher);
RegisterSpellScript(spell_summon_all_players_dummy);
}
|