Skip to content

Commit c867a1a

Browse files
authored
Scripts/Gruul's Lair: Create base AI for Maulgar's ogres (TrinityCore#31119)
1 parent bb4424c commit c867a1a

File tree

2 files changed

+111
-215
lines changed

2 files changed

+111
-215
lines changed

src/server/scripts/Outland/GruulsLair/boss_high_king_maulgar.cpp

Lines changed: 104 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -171,245 +171,163 @@ struct boss_high_king_maulgar : public BossAI
171171
bool _enraged;
172172
};
173173

174-
// 18834 - Olm the Summoner
175-
struct boss_olm_the_summoner : public ScriptedAI
174+
struct OgreBaseAI : public ScriptedAI
176175
{
177-
boss_olm_the_summoner(Creature* creature) : ScriptedAI(creature), _instance(creature->GetInstanceScript()) { }
176+
OgreBaseAI(Creature* creature) : ScriptedAI(creature), instance(creature->GetInstanceScript()) { }
178177

179178
void Reset() override
180179
{
181-
_scheduler.CancelAll();
180+
scheduler.CancelAll();
181+
scheduler.SetValidator([this]
182+
{
183+
return !me->HasUnitState(UNIT_STATE_CASTING);
184+
});
182185
}
183186

184187
void JustEngagedWith(Unit* /*who*/) override
185188
{
186-
_scheduler.Schedule(10s, [this](TaskContext task)
187-
{
188-
DoCastVictim(SPELL_DARK_DECAY);
189-
task.Repeat(20s);
190-
});
191-
192-
_scheduler.Schedule(0s, 10s, [this](TaskContext task)
193-
{
194-
DoCastSelf(SPELL_SUMMON_WILD_FELHUNTER);
195-
task.Repeat(50s, 60s);
196-
});
197-
198-
_scheduler.Schedule(20s, [this](TaskContext task)
199-
{
200-
if (Unit* target = SelectTarget(SelectTargetMethod::Random, 0))
201-
DoCast(target, SPELL_DEATH_COIL);
202-
task.Repeat(20s);
203-
});
189+
ScheduleEvents();
204190
}
205191

192+
virtual void ScheduleEvents() = 0;
193+
206194
void JustDied(Unit* /*killer*/) override
207195
{
208-
if (Creature* maulgar = ObjectAccessor::GetCreature(*me, _instance->GetGuidData(DATA_MAULGAR)))
196+
if (Creature* maulgar = instance->GetCreature(DATA_MAULGAR))
209197
maulgar->AI()->DoAction(ACTION_ADD_DEATH);
210198

211-
_instance->SetBossState(DATA_MAULGAR, DONE);
199+
instance->SetBossState(DATA_MAULGAR, DONE);
212200
}
213201

214202
void UpdateAI(uint32 diff) override
215203
{
216204
if (!UpdateVictim())
217205
return;
218206

219-
if (me->HasUnitState(UNIT_STATE_CASTING))
220-
return;
221-
222-
_scheduler.Update(diff);
207+
scheduler.Update(diff);
223208

224209
DoMeleeAttackIfReady();
225210
}
226211

227-
private:
228-
TaskScheduler _scheduler;
229-
InstanceScript* _instance;
212+
protected:
213+
InstanceScript* instance;
214+
TaskScheduler scheduler;
230215
};
231216

232-
// 18835 - Kiggler the Crazed
233-
struct boss_kiggler_the_crazed : public ScriptedAI
217+
// 18834 - Olm the Summoner
218+
struct boss_olm_the_summoner : public OgreBaseAI
234219
{
235-
boss_kiggler_the_crazed(Creature* creature) : ScriptedAI(creature), _instance(creature->GetInstanceScript()) { }
220+
boss_olm_the_summoner(Creature* creature) : OgreBaseAI(creature) { }
236221

237-
void Reset() override
222+
void ScheduleEvents() override
238223
{
239-
_scheduler.CancelAll();
224+
scheduler
225+
.Schedule(10s, [this](TaskContext task)
226+
{
227+
DoCastVictim(SPELL_DARK_DECAY);
228+
task.Repeat(20s);
229+
})
230+
.Schedule(0s, 10s, [this](TaskContext task)
231+
{
232+
DoCastSelf(SPELL_SUMMON_WILD_FELHUNTER);
233+
task.Repeat(50s, 60s);
234+
})
235+
.Schedule(20s, [this](TaskContext task)
236+
{
237+
if (Unit* target = SelectTarget(SelectTargetMethod::Random, 0))
238+
DoCast(target, SPELL_DEATH_COIL);
239+
task.Repeat(20s);
240+
});
240241
}
242+
};
243+
244+
// 18835 - Kiggler the Crazed
245+
struct boss_kiggler_the_crazed : public OgreBaseAI
246+
{
247+
boss_kiggler_the_crazed(Creature* creature) : OgreBaseAI(creature) { }
241248

242249
void AttackStart(Unit* who) override
243250
{
244251
ScriptedAI::AttackStartCaster(who, 40.0f);
245252
}
246253

247-
void JustEngagedWith(Unit* /*who*/) override
248-
{
249-
_scheduler.Schedule(5s, [this](TaskContext task)
250-
{
251-
if (Unit* target = SelectTarget(SelectTargetMethod::Random, 0))
252-
DoCast(target, SPELL_GREATER_POLYMORPH);
253-
task.Repeat(15s, 20s);
254-
});
255-
256-
_scheduler.Schedule(0s, [this](TaskContext task)
257-
{
258-
DoCastVictim(SPELL_LIGHTNING_BOLT);
259-
task.Repeat(2s);
260-
});
261-
262-
_scheduler.Schedule(20s, [this](TaskContext task)
263-
{
264-
DoCastVictim(SPELL_ARCANE_SHOCK);
265-
task.Repeat(20s);
266-
});
267-
268-
_scheduler.Schedule(30s, [this](TaskContext task)
269-
{
270-
DoCastSelf(SPELL_ARCANE_EXPLOSION);
271-
task.Repeat(30s);
272-
});
273-
}
274-
275-
void JustDied(Unit* /*killer*/) override
254+
void ScheduleEvents() override
276255
{
277-
if (Creature* maulgar = ObjectAccessor::GetCreature(*me, _instance->GetGuidData(DATA_MAULGAR)))
278-
maulgar->AI()->DoAction(ACTION_ADD_DEATH);
279-
280-
_instance->SetBossState(DATA_MAULGAR, DONE);
281-
}
282-
283-
void UpdateAI(uint32 diff) override
284-
{
285-
if (!UpdateVictim())
286-
return;
287-
288-
if (me->HasUnitState(UNIT_STATE_CASTING))
289-
return;
290-
291-
_scheduler.Update(diff);
292-
293-
DoMeleeAttackIfReady();
256+
scheduler
257+
.Schedule(5s, [this](TaskContext task)
258+
{
259+
if (Unit* target = SelectTarget(SelectTargetMethod::Random, 0))
260+
DoCast(target, SPELL_GREATER_POLYMORPH);
261+
task.Repeat(15s, 20s);
262+
})
263+
.Schedule(0s, [this](TaskContext task)
264+
{
265+
DoCastVictim(SPELL_LIGHTNING_BOLT);
266+
task.Repeat(2s);
267+
})
268+
.Schedule(20s, [this](TaskContext task)
269+
{
270+
DoCastVictim(SPELL_ARCANE_SHOCK);
271+
task.Repeat(20s);
272+
})
273+
.Schedule(30s, [this](TaskContext task)
274+
{
275+
DoCastSelf(SPELL_ARCANE_EXPLOSION);
276+
task.Repeat(30s);
277+
});
294278
}
295-
296-
private:
297-
TaskScheduler _scheduler;
298-
InstanceScript* _instance;
299279
};
300280

301281
// 18836 - Blindeye the Seer
302-
struct boss_blindeye_the_seer : public ScriptedAI
282+
struct boss_blindeye_the_seer : public OgreBaseAI
303283
{
304-
boss_blindeye_the_seer(Creature* creature) : ScriptedAI(creature), _instance(creature->GetInstanceScript()) { }
305-
306-
void Reset() override
307-
{
308-
_scheduler.CancelAll();
309-
}
310-
311-
void JustEngagedWith(Unit* /*who*/) override
312-
{
313-
_scheduler.Schedule(5s, [this](TaskContext task)
314-
{
315-
DoCastSelf(SPELL_GREATER_PW_SHIELD);
316-
task.Repeat(40s);
317-
});
318-
319-
_scheduler.Schedule(25s, 40s, [this](TaskContext task)
320-
{
321-
DoCastSelf(SPELL_HEAL);
322-
task.Repeat(25s, 40s);
323-
});
324-
325-
_scheduler.Schedule(45s, 55s, [this](TaskContext task)
326-
{
327-
DoCastSelf(SPELL_PRAYER_OH);
328-
task.Repeat(35s, 50s);
329-
});
330-
}
331-
332-
void JustDied(Unit* /*killer*/) override
333-
{
334-
if (Creature* maulgar = ObjectAccessor::GetCreature(*me, _instance->GetGuidData(DATA_MAULGAR)))
335-
maulgar->AI()->DoAction(ACTION_ADD_DEATH);
284+
boss_blindeye_the_seer(Creature* creature) : OgreBaseAI(creature) { }
336285

337-
_instance->SetBossState(DATA_MAULGAR, DONE);
338-
}
339-
340-
void UpdateAI(uint32 diff) override
286+
void ScheduleEvents() override
341287
{
342-
if (!UpdateVictim())
343-
return;
344-
345-
if (me->HasUnitState(UNIT_STATE_CASTING))
346-
return;
347-
348-
_scheduler.Update(diff);
349-
350-
DoMeleeAttackIfReady();
288+
scheduler
289+
.Schedule(5s, [this](TaskContext task)
290+
{
291+
DoCastSelf(SPELL_GREATER_PW_SHIELD);
292+
task.Repeat(40s);
293+
})
294+
.Schedule(25s, 40s, [this](TaskContext task)
295+
{
296+
DoCastSelf(SPELL_HEAL);
297+
task.Repeat(25s, 40s);
298+
})
299+
.Schedule(45s, 55s, [this](TaskContext task)
300+
{
301+
DoCastSelf(SPELL_PRAYER_OH);
302+
task.Repeat(35s, 50s);
303+
});
351304
}
352-
353-
private:
354-
TaskScheduler _scheduler;
355-
InstanceScript* _instance;
356305
};
357306

358307
// 18832 - Krosh Firehand
359-
struct boss_krosh_firehand : public ScriptedAI
308+
struct boss_krosh_firehand : public OgreBaseAI
360309
{
361-
boss_krosh_firehand(Creature* creature) : ScriptedAI(creature), _instance(creature->GetInstanceScript()) { }
362-
363-
void Reset() override
364-
{
365-
_scheduler.CancelAll();
366-
}
367-
368-
void JustEngagedWith(Unit* /*who*/) override
369-
{
370-
_scheduler.Schedule(0s, 5s, [this](TaskContext task)
371-
{
372-
DoCastVictim(SPELL_GREATER_FIREBALL);
373-
task.Repeat(2s, 5s);
374-
});
375-
376-
_scheduler.Schedule(0s, [this](TaskContext task)
377-
{
378-
DoCastSelf(SPELL_SPELLSHIELD);
379-
task.Repeat(30s);
380-
});
381-
382-
_scheduler.Schedule(10s, 20s, [this](TaskContext task)
383-
{
384-
DoCastSelf(SPELL_BLAST_WAVE);
385-
task.Repeat(5s, 15s);
386-
});
387-
}
388-
389-
void JustDied(Unit* /*killer*/) override
390-
{
391-
if (Creature* maulgar = ObjectAccessor::GetCreature(*me, _instance->GetGuidData(DATA_MAULGAR)))
392-
maulgar->AI()->DoAction(ACTION_ADD_DEATH);
393-
394-
_instance->SetBossState(DATA_MAULGAR, DONE);
395-
}
310+
boss_krosh_firehand(Creature* creature) : OgreBaseAI(creature) { }
396311

397-
void UpdateAI(uint32 diff) override
312+
void ScheduleEvents() override
398313
{
399-
if (!UpdateVictim())
400-
return;
401-
402-
if (me->HasUnitState(UNIT_STATE_CASTING))
403-
return;
404-
405-
_scheduler.Update(diff);
406-
407-
DoMeleeAttackIfReady();
314+
scheduler
315+
.Schedule(0s, 5s, [this](TaskContext task)
316+
{
317+
DoCastVictim(SPELL_GREATER_FIREBALL);
318+
task.Repeat(2s, 5s);
319+
})
320+
.Schedule(0s, [this](TaskContext task)
321+
{
322+
DoCastSelf(SPELL_SPELLSHIELD);
323+
task.Repeat(30s);
324+
})
325+
.Schedule(10s, 20s, [this](TaskContext task)
326+
{
327+
DoCastSelf(SPELL_BLAST_WAVE);
328+
task.Repeat(5s, 15s);
329+
});
408330
}
409-
410-
private:
411-
TaskScheduler _scheduler;
412-
InstanceScript* _instance;
413331
};
414332

415333
void AddSC_boss_high_king_maulgar()

0 commit comments

Comments
 (0)