TrinityCore
Loading...
Searching...
No Matches
zone_dalaran.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/* Script Data Start
19SDName: Dalaran
20SDAuthor: WarHead, MaXiMiUS
21SD%Complete: 99%
22SDComment: For what is 63990+63991? Same function but don't work correct...
23SDCategory: Dalaran
24Script Data End */
25
26#include "ScriptMgr.h"
27#include "Containers.h"
28#include "DatabaseEnv.h"
29#include "Mail.h"
30#include "Map.h"
31#include "MotionMaster.h"
32#include "Player.h"
33#include "ScriptedCreature.h"
34#include "ScriptedGossip.h"
35#include "SpellScript.h"
36#include "WorldSession.h"
37
38/*******************************************************
39 * npc_mageguard_dalaran
40 *******************************************************/
41
52
53enum NPCs // All outdoor guards are within 35.0f of these NPCs
54{
59};
60
62{
63 npc_mageguard_dalaran(Creature* creature) : ScriptedAI(creature) { }
64
65 void Reset() override { }
66
67 void JustEngagedWith(Unit* /*who*/) override { }
68
69 void AttackStart(Unit* /*who*/) override { }
70
71 void MoveInLineOfSight(Unit* who) override
72 {
73 if (!who || !who->IsInWorld() || who->GetZoneId() != 4395)
74 return;
75
76 if (!me->IsWithinDist(who, 65.0f, false))
77 return;
78
80
81 if (!player || player->IsGameMaster() || player->IsBeingTeleported() ||
82 // If player has Disguise aura for quest A Meeting With The Magister or An Audience With The Arcanist, do not teleport it away but let it pass
85 // If player has already been teleported, don't try to teleport again
87 return;
88
89 switch (me->GetEntry())
90 {
92 if (player->GetTeam() == HORDE) // Horde unit found in Alliance area
93 {
95 {
96 if (me->isInBackInMap(who, 12.0f)) // In my line of sight, "outdoors", and behind me
97 DoCast(who, SPELL_TRESPASSER_A); // Teleport the Horde unit out
98 }
99 else // In my line of sight, and "indoors"
100 DoCast(who, SPELL_TRESPASSER_A); // Teleport the Horde unit out
101 }
102 break;
104 if (player->GetTeam() == ALLIANCE) // Alliance unit found in Horde area
105 {
107 {
108 if (me->isInBackInMap(who, 12.0f)) // In my line of sight, "outdoors", and behind me
109 DoCast(who, SPELL_TRESPASSER_H); // Teleport the Alliance unit out
110 }
111 else // In my line of sight, and "indoors"
112 DoCast(who, SPELL_TRESPASSER_H); // Teleport the Alliance unit out
113 }
114 break;
115 }
116 return;
117 }
118
119 void UpdateAI(uint32 /*diff*/) override { }
120};
121
143
145{
147 {
148 me->setActive(true);
149 }
150
151 void Reset() override
152 {
154 me->SetVisible(false);
156 }
157
158 void GetPlayersInDalaran(std::vector<Player*>& playerList) const
159 {
160 Map::PlayerList const& players = me->GetMap()->GetPlayers();
161 for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
162 if (Player* player = itr->GetSource()->ToPlayer())
163 if (player->GetZoneId() == ZONE_DALARAN && !player->IsFlying() && !player->IsMounted() && !player->IsGameMaster())
164 playerList.push_back(player);
165 }
166
167 static Player* SelectTargetInDalaran(std::vector<Player*>& PlayerInDalaranList)
168 {
169 if (PlayerInDalaranList.empty())
170 return nullptr;
171
172 return Trinity::Containers::SelectRandomContainerElement(PlayerInDalaranList);
173 }
174
175 void SendMailToPlayer(Player* player) const
176 {
177 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
180 CharacterDatabase.CommitTransaction(trans);
181 }
182
183 void UpdateAI(uint32 diff) override
184 {
185 events.Update(diff);
186
187 while (uint32 eventId = events.ExecuteEvent())
188 {
189 switch (eventId)
190 {
192 {
193 std::vector<Player*> PlayerInDalaranList;
194 GetPlayersInDalaran(PlayerInDalaranList);
195
196 // Increases chance of event based on player count in Dalaran (100 players or more = 100% else player count%)
197 if (PlayerInDalaranList.empty() || urand(1, 100) > PlayerInDalaranList.size())
199
200 me->SetVisible(true);
202 if (Player* player = SelectTargetInDalaran(PlayerInDalaranList))
203 {
204 playerGuid = player->GetGUID();
205 Position pos = player->GetPosition();
206 float dist = frand(10.0f, 30.0f);
207 float angle = frand(0.0f, 1.0f) * M_PI * 2.0f;
208 player->MovePositionToFirstCollision(pos, dist, angle);
210 }
212 break;
213 }
214 case EVENT_LAUGH_1:
217 break;
218 case EVENT_WANDER:
221 break;
222 case EVENT_PAUSE:
225 break;
226 case EVENT_CAST:
227 if (Player* player = me->GetMap()->GetPlayer(playerGuid))
228 {
229 DoCast(player, SPELL_MANABONKED);
230 SendMailToPlayer(player);
231 }
232 else
234
236 break;
237 case EVENT_LAUGH_2:
240 break;
241 case EVENT_BLINK:
244 break;
245 case EVENT_DESPAWN:
247 break;
248 default:
249 break;
250 }
251 }
252 }
253
254private:
257};
258
263
264// 54620 - Teleport Crystal: Teleport to Dalaran AICast Script
284
289
290// 58622 - Teleport to Lake Wintergrasp
310
@ MINUTE
Definition Common.h:29
#define M_PI
Definition Common.h:72
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
int16_t int16
Definition Define.h:130
uint32_t uint32
Definition Define.h:133
std::chrono::seconds Seconds
Seconds shorthand typedef.
Definition Duration.h:27
@ MAIL_CHECK_MASK_NONE
Definition Mail.h:46
@ MAIL_CREATURE
Definition Mail.h:39
Spells
Definition PlayerAI.cpp:32
float frand(float min, float max)
Definition Random.cpp:55
int32 irand(int32 min, int32 max)
Definition Random.cpp:35
uint32 urand(uint32 min, uint32 max)
Definition Random.cpp:42
#define RegisterCreatureAI(ai_name)
Definition ScriptMgr.h:1139
#define RegisterSpellScript(spell_script)
Definition ScriptMgr.h:1128
Creature * GetClosestCreatureWithEntry(WorldObject *source, uint32 entry, float maxSearchRange, bool alive=true)
SpellEffIndex
@ EFFECT_0
@ SPELL_EFFECT_SCRIPT_EFFECT
@ EMOTE_ONESHOT_LAUGH_NO_SHEATHE
@ ALLIANCE
@ HORDE
#define SpellEffectFn(F, I, N)
Creature *const me
Definition CreatureAI.h:82
void Update(uint32 time)
Definition EventMap.h:67
EventId ExecuteEvent()
Definition EventMap.cpp:73
void ScheduleEvent(EventId eventId, Milliseconds time, GroupIndex group=0u, PhaseIndex phase=0u)
Definition EventMap.cpp:36
void SendMailTo(CharacterDatabaseTransaction trans, MailReceiver const &receiver, MailSender const &sender, MailCheckMask checked=MAIL_CHECK_MASK_NONE, uint32 deliver_delay=0)
Definition Mail.cpp:188
iterator end()
iterator begin()
Player * GetPlayer(ObjectGuid const &guid)
Definition Map.cpp:4387
PlayerList const & GetPlayers() const
Definition Map.h:448
void MoveRandom(float wanderDistance=0.0f)
bool IsInWorld() const
Definition Object.h:73
uint32 GetEntry() const
Definition Object.h:81
static Player * ToPlayer(Object *o)
Definition Object.h:180
uint32 GetTeam() const
Definition Player.h:1832
bool IsGameMaster() const
Definition Player.h:998
bool IsBeingTeleported() const
Definition Player.h:1820
Unit * GetHitUnit() const
HookList< EffectHandler > OnEffectHitTarget
SpellCastResult DoCastSelf(uint32 spellId, CastSpellExtraArgs const &args={})
Definition UnitAI.h:241
SpellCastResult DoCast(uint32 spellId)
Definition UnitAI.cpp:106
Definition Unit.h:769
void SetVisible(bool x)
Definition Unit.cpp:8513
bool isInBackInMap(Unit const *target, float distance, float arc=float(M_PI)) const
Definition Unit.cpp:3149
MotionMaster * GetMotionMaster()
Definition Unit.h:1667
bool HasAura(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, ObjectGuid itemCasterGUID=ObjectGuid::Empty, uint8 reqEffMask=0) const
Definition Unit.cpp:4535
void NearTeleportTo(Position const &pos, bool casting=false)
Definition Unit.cpp:12832
void HandleEmoteCommand(Emote emoteId)
Definition Unit.cpp:1568
Map * GetMap() const
Definition Object.h:449
SpellCastResult CastSpell(CastSpellTargetArg const &targets, uint32 spellId, CastSpellExtraArgs const &args={ })
Definition Object.cpp:2832
void setActive(bool isActiveObject)
Definition Object.cpp:991
void AddObjectToRemoveList()
Definition Object.cpp:1838
Player * GetCharmerOrOwnerPlayerOrPlayerItself() const
Definition Object.cpp:2203
bool IsWithinDist(WorldObject const *obj, float dist2compare, bool is3D=true) const
Definition Object.cpp:1187
uint32 GetZoneId() const
Definition Object.h:373
static bool ValidateSpellInfo(std::initializer_list< uint32 > spellIds)
PrepareSpellScript(spell_dalaran_teleport_to_dalaran)
bool Validate(SpellInfo const *) override
bool Validate(SpellInfo const *) override
PrepareSpellScript(spell_dalaran_teleport_to_lake_wintergrasp)
auto SelectRandomContainerElement(C const &container) -> typename std::add_const< decltype(*std::begin(container))>::type &
Definition Containers.h:108
float GetPositionZ() const
Definition Position.h:81
float GetOrientation() const
Definition Position.h:82
float GetPositionX() const
Definition Position.h:79
void GetPosition(float &x, float &y) const
Definition Position.h:84
float GetPositionY() const
Definition Position.h:80
void Reset() override
npc_mageguard_dalaran(Creature *creature)
void JustEngagedWith(Unit *) override
void UpdateAI(uint32) override
void AttackStart(Unit *) override
void MoveInLineOfSight(Unit *who) override
void SendMailToPlayer(Player *player) const
static Player * SelectTargetInDalaran(std::vector< Player * > &PlayerInDalaranList)
void Reset() override
void GetPlayersInDalaran(std::vector< Player * > &playerList) const
npc_minigob_manabonk(Creature *creature)
void UpdateAI(uint32 diff) override
@ SPELL_SUNREAVER_DISGUISE_MALE
@ SPELL_SILVER_COVENANT_DISGUISE_FEMALE
@ SPELL_TRESPASSER_H
@ SPELL_SILVER_COVENANT_DISGUISE_MALE
@ SPELL_TRESPASSER_A
@ SPELL_SUNREAVER_DISGUISE_FEMALE
void AddSC_dalaran()
@ NPC_SWEETBERRY_H
@ NPC_SILVER_COVENANT_GUARDIAN_MAGE
@ NPC_SUNREAVER_GUARDIAN_MAGE
@ NPC_APPLEBOUGH_A
TeleportToDalaran
@ SPELL_TELEPORT_TO_DALARAN
TeleportToLakeWintergrasp
@ SPELL_TELEPORT_TO_LAKE_WINTERGRASP
MinigobData
@ EVENT_BLINK
@ MAIL_DELIVER_DELAY_MIN
@ SPELL_MANABONKED
@ MAIL_DELIVER_DELAY_MAX
@ ZONE_DALARAN
@ EVENT_DESPAWN
@ EVENT_PAUSE
@ EVENT_LAUGH_2
@ MAIL_MINIGOB_ENTRY
@ EVENT_SELECT_TARGET
@ EVENT_LAUGH_1
@ SPELL_TELEPORT_VISUAL
@ EVENT_WANDER
@ EVENT_CAST
@ SPELL_IMPROVED_BLINK