TrinityCore
Loading...
Searching...
No Matches
ScriptMgr.h
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#ifndef SC_SCRIPTMGR_H
19#define SC_SCRIPTMGR_H
20
21#include "Common.h"
22#include "ObjectGuid.h"
23#include "Tuples.h"
24#include "Types.h"
25#include <memory>
26#include <vector>
27
28class AccountMgr;
30class Aura;
31class AuraScript;
32class Battlefield;
33class Battleground;
34class BattlegroundMap;
35class Channel;
36class Creature;
37class CreatureAI;
38class DynamicObject;
39class GameObject;
40class GameObjectAI;
41class Guild;
42class GridMap;
43class Group;
44class InstanceMap;
45class InstanceScript;
46class Item;
47class Map;
48class ModuleReference;
49class OutdoorPvP;
50class Player;
51class Quest;
52class ScriptMgr;
53class Spell;
54class SpellInfo;
55class SpellScript;
57class Transport;
58class Unit;
59class Vehicle;
60class Weather;
61class WorldPacket;
62class WorldSocket;
63class WorldObject;
64class WorldSession;
65
66struct AreaTriggerEntry;
67struct AuctionEntry;
69struct Condition;
70struct CreatureTemplate;
71struct CreatureData;
72struct ItemTemplate;
73struct MapEntry;
74struct Position;
75
76namespace Trinity::ChatCommands { struct ChatCommandBuilder; }
77
79enum ContentLevels : uint8;
80enum Difficulty : uint8;
82enum Emote : uint32;
83enum QuestStatus : uint8;
84enum RemoveMethod : uint8;
86enum ShutdownMask : uint32;
87enum SpellEffIndex : uint8;
88enum WeatherState : uint32;
89enum XPColorChar : uint8;
90
91#define VISIBLE_RANGE 166.0f //MAX visible range (size of grid)
92
93/*
94 @todo Add more script type classes.
95
96 MailScript
97 SessionScript
98 CollisionScript
99 ArenaTeamScript
100
101*/
102
103/*
104 Standard procedure when adding new script type classes:
105
106 First of all, define the actual class, and have it inherit from ScriptObject, like so:
107
108 class MyScriptType : public ScriptObject
109 {
110 uint32 _someId;
111
112 private:
113
114 void RegisterSelf();
115
116 protected:
117
118 MyScriptType(char const* name, uint32 someId)
119 : ScriptObject(name), _someId(someId)
120 {
121 ScriptRegistry<MyScriptType>::AddScript(this);
122 }
123
124 public:
125
126 // If a virtual function in your script type class is not necessarily
127 // required to be overridden, just declare it virtual with an empty
128 // body. If, on the other hand, it's logical only to override it (i.e.
129 // if it's the only method in the class), make it pure virtual, by adding
130 // = 0 to it.
131 virtual void OnSomeEvent(uint32 someArg1, std::string& someArg2) { }
132
133 // This is a pure virtual function:
134 virtual void OnAnotherEvent(uint32 someArg) = 0;
135 }
136
137 Next, you need to add a specialization for ScriptRegistry. Put this in the bottom of
138 ScriptMgr.cpp:
139
140 template class ScriptRegistry<MyScriptType>;
141
142 Now, add a cleanup routine in ScriptMgr::~ScriptMgr:
143
144 SCR_CLEAR(MyScriptType);
145
146 Now your script type is good to go with the script system. What you need to do now
147 is add functions to ScriptMgr that can be called from the core to actually trigger
148 certain events. For example, in ScriptMgr.h:
149
150 void OnSomeEvent(uint32 someArg1, std::string& someArg2);
151 void OnAnotherEvent(uint32 someArg);
152
153 In ScriptMgr.cpp:
154
155 void ScriptMgr::OnSomeEvent(uint32 someArg1, std::string& someArg2)
156 {
157 FOREACH_SCRIPT(MyScriptType)->OnSomeEvent(someArg1, someArg2);
158 }
159
160 void ScriptMgr::OnAnotherEvent(uint32 someArg)
161 {
162 FOREACH_SCRIPT(MyScriptType)->OnAnotherEvent(someArg1, someArg2);
163 }
164
165 Now you simply call these two functions from anywhere in the core to trigger the
166 event on all registered scripts of that type.
167*/
168
170{
171 friend class ScriptMgr;
172
173 public:
174
175 std::string const& GetName() const;
176
177 protected:
178
179 ScriptObject(char const* name);
180 virtual ~ScriptObject();
181
182 private:
183
184 std::string const _name;
185};
186
188{
189 protected:
190
191 explicit SpellScriptLoader(char const* name);
192
193 public:
194
195 // Should return a fully valid SpellScript pointer.
196 virtual SpellScript* GetSpellScript() const;
197
198 // Should return a fully valid AuraScript pointer.
199 virtual AuraScript* GetAuraScript() const;
200};
201
203{
204 protected:
205
206 explicit ServerScript(char const* name);
207
208 public:
209
210 // Called when reactive socket I/O is started (WorldTcpSessionMgr).
211 virtual void OnNetworkStart();
212
213 // Called when reactive I/O is stopped.
214 virtual void OnNetworkStop();
215
216 // Called when a remote socket establishes a connection to the server. Do not store the socket object.
217 virtual void OnSocketOpen(std::shared_ptr<WorldSocket> socket);
218
219 // Called when a socket is closed. Do not store the socket object, and do not rely on the connection
220 // being open; it is not.
221 virtual void OnSocketClose(std::shared_ptr<WorldSocket> socket);
222
223 // Called when a packet is sent to a client. The packet object is a copy of the original packet, so reading
224 // and modifying it is safe.
225 virtual void OnPacketSend(WorldSession* session, WorldPacket& packet);
226
227 // Called when a (valid) packet is received by a client. The packet object is a copy of the original packet, so
228 // reading and modifying it is safe. Make sure to check WorldSession pointer before usage, it might be null in case of auth packets
229 virtual void OnPacketReceive(WorldSession* session, WorldPacket& packet);
230};
231
233{
234 protected:
235
236 explicit WorldScript(char const* name);
237
238 public:
239
240 // Called when the open/closed state of the world changes.
241 virtual void OnOpenStateChange(bool open);
242
243 // Called after the world configuration is (re)loaded.
244 virtual void OnConfigLoad(bool reload);
245
246 // Called before the message of the day is changed.
247 virtual void OnMotdChange(std::string& newMotd);
248
249 // Called when a world shutdown is initiated.
250 virtual void OnShutdownInitiate(ShutdownExitCode code, ShutdownMask mask);
251
252 // Called when a world shutdown is cancelled.
253 virtual void OnShutdownCancel();
254
255 // Called on every world tick (don't execute too heavy code here).
256 virtual void OnUpdate(uint32 diff);
257
258 // Called when the world is started.
259 virtual void OnStartup();
260
261 // Called when the world is actually shut down.
262 virtual void OnShutdown();
263};
264
266{
267 protected:
268
269 explicit FormulaScript(char const* name);
270
271 public:
272
273 // Called after calculating honor.
274 virtual void OnHonorCalculation(float& honor, uint8 level, float multiplier);
275
276 // Called after gray level calculation.
277 virtual void OnGrayLevelCalculation(uint8& grayLevel, uint8 playerLevel);
278
279 // Called after calculating experience color.
280 virtual void OnColorCodeCalculation(XPColorChar& color, uint8 playerLevel, uint8 mobLevel);
281
282 // Called after calculating zero difference.
283 virtual void OnZeroDifferenceCalculation(uint8& diff, uint8 playerLevel);
284
285 // Called after calculating base experience gain.
286 virtual void OnBaseGainCalculation(uint32& gain, uint8 playerLevel, uint8 mobLevel, ContentLevels content);
287
288 // Called after calculating experience gain.
289 virtual void OnGainCalculation(uint32& gain, Player* player, Unit* unit);
290
291 // Called when calculating the experience rate for group experience.
292 virtual void OnGroupRateCalculation(float& rate, uint32 count, bool isRaid);
293};
294
295template<class TMap>
297{
299
300 protected:
301
302 explicit MapScript(MapEntry const* mapEntry);
303
304 public:
305
306 // Gets the MapEntry structure associated with this script. Can return NULL.
307 MapEntry const* GetEntry() const;
308
309 // Called when the map is created.
310 virtual void OnCreate(TMap* map);
311
312 // Called just before the map is destroyed.
313 virtual void OnDestroy(TMap* map);
314
315 // Called when a grid map is loaded.
316 virtual void OnLoadGridMap(TMap* /*map*/, GridMap* /*gmap*/, uint32 /*gx*/, uint32 /*gy*/) { }
317
318 // Called when a grid map is unloaded.
319 virtual void OnUnloadGridMap(TMap* /*map*/, GridMap* /*gmap*/, uint32 /*gx*/, uint32 /*gy*/) { }
320
321 // Called when a player enters the map.
322 virtual void OnPlayerEnter(TMap* map, Player* player);
323
324 // Called when a player leaves the map.
325 virtual void OnPlayerLeave(TMap* map, Player* player);
326
327 virtual void OnUpdate(TMap* map, uint32 diff);
328};
329
331{
332 protected:
333
334 explicit WorldMapScript(char const* name, uint32 mapId);
335};
336
337class TC_GAME_API InstanceMapScript : public ScriptObject, public MapScript<InstanceMap>
338{
339 protected:
340
341 explicit InstanceMapScript(char const* name, uint32 mapId);
342
343 public:
344
345 // Gets an InstanceScript object for this instance.
346 virtual InstanceScript* GetInstanceScript(InstanceMap* map) const;
347};
348
349class TC_GAME_API BattlegroundMapScript : public ScriptObject, public MapScript<BattlegroundMap>
350{
351 protected:
352
353 explicit BattlegroundMapScript(char const* name, uint32 mapId);
354};
355
357{
358 protected:
359
360 explicit ItemScript(char const* name);
361
362 public:
363
364 // Called when a player accepts a quest from the item.
365 virtual bool OnQuestAccept(Player* player, Item* item, Quest const* quest);
366
367 // Called when a player uses the item.
368 virtual bool OnUse(Player* player, Item* item, SpellCastTargets const& targets);
369
370 // Called when the item expires (is destroyed).
371 virtual bool OnExpire(Player* player, ItemTemplate const* proto);
372
373 // Called when the item is destroyed.
374 virtual bool OnRemove(Player* player, Item* item);
375
376 // Called before casting a combat spell from this item (chance on hit spells of item template, can be used to prevent cast if returning false)
377 virtual bool OnCastItemCombatSpell(Player* player, Unit* victim, SpellInfo const* spellInfo, Item* item);
378};
379
381{
382 protected:
383
384 explicit UnitScript(char const* name);
385
386 public:
387 // Called when a unit deals healing to another unit
388 virtual void OnHeal(Unit* healer, Unit* reciever, uint32& gain);
389
390 // Called when a unit deals damage to another unit
391 virtual void OnDamage(Unit* attacker, Unit* victim, uint32& damage);
392
393 // Called when DoT's Tick Damage is being Dealt
394 virtual void ModifyPeriodicDamageAurasTick(Unit* target, Unit* attacker, uint32& damage);
395
396 // Called when Melee Damage is being Dealt
397 virtual void ModifyMeleeDamage(Unit* target, Unit* attacker, uint32& damage);
398
399 // Called when Spell Damage is being Dealt
400 virtual void ModifySpellDamageTaken(Unit* target, Unit* attacker, int32& damage);
401};
402
404{
405 protected:
406
407 explicit CreatureScript(char const* name);
408
409 public:
410 // Called when a CreatureAI object is needed for the creature.
411 virtual CreatureAI* GetAI(Creature* creature) const = 0;
412};
413
415{
416 protected:
417
418 explicit GameObjectScript(char const* name);
419
420 public:
421
422 // Called when a GameObjectAI object is needed for the gameobject.
423 virtual GameObjectAI* GetAI(GameObject* go) const = 0;
424};
425
427{
428 protected:
429
430 explicit AreaTriggerScript(char const* name);
431
432 public:
433
434 // Called when the area trigger is activated by a player.
435 virtual bool OnTrigger(Player* player, AreaTriggerEntry const* trigger);
436};
437
439{
441
442 public:
443 bool OnTrigger(Player* /*player*/, AreaTriggerEntry const* /*trigger*/) final override;
444
445 protected:
446 // returns true if the trigger was successfully handled, false if we should try again next time
447 virtual bool TryHandleOnce(Player* player, AreaTriggerEntry const* trigger) = 0;
448 void ResetAreaTriggerDone(InstanceScript* instance, uint32 triggerId);
449 void ResetAreaTriggerDone(Player const* player, AreaTriggerEntry const* trigger);
450};
451
453{
454 protected:
455
456 explicit BattlefieldScript(char const* name);
457
458 public:
459
460 virtual Battlefield* GetBattlefield() const = 0;
461};
462
464{
465 protected:
466
467 explicit BattlegroundScript(char const* name);
468
469 public:
470
471 // Should return a fully valid Battleground object for the type ID.
472 virtual Battleground* GetBattleground() const = 0;
473};
474
476{
477 protected:
478
479 explicit OutdoorPvPScript(char const* name);
480
481 public:
482
483 // Should return a fully valid OutdoorPvP object for the type ID.
484 virtual OutdoorPvP* GetOutdoorPvP() const = 0;
485};
486
488{
489 protected:
490
491 explicit CommandScript(char const* name);
492
493 public:
494
495 // Should return a pointer to a valid command table (ChatCommand array) to be used by ChatHandler.
496 virtual std::vector<Trinity::ChatCommands::ChatCommandBuilder> GetCommands() const = 0;
497};
498
500{
501 protected:
502
503 explicit WeatherScript(char const* name);
504
505 public:
506
507 // Called when the weather changes in the zone this script is associated with.
508 virtual void OnChange(Weather* weather, WeatherState state, float grade);
509
510 virtual void OnUpdate(Weather* weather, uint32 diff);
511};
512
514{
515 protected:
516
517 explicit AuctionHouseScript(char const* name);
518
519 public:
520
521 // Called when an auction is added to an auction house.
522 virtual void OnAuctionAdd(AuctionHouseObject* ah, AuctionEntry* entry);
523
524 // Called when an auction is removed from an auction house.
525 virtual void OnAuctionRemove(AuctionHouseObject* ah, AuctionEntry* entry);
526
527 // Called when an auction was succesfully completed.
528 virtual void OnAuctionSuccessful(AuctionHouseObject* ah, AuctionEntry* entry);
529
530 // Called when an auction expires.
531 virtual void OnAuctionExpire(AuctionHouseObject* ah, AuctionEntry* entry);
532};
533
535{
536 protected:
537
538 explicit ConditionScript(char const* name);
539
540 public:
541
542 // Called when a single condition is checked for a player.
543 virtual bool OnConditionCheck(Condition const* condition, ConditionSourceInfo& sourceInfo);
544};
545
547{
548 protected:
549
550 explicit VehicleScript(char const* name);
551
552 public:
553
554 // Called after a vehicle is installed.
555 virtual void OnInstall(Vehicle* veh);
556
557 // Called after a vehicle is uninstalled.
558 virtual void OnUninstall(Vehicle* veh);
559
560 // Called when a vehicle resets.
561 virtual void OnReset(Vehicle* veh);
562
563 // Called after an accessory is installed in a vehicle.
564 virtual void OnInstallAccessory(Vehicle* veh, Creature* accessory);
565
566 // Called after a passenger is added to a vehicle.
567 virtual void OnAddPassenger(Vehicle* veh, Unit* passenger, int8 seatId);
568
569 // Called after a passenger is removed from a vehicle.
570 virtual void OnRemovePassenger(Vehicle* veh, Unit* passenger);
571};
572
574{
575 protected:
576
577 explicit DynamicObjectScript(char const* name);
578
579 public:
580
581 virtual void OnUpdate(DynamicObject* obj, uint32 diff);
582};
583
585{
586 protected:
587
588 explicit TransportScript(char const* name);
589
590 public:
591
592 // Called when a player boards the transport.
593 virtual void OnAddPassenger(Transport* transport, Player* player);
594
595 // Called when a creature boards the transport.
596 virtual void OnAddCreaturePassenger(Transport* transport, Creature* creature);
597
598 // Called when a player exits the transport.
599 virtual void OnRemovePassenger(Transport* transport, Player* player);
600
601 // Called when a transport moves.
602 virtual void OnRelocate(Transport* transport, uint32 waypointId, uint32 mapId, float x, float y, float z);
603
604 virtual void OnUpdate(Transport* transport, uint32 diff);
605};
606
608{
609 protected:
610
611 explicit AchievementCriteriaScript(char const* name);
612
613 public:
614
615 // Called when an additional criteria is checked.
616 virtual bool OnCheck(Player* source, Unit* target) = 0;
617};
618
620{
621 protected:
622
623 explicit PlayerScript(char const* name);
624
625 public:
626
627 // Called when a player kills another player
628 virtual void OnPVPKill(Player* killer, Player* killed);
629
630 // Called when a player kills a creature
631 virtual void OnCreatureKill(Player* killer, Creature* killed);
632
633 // Called when a player is killed by a creature
634 virtual void OnPlayerKilledByCreature(Creature* killer, Player* killed);
635
636 // Called when a player's level changes (after the level is applied)
637 virtual void OnLevelChanged(Player* player, uint8 oldLevel);
638
639 // Called when a player's free talent points change (right before the change is applied)
640 virtual void OnFreeTalentPointsChanged(Player* player, uint32 points);
641
642 // Called when a player's talent points are reset (right before the reset is done)
643 virtual void OnTalentsReset(Player* player, bool involuntarily);
644
645 // Called when a player's money is modified (before the modification is done)
646 virtual void OnMoneyChanged(Player* player, int32& amount);
647
648 // Called when a player's money is at limit (amount = money tried to add)
649 virtual void OnMoneyLimit(Player* player, int32 amount);
650
651 // Called when a player gains XP (before anything is given)
652 virtual void OnGiveXP(Player* player, uint32& amount, Unit* victim);
653
654 // Called when a player's reputation changes (before it is actually changed)
655 virtual void OnReputationChange(Player* player, uint32 factionId, int32& standing, bool incremental);
656
657 // Called when a duel is requested
658 virtual void OnDuelRequest(Player* target, Player* challenger);
659
660 // Called when a duel starts (after 3s countdown)
661 virtual void OnDuelStart(Player* player1, Player* player2);
662
663 // Called when a duel ends
664 virtual void OnDuelEnd(Player* winner, Player* loser, DuelCompleteType type);
665
666 // The following methods are called when a player sends a chat message.
667 virtual void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg);
668
669 virtual void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Player* receiver);
670
671 virtual void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Group* group);
672
673 virtual void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Guild* guild);
674
675 virtual void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Channel* channel);
676
677 // Both of the below are called on emote opcodes.
678 virtual void OnEmote(Player* player, Emote emote);
679
680 virtual void OnTextEmote(Player* player, uint32 textEmote, uint32 emoteNum, ObjectGuid guid);
681
682 // Called in Spell::Cast.
683 virtual void OnSpellCast(Player* player, Spell* spell, bool skipCheck);
684
685 // Called when a player logs in.
686 virtual void OnLogin(Player* player, bool firstLogin);
687
688 // Called when a player logs out.
689 virtual void OnLogout(Player* player);
690
691 // Called when a player is created.
692 virtual void OnCreate(Player* player);
693
694 // Called when a player is deleted.
695 virtual void OnDelete(ObjectGuid guid, uint32 accountId);
696
697 // Called when a player delete failed
698 virtual void OnFailedDelete(ObjectGuid guid, uint32 accountId);
699
700 // Called when a player is about to be saved.
701 virtual void OnSave(Player* player);
702
703 // Called when a player is bound to an instance
704 virtual void OnBindToInstance(Player* player, Difficulty difficulty, uint32 mapId, bool permanent, uint8 extendState);
705
706 // Called when a player switches to a new zone
707 virtual void OnUpdateZone(Player* player, uint32 newZone, uint32 newArea);
708
709 // Called when a player changes to a new map (after moving to new map)
710 virtual void OnMapChanged(Player* player);
711
712 // Called when a player obtains progress on a quest's objective
713 virtual void OnQuestObjectiveProgress(Player* /*player*/, Quest const* /*quest*/, uint32 /*objectiveIndex*/, uint16 /*progress*/) { }
714
715 // Called after a player's quest status has been changed
716 virtual void OnQuestStatusChange(Player* player, uint32 questId);
717
718 // Called when a player presses release when he died
719 virtual void OnPlayerRepop(Player* player);
720
721 // Called when a player completes a movie
722 virtual void OnMovieComplete(Player* player, uint32 movieId);
723
724};
725
727{
728 protected:
729
730 explicit AccountScript(char const* name);
731
732 public:
733
734 // Called when an account logged in succesfully
735 virtual void OnAccountLogin(uint32 accountId);
736
737 // Called when an account login failed
738 virtual void OnFailedAccountLogin(uint32 accountId);
739
740 // Called when Email is successfully changed for Account
741 virtual void OnEmailChange(uint32 accountId);
742
743 // Called when Email failed to change for Account
744 virtual void OnFailedEmailChange(uint32 accountId);
745
746 // Called when Password is successfully changed for Account
747 virtual void OnPasswordChange(uint32 accountId);
748
749 // Called when Password failed to change for Account
750 virtual void OnFailedPasswordChange(uint32 accountId);
751};
752
754{
755 protected:
756
757 explicit GuildScript(char const* name);
758
759 public:
760
761 // Called when a member is added to the guild.
762 virtual void OnAddMember(Guild* guild, Player* player, uint8& plRank);
763
764 // Called when a member is removed from the guild.
765 virtual void OnRemoveMember(Guild* guild, Player* player, bool isDisbanding, bool isKicked);
766
767 // Called when the guild MOTD (message of the day) changes.
768 virtual void OnMOTDChanged(Guild* guild, std::string const& newMotd);
769
770 // Called when the guild info is altered.
771 virtual void OnInfoChanged(Guild* guild, std::string const& newInfo);
772
773 // Called when a guild is created.
774 virtual void OnCreate(Guild* guild, Player* leader, std::string const& name);
775
776 // Called when a guild is disbanded.
777 virtual void OnDisband(Guild* guild);
778
779 // Called when a guild member withdraws money from a guild bank.
780 virtual void OnMemberWitdrawMoney(Guild* guild, Player* player, uint32& amount, bool isRepair);
781
782 // Called when a guild member deposits money in a guild bank.
783 virtual void OnMemberDepositMoney(Guild* guild, Player* player, uint32& amount);
784
785 // Called when a guild member moves an item in a guild bank.
786 virtual void OnItemMove(Guild* guild, Player* player, Item* pItem, bool isSrcBank, uint8 srcContainer, uint8 srcSlotId,
787 bool isDestBank, uint8 destContainer, uint8 destSlotId);
788
789 virtual void OnEvent(Guild* guild, uint8 eventType, ObjectGuid::LowType playerGuid1, ObjectGuid::LowType playerGuid2, uint8 newRank);
790
791 virtual void OnBankEvent(Guild* guild, uint8 eventType, uint8 tabId, ObjectGuid::LowType playerGuid, uint32 itemOrMoney, uint16 itemStackCount, uint8 destTabId);
792};
793
795{
796 protected:
797
798 explicit GroupScript(char const* name);
799
800 public:
801
802 // Called when a member is added to a group.
803 virtual void OnAddMember(Group* group, ObjectGuid guid);
804
805 // Called when a member is invited to join a group.
806 virtual void OnInviteMember(Group* group, ObjectGuid guid);
807
808 // Called when a member is removed from a group.
809 virtual void OnRemoveMember(Group* group, ObjectGuid guid, RemoveMethod method, ObjectGuid kicker, char const* reason);
810
811 // Called when the leader of a group is changed.
812 virtual void OnChangeLeader(Group* group, ObjectGuid newLeaderGuid, ObjectGuid oldLeaderGuid);
813
814 // Called when a group is disbanded.
815 virtual void OnDisband(Group* group);
816};
817
818// Manages registration, loading, and execution of scripts.
820{
821 friend class ScriptObject;
822
823 private:
824 ScriptMgr();
825 virtual ~ScriptMgr();
826
827 void FillSpellSummary();
828 void LoadDatabase();
829
830 void IncreaseScriptCount() { ++_scriptCount; }
831 void DecreaseScriptCount() { --_scriptCount; }
832
833 public: /* Initialization */
834 static ScriptMgr* instance();
835
836 void Initialize();
837
838 uint32 GetScriptCount() const { return _scriptCount; }
839
840 typedef void(*ScriptLoaderCallbackType)();
841
844 void SetScriptLoader(ScriptLoaderCallbackType script_loader_callback)
845 {
846 _script_loader_callback = script_loader_callback;
847 }
848
849 public: /* Script contexts */
853 void SetScriptContext(std::string const& context);
855 std::string const& GetCurrentScriptContext() const { return _currentContext; }
858 void ReleaseScriptContext(std::string const& context);
862 void SwapScriptContext(bool initialize = false);
863
865 static std::string const& GetNameOfStaticContext();
866
870 std::shared_ptr<ModuleReference> AcquireModuleReferenceOfScriptName(
871 std::string const& scriptname) const;
872
873 public: /* Unloading */
874
875 void Unload();
876
877 public: /* SpellScriptLoader */
878
879 void CreateSpellScripts(uint32 spellId, std::vector<SpellScript*>& scriptVector, Spell* invoker) const;
880 void CreateAuraScripts(uint32 spellId, std::vector<AuraScript*>& scriptVector, Aura* invoker) const;
881 SpellScriptLoader* GetSpellScriptLoader(uint32 scriptId);
882
883 public: /* ServerScript */
884
885 void OnNetworkStart();
886 void OnNetworkStop();
887 void OnSocketOpen(std::shared_ptr<WorldSocket> const& socket);
888 void OnSocketClose(std::shared_ptr<WorldSocket> const& socket);
889 void OnPacketReceive(WorldSession* session, WorldPacket const& packet);
890 void OnPacketSend(WorldSession* session, WorldPacket const& packet);
891
892 public: /* WorldScript */
893
894 void OnOpenStateChange(bool open);
895 void OnConfigLoad(bool reload);
896 void OnMotdChange(std::string& newMotd);
897 void OnShutdownInitiate(ShutdownExitCode code, ShutdownMask mask);
898 void OnShutdownCancel();
899 void OnWorldUpdate(uint32 diff);
900 void OnStartup();
901 void OnShutdown();
902
903 public: /* FormulaScript */
904
905 void OnHonorCalculation(float& honor, uint8 level, float multiplier);
906 void OnGrayLevelCalculation(uint8& grayLevel, uint8 playerLevel);
907 void OnColorCodeCalculation(XPColorChar& color, uint8 playerLevel, uint8 mobLevel);
908 void OnZeroDifferenceCalculation(uint8& diff, uint8 playerLevel);
909 void OnBaseGainCalculation(uint32& gain, uint8 playerLevel, uint8 mobLevel, ContentLevels content);
910 void OnGainCalculation(uint32& gain, Player* player, Unit* unit);
911 void OnGroupRateCalculation(float& rate, uint32 count, bool isRaid);
912
913 public: /* MapScript */
914
915 void OnCreateMap(Map* map);
916 void OnDestroyMap(Map* map);
917 void OnLoadGridMap(Map* map, GridMap* gmap, uint32 gx, uint32 gy);
918 void OnUnloadGridMap(Map* map, GridMap* gmap, uint32 gx, uint32 gy);
919 void OnPlayerEnterMap(Map* map, Player* player);
920 void OnPlayerLeaveMap(Map* map, Player* player);
921 void OnMapUpdate(Map* map, uint32 diff);
922
923 public: /* InstanceMapScript */
924
925 InstanceScript* CreateInstanceData(InstanceMap* map);
926
927 public: /* ItemScript */
928
929 bool OnQuestAccept(Player* player, Item* item, Quest const* quest);
930 bool OnItemUse(Player* player, Item* item, SpellCastTargets const& targets);
931 bool OnItemExpire(Player* player, ItemTemplate const* proto);
932 bool OnItemRemove(Player* player, Item* item);
933 bool OnCastItemCombatSpell(Player* player, Unit* victim, SpellInfo const* spellInfo, Item* item);
934
935 public: /* CreatureScript */
936
937 CreatureAI* GetCreatureAI(Creature* creature);
938
939 public: /* GameObjectScript */
940
941 GameObjectAI* GetGameObjectAI(GameObject* go);
942
943 public: /* AreaTriggerScript */
944
945 bool OnAreaTrigger(Player* player, AreaTriggerEntry const* trigger);
946
947 public: /* BattlefieldScript */
948
949 Battlefield* CreateBattlefield(uint32 scriptId);
950
951 public: /* BattlegroundScript */
952
953 Battleground* CreateBattleground(BattlegroundTypeId typeId);
954
955 public: /* OutdoorPvPScript */
956
957 OutdoorPvP* CreateOutdoorPvP(uint32 scriptId);
958
959 public: /* CommandScript */
960
961 std::vector<Trinity::ChatCommands::ChatCommandBuilder> GetChatCommands();
962
963 public: /* WeatherScript */
964
965 void OnWeatherChange(Weather* weather, WeatherState state, float grade);
966 void OnWeatherUpdate(Weather* weather, uint32 diff);
967
968 public: /* AuctionHouseScript */
969
970 void OnAuctionAdd(AuctionHouseObject* ah, AuctionEntry* entry);
971 void OnAuctionRemove(AuctionHouseObject* ah, AuctionEntry* entry);
972 void OnAuctionSuccessful(AuctionHouseObject* ah, AuctionEntry* entry);
973 void OnAuctionExpire(AuctionHouseObject* ah, AuctionEntry* entry);
974
975 public: /* ConditionScript */
976
977 bool OnConditionCheck(Condition const* condition, ConditionSourceInfo& sourceInfo);
978
979 public: /* VehicleScript */
980
981 void OnInstall(Vehicle* veh);
982 void OnUninstall(Vehicle* veh);
983 void OnReset(Vehicle* veh);
984 void OnInstallAccessory(Vehicle* veh, Creature* accessory);
985 void OnAddPassenger(Vehicle* veh, Unit* passenger, int8 seatId);
986 void OnRemovePassenger(Vehicle* veh, Unit* passenger);
987
988 public: /* DynamicObjectScript */
989
990 void OnDynamicObjectUpdate(DynamicObject* dynobj, uint32 diff);
991
992 public: /* TransportScript */
993
994 void OnAddPassenger(Transport* transport, Player* player);
995 void OnAddCreaturePassenger(Transport* transport, Creature* creature);
996 void OnRemovePassenger(Transport* transport, Player* player);
997 void OnTransportUpdate(Transport* transport, uint32 diff);
998 void OnRelocate(Transport* transport, uint32 waypointId, uint32 mapId, float x, float y, float z);
999
1000 public: /* AchievementCriteriaScript */
1001
1002 bool OnCriteriaCheck(uint32 scriptId, Player* source, Unit* target);
1003
1004 public: /* PlayerScript */
1005
1006 void OnPVPKill(Player* killer, Player* killed);
1007 void OnCreatureKill(Player* killer, Creature* killed);
1008 void OnPlayerKilledByCreature(Creature* killer, Player* killed);
1009 void OnPlayerLevelChanged(Player* player, uint8 oldLevel);
1010 void OnPlayerFreeTalentPointsChanged(Player* player, uint32 newPoints);
1011 void OnPlayerTalentsReset(Player* player, bool involuntarily);
1012 void OnPlayerMoneyChanged(Player* player, int32& amount);
1013 void OnPlayerMoneyLimit(Player* player, int32 amount);
1014 void OnGivePlayerXP(Player* player, uint32& amount, Unit* victim);
1015 void OnPlayerReputationChange(Player* player, uint32 factionID, int32& standing, bool incremental);
1016 void OnPlayerDuelRequest(Player* target, Player* challenger);
1017 void OnPlayerDuelStart(Player* player1, Player* player2);
1018 void OnPlayerDuelEnd(Player* winner, Player* loser, DuelCompleteType type);
1019 void OnPlayerChat(Player* player, uint32 type, uint32 lang, std::string& msg);
1020 void OnPlayerChat(Player* player, uint32 type, uint32 lang, std::string& msg, Player* receiver);
1021 void OnPlayerChat(Player* player, uint32 type, uint32 lang, std::string& msg, Group* group);
1022 void OnPlayerChat(Player* player, uint32 type, uint32 lang, std::string& msg, Guild* guild);
1023 void OnPlayerChat(Player* player, uint32 type, uint32 lang, std::string& msg, Channel* channel);
1024 void OnPlayerEmote(Player* player, Emote emote);
1025 void OnPlayerTextEmote(Player* player, uint32 textEmote, uint32 emoteNum, ObjectGuid guid);
1026 void OnPlayerSpellCast(Player* player, Spell* spell, bool skipCheck);
1027 void OnPlayerLogin(Player* player, bool firstLogin);
1028 void OnPlayerLogout(Player* player);
1029 void OnPlayerCreate(Player* player);
1030 void OnPlayerDelete(ObjectGuid guid, uint32 accountId);
1031 void OnPlayerFailedDelete(ObjectGuid guid, uint32 accountId);
1032 void OnPlayerSave(Player* player);
1033 void OnPlayerBindToInstance(Player* player, Difficulty difficulty, uint32 mapid, bool permanent, uint8 extendState);
1034 void OnPlayerUpdateZone(Player* player, uint32 newZone, uint32 newArea);
1035 void OnQuestObjectiveProgress(Player* player, Quest const* quest, uint32 objectiveIndex, uint16 progress);
1036 void OnQuestStatusChange(Player* player, uint32 questId);
1037 void OnMovieComplete(Player* player, uint32 movieId);
1038 void OnPlayerRepop(Player* player);
1039
1040 public: /* AccountScript */
1041
1042 void OnAccountLogin(uint32 accountId);
1043 void OnFailedAccountLogin(uint32 accountId);
1044 void OnEmailChange(uint32 accountId);
1045 void OnFailedEmailChange(uint32 accountId);
1046 void OnPasswordChange(uint32 accountId);
1047 void OnFailedPasswordChange(uint32 accountId);
1048
1049 public: /* GuildScript */
1050
1051 void OnGuildAddMember(Guild* guild, Player* player, uint8& plRank);
1052 void OnGuildRemoveMember(Guild* guild, Player* player, bool isDisbanding, bool isKicked);
1053 void OnGuildMOTDChanged(Guild* guild, const std::string& newMotd);
1054 void OnGuildInfoChanged(Guild* guild, const std::string& newInfo);
1055 void OnGuildCreate(Guild* guild, Player* leader, const std::string& name);
1056 void OnGuildDisband(Guild* guild);
1057 void OnGuildMemberWitdrawMoney(Guild* guild, Player* player, uint32 &amount, bool isRepair);
1058 void OnGuildMemberDepositMoney(Guild* guild, Player* player, uint32 &amount);
1059 void OnGuildItemMove(Guild* guild, Player* player, Item* pItem, bool isSrcBank, uint8 srcContainer, uint8 srcSlotId,
1060 bool isDestBank, uint8 destContainer, uint8 destSlotId);
1061 void OnGuildEvent(Guild* guild, uint8 eventType, ObjectGuid::LowType playerGuid1, ObjectGuid::LowType playerGuid2, uint8 newRank);
1062 void OnGuildBankEvent(Guild* guild, uint8 eventType, uint8 tabId, ObjectGuid::LowType playerGuid, uint32 itemOrMoney, uint16 itemStackCount, uint8 destTabId);
1063
1064 public: /* GroupScript */
1065
1066 void OnGroupAddMember(Group* group, ObjectGuid guid);
1067 void OnGroupInviteMember(Group* group, ObjectGuid guid);
1068 void OnGroupRemoveMember(Group* group, ObjectGuid guid, RemoveMethod method, ObjectGuid kicker, char const* reason);
1069 void OnGroupChangeLeader(Group* group, ObjectGuid newLeaderGuid, ObjectGuid oldLeaderGuid);
1070 void OnGroupDisband(Group* group);
1071
1072 public: /* UnitScript */
1073
1074 void OnHeal(Unit* healer, Unit* reciever, uint32& gain);
1075 void OnDamage(Unit* attacker, Unit* victim, uint32& damage);
1076 void ModifyPeriodicDamageAurasTick(Unit* target, Unit* attacker, uint32& damage);
1077 void ModifyMeleeDamage(Unit* target, Unit* attacker, uint32& damage);
1078 void ModifySpellDamageTaken(Unit* target, Unit* attacker, int32& damage);
1079
1080 private:
1082
1083 ScriptLoaderCallbackType _script_loader_callback;
1084
1085 std::string _currentContext;
1086};
1087
1089{
1090 template<typename T>
1091 using is_SpellScript = std::is_base_of<SpellScript, T>;
1092
1093 template<typename T>
1094 using is_AuraScript = std::is_base_of<AuraScript, T>;
1095}
1096
1097template <typename... Ts>
1099{
1103
1104public:
1105 GenericSpellAndAuraScriptLoader(char const* name, ArgsType&& args) : SpellScriptLoader(name), _args(std::move(args)) { }
1106
1107private:
1108 SpellScript* GetSpellScript() const override
1109 {
1110 if constexpr (!std::is_same_v<SpellScriptType, Trinity::find_type_end>)
1111 return Trinity::new_from_tuple<SpellScriptType>(_args);
1112 else
1113 return nullptr;
1114 }
1115
1116 AuraScript* GetAuraScript() const override
1117 {
1118 if constexpr (!std::is_same_v<AuraScriptType, Trinity::find_type_end>)
1119 return Trinity::new_from_tuple<AuraScriptType>(_args);
1120 else
1121 return nullptr;
1122 }
1123
1125};
1126
1127#define RegisterSpellScriptWithArgs(spell_script, script_name, ...) new GenericSpellAndAuraScriptLoader<spell_script, decltype(std::make_tuple(__VA_ARGS__))>(script_name, std::make_tuple(__VA_ARGS__))
1128#define RegisterSpellScript(spell_script) RegisterSpellScriptWithArgs(spell_script, #spell_script)
1129#define RegisterSpellAndAuraScriptPairWithArgs(script_1, script_2, script_name, ...) new GenericSpellAndAuraScriptLoader<script_1, script_2, decltype(std::make_tuple(__VA_ARGS__))>(script_name, std::make_tuple(__VA_ARGS__))
1130#define RegisterSpellAndAuraScriptPair(script_1, script_2) RegisterSpellAndAuraScriptPairWithArgs(script_1, script_2, #script_1)
1131
1132template <class AI>
1134{
1135 public:
1136 GenericCreatureScript(char const* name) : CreatureScript(name) { }
1137 CreatureAI* GetAI(Creature* me) const override { return new AI(me); }
1138};
1139#define RegisterCreatureAI(ai_name) new GenericCreatureScript<ai_name>(#ai_name)
1140
1141template <class AI, AI* (*AIFactory)(Creature*)>
1143{
1144 public:
1145 FactoryCreatureScript(char const* name) : CreatureScript(name) { }
1146 CreatureAI* GetAI(Creature* me) const override { return AIFactory(me); }
1147};
1148#define RegisterCreatureAIWithFactory(ai_name, factory_fn) new FactoryCreatureScript<ai_name, &factory_fn>(#ai_name)
1149
1150template <class AI>
1152{
1153 public:
1154 GenericGameObjectScript(char const* name) : GameObjectScript(name) { }
1155 GameObjectAI* GetAI(GameObject* go) const override { return new AI(go); }
1156};
1157#define RegisterGameObjectAI(ai_name) new GenericGameObjectScript<ai_name>(#ai_name)
1158
1159template <class AI, AI* (*AIFactory)(GameObject*)>
1161{
1162 public:
1163 FactoryGameObjectScript(char const* name) : GameObjectScript(name) { }
1164 GameObjectAI* GetAI(GameObject* me) const override { return AIFactory(me); }
1165};
1166#define RegisterGameObjectAIWithFactory(ai_name, factory_fn) new FactoryGameObjectScript<ai_name, &factory_fn>(#ai_name)
1167
1168#define sScriptMgr ScriptMgr::instance()
1169
1170#endif
Difficulty
Definition DBCEnums.h:279
ContentLevels
Definition DBCStores.h:51
#define TC_GAME_API
Definition Define.h:114
uint8_t uint8
Definition Define.h:135
int8_t int8
Definition Define.h:131
int32_t int32
Definition Define.h:129
uint16_t uint16
Definition Define.h:134
uint32_t uint32
Definition Define.h:133
QuestStatus
Definition QuestDef.h:103
SpellEffIndex
XPColorChar
DuelCompleteType
BattlegroundTypeId
RemoveMethod
virtual bool OnCheck(Player *source, Unit *target)=0
AreaTriggerScript(char const *name)
virtual Battlefield * GetBattlefield() const =0
virtual Battleground * GetBattleground() const =0
virtual std::vector< Trinity::ChatCommands::ChatCommandBuilder > GetCommands() const =0
virtual CreatureAI * GetAI(Creature *creature) const =0
CreatureAI * GetAI(Creature *me) const override
Definition ScriptMgr.h:1146
FactoryCreatureScript(char const *name)
Definition ScriptMgr.h:1145
GameObjectAI * GetAI(GameObject *me) const override
Definition ScriptMgr.h:1164
FactoryGameObjectScript(char const *name)
Definition ScriptMgr.h:1163
virtual GameObjectAI * GetAI(GameObject *go) const =0
GenericCreatureScript(char const *name)
Definition ScriptMgr.h:1136
CreatureAI * GetAI(Creature *me) const override
Definition ScriptMgr.h:1137
GenericGameObjectScript(char const *name)
Definition ScriptMgr.h:1154
GameObjectAI * GetAI(GameObject *go) const override
Definition ScriptMgr.h:1155
typename Trinity::find_type_if_t< Trinity::SpellScripts::is_AuraScript, Ts... > AuraScriptType
Definition ScriptMgr.h:1101
AuraScript * GetAuraScript() const override
Definition ScriptMgr.h:1116
typename Trinity::find_type_if_t< Trinity::SpellScripts::is_SpellScript, Ts... > SpellScriptType
Definition ScriptMgr.h:1100
SpellScript * GetSpellScript() const override
Definition ScriptMgr.h:1108
typename Trinity::find_type_if_t< Trinity::is_tuple, Ts... > ArgsType
Definition ScriptMgr.h:1102
GenericSpellAndAuraScriptLoader(char const *name, ArgsType &&args)
Definition ScriptMgr.h:1105
Definition Map.h:155
Definition Group.h:165
Definition Guild.h:284
Definition Item.h:62
MapEntry const * _mapEntry
Definition ScriptMgr.h:298
virtual void OnUnloadGridMap(TMap *, GridMap *, uint32, uint32)
Definition ScriptMgr.h:319
virtual void OnLoadGridMap(TMap *, GridMap *, uint32, uint32)
Definition ScriptMgr.h:316
Definition Map.h:281
uint32 LowType
Definition ObjectGuid.h:142
virtual bool TryHandleOnce(Player *player, AreaTriggerEntry const *trigger)=0
virtual OutdoorPvP * GetOutdoorPvP() const =0
virtual void OnQuestObjectiveProgress(Player *, Quest const *, uint32, uint16)
Definition ScriptMgr.h:713
void IncreaseScriptCount()
Definition ScriptMgr.h:830
void SetScriptLoader(ScriptLoaderCallbackType script_loader_callback)
Definition ScriptMgr.h:844
void DecreaseScriptCount()
Definition ScriptMgr.h:831
uint32 GetScriptCount() const
Definition ScriptMgr.h:838
std::string const & GetCurrentScriptContext() const
Returns the current script context.
Definition ScriptMgr.h:855
std::string _currentContext
Definition ScriptMgr.h:1085
ScriptLoaderCallbackType _script_loader_callback
Definition ScriptMgr.h:1083
uint32 _scriptCount
Definition ScriptMgr.h:1081
std::string const _name
Definition ScriptMgr.h:184
Definition Spell.h:152
Definition Unit.h:769
Weather for one zone.
Definition Weather.h:67
Player session in the World.
WeatherState
Definition Weather.h:47
ShutdownExitCode
Definition World.h:62
ShutdownMask
Definition World.h:55
std::is_base_of< AuraScript, T > is_AuraScript
Definition ScriptMgr.h:1094
std::is_base_of< SpellScript, T > is_SpellScript
Definition ScriptMgr.h:1091
typename find_type_if< Check, Ts... >::type find_type_if_t
Definition Types.h:65
STL namespace.