TrinityCore
lunar_festival.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 "GameObject.h"
19#include "ScriptMgr.h"
20#include "MotionMaster.h"
21#include "Player.h"
22#include "ScriptedCreature.h"
23#include "SpellInfo.h"
24#include "SpellMgr.h"
25#include "SpellScript.h"
26#include "TemporarySummon.h"
27
29{
30 NPC_OMEN = 15467,
44
58
66
80
83};
84
85Position omenSummonPos = {7558.993f, -2839.999f, 450.0214f, 4.46f};
86
87struct npc_firework : public ScriptedAI
88{
89 npc_firework(Creature* creature) : ScriptedAI(creature) { }
90
91 bool isCluster()
92 {
93 switch (me->GetEntry())
94 {
107 return false;
108 case NPC_CLUSTER_BLUE:
111 case NPC_CLUSTER_RED:
121 default:
122 return true;
123 }
124 }
125
127 {
128 GameObject* launcher = nullptr;
129
130 if (isCluster())
131 {
136
137 if (launcher1)
138 launcher = launcher1;
139 else if (launcher2)
140 launcher = launcher2;
141 else if (launcher3)
142 launcher = launcher3;
143 else if (launcher4)
144 launcher = launcher4;
145 }
146 else
147 {
151
152 if (launcher1)
153 launcher = launcher1;
154 else if (launcher2)
155 launcher = launcher2;
156 else if (launcher3)
157 launcher = launcher3;
158 }
159
160 return launcher;
161 }
162
164 {
165 switch (entry)
166 {
168 return SPELL_ROCKET_BLUE;
170 return SPELL_ROCKET_GREEN;
172 return SPELL_ROCKET_PURPLE;
173 case NPC_FIREWORK_RED:
174 return SPELL_ROCKET_RED;
176 return SPELL_ROCKET_YELLOW;
178 return SPELL_ROCKET_WHITE;
191 default:
192 return 0;
193 }
194 }
195
197 {
198 uint32 spellId = 0;
199
200 switch (me->GetEntry())
201 {
202 case NPC_CLUSTER_BLUE:
204 break;
207 break;
210 break;
211 case NPC_CLUSTER_RED:
213 break;
216 break;
219 break;
222 break;
225 break;
228 break;
231 break;
234 break;
237 break;
240 break;
241 }
242
243 SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId, DIFFICULTY_NONE);
244
245 if (spellInfo && spellInfo->GetEffect(EFFECT_0).Effect == SPELL_EFFECT_SUMMON_OBJECT_WILD)
246 return spellInfo->GetEffect(EFFECT_0).MiscValue;
247
248 return 0;
249 }
250
251 void Reset() override
252 {
253 if (GameObject* launcher = FindNearestLauncher())
254 {
255 launcher->SendCustomAnim(ANIM_GO_LAUNCH_FIREWORK);
256 me->SetOrientation(launcher->GetOrientation() + float(M_PI) / 2);
257 }
258 else
259 return;
260
261 if (isCluster())
262 {
263 // Check if we are near Elune'ara lake south, if so try to summon Omen or a minion
264 if (me->GetZoneId() == ZONE_MOONGLADE)
265 {
267 {
268 switch (urand(0, 9))
269 {
270 case 0:
271 case 1:
272 case 2:
273 case 3:
274 if (Creature* minion = me->SummonCreature(NPC_MINION_OF_OMEN, me->GetPositionX()+frand(-5.0f, 5.0f), me->GetPositionY()+frand(-5.0f, 5.0f), me->GetPositionZ(), 0.0f, TEMPSUMMON_CORPSE_TIMED_DESPAWN, 20s))
275 minion->AI()->AttackStart(me->SelectNearestPlayer(20.0f));
276 break;
277 case 9:
279 break;
280 }
281 }
282 }
283 if (me->GetEntry() == NPC_CLUSTER_ELUNE)
285
286 float displacement = 0.7f;
287 for (uint8 i = 0; i < 4; i++)
288 me->SummonGameObject(GetFireworkGameObjectId(), me->GetPositionX() + (i % 2 == 0 ? displacement : -displacement), me->GetPositionY() + (i > 1 ? displacement : -displacement), me->GetPositionZ() + 4.0f, me->GetOrientation(), QuaternionData::fromEulerAnglesZYX(me->GetOrientation(), 0.0f, 0.0f), 1s);
289 }
290 else
291 //me->CastSpell(me, GetFireworkSpell(me->GetEntry()), true);
293 }
294};
295
296/*####
297# npc_omen
298####*/
299
301{
306
309
313};
314
315struct npc_omen : public ScriptedAI
316{
317 npc_omen(Creature* creature) : ScriptedAI(creature)
318 {
319 me->SetImmuneToPC(true);
320 me->GetMotionMaster()->MovePoint(1, 7549.977f, -2855.137f, 456.9678f);
321 }
322
324
325 void MovementInform(uint32 type, uint32 pointId) override
326 {
327 if (type != POINT_MOTION_TYPE)
328 return;
329
330 if (pointId == 1)
331 {
333 me->SetImmuneToPC(false);
334 if (Player* player = me->SelectNearestPlayer(40.0f))
335 AttackStart(player);
336 }
337 }
338
339 void JustEngagedWith(Unit* /*attacker*/) override
340 {
341 events.Reset();
344 }
345
346 void JustDied(Unit* /*killer*/) override
347 {
349 }
350
351 void SpellHit(WorldObject* /*caster*/, SpellInfo const* spellInfo) override
352 {
353 if (spellInfo->Id == SPELL_ELUNE_CANDLE)
354 {
357
359 }
360 }
361
362 void UpdateAI(uint32 diff) override
363 {
364 if (!UpdateVictim())
365 return;
366
367 events.Update(diff);
368
369 switch (events.ExecuteEvent())
370 {
374 break;
379 break;
380 }
381 }
382};
383
385{
386 npc_giant_spotlight(Creature* creature) : ScriptedAI(creature) { }
387
389
390 void Reset() override
391 {
392 events.Reset();
394 }
395
396 void UpdateAI(uint32 diff) override
397 {
398 events.Update(diff);
399
401 {
403 trap->RemoveFromWorld();
404
406 trap->RemoveFromWorld();
407
408 if (Creature* omen = me->FindNearestCreature(NPC_OMEN, 5.0f, false))
409 omen->DespawnOrUnsummon();
410
412 }
413 }
414};
415
417{
424
425// 26374 - Elune's Candle
427{
428 bool Validate(SpellInfo const* /*spellInfo*/) override
429 {
430 return ValidateSpellInfo(
431 {
437 });
438 }
439
440 void HandleScript(SpellEffIndex /*effIndex*/)
441 {
442 uint32 spellId = 0;
443
444 if (GetHitUnit()->GetEntry() == NPC_OMEN)
445 {
446 switch (urand(0, 3))
447 {
448 case 0:
450 break;
451 case 1:
453 break;
454 case 2:
456 break;
457 case 3:
459 break;
460 }
461 }
462 else
464
465 GetCaster()->CastSpell(GetHitUnit(), spellId, true);
466 }
467
468 void Register() override
469 {
471 }
472};
473
475{
480}
#define M_PI
Definition: Common.h:115
T GetEntry(std::unordered_map< uint32, T > const &map, CriteriaTreeEntry const *tree)
@ DIFFICULTY_NONE
Definition: DBCEnums.h:874
uint8_t uint8
Definition: Define.h:144
uint32_t uint32
Definition: Define.h:142
@ POINT_MOTION_TYPE
@ TEMPSUMMON_CORPSE_TIMED_DESPAWN
Definition: ObjectDefines.h:68
float frand(float min, float max)
Definition: Random.cpp:55
uint32 urand(uint32 min, uint32 max)
Definition: Random.cpp:42
#define RegisterCreatureAI(ai_name)
Definition: ScriptMgr.h:1380
#define RegisterSpellScript(spell_script)
Definition: ScriptMgr.h:1369
GameObject * GetClosestGameObjectWithEntry(WorldObject *source, uint32 entry, float maxSearchRange, bool spawnedOnly=true)
SpellEffIndex
Definition: SharedDefines.h:29
@ EFFECT_0
Definition: SharedDefines.h:30
@ SPELL_EFFECT_DUMMY
@ SPELL_EFFECT_SUMMON_OBJECT_WILD
#define sSpellMgr
Definition: SpellMgr.h:849
#define SpellEffectFn(F, I, N)
Definition: SpellScript.h:842
bool UpdateVictim()
Definition: CreatureAI.cpp:245
Creature *const me
Definition: CreatureAI.h:61
void SetHomePosition(float x, float y, float z, float o)
Definition: Creature.h:371
void SetImmuneToPC(bool apply) override
Definition: Creature.h:170
void DespawnOrUnsummon(Milliseconds timeToDespawn=0s, Seconds forceRespawnTime=0s)
Definition: Creature.cpp:2415
uint32 ExecuteEvent()
Definition: EventMap.cpp:73
void Update(uint32 time)
Definition: EventMap.h:56
void ScheduleEvent(uint32 eventId, Milliseconds time, uint32 group=0, uint8 phase=0)
Definition: EventMap.cpp:36
void RescheduleEvent(uint32 eventId, Milliseconds time, uint32 group=0, uint8 phase=0)
Definition: EventMap.cpp:52
void Reset()
Definition: EventMap.cpp:21
void MovePoint(uint32 id, Position const &pos, bool generatePath=true, Optional< float > finalOrient={}, Optional< float > speed={}, MovementWalkRunSpeedSelectionMode speedSelectionMode=MovementWalkRunSpeedSelectionMode::Default, Optional< float > closeEnoughDistance={})
uint32 GetEntry() const
Definition: Object.h:161
SpellEffectName Effect
Definition: SpellInfo.h:218
uint32 const Id
Definition: SpellInfo.h:325
SpellEffectInfo const & GetEffect(SpellEffIndex index) const
Definition: SpellInfo.h:577
static bool ValidateSpellInfo(std::initializer_list< uint32 > spellIds)
Definition: SpellScript.h:162
Unit * GetCaster() const
Unit * GetHitUnit() const
HookList< EffectHandler > OnEffectHitTarget
Definition: SpellScript.h:840
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 DoCast(uint32 spellId)
Definition: UnitAI.cpp:89
Definition: Unit.h:627
MotionMaster * GetMotionMaster()
Definition: Unit.h:1652
bool HasAura(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, ObjectGuid itemCasterGUID=ObjectGuid::Empty, uint32 reqEffMask=0) const
Definition: Unit.cpp:4664
void RemoveAurasDueToSpell(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, uint32 reqEffMask=0, AuraRemoveMode removeMode=AURA_REMOVE_BY_DEFAULT)
Definition: Unit.cpp:3831
Player * SelectNearestPlayer(float range) const
Definition: Object.cpp:2210
GameObject * FindNearestGameObject(uint32 entry, float range, bool spawnedOnly=true) const
Definition: Object.cpp:2170
SpellCastResult CastSpell(CastSpellTargetArg const &targets, uint32 spellId, CastSpellExtraArgs const &args={ })
Definition: Object.cpp:2896
TempSummon * SummonCreature(uint32 entry, Position const &pos, TempSummonType despawnType=TEMPSUMMON_MANUAL_DESPAWN, Milliseconds despawnTime=0s, uint32 vehId=0, uint32 spellId=0, ObjectGuid privateObjectOwner=ObjectGuid::Empty)
Definition: Object.cpp:2025
float GetDistance2d(WorldObject const *obj) const
Definition: Object.cpp:1096
GameObject * SummonGameObject(uint32 entry, Position const &pos, QuaternionData const &rot, Seconds respawnTime, GOSummonType summonType=GO_SUMMON_TIMED_OR_CORPSE_DESPAWN)
Definition: Object.cpp:2065
Creature * FindNearestCreature(uint32 entry, float range, bool alive=true) const
Definition: Object.cpp:2148
uint32 GetZoneId() const
Definition: Object.h:545
bool Validate(SpellInfo const *) override
Fireworks
@ SPELL_ROCKET_BIG_RED
@ ANIM_GO_LAUNCH_FIREWORK
@ NPC_FIREWORK_BIG_YELLOW
@ NPC_FIREWORK_BIG_WHITE
@ NPC_FIREWORK_BIG_GREEN
@ NPC_FIREWORK_GREEN
@ NPC_CLUSTER_RED
@ NPC_FIREWORK_BIG_RED
@ ZONE_MOONGLADE
@ SPELL_ROCKET_YELLOW
@ GO_CLUSTER_LAUNCHER_1
@ GO_CLUSTER_LAUNCHER_3
@ NPC_CLUSTER_WHITE
@ GO_FIREWORK_LAUNCHER_2
@ GO_FIREWORK_LAUNCHER_1
@ NPC_FIREWORK_BIG_PURPLE
@ NPC_CLUSTER_BIG_YELLOW
@ NPC_CLUSTER_PURPLE
@ NPC_OMEN
@ NPC_CLUSTER_YELLOW
@ NPC_FIREWORK_WHITE
@ GO_CLUSTER_LAUNCHER_2
@ NPC_CLUSTER_BIG_WHITE
@ NPC_CLUSTER_GREEN
@ NPC_FIREWORK_RED
@ NPC_FIREWORK_PURPLE
@ NPC_FIREWORK_BIG_BLUE
@ NPC_CLUSTER_BIG_PURPLE
@ SPELL_ROCKET_BIG_WHITE
@ SPELL_ROCKET_RED
@ SPELL_LUNAR_FORTUNE
@ NPC_FIREWORK_YELLOW
@ GO_CLUSTER_LAUNCHER_4
@ NPC_CLUSTER_BIG_GREEN
@ SPELL_ROCKET_PURPLE
@ SPELL_ROCKET_BLUE
@ NPC_CLUSTER_BLUE
@ SPELL_ROCKET_BIG_YELLOW
@ NPC_MINION_OF_OMEN
@ SPELL_ROCKET_WHITE
@ SPELL_ROCKET_BIG_BLUE
@ NPC_FIREWORK_BLUE
@ SPELL_ROCKET_GREEN
@ SPELL_ROCKET_BIG_GREEN
@ NPC_CLUSTER_BIG_BLUE
@ NPC_CLUSTER_BIG_RED
@ GO_FIREWORK_LAUNCHER_3
@ SPELL_ROCKET_BIG_PURPLE
@ NPC_CLUSTER_ELUNE
void AddSC_event_lunar_festival()
Position omenSummonPos
@ SPELL_OMEN_SUMMON_SPOTLIGHT
@ SPELL_ELUNE_CANDLE
@ EVENT_DESPAWN
@ SPELL_OMEN_CLEAVE
@ GO_ELUNE_TRAP_1
@ EVENT_CAST_STARFALL
@ GO_ELUNE_TRAP_2
@ SPELL_OMEN_STARFALL
@ EVENT_CAST_CLEAVE
EluneCandle
@ SPELL_ELUNE_CANDLE_OMEN_HAND_R
@ SPELL_ELUNE_CANDLE_NORMAL
@ SPELL_ELUNE_CANDLE_OMEN_HEAD
@ SPELL_ELUNE_CANDLE_OMEN_CHEST
@ SPELL_ELUNE_CANDLE_OMEN_HAND_L
constexpr void SetOrientation(float orientation)
Definition: Position.h:71
constexpr float GetPositionX() const
Definition: Position.h:76
constexpr float GetPositionY() const
Definition: Position.h:77
constexpr void GetPosition(float &x, float &y) const
Definition: Position.h:81
constexpr float GetOrientation() const
Definition: Position.h:79
constexpr float GetPositionZ() const
Definition: Position.h:78
static QuaternionData fromEulerAnglesZYX(float Z, float Y, float X)
Definition: GameObject.cpp:118
void AttackStart(Unit *) override
== Triggered Actions Requested ==================
GameObject * FindNearestLauncher()
uint32 GetFireworkGameObjectId()
uint32 GetFireworkSpell(uint32 entry)
void Reset() override
npc_firework(Creature *creature)
npc_giant_spotlight(Creature *creature)
void Reset() override
void UpdateAI(uint32 diff) override
void JustDied(Unit *) override
void SpellHit(WorldObject *, SpellInfo const *spellInfo) override
void MovementInform(uint32 type, uint32 pointId) override
void JustEngagedWith(Unit *) override
npc_omen(Creature *creature)
EventMap events
void UpdateAI(uint32 diff) override