TrinityCore
Loading...
Searching...
No Matches
areatrigger_scripts.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 "ScriptMgr.h"
19#include "AreaTrigger.h"
20#include "AreaTriggerAI.h"
21#include "DB2Structure.h"
22#include "GameObject.h"
23#include "GameTime.h"
24#include "MotionMaster.h"
25#include "ObjectAccessor.h"
26#include "PathGenerator.h"
27#include "ScriptedCreature.h"
28#include "Spell.h"
29#include "SpellInfo.h"
30#include "Player.h"
31#include "TemporarySummon.h"
32#include "World.h"
33#include "ZoneScript.h"
34
35/*######
36## at_coilfang_waterfall
37######*/
38
43
45{
46 public:
48
49 bool OnTrigger(Player* player, AreaTriggerEntry const* /*areaTrigger*/) override
50 {
52 if (go->getLootState() == GO_READY)
53 go->UseDoorOrButton();
54
55 return false;
56 }
57};
58
59/*#####
60## at_legion_teleporter
61#####*/
62
71
73{
74 public:
76
77 bool OnTrigger(Player* player, AreaTriggerEntry const* /*areaTrigger*/) override
78 {
79 if (player->IsAlive() && !player->IsInCombat())
80 {
82 {
83 player->CastSpell(player, SPELL_TELE_A_TO, false);
84 return true;
85 }
86
87 if (player->GetTeam() == HORDE && player->GetQuestRewardStatus(QUEST_GAINING_ACCESS_H))
88 {
89 player->CastSpell(player, SPELL_TELE_H_TO, false);
90 return true;
91 }
92
93 return false;
94 }
95 return false;
96 }
97};
98
99/*######
100## at_scent_larkorwi
101######*/
102
108
110{
111 public:
113
114 bool OnTrigger(Player* player, AreaTriggerEntry const* /*areaTrigger*/) override
115 {
117 {
118 if (!player->FindNearestCreature(NPC_LARKORWI_MATE, 15))
120 }
121
122 return false;
123 }
124};
125
126/*######
127## at_sholazar_waygate
128######*/
129
142
144{
145 public:
147
148 bool OnTrigger(Player* player, AreaTriggerEntry const* trigger) override
149 {
150 if (!player->isDead() && (player->GetQuestStatus(QUEST_MEETING_A_GREAT_ONE) != QUEST_STATUS_NONE ||
152 {
153 switch (trigger->ID)
154 {
155 case AT_SHOLAZAR:
156 player->CastSpell(player, SPELL_SHOLAZAR_TO_UNGORO_TELEPORT, true);
157 break;
158
159 case AT_UNGORO:
160 player->CastSpell(player, SPELL_UNGORO_TO_SHOLAZAR_TELEPORT, true);
161 break;
162 }
163 }
164
165 return false;
166 }
167};
168
169/*######
170## at_nats_landing
171######*/
172
179
181{
182 public:
184
185 bool OnTrigger(Player* player, AreaTriggerEntry const* /*areaTrigger*/) override
186 {
187 if (!player->IsAlive() || !player->HasAura(SPELL_FISH_PASTE))
188 return false;
189
191 {
192 if (!player->FindNearestCreature(NPC_LURKING_SHARK, 20.0f))
193 {
194 if (Creature* shark = player->SummonCreature(NPC_LURKING_SHARK, -4246.243f, -3922.356f, -7.488f, 5.0f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 100s))
195 shark->AI()->AttackStart(player);
196
197 return false;
198 }
199 }
200 return true;
201 }
202};
203
204/*######
205## at_brewfest
206######*/
207
220
222{
223 public:
225 {
226 // Initialize for cooldown
228 }
229
230 bool OnTrigger(Player* player, AreaTriggerEntry const* trigger) override
231 {
232 uint32 triggerId = trigger->ID;
233 // Second trigger happened too early after first, skip for now
235 return false;
236
237 switch (triggerId)
238 {
240 if (Creature* tapper = player->FindNearestCreature(NPC_TAPPER_SWINDLEKEG, 20.0f))
241 tapper->AI()->Talk(SAY_WELCOME, player);
242 break;
244 if (Creature* ipfelkofer = player->FindNearestCreature(NPC_IPFELKOFER_IRONKEG, 20.0f))
245 ipfelkofer->AI()->Talk(SAY_WELCOME, player);
246 break;
247 default:
248 break;
249 }
250
252 return false;
253 }
254
255 private:
256 std::map<uint32, time_t> _triggerTimes;
257};
258
259/*######
260## at_area_52_entrance
261######*/
262
274
276{
277 public:
282
283 bool OnTrigger(Player* player, AreaTriggerEntry const* trigger) override
284 {
285 float x = 0.0f, y = 0.0f, z = 0.0f;
286
287 if (!player->IsAlive())
288 return false;
289
290 uint32 triggerId = trigger->ID;
292 return false;
293
294 switch (triggerId)
295 {
296 case AT_AREA_52_EAST:
297 x = 3044.176f;
298 y = 3610.692f;
299 z = 143.61f;
300 break;
301 case AT_AREA_52_NORTH:
302 x = 3114.87f;
303 y = 3687.619f;
304 z = 143.62f;
305 break;
306 case AT_AREA_52_WEST:
307 x = 3017.79f;
308 y = 3746.806f;
309 z = 144.27f;
310 break;
311 case AT_AREA_52_SOUTH:
312 x = 2950.63f;
313 y = 3719.905f;
314 z = 143.33f;
315 break;
316 }
317
318 player->SummonCreature(NPC_SPOTLIGHT, x, y, z, 0.0f, TEMPSUMMON_TIMED_DESPAWN, 5s);
319 player->AddAura(SPELL_A52_NEURALYZER, player);
321 return false;
322 }
323
324 private:
325 std::map<uint32, time_t> _triggerTimes;
326};
327
328/*######
329 ## at_frostgrips_hollow
330 ######*/
331
342
343Position const stormforgedMonitorPosition = {6963.95f, 45.65f, 818.71f, 4.948f};
344Position const stormforgedEradictorPosition = {6983.18f, 7.15f, 806.33f, 2.228f};
345
347{
348public:
354
355 bool OnTrigger(Player* player, AreaTriggerEntry const* /*areaTrigger*/) override
356 {
358 return false;
359
360 Creature* stormforgedMonitor = ObjectAccessor::GetCreature(*player, stormforgedMonitorGUID);
361 if (stormforgedMonitor)
362 return false;
363
364 Creature* stormforgedEradictor = ObjectAccessor::GetCreature(*player, stormforgedEradictorGUID);
365 if (stormforgedEradictor)
366 return false;
367
369 if (stormforgedMonitor)
370 {
371 stormforgedMonitorGUID = stormforgedMonitor->GetGUID();
372 stormforgedMonitor->SetWalk(false);
374 stormforgedMonitor->AddUnitState(UNIT_STATE_IGNORE_PATHFINDING);
375 stormforgedMonitor->GetMotionMaster()->MovePath((NPC_STORMFORGED_MONITOR * 100) << 3, false);
376 }
377
379 if (stormforgedEradictor)
380 {
381 stormforgedEradictorGUID = stormforgedEradictor->GetGUID();
382 stormforgedEradictor->GetMotionMaster()->MovePath((NPC_STORMFORGED_ERADICTOR * 100) << 3, false);
383 }
384
385 return true;
386 }
387
388private:
391};
392
394{
401
403
404 void OnUnitEnter(Unit* unit) override
405 {
406 Player* player = unit->ToPlayer();
407 if (!player)
408 return;
409
412 }
413};
414
416{
417 if (GameObject* buffObject = player->FindNearestGameObjectWithOptions(4.0f, { .StringId = "bg_buff_object" }))
418 {
419 buffObject->ActivateObject(GameObjectActions::Disturb, 0, player);
420 buffObject->DespawnOrUnsummon();
421 }
422}
423
425{
427
428 void OnUnitEnter(Unit* unit) override
429 {
430 if (!unit->IsPlayer())
431 return;
432
434 }
435};
436
438{
439public:
441
442 bool OnTrigger(Player* player, AreaTriggerEntry const* /*areaTrigger*/) override
443 {
444 HandleBuffAreaTrigger(player);
445 return true;
446 }
447};
448
450{
452
453 void OnUnitEnter(Unit* unit) override
454 {
455 if (!unit->IsPlayer())
456 return;
457
458 Player* player = unit->ToPlayer();
459 if (ZoneScript* zoneScript = at->GetZoneScript())
460 if (zoneScript->CanCaptureFlag(at, player))
461 zoneScript->OnCaptureFlag(at, player);
462 }
463};
464
465// 18235 - Void Orb
467{
468 at_void_orb_harbinger(AreaTrigger* areatrigger) : AreaTriggerAI(areatrigger) { }
469
471 {
473 };
474
475 void OnInitialize() override
476 {
477 if (Unit* caster = at->GetCaster())
478 {
479 at->SetOrientation(caster->GetOrientation());
480
481 Position destPos = caster->GetPosition();
482 at->MovePositionToFirstCollision(destPos, 35.0f, 0.0f);
483
484 PathGenerator path(at);
485 path.CalculatePath(destPos.GetPositionX(), destPos.GetPositionY(), destPos.GetPositionZ(), false);
486
487 at->InitSplines(path.GetPath());
488 }
489 }
490
491 void OnDestinationReached() override
492 {
493 at->Remove();
494 }
495
496 void OnUnitEnter(Unit* unit) override
497 {
498 Unit* caster = at->GetCaster();
499 if (!caster)
500 return;
501
502 if (caster->IsFriendlyTo(unit))
503 return;
504
505 caster->CastSpell(unit, SPELL_VOID_ORB_DAMAGE);
506 }
507};
508
509// 18242 - Abyssal Portal
511{
513
515 {
517 };
518
519 void OnCreate(Spell const* creatingSpell) override
520 {
521 if (Unit* caster = at->GetCaster())
523
524 _scheduler.Schedule(500ms, [this](TaskContext& task)
525 {
526 if (Unit* caster = at->GetCaster())
527 caster->CastSpell(at->GetRandomNearPosition(3.0f), SPELL_ABYSSAL_PORTAL_SUMMON, true);
528
530 if (_remainingSummons > 0)
531 task.Repeat(1s);
532 });
533 }
534
535 void OnUpdate(uint32 diff) override
536 {
537 _scheduler.Update(diff);
538 }
539
540private:
543};
544
uint8_t uint8
Definition Define.h:156
uint32_t uint32
Definition Define.h:154
@ GO_READY
Definition GameObject.h:157
@ TEMPSUMMON_TIMED_DESPAWN
@ TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT
@ QUEST_STATUS_REWARDED
Definition QuestDef.h:153
@ QUEST_STATUS_INCOMPLETE
Definition QuestDef.h:150
@ QUEST_STATUS_NONE
Definition QuestDef.h:147
#define RegisterAreaTriggerAI(ai_name)
Definition ScriptMgr.h:1428
GameObject * GetClosestGameObjectWithEntry(WorldObject *source, uint32 entry, float maxSearchRange, bool spawnedOnly=true)
@ EFFECT_0
@ ALLIANCE
@ HORDE
@ UNIT_STATE_IGNORE_PATHFINDING
Definition Unit.h:289
void HandleBuffAreaTrigger(Player *player)
@ QUEST_MEETING_A_GREAT_ONE
@ QUEST_THE_MAKERS_OVERLOOK
@ SPELL_UNGORO_TO_SHOLAZAR_TELEPORT
@ QUEST_THE_MAKERS_PERCH
@ SPELL_SHOLAZAR_TO_UNGORO_TELEPORT
@ SPELL_FISH_PASTE
@ QUEST_NATS_BARGAIN
@ NPC_LURKING_SHARK
Position const stormforgedEradictorPosition
@ QUEST_SCENT_OF_LARKORWI
@ NPC_LARKORWI_MATE
@ AT_AREA_52_EAST
@ AT_AREA_52_WEST
@ AT_AREA_52_NORTH
@ SUMMON_COOLDOWN
@ AT_AREA_52_SOUTH
@ SPELL_A52_NEURALYZER
@ GO_COILFANG_WATERFALL
void AddSC_areatrigger_scripts()
@ NPC_IPFELKOFER_IRONKEG
@ AT_BREWFEST_DUROTAR
@ AREATRIGGER_TALK_COOLDOWN
@ AT_BREWFEST_DUN_MOROGH
@ NPC_TAPPER_SWINDLEKEG
Position const stormforgedMonitorPosition
@ SPELL_TELE_H_TO
@ SPELL_TELE_A_TO
@ QUEST_GAINING_ACCESS_A
@ QUEST_GAINING_ACCESS_H
@ NPC_STORMFORGED_ERADICTOR
@ QUEST_THE_LONESOME_WATCHER
@ NPC_STORMFORGED_MONITOR
AreaTrigger *const at
std::map< uint32, time_t > _triggerTimes
bool OnTrigger(Player *player, AreaTriggerEntry const *trigger) override
bool OnTrigger(Player *player, AreaTriggerEntry const *) override
bool OnTrigger(Player *player, AreaTriggerEntry const *trigger) override
std::map< uint32, time_t > _triggerTimes
bool OnTrigger(Player *player, AreaTriggerEntry const *) override
bool OnTrigger(Player *player, AreaTriggerEntry const *) override
bool OnTrigger(Player *player, AreaTriggerEntry const *) override
bool OnTrigger(Player *player, AreaTriggerEntry const *) override
bool OnTrigger(Player *player, AreaTriggerEntry const *) override
bool OnTrigger(Player *player, AreaTriggerEntry const *trigger) override
void InitSplines(std::vector< G3D::Vector3 > const &splinePoints, Optional< float > overrideSpeed={}, Optional< bool > speedIsTimeInSeconds={})
Unit * GetCaster() const
ObjectGuid const & GetGUID() const
Definition BaseEntity.h:163
bool IsPlayer() const
Definition BaseEntity.h:173
void MovePath(uint32 pathId, bool repeatable, Optional< Milliseconds > duration={}, Optional< float > speed={}, MovementWalkRunSpeedSelectionMode speedSelectionMode=MovementWalkRunSpeedSelectionMode::Default, Optional< std::pair< Milliseconds, Milliseconds > > waitTimeRangeAtPathEnd={}, Optional< float > wanderDistanceAtPathEnds={}, Optional< bool > followPathBackwardsFromEndToStart={}, Optional< bool > exactSplinePath={}, bool generatePath=true, Optional< MovementFadeObject > fadeObject={}, Scripting::v2::ActionResultSetter< MovementStopReason > &&scriptResult={})
void Clear()
Definition ObjectGuid.h:329
Player * ToPlayer()
Definition Object.h:126
Movement::PointsArray const & GetPath() const
bool CalculatePath(float srcX, float srcY, float srcZ, float destX, float destY, float destZ, bool forceDest=false)
void KilledMonsterCredit(uint32 entry, ObjectGuid guid=ObjectGuid::Empty)
Definition Player.cpp:16679
bool GetQuestRewardStatus(uint32 quest_id) const
Definition Player.cpp:15945
QuestStatus GetQuestStatus(uint32 quest_id) const
Definition Player.cpp:15962
Team GetTeam() const
Definition Player.h:2423
int32 CalcValueAsInt(WorldObject const *caster=nullptr, SpellEffectValue const *basePoints=nullptr, Unit const *target=nullptr, float *variance=nullptr, uint32 castItemId=0, int32 itemLevel=-1) const
SpellEffectInfo const & GetEffect(SpellEffIndex index) const
Definition SpellInfo.h:588
Definition Spell.h:277
SpellInfo const * GetSpellInfo() const
Definition Spell.h:702
TaskContext & Repeat(TaskScheduler::duration_t duration)
TaskScheduler & Schedule(duration_t time, task_handler_t task)
TaskScheduler & Update()
Update the scheduler to the current time.
Definition Unit.h:635
MotionMaster * GetMotionMaster()
Definition Unit.h:1723
Aura * AddAura(uint32 spellId, Unit *target)
Definition Unit.cpp:12249
bool IsAlive() const
Definition Unit.h:1185
void AddUnitState(uint32 f)
Definition Unit.h:742
bool SetWalk(bool enable)
Definition Unit.cpp:13343
bool HasAura(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, ObjectGuid itemCasterGUID=ObjectGuid::Empty, uint32 reqEffMask=0) const
Definition Unit.cpp:4804
bool IsInCombat() const
Definition Unit.h:1058
bool isDead() const
Definition Unit.h:1187
SpellCastResult CastSpell(CastSpellTargetArg const &targets, uint32 spellId, CastSpellExtraArgs const &args={ })
Definition Object.cpp:2217
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:1398
ZoneScript * GetZoneScript() const
Definition Object.h:417
Position GetRandomNearPosition(float radius)
Definition Object.cpp:2769
GameObject * FindNearestGameObjectWithOptions(float range, FindGameObjectOptions const &options) const
Definition Object.cpp:1548
Creature * FindNearestCreature(uint32 entry, float range, bool alive=true) const
Definition Object.cpp:1517
void MovePositionToFirstCollision(Position &pos, float dist, float angle) const
Definition Object.cpp:2828
bool IsFriendlyTo(WorldObject const *target) const
Definition Object.cpp:2186
time_t GetGameTime()
Definition GameTime.cpp:52
TC_GAME_API Creature * GetCreature(WorldObject const &u, ObjectGuid const &guid)
constexpr void SetOrientation(float orientation)
Definition Position.h:82
constexpr float GetPositionX() const
Definition Position.h:87
constexpr float GetPositionY() const
Definition Position.h:88
constexpr void GetPosition(float &x, float &y) const
Definition Position.h:92
constexpr float GetPositionZ() const
Definition Position.h:89
void OnUnitEnter(Unit *unit) override
areatrigger_action_capture_flag(AreaTrigger *areatrigger)
areatrigger_battleground_buffs(AreaTrigger *areatrigger)
void OnUnitEnter(Unit *unit) override
areatrigger_stormwind_teleport_unit(AreaTrigger *areatrigger)
void OnUpdate(uint32 diff) override
void OnCreate(Spell const *creatingSpell) override
at_abyssal_portal_harbinger(AreaTrigger *areatrigger)
void OnUnitEnter(Unit *unit) override
at_void_orb_harbinger(AreaTrigger *areatrigger)
void OnDestinationReached() override