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
35/*******************************************************
36 * npc_mageguard_dalaran
37 *******************************************************/
38
49
50enum NPCs // All outdoor guards are within 35.0f of these NPCs
51{
56};
57
59{
60 npc_mageguard_dalaran(Creature* creature) : ScriptedAI(creature) { }
61
62 void Reset() override { }
63
64 void JustEngagedWith(Unit* /*who*/) override { }
65
66 void AttackStart(Unit* /*who*/) override { }
67
68 void MoveInLineOfSight(Unit* who) override
69 {
70 if (!who || !who->IsInWorld() || who->GetZoneId() != 4395)
71 return;
72
73 if (!me->IsWithinDist(who, 65.0f, false))
74 return;
75
77
78 if (!player || player->IsGameMaster() || player->IsBeingTeleported() ||
79 // 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
82 // If player has already been teleported, don't try to teleport again
84 return;
85
86 switch (me->GetEntry())
87 {
89 if (player->GetTeam() == HORDE) // Horde unit found in Alliance area
90 {
92 {
93 if (me->isInBackInMap(who, 12.0f)) // In my line of sight, "outdoors", and behind me
94 DoCast(who, SPELL_TRESPASSER_A); // Teleport the Horde unit out
95 }
96 else // In my line of sight, and "indoors"
97 DoCast(who, SPELL_TRESPASSER_A); // Teleport the Horde unit out
98 }
99 break;
101 if (player->GetTeam() == ALLIANCE) // Alliance unit found in Horde area
102 {
104 {
105 if (me->isInBackInMap(who, 12.0f)) // In my line of sight, "outdoors", and behind me
106 DoCast(who, SPELL_TRESPASSER_H); // Teleport the Alliance unit out
107 }
108 else // In my line of sight, and "indoors"
109 DoCast(who, SPELL_TRESPASSER_H); // Teleport the Alliance unit out
110 }
111 break;
112 }
113 return;
114 }
115
116 void UpdateAI(uint32 /*diff*/) override { }
117};
118
140
142{
144 {
145 me->setActive(true);
146 }
147
148 void Reset() override
149 {
151 me->SetVisible(false);
153 }
154
155 void GetPlayersInDalaran(std::vector<Player*>& playerList) const
156 {
157 Map::PlayerList const& players = me->GetMap()->GetPlayers();
158 for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
159 if (Player* player = itr->GetSource()->ToPlayer())
160 if (player->GetZoneId() == ZONE_DALARAN && !player->IsFlying() && !player->IsMounted() && !player->IsGameMaster())
161 playerList.push_back(player);
162 }
163
164 static Player* SelectTargetInDalaran(std::vector<Player*>& PlayerInDalaranList)
165 {
166 if (PlayerInDalaranList.empty())
167 return nullptr;
168
169 return Trinity::Containers::SelectRandomContainerElement(PlayerInDalaranList);
170 }
171
172 void SendMailToPlayer(Player* player) const
173 {
174 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
177 CharacterDatabase.CommitTransaction(trans);
178 }
179
180 void UpdateAI(uint32 diff) override
181 {
182 events.Update(diff);
183
184 while (uint32 eventId = events.ExecuteEvent())
185 {
186 switch (eventId)
187 {
189 {
190 std::vector<Player*> PlayerInDalaranList;
191 GetPlayersInDalaran(PlayerInDalaranList);
192
193 // Increases chance of event based on player count in Dalaran (100 players or more = 100% else player count%)
194 if (PlayerInDalaranList.empty() || urand(1, 100) > PlayerInDalaranList.size())
196
197 me->SetVisible(true);
199 if (Player* player = SelectTargetInDalaran(PlayerInDalaranList))
200 {
201 playerGuid = player->GetGUID();
202 Position pos = player->GetPosition();
203 float dist = frand(10.0f, 30.0f);
204 float angle = frand(0.0f, 1.0f) * M_PI * 2.0f;
205 player->MovePositionToFirstCollision(pos, dist, angle);
207 }
209 break;
210 }
211 case EVENT_LAUGH_1:
214 break;
215 case EVENT_WANDER:
218 break;
219 case EVENT_PAUSE:
222 break;
223 case EVENT_CAST:
224 if (Player* player = me->GetMap()->GetPlayer(playerGuid))
225 {
226 DoCast(player, SPELL_MANABONKED);
227 SendMailToPlayer(player);
228 }
229 else
231
233 break;
234 case EVENT_LAUGH_2:
237 break;
238 case EVENT_BLINK:
241 break;
242 case EVENT_DESPAWN:
244 break;
245 default:
246 break;
247 }
248 }
249 }
250
251private:
254};
255
@ MINUTE
Definition Common.h:32
#define M_PI
Definition Common.h:118
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
int16_t int16
Definition Define.h:151
uint64_t uint64
Definition Define.h:153
uint32_t uint32
Definition Define.h:154
std::chrono::seconds Seconds
Seconds shorthand typedef.
Definition Duration.h:28
@ MAIL_CHECK_MASK_NONE
Definition Mail.h:52
@ MAIL_CREATURE
Definition Mail.h:41
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:1392
Creature * GetClosestCreatureWithEntry(WorldObject *source, uint32 entry, float maxSearchRange, bool alive=true)
@ EMOTE_ONESHOT_LAUGH_NO_SHEATHE
@ ALLIANCE
@ HORDE
bool IsInWorld() const
Definition BaseEntity.h:158
Creature *const me
Definition CreatureAI.h:63
uint32 ExecuteEvent()
Definition EventMap.cpp:77
void Update(uint32 time)
Definition EventMap.h:61
void ScheduleEvent(uint32 eventId, Milliseconds time, uint32 group=0, uint8 phase=0)
Definition EventMap.cpp:40
void push_back(LinkedListElement *pElem)
Definition LinkedList.h:114
void SendMailTo(CharacterDatabaseTransaction trans, MailReceiver const &receiver, MailSender const &sender, MailCheckMask checked=MAIL_CHECK_MASK_NONE, uint32 deliver_delay=0)
Definition Mail.cpp:195
Player * GetPlayer(ObjectGuid const &guid)
Definition Map.cpp:3532
PlayerList const & GetPlayers() const
Definition Map.h:403
void MoveRandom(float wanderDistance=0.0f, Optional< Milliseconds > duration={}, Optional< float > speed={}, MovementWalkRunSpeedSelectionMode speedSelectionMode=MovementWalkRunSpeedSelectionMode::ForceWalk, MovementSlot slot=MOTION_SLOT_DEFAULT, Scripting::v2::ActionResultSetter< MovementStopReason > &&scriptResult={})
Player * ToPlayer()
Definition Object.h:126
uint32 GetEntry() const
Definition Object.h:89
bool IsGameMaster() const
Definition Player.h:1309
bool IsBeingTeleported() const
Definition Player.h:2402
Team GetTeam() const
Definition Player.h:2423
iterator end()
Definition RefManager.h:36
iterator begin()
Definition RefManager.h:35
SpellCastResult DoCastSelf(uint32 spellId, CastSpellExtraArgs const &args={})
Definition UnitAI.h:160
SpellCastResult DoCast(uint32 spellId)
Definition UnitAI.cpp:89
Definition Unit.h:635
void SetVisible(bool x)
Definition Unit.cpp:8768
bool isInBackInMap(Unit const *target, float distance, float arc=float(M_PI)) const
Definition Unit.cpp:3305
MotionMaster * GetMotionMaster()
Definition Unit.h:1723
void NearTeleportTo(TeleportLocation const &target, bool casting=false)
Definition Unit.cpp:12958
bool HasAura(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, ObjectGuid itemCasterGUID=ObjectGuid::Empty, uint32 reqEffMask=0) const
Definition Unit.cpp:4804
void HandleEmoteCommand(Emote emoteId, Player *target=nullptr, Trinity::IteratorPair< int32 const * > spellVisualKitIds={}, int32 sequenceVariation=0)
Definition Unit.cpp:1657
Map * GetMap() const
Definition Object.h:411
void setActive(bool isActiveObject)
Definition Object.cpp:276
void AddObjectToRemoveList()
Definition Object.cpp:1174
Player * GetCharmerOrOwnerPlayerOrPlayerItself() const
Definition Object.cpp:1621
uint32 GetZoneId() const
Definition Object.h:332
bool IsWithinDist(WorldObject const *obj, float dist2compare, bool is3D=true, bool incOwnRadius=true, bool incTargetRadius=true) const
Definition Object.cpp:496
auto SelectRandomContainerElement(C const &container) -> std::add_const_t< decltype(*std::ranges::begin(container))> &
Definition Containers.h:110
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 GetOrientation() const
Definition Position.h:90
constexpr float GetPositionZ() const
Definition Position.h:89
void Reset() override
npc_mageguard_dalaran(Creature *creature)
void JustEngagedWith(Unit *) override
void UpdateAI(uint32) override
void AttackStart(Unit *) override
== Triggered Actions Requested ==================
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
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