summaryrefslogtreecommitdiff
path: root/src/server/scripts/Outland/GruulsLair/boss_gruul.cpp
blob: 9c0dfcd9c929af4473626158f8cffb10a7eb3c48 (plain)
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
/*
 * 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 "CreatureScript.h"
#include "PassiveAI.h"
#include "ScriptedCreature.h"
#include "SpellScript.h"
#include "SpellScriptLoader.h"
#include "gruuls_lair.h"
#include "SpellAuraEffects.h"

enum Yells
{
    SAY_AGGRO                   = 0,
    SAY_SLAM                    = 1,
    SAY_SHATTER                 = 2,
    SAY_SLAY                    = 3,
    SAY_DEATH                   = 4,

    EMOTE_GROW                  = 5
};

enum Spells
{
    SPELL_GROWTH                        = 36300,
    SPELL_CAVE_IN                       = 36240,
    SPELL_GROUND_SLAM                   = 33525,
    SPELL_REVERBERATION                 = 36297,
    SPELL_HURTFUL_STRIKE                = 33813,
    SPELL_SHATTER                       = 33654,
    SPELL_LOOK_AROUND                   = 33965,

    // Ground Slam spells
    SPELL_SUMMON_TRACTOR_BEAM_CREATOR   = 33496,
    SPELL_TRACTOR_BEAM_PULL             = 33497,
    SPELL_SUMMON_TRACTOR_BEAM_1         = 33495,
    SPELL_SUMMON_TRACTOR_BEAM_2         = 33514,
    SPELL_SUMMON_TRACTOR_BEAM_3         = 33515,
    SPELL_SUMMON_TRACTOR_BEAM_4         = 33516,
    SPELL_SUMMON_TRACTOR_BEAM_5         = 33517,
    SPELL_SUMMON_TRACTOR_BEAM_6         = 33518,
    SPELL_SUMMON_TRACTOR_BEAM_7         = 33519,
    SPELL_SUMMON_TRACTOR_BEAM_8         = 33520,

    SPELL_SHATTER_EFFECT                = 33671,
    SPELL_STONED                        = 33652,
};

struct boss_gruul : public BossAI
{
    boss_gruul(Creature* creature) : BossAI(creature, DATA_GRUUL) { }

    void Reset() override
    {
        _Reset();
        _recentlySpoken = false;
        _caveInTimer = 29s;
    }

    void JustEngagedWith(Unit* /*who*/) override
    {
        _JustEngagedWith();
        Talk(SAY_AGGRO);

        scheduler.Schedule(30300ms, [this](TaskContext context)
        {
            Talk(EMOTE_GROW);
            DoCastSelf(SPELL_GROWTH);
            context.Repeat(30300ms);
        }).Schedule(_caveInTimer, [this](TaskContext context)
        {
            DoCastRandomTarget(SPELL_CAVE_IN);
            if (_caveInTimer > 4s)
            {
                _caveInTimer = _caveInTimer - 1500ms;
            }
            context.Repeat(_caveInTimer);
        }).Schedule(39900ms, 55700ms, [this](TaskContext context)
        {
            DoCastSelf(SPELL_REVERBERATION);
            context.Repeat(39900ms, 55700ms);
        }).Schedule(5600ms, [this](TaskContext context)
        {
            if (Unit* target = SelectTarget(SelectTargetMethod::MaxThreat, 0, 5.0f, false, false))
            {
                DoCast(target, SPELL_HURTFUL_STRIKE);
            }
            else
            {
                DoCastVictim(SPELL_HURTFUL_STRIKE);
            }
            context.Repeat(8400ms);
        }).Schedule(35s, [this](TaskContext context)
        {
            Talk(SAY_SLAM);
            DoCastSelf(SPELL_GROUND_SLAM);
            scheduler.DelayAll(9701ms);
            scheduler.Schedule(9700ms, [this](TaskContext)
            {
                Talk(SAY_SHATTER);
                me->RemoveAurasDueToSpell(SPELL_LOOK_AROUND);
                DoCastSelf(SPELL_SHATTER);
            });
            context.Repeat(60s);
        });
    }

    void KilledUnit(Unit* /*who*/) override
    {
        if (!_recentlySpoken)
        {
            Talk(SAY_SLAY);
            _recentlySpoken = true;
        }

        scheduler.Schedule(5s, [this](TaskContext)
        {
            _recentlySpoken = false;
        });
    }

    void JustDied(Unit* /*killer*/) override
    {
        _JustDied();
        Talk(SAY_DEATH);
    }

    void UpdateAI(uint32 diff) override
    {
        if (!UpdateVictim())
            return;

        scheduler.Update(diff);

        if (!me->HasUnitState(UNIT_STATE_ROOT))
        {
            DoMeleeAttackIfReady();
        }
    }

private:
    std::chrono::milliseconds _caveInTimer;
    bool _recentlySpoken;
};

struct npc_invisible_tractor_beam_source : public NullCreatureAI
{
    npc_invisible_tractor_beam_source(Creature* creature) : NullCreatureAI(creature) { }

    void IsSummonedBy(WorldObject* summoner) override
    {
        if (Unit* summonerUnit = summoner->ToUnit())
        {
            DoCast(summonerUnit, SPELL_TRACTOR_BEAM_PULL, true);
        }
    }
};

class spell_gruul_ground_slam : public SpellScript
{
    PrepareSpellScript(spell_gruul_ground_slam);

    bool Validate(SpellInfo const* /*spellInfo*/) override
    {
        return ValidateSpellInfo({ SPELL_SUMMON_TRACTOR_BEAM_CREATOR });
    }

    void ApplyStun()
    {
        if (Unit* caster = GetCaster())
        {
            caster->CastSpell(caster, SPELL_LOOK_AROUND, true);
        }
    }

    void HandleScriptEffect(SpellEffIndex /*effIndex*/)
    {
        if (Unit* target = GetHitUnit())
        {
            target->CastSpell(target, SPELL_SUMMON_TRACTOR_BEAM_CREATOR, true);
        }
    }

    void Register() override
    {
        AfterCast += SpellCastFn(spell_gruul_ground_slam::ApplyStun);
        OnEffectHitTarget += SpellEffectFn(spell_gruul_ground_slam::HandleScriptEffect, EFFECT_1, SPELL_EFFECT_SCRIPT_EFFECT);
    }
};

class spell_tractor_beam_creator : public SpellScript
{
    PrepareSpellScript(spell_tractor_beam_creator);

    void HandleScriptEffect(SpellEffIndex /*effIndex*/)
    {
        if (Unit* caster = GetCaster())
        {
            std::vector<uint32> tractorBeamSummons = { SPELL_SUMMON_TRACTOR_BEAM_1, SPELL_SUMMON_TRACTOR_BEAM_2, SPELL_SUMMON_TRACTOR_BEAM_3, SPELL_SUMMON_TRACTOR_BEAM_4,
                SPELL_SUMMON_TRACTOR_BEAM_5, SPELL_SUMMON_TRACTOR_BEAM_6, SPELL_SUMMON_TRACTOR_BEAM_7, SPELL_SUMMON_TRACTOR_BEAM_8 };
            uint32 randomTractorSpellID = Acore::Containers::SelectRandomContainerElement(tractorBeamSummons);
            caster->CastSpell(caster, randomTractorSpellID, true);
        }
    }

    void Register() override
    {
        OnEffectHitTarget += SpellEffectFn(spell_tractor_beam_creator::HandleScriptEffect, EFFECT_0, SPELL_EFFECT_SCRIPT_EFFECT);
    }
};

class spell_gruul_ground_slam_trigger : public AuraScript
{
    PrepareAuraScript(spell_gruul_ground_slam_trigger);

    bool Validate(SpellInfo const* /*spellInfo*/) override
    {
        return ValidateSpellInfo({ SPELL_STONED });
    }

    void OnApply(AuraEffect const* aurEff, AuraEffectHandleModes /*mode*/)
    {
        if (GetUnitOwner()->GetAuraCount(GetSpellInfo()->Effects[aurEff->GetEffIndex()].TriggerSpell) == 5)
        {
            GetUnitOwner()->CastSpell(GetUnitOwner(), SPELL_STONED, true);
        }
    }

    void Register() override
    {
        AfterEffectRemove += AuraEffectRemoveFn(spell_gruul_ground_slam_trigger::OnApply, EFFECT_0, SPELL_AURA_PERIODIC_TRIGGER_SPELL, AURA_EFFECT_HANDLE_REAL);
    }
};

class spell_gruul_shatter : public SpellScript
{
    PrepareSpellScript(spell_gruul_shatter);

    bool Validate(SpellInfo const* /*spellInfo*/) override
    {
        return ValidateSpellInfo({ SPELL_SHATTER_EFFECT });
    }

    void HandleScriptEffect(SpellEffIndex /*effIndex*/)
    {
        if (Unit* target = GetHitUnit())
        {
            target->RemoveAurasDueToSpell(SPELL_STONED);

            if (target->IsPlayer())
            {
                target->CastSpell((Unit*)nullptr, SPELL_SHATTER_EFFECT, true);
            }
        }
    }

    void Register() override
    {
        OnEffectHitTarget += SpellEffectFn(spell_gruul_shatter::HandleScriptEffect, EFFECT_0, SPELL_EFFECT_SCRIPT_EFFECT);
    }
};

class spell_gruul_shatter_effect : public SpellScript
{
    PrepareSpellScript(spell_gruul_shatter_effect);

    void CalculateDamage()
    {
        if (!GetHitUnit())
        {
            return;
        }

        float radius = GetSpellInfo()->Effects[EFFECT_0].CalcRadius(GetCaster());
        if (!radius)
        {
            return;
        }

        float distance = GetCaster()->GetDistance2d(GetHitUnit());
        if (distance > 1.0f)
        {
            SetHitDamage(int32(GetHitDamage() * ((radius - distance) / radius)));
        }
    }

    void Register() override
    {
        OnHit += SpellHitFn(spell_gruul_shatter_effect::CalculateDamage);
    }
};

void AddSC_boss_gruul()
{
    RegisterGruulsLairAI(boss_gruul);
    RegisterGruulsLairAI(npc_invisible_tractor_beam_source);

    RegisterSpellScript(spell_gruul_ground_slam);
    RegisterSpellScript(spell_tractor_beam_creator);
    RegisterSpellScript(spell_gruul_ground_slam_trigger);
    RegisterSpellScript(spell_gruul_shatter);
    RegisterSpellScript(spell_gruul_shatter_effect);
}