TrinityCore
boss_mal_ganis.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
19#include "InstanceScript.h"
20#include "Map.h"
21#include "PassiveAI.h"
22#include "ScriptedCreature.h"
23#include "ScriptMgr.h"
24
26{
28};
29
30#define SPELL_CARRION_SWARM DUNGEON_MODE(52720,58852)
31#define SPELL_MIND_BLAST DUNGEON_MODE(52722,58850)
32#define SPELL_SLEEP DUNGEON_MODE(52721,58849)
33
35{
40 SAY_15HEALTH = 7
41};
42
44{
49};
50
52{
53 public:
54 boss_mal_ganis() : CreatureScript("boss_mal_ganis") { }
55
56 CreatureAI* GetAI(Creature* creature) const override
57 {
58 if (!InstanceHasScript(creature, CoSScriptName))
59 return nullptr;
60
62 return new NullCreatureAI(creature);
63 else
64 return new boss_mal_ganisAI(creature);
65 }
66
67 struct boss_mal_ganisAI : public BossAI
68 {
69 boss_mal_ganisAI(Creature* creature) : BossAI(creature, DATA_MAL_GANIS), _defeated(false), _hadYell30(false), _hadYell15(false) { }
70
71 void Reset() override
72 {
73 if (!_defeated)
75 }
76
77 void DamageTaken(Unit* /*source*/, uint32& damage, DamageEffectType /*damageType*/, SpellInfo const* /*spellInfo = nullptr*/) override
78 {
79 if (damage >= me->GetHealth())
80 {
81 damage = me->GetHealth() - 1;
82 if (_defeated)
83 return;
84 _defeated = true;
85 }
86 }
87
88 void JustEngagedWith(Unit* /*who*/) override
89 {
90 _defeated = false;
91 _hadYell30 = false;
92 _hadYell15 = false;
97 }
98
99 void JustReachedHome() override
100 {
101 if (!_defeated)
103 }
104
105 void UpdateAI(uint32 diff) override
106 {
107 if (_defeated)
108 {
109 if (me->IsInCombat())
110 {
112 me->SetImmuneToAll(true);
113 }
114 return;
115 }
116
117 if (!UpdateVictim())
118 return;
119
120 if (!_hadYell30 && HealthBelowPct(30))
121 {
123 _hadYell30 = true;
124 }
125
126 if (!_hadYell15 && HealthBelowPct(15))
127 {
129 _hadYell15 = true;
130 }
131
132 events.Update(diff);
133
135 return;
136
137 while (uint32 eventId = events.ExecuteEvent())
138 {
139 switch (eventId)
140 {
144 break;
145 case EVENT_MIND_BLAST:
146 if (Unit* target = SelectTarget(SelectTargetMethod::Random, 1, 100.0f, true, -int32(SPELL_SLEEP)))
147 DoCast(target, SPELL_MIND_BLAST);
148 else
150 events.Repeat(Seconds(8), Seconds(12));
151 break;
154 events.Repeat(Seconds(30));
155 break;
156 case EVENT_SLEEP:
157 if (Unit* target = SelectTarget(SelectTargetMethod::Random, 1, 100.0f))
158 DoCast(target, SPELL_SLEEP);
159 else
161 events.Repeat(Seconds(10), Seconds(15));
162 break;
163 default:
164 break;
165 }
166
168 return;
169 }
170 }
171
172 void KilledUnit(Unit* victim) override
173 {
174 if (!_defeated && victim->GetTypeId() == TYPEID_PLAYER)
175 Talk(SAY_SLAY);
176 }
177
178 private:
182 };
183};
184
186{
187 new boss_mal_ganis();
188}
TC_GAME_API bool InstanceHasScript(WorldObject const *obj, char const *scriptName)
int32_t int32
Definition: Define.h:138
uint32_t uint32
Definition: Define.h:142
std::chrono::seconds Seconds
Seconds shorthand typedef.
Definition: Duration.h:32
@ NOT_STARTED
@ TYPEID_PLAYER
Definition: ObjectGuid.h:41
Spells
Definition: PlayerAI.cpp:32
DamageEffectType
Definition: UnitDefines.h:131
@ UNIT_STATE_CASTING
Definition: Unit.h:270
#define SPELL_MIND_BLAST
@ SAY_30HEALTH
@ SAY_SLEEP
@ SAY_KILL
@ SAY_SLAY
@ SAY_15HEALTH
void AddSC_boss_mal_ganis()
#define SPELL_CARRION_SWARM
@ SPELL_VAMPIRIC_TOUCH
#define SPELL_SLEEP
@ EVENT_CARRION_SWARM
@ EVENT_MIND_BLAST
@ EVENT_SLEEP
@ EVENT_VAMPIRIC_TOUCH
Yells
InstanceScript *const instance
EventMap events
virtual void EnterEvadeMode(EvadeReason why=EvadeReason::Other)
Definition: CreatureAI.cpp:219
void Talk(uint8 id, WorldObject const *whisperTarget=nullptr)
Definition: CreatureAI.cpp:56
bool UpdateVictim()
Definition: CreatureAI.cpp:245
Creature *const me
Definition: CreatureAI.h:61
void DespawnOrUnsummon(Milliseconds timeToDespawn=0s, Seconds forceRespawnTime=0s)
Definition: Creature.cpp:2415
void SetImmuneToAll(bool apply) override
Definition: Creature.h:167
uint32 ExecuteEvent()
Definition: EventMap.cpp:73
void Update(uint32 time)
Definition: EventMap.h:56
void Repeat(Milliseconds time)
Definition: EventMap.cpp:63
void ScheduleEvent(uint32 eventId, Milliseconds time, uint32 group=0, uint8 phase=0)
Definition: EventMap.cpp:36
virtual bool SetBossState(uint32 id, EncounterState state)
TypeID GetTypeId() const
Definition: Object.h:173
SpellCastResult DoCastSelf(uint32 spellId, CastSpellExtraArgs const &args={})
Definition: UnitAI.h:159
SpellCastResult DoCastVictim(uint32 spellId, CastSpellExtraArgs const &args={})
Definition: UnitAI.cpp:180
Unit * SelectTarget(SelectTargetMethod targetType, uint32 offset=0, float dist=0.0f, bool playerOnly=false, bool withTank=true, int32 aura=0)
Definition: UnitAI.cpp:79
SpellCastResult DoCastAOE(uint32 spellId, CastSpellExtraArgs const &args={})
Definition: UnitAI.h:161
SpellCastResult DoCast(uint32 spellId)
Definition: UnitAI.cpp:89
Definition: Unit.h:627
uint64 GetHealth() const
Definition: Unit.h:776
bool HasUnitState(const uint32 f) const
Definition: Unit.h:732
bool IsInCombat() const
Definition: Unit.h:1043
InstanceScript * GetInstanceScript() const
Definition: Object.cpp:1042
virtual uint32 GetData(uint32) const
Definition: ZoneScript.h:91
CreatureAI * GetAI(Creature *creature) const override
@ DATA_INSTANCE_PROGRESS
@ DATA_MAL_GANIS
#define CoSScriptName
@ MALGANIS_IN_PROGRESS
bool HealthBelowPct(uint32 pct) const
boss_mal_ganisAI(Creature *creature)
void DamageTaken(Unit *, uint32 &damage, DamageEffectType, SpellInfo const *) override
void UpdateAI(uint32 diff) override
void KilledUnit(Unit *victim) override
void JustEngagedWith(Unit *) override