Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
ScriptMgr.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#include "Chat.h"
7#include "Config.h"
8#include "CreatureAIImpl.h"
9#include "DatabaseEnv.h"
10#include "DBCStores.h"
11#include "GossipDef.h"
12#include "ObjectMgr.h"
13#include "OutdoorPvPMgr.h"
14#include "Player.h"
15#include "ScriptLoader.h"
16#include "ScriptMgr.h"
17#include "ScriptSystem.h"
18#include "SpellInfo.h"
19#include "SpellScript.h"
20#include "Transport.h"
21#include "Vehicle.h"
22#include "WorldPacket.h"
23
24namespace
25{
26 typedef std::set<ScriptObject*> ExampleScriptContainer;
27 ExampleScriptContainer ExampleScripts;
28}
29
30// This is the global static registry of scripts.
31template<class TScript>
33{
34public:
35 typedef std::map<uint32, TScript*> ScriptMap;
36 typedef typename ScriptMap::iterator ScriptMapIterator;
37
38 // The actual list of scripts. This will be accessed concurrently, so it must not be modified
39 // after server startup.
41
42 static void AddScript(TScript* const script)
43 {
44 ASSERT(script);
45
46 // See if the script is using the same memory as another script. If this happens, it means that
47 // someone forgot to allocate new memory for a script.
48 for (ScriptMapIterator it = ScriptPointerList.begin(); it != ScriptPointerList.end(); ++it)
49 {
50 if (it->second == script)
51 {
52 SF_LOG_ERROR("scripts", "Script '%s' has same memory pointer as '%s'.",
53 script->GetName().c_str(), it->second->GetName().c_str());
54
55 return;
56 }
57 }
58
59 if (script->IsDatabaseBound())
60 {
61 // Get an ID for the script. An ID only exists if it's a script that is assigned in the database
62 // through a script name (or similar).
63 uint32 id = sObjectMgr->GetScriptId(script->GetName().c_str());
64 if (id)
65 {
66 // Try to find an existing script.
67 bool existing = false;
68 for (ScriptMapIterator it = ScriptPointerList.begin(); it != ScriptPointerList.end(); ++it)
69 {
70 // If the script names match...
71 if (it->second->GetName() == script->GetName())
72 {
73 // ... It exists.
74 existing = true;
75 break;
76 }
77 }
78
79 // If the script isn't assigned -> assign it!
80 if (!existing)
81 {
82 ScriptPointerList[id] = script;
83 sScriptMgr->IncrementScriptCount();
84 }
85 else
86 {
87 // If the script is already assigned -> delete it!
88 SF_LOG_ERROR("scripts", "Script '%s' already assigned with the same script name, so the script can't work.",
89 script->GetName().c_str());
90
91 ASSERT(false); // Error that should be fixed ASAP.
92 }
93 }
94 else
95 {
96 // The script uses a script name from database, but isn't assigned to anything.
97 if (script->GetName().find("example") == std::string::npos && script->GetName().find("Smart") == std::string::npos)
98 SF_LOG_ERROR("sql.sql", "Script named '%s' does not have a script name assigned in database.",
99 script->GetName().c_str());
100
101 // These scripts don't get stored anywhere so throw them into this to avoid leaking memory
102 ExampleScripts.insert(script);
103 }
104 }
105 else
106 {
107 // We're dealing with a code-only script; just add it.
109 sScriptMgr->IncrementScriptCount();
110 }
111 }
112
113 // Gets a script by its ID (assigned by ObjectMgr).
114 static TScript* GetScriptById(uint32 id)
115 {
117 if (it != ScriptPointerList.end())
118 return it->second;
119
120 return NULL;
121 }
122
123private:
124 // Counter used for code-only scripts.
126};
127
128// Utility macros to refer to the script registry.
129#define SCR_REG_MAP(T) ScriptRegistry<T>::ScriptMap
130#define SCR_REG_ITR(T) ScriptRegistry<T>::ScriptMapIterator
131#define SCR_REG_LST(T) ScriptRegistry<T>::ScriptPointerList
132
133// Utility macros for looping over scripts.
134#define FOR_SCRIPTS(T, C, E) \
135 if (SCR_REG_LST(T).empty()) \
136 return; \
137 for (SCR_REG_ITR(T) C = SCR_REG_LST(T).begin(); \
138 C != SCR_REG_LST(T).end(); ++C)
139#define FOR_SCRIPTS_RET(T, C, E, R) \
140 if (SCR_REG_LST(T).empty()) \
141 return R; \
142 for (SCR_REG_ITR(T) C = SCR_REG_LST(T).begin(); \
143 C != SCR_REG_LST(T).end(); ++C)
144#define FOREACH_SCRIPT(T) \
145 FOR_SCRIPTS(T, itr, end) \
146 itr->second
147
148// Utility macros for finding specific scripts.
149#define GET_SCRIPT(T, I, V) \
150 T* V = ScriptRegistry<T>::GetScriptById(I); \
151 if (!V) \
152 return;
153#define GET_SCRIPT_RET(T, I, V, R) \
154 T* V = ScriptRegistry<T>::GetScriptById(I); \
155 if (!V) \
156 return R;
157
159
162
164
166{
167 uint32 oldMSTime = getMSTime();
168
169 LoadDatabase();
170
171 SF_LOG_INFO("server.loading", "Loading C++ scripts");
172
174 AddScripts();
175
176 SF_LOG_INFO("server.loading", ">> Loaded %u C++ scripts in %u ms", GetScriptCount(), GetMSTimeDiffToNow(oldMSTime));
177}
178
180{
181#define SCR_CLEAR(T) \
182 for (SCR_REG_ITR(T) itr = SCR_REG_LST(T).begin(); itr != SCR_REG_LST(T).end(); ++itr) \
183 delete itr->second; \
184 SCR_REG_LST(T).clear();
185
186 // Clear scripts for every script type.
212
213#undef SCR_CLEAR
214
215 for (ExampleScriptContainer::iterator itr = ExampleScripts.begin(); itr != ExampleScripts.end(); ++itr)
216 delete* itr;
217 ExampleScripts.clear();
218
219 delete[] SpellSummary;
220 delete[] UnitAI::AISpellInfo;
221}
222
224{
225 sScriptSystemMgr->LoadScriptWaypoints();
226}
227
229{
231
232 SpellSummary = new TSpellSummary[sSpellMgr->GetSpellInfoStoreSize()];
233
234 SpellInfo const* pTempSpell;
235
236 for (uint32 i = 0; i < sSpellMgr->GetSpellInfoStoreSize(); ++i)
237 {
238 SpellSummary[i].Effects = 0;
239 SpellSummary[i].Targets = 0;
240
241 pTempSpell = sSpellMgr->GetSpellInfo(i);
242 // This spell doesn't exist.
243 if (!pTempSpell)
244 continue;
245
246 for (uint32 j = 0; j < MAX_SPELL_EFFECTS; ++j)
247 {
248 // Spell targets self.
249 if (pTempSpell->Effects[j].TargetA.GetTarget() == TARGET_UNIT_CASTER)
250 SpellSummary[i].Targets |= 1 << (SELECT_TARGET_SELF - 1);
251
252 // Spell targets a single enemy.
253 if (pTempSpell->Effects[j].TargetA.GetTarget() == TARGET_UNIT_TARGET_ENEMY ||
255 SpellSummary[i].Targets |= 1 << (SELECT_TARGET_SINGLE_ENEMY - 1);
256
257 // Spell targets AoE at enemy.
258 if (pTempSpell->Effects[j].TargetA.GetTarget() == TARGET_UNIT_SRC_AREA_ENEMY ||
260 pTempSpell->Effects[j].TargetA.GetTarget() == TARGET_SRC_CASTER ||
262 SpellSummary[i].Targets |= 1 << (SELECT_TARGET_AOE_ENEMY - 1);
263
264 // Spell targets an enemy.
265 if (pTempSpell->Effects[j].TargetA.GetTarget() == TARGET_UNIT_TARGET_ENEMY ||
269 pTempSpell->Effects[j].TargetA.GetTarget() == TARGET_SRC_CASTER ||
271 SpellSummary[i].Targets |= 1 << (SELECT_TARGET_ANY_ENEMY - 1);
272
273 // Spell targets a single friend (or self).
274 if (pTempSpell->Effects[j].TargetA.GetTarget() == TARGET_UNIT_CASTER ||
275 pTempSpell->Effects[j].TargetA.GetTarget() == TARGET_UNIT_TARGET_ALLY ||
277 SpellSummary[i].Targets |= 1 << (SELECT_TARGET_SINGLE_FRIEND - 1);
278
279 // Spell targets AoE friends.
280 if (pTempSpell->Effects[j].TargetA.GetTarget() == TARGET_UNIT_CASTER_AREA_PARTY ||
283 pTempSpell->Effects[j].TargetA.GetTarget() == TARGET_SRC_CASTER)
284 SpellSummary[i].Targets |= 1 << (SELECT_TARGET_AOE_FRIEND - 1);
285
286 // Spell targets any friend (or self).
287 if (pTempSpell->Effects[j].TargetA.GetTarget() == TARGET_UNIT_CASTER ||
288 pTempSpell->Effects[j].TargetA.GetTarget() == TARGET_UNIT_TARGET_ALLY ||
292 pTempSpell->Effects[j].TargetA.GetTarget() == TARGET_SRC_CASTER)
293 SpellSummary[i].Targets |= 1 << (SELECT_TARGET_ANY_FRIEND - 1);
294
295 // Make sure that this spell includes a damage effect.
296 if (pTempSpell->Effects[j].Effect == SPELL_EFFECT_SCHOOL_DAMAGE ||
297 pTempSpell->Effects[j].Effect == SPELL_EFFECT_INSTAKILL ||
299 pTempSpell->Effects[j].Effect == SPELL_EFFECT_HEALTH_LEECH)
300 SpellSummary[i].Effects |= 1 << (SELECT_EFFECT_DAMAGE - 1);
301
302 // Make sure that this spell includes a healing effect (or an apply aura with a periodic heal).
303 if (pTempSpell->Effects[j].Effect == SPELL_EFFECT_HEAL ||
304 pTempSpell->Effects[j].Effect == SPELL_EFFECT_HEAL_MAX_HEALTH ||
305 pTempSpell->Effects[j].Effect == SPELL_EFFECT_HEAL_MECHANICAL ||
306 (pTempSpell->Effects[j].Effect == SPELL_EFFECT_APPLY_AURA && pTempSpell->Effects[j].ApplyAuraName == 8))
307 SpellSummary[i].Effects |= 1 << (SELECT_EFFECT_HEALING - 1);
308
309 // Make sure that this spell applies an aura.
310 if (pTempSpell->Effects[j].Effect == SPELL_EFFECT_APPLY_AURA)
311 SpellSummary[i].Effects |= 1 << (SELECT_EFFECT_AURA - 1);
312 }
313 }
314}
315
316void ScriptMgr::CreateSpellScripts(uint32 spellId, std::list<SpellScript*>& scriptVector)
317{
318 SpellScriptsBounds bounds = sObjectMgr->GetSpellScriptsBounds(spellId);
319
320 for (SpellScriptsContainer::iterator itr = bounds.first; itr != bounds.second; ++itr)
321 {
323 if (!tmpscript)
324 continue;
325
326 SpellScript* script = tmpscript->GetSpellScript();
327
328 if (!script)
329 continue;
330
331 script->_Init(&tmpscript->GetName(), spellId);
332
333 scriptVector.push_back(script);
334 }
335}
336
337void ScriptMgr::CreateAuraScripts(uint32 spellId, std::list<AuraScript*>& scriptVector)
338{
339 SpellScriptsBounds bounds = sObjectMgr->GetSpellScriptsBounds(spellId);
340
341 for (SpellScriptsContainer::iterator itr = bounds.first; itr != bounds.second; ++itr)
342 {
344 if (!tmpscript)
345 continue;
346
347 AuraScript* script = tmpscript->GetAuraScript();
348
349 if (!script)
350 continue;
351
352 script->_Init(&tmpscript->GetName(), spellId);
353
354 scriptVector.push_back(script);
355 }
356}
357
358void ScriptMgr::CreateSpellScriptLoaders(uint32 spellId, std::vector<std::pair<SpellScriptLoader*, SpellScriptsContainer::iterator> >& scriptVector)
359{
360 SpellScriptsBounds bounds = sObjectMgr->GetSpellScriptsBounds(spellId);
361 scriptVector.reserve(std::distance(bounds.first, bounds.second));
362
363 for (SpellScriptsContainer::iterator itr = bounds.first; itr != bounds.second; ++itr)
364 {
366 if (!tmpscript)
367 continue;
368
369 scriptVector.push_back(std::make_pair(tmpscript, itr));
370 }
371}
372
374{
375 FOREACH_SCRIPT(ServerScript)->OnNetworkStart();
376}
377
379{
380 FOREACH_SCRIPT(ServerScript)->OnNetworkStop();
381}
382
384{
385 ASSERT(socket);
386
387 FOREACH_SCRIPT(ServerScript)->OnSocketOpen(socket);
388}
389
390void ScriptMgr::OnSocketClose(WorldSocket* socket, bool wasNew)
391{
392 ASSERT(socket);
393
394 FOREACH_SCRIPT(ServerScript)->OnSocketClose(socket, wasNew);
395}
396
398{
399 ASSERT(socket);
400
401 FOREACH_SCRIPT(ServerScript)->OnPacketReceive(socket, packet);
402}
403
405{
406 ASSERT(socket);
407
408 FOREACH_SCRIPT(ServerScript)->OnPacketSend(socket, packet);
409}
410
412{
413 ASSERT(socket);
414
415 FOREACH_SCRIPT(ServerScript)->OnUnknownPacketReceive(socket, packet);
416}
417
419{
420 FOREACH_SCRIPT(WorldScript)->OnOpenStateChange(open);
421}
422
423void ScriptMgr::OnConfigLoad(bool reload)
424{
425 FOREACH_SCRIPT(WorldScript)->OnConfigLoad(reload);
426}
427
428void ScriptMgr::OnMotdChange(std::string& newMotd)
429{
430 FOREACH_SCRIPT(WorldScript)->OnMotdChange(newMotd);
431}
432
434{
435 FOREACH_SCRIPT(WorldScript)->OnShutdownInitiate(code, mask);
436}
437
439{
440 FOREACH_SCRIPT(WorldScript)->OnShutdownCancel();
441}
442
444{
445 FOREACH_SCRIPT(WorldScript)->OnUpdate(diff);
446}
447
448void ScriptMgr::OnHonorCalculation(float& honor, uint8 level, float multiplier)
449{
450 FOREACH_SCRIPT(FormulaScript)->OnHonorCalculation(honor, level, multiplier);
451}
452
453void ScriptMgr::OnGrayLevelCalculation(uint8& grayLevel, uint8 playerLevel)
454{
455 FOREACH_SCRIPT(FormulaScript)->OnGrayLevelCalculation(grayLevel, playerLevel);
456}
457
458void ScriptMgr::OnColorCodeCalculation(XPColorChar& color, uint8 playerLevel, uint8 mobLevel)
459{
460 FOREACH_SCRIPT(FormulaScript)->OnColorCodeCalculation(color, playerLevel, mobLevel);
461}
462
464{
465 FOREACH_SCRIPT(FormulaScript)->OnZeroDifferenceCalculation(diff, playerLevel);
466}
467
468void ScriptMgr::OnBaseGainCalculation(uint32& gain, uint8 playerLevel, uint8 mobLevel, ContentLevels content)
469{
470 FOREACH_SCRIPT(FormulaScript)->OnBaseGainCalculation(gain, playerLevel, mobLevel, content);
471}
472
474{
475 ASSERT(player);
476 ASSERT(unit);
477
478 FOREACH_SCRIPT(FormulaScript)->OnGainCalculation(gain, player, unit);
479}
480
481void ScriptMgr::OnGroupRateCalculation(float& rate, uint32 count, bool isRaid)
482{
483 FOREACH_SCRIPT(FormulaScript)->OnGroupRateCalculation(rate, count, isRaid);
484}
485
486#define SCR_MAP_BGN(M, V, I, E, C, T) \
487 if (V->GetEntry() && V->GetEntry()->T()) \
488 { \
489 FOR_SCRIPTS(M, I, E) \
490 { \
491 MapEntry const* C = I->second->GetEntry(); \
492 if (!C) \
493 continue; \
494 if (C->MapID == V->GetId()) \
495 {
496#define SCR_MAP_END \
497 return; \
498 } \
499 } \
500 }
501
503{
504 ASSERT(map);
505
506 SCR_MAP_BGN(WorldMapScript, map, itr, end, entry, IsWorldMap);
507 itr->second->OnCreate(map);
509
510 SCR_MAP_BGN(InstanceMapScript, map, itr, end, entry, IsInstance);
511 itr->second->OnCreate((InstanceMap*)map);
513
514 SCR_MAP_BGN(BattlegroundMapScript, map, itr, end, entry, IsBattleground);
515 itr->second->OnCreate((BattlegroundMap*)map);
517}
518
520{
521 ASSERT(map);
522
523 SCR_MAP_BGN(WorldMapScript, map, itr, end, entry, IsWorldMap);
524 itr->second->OnDestroy(map);
526
527 SCR_MAP_BGN(InstanceMapScript, map, itr, end, entry, IsInstance);
528 itr->second->OnDestroy((InstanceMap*)map);
530
531 SCR_MAP_BGN(BattlegroundMapScript, map, itr, end, entry, IsBattleground);
532 itr->second->OnDestroy((BattlegroundMap*)map);
534}
535
537{
538 ASSERT(map);
539 ASSERT(gmap);
540
541 SCR_MAP_BGN(WorldMapScript, map, itr, end, entry, IsWorldMap);
542 itr->second->OnLoadGridMap(map, gmap, gx, gy);
544
545 SCR_MAP_BGN(InstanceMapScript, map, itr, end, entry, IsInstance);
546 itr->second->OnLoadGridMap((InstanceMap*)map, gmap, gx, gy);
548
549 SCR_MAP_BGN(BattlegroundMapScript, map, itr, end, entry, IsBattleground);
550 itr->second->OnLoadGridMap((BattlegroundMap*)map, gmap, gx, gy);
552}
553
555{
556 ASSERT(map);
557 ASSERT(gmap);
558
559 SCR_MAP_BGN(WorldMapScript, map, itr, end, entry, IsWorldMap);
560 itr->second->OnUnloadGridMap(map, gmap, gx, gy);
562
563 SCR_MAP_BGN(InstanceMapScript, map, itr, end, entry, IsInstance);
564 itr->second->OnUnloadGridMap((InstanceMap*)map, gmap, gx, gy);
566
567 SCR_MAP_BGN(BattlegroundMapScript, map, itr, end, entry, IsBattleground);
568 itr->second->OnUnloadGridMap((BattlegroundMap*)map, gmap, gx, gy);
570}
571
573{
574 ASSERT(map);
575 ASSERT(player);
576
577 FOREACH_SCRIPT(PlayerScript)->OnMapChanged(player);
578
579 SCR_MAP_BGN(WorldMapScript, map, itr, end, entry, IsWorldMap);
580 itr->second->OnPlayerEnter(map, player);
582
583 SCR_MAP_BGN(InstanceMapScript, map, itr, end, entry, IsInstance);
584 itr->second->OnPlayerEnter((InstanceMap*)map, player);
586
587 SCR_MAP_BGN(BattlegroundMapScript, map, itr, end, entry, IsBattleground);
588 itr->second->OnPlayerEnter((BattlegroundMap*)map, player);
590}
591
593{
594 ASSERT(map);
595 ASSERT(player);
596
597 SCR_MAP_BGN(WorldMapScript, map, itr, end, entry, IsWorldMap);
598 itr->second->OnPlayerLeave(map, player);
600
601 SCR_MAP_BGN(InstanceMapScript, map, itr, end, entry, IsInstance);
602 itr->second->OnPlayerLeave((InstanceMap*)map, player);
604
605 SCR_MAP_BGN(BattlegroundMapScript, map, itr, end, entry, IsBattleground);
606 itr->second->OnPlayerLeave((BattlegroundMap*)map, player);
608}
609
611{
612 ASSERT(map);
613
614 SCR_MAP_BGN(WorldMapScript, map, itr, end, entry, IsWorldMap);
615 itr->second->OnUpdate(map, diff);
617
618 SCR_MAP_BGN(InstanceMapScript, map, itr, end, entry, IsInstance);
619 itr->second->OnUpdate((InstanceMap*)map, diff);
621
622 SCR_MAP_BGN(BattlegroundMapScript, map, itr, end, entry, IsBattleground);
623 itr->second->OnUpdate((BattlegroundMap*)map, diff);
625}
626
627#undef SCR_MAP_BGN
628#undef SCR_MAP_END
629
631{
632 ASSERT(map);
633
634 GET_SCRIPT_RET(InstanceMapScript, map->GetScriptId(), tmpscript, NULL);
635 return tmpscript->GetInstanceScript(map);
636}
637
638bool ScriptMgr::OnDummyEffect(Unit* caster, uint32 spellId, SpellEffIndex effIndex, Item* target)
639{
640 ASSERT(caster);
641 ASSERT(target);
642
643 GET_SCRIPT_RET(ItemScript, target->GetScriptId(), tmpscript, false);
644 return tmpscript->OnDummyEffect(caster, spellId, effIndex, target);
645}
646
647bool ScriptMgr::OnQuestAccept(Player* player, Item* item, Quest const* quest)
648{
649 ASSERT(player);
650 ASSERT(item);
651 ASSERT(quest);
652
653 GET_SCRIPT_RET(ItemScript, item->GetScriptId(), tmpscript, false);
654 player->PlayerTalkClass->ClearMenus();
655 return tmpscript->OnQuestAccept(player, item, quest);
656}
657
658bool ScriptMgr::OnItemUse(Player* player, Item* item, SpellCastTargets const& targets)
659{
660 ASSERT(player);
661 ASSERT(item);
662
663 GET_SCRIPT_RET(ItemScript, item->GetScriptId(), tmpscript, false);
664 return tmpscript->OnUse(player, item, targets);
665}
666
667bool ScriptMgr::OnItemExpire(Player* player, ItemTemplate const* proto)
668{
669 ASSERT(player);
670 ASSERT(proto);
671
672 GET_SCRIPT_RET(ItemScript, proto->ScriptId, tmpscript, false);
673 return tmpscript->OnExpire(player, proto);
674}
675
676bool ScriptMgr::OnDummyEffect(Unit* caster, uint32 spellId, SpellEffIndex effIndex, Creature* target)
677{
678 ASSERT(caster);
679 ASSERT(target);
680
681 GET_SCRIPT_RET(CreatureScript, target->GetScriptId(), tmpscript, false);
682 return tmpscript->OnDummyEffect(caster, spellId, effIndex, target);
683}
684
686{
687 ASSERT(player);
688 ASSERT(creature);
689
690 GET_SCRIPT_RET(CreatureScript, creature->GetScriptId(), tmpscript, false);
691 player->PlayerTalkClass->ClearMenus();
692 return tmpscript->OnGossipHello(player, creature);
693}
694
695bool ScriptMgr::OnGossipSelect(Player* player, Creature* creature, uint32 sender, uint32 action)
696{
697 ASSERT(player);
698 ASSERT(creature);
699
700 GET_SCRIPT_RET(CreatureScript, creature->GetScriptId(), tmpscript, false);
701 return tmpscript->OnGossipSelect(player, creature, sender, action);
702}
703
704bool ScriptMgr::OnGossipSelectCode(Player* player, Creature* creature, uint32 sender, uint32 action, const char* code)
705{
706 ASSERT(player);
707 ASSERT(creature);
708 ASSERT(code);
709
710 GET_SCRIPT_RET(CreatureScript, creature->GetScriptId(), tmpscript, false);
711 return tmpscript->OnGossipSelectCode(player, creature, sender, action, code);
712}
713
714bool ScriptMgr::OnQuestAccept(Player* player, Creature* creature, Quest const* quest)
715{
716 ASSERT(player);
717 ASSERT(creature);
718 ASSERT(quest);
719
720 GET_SCRIPT_RET(CreatureScript, creature->GetScriptId(), tmpscript, false);
721 player->PlayerTalkClass->ClearMenus();
722 return tmpscript->OnQuestAccept(player, creature, quest);
723}
724
725bool ScriptMgr::OnQuestSelect(Player* player, Creature* creature, Quest const* quest)
726{
727 ASSERT(player);
728 ASSERT(creature);
729 ASSERT(quest);
730
731 GET_SCRIPT_RET(CreatureScript, creature->GetScriptId(), tmpscript, false);
732 player->PlayerTalkClass->ClearMenus();
733 return tmpscript->OnQuestSelect(player, creature, quest);
734}
735
736bool ScriptMgr::OnQuestComplete(Player* player, Creature* creature, Quest const* quest)
737{
738 ASSERT(player);
739 ASSERT(creature);
740 ASSERT(quest);
741
742 GET_SCRIPT_RET(CreatureScript, creature->GetScriptId(), tmpscript, false);
743 player->PlayerTalkClass->ClearMenus();
744 return tmpscript->OnQuestComplete(player, creature, quest);
745}
746
747bool ScriptMgr::OnQuestReward(Player* player, Creature* creature, Quest const* quest, uint32 opt)
748{
749 ASSERT(player);
750 ASSERT(creature);
751 ASSERT(quest);
752
753 GET_SCRIPT_RET(CreatureScript, creature->GetScriptId(), tmpscript, false);
754 player->PlayerTalkClass->ClearMenus();
755 return tmpscript->OnQuestReward(player, creature, quest, opt);
756}
757
759{
760 ASSERT(player);
761 ASSERT(creature);
762
764 GET_SCRIPT_RET(CreatureScript, creature->GetScriptId(), tmpscript, 100);
765 player->PlayerTalkClass->ClearMenus();
766 return tmpscript->GetDialogStatus(player, creature);
767}
768
770{
771 ASSERT(creature);
772
773 GET_SCRIPT_RET(CreatureScript, creature->GetScriptId(), tmpscript, NULL);
774 return tmpscript->GetAI(creature);
775}
776
778{
779 ASSERT(gameobject);
780
781 GET_SCRIPT_RET(GameObjectScript, gameobject->GetScriptId(), tmpscript, NULL);
782 return tmpscript->GetAI(gameobject);
783}
784
786{
787 ASSERT(creature);
788
789 GET_SCRIPT(CreatureScript, creature->GetScriptId(), tmpscript);
790 tmpscript->OnUpdate(creature, diff);
791}
792
794{
795 ASSERT(player);
796 ASSERT(go);
797
798 GET_SCRIPT_RET(GameObjectScript, go->GetScriptId(), tmpscript, false);
799 player->PlayerTalkClass->ClearMenus();
800 return tmpscript->OnGossipHello(player, go);
801}
802
803bool ScriptMgr::OnGossipSelect(Player* player, GameObject* go, uint32 sender, uint32 action)
804{
805 ASSERT(player);
806 ASSERT(go);
807
808 GET_SCRIPT_RET(GameObjectScript, go->GetScriptId(), tmpscript, false);
809 return tmpscript->OnGossipSelect(player, go, sender, action);
810}
811
812bool ScriptMgr::OnGossipSelectCode(Player* player, GameObject* go, uint32 sender, uint32 action, const char* code)
813{
814 ASSERT(player);
815 ASSERT(go);
816 ASSERT(code);
817
818 GET_SCRIPT_RET(GameObjectScript, go->GetScriptId(), tmpscript, false);
819 return tmpscript->OnGossipSelectCode(player, go, sender, action, code);
820}
821
822bool ScriptMgr::OnQuestAccept(Player* player, GameObject* go, Quest const* quest)
823{
824 ASSERT(player);
825 ASSERT(go);
826 ASSERT(quest);
827
828 GET_SCRIPT_RET(GameObjectScript, go->GetScriptId(), tmpscript, false);
829 player->PlayerTalkClass->ClearMenus();
830 return tmpscript->OnQuestAccept(player, go, quest);
831}
832
833bool ScriptMgr::OnQuestReward(Player* player, GameObject* go, Quest const* quest, uint32 opt)
834{
835 ASSERT(player);
836 ASSERT(go);
837 ASSERT(quest);
838
839 GET_SCRIPT_RET(GameObjectScript, go->GetScriptId(), tmpscript, false);
840 player->PlayerTalkClass->ClearMenus();
841 return tmpscript->OnQuestReward(player, go, quest, opt);
842}
843
845{
846 ASSERT(player);
847 ASSERT(go);
848
850 GET_SCRIPT_RET(GameObjectScript, go->GetScriptId(), tmpscript, 100);
851 player->PlayerTalkClass->ClearMenus();
852 return tmpscript->GetDialogStatus(player, go);
853}
854
856{
857 ASSERT(go);
858
859 GET_SCRIPT(GameObjectScript, go->GetScriptId(), tmpscript);
860 tmpscript->OnDestroyed(go, player);
861}
862
864{
865 ASSERT(go);
866
867 GET_SCRIPT(GameObjectScript, go->GetScriptId(), tmpscript);
868 tmpscript->OnDamaged(go, player);
869}
870
872{
873 ASSERT(go);
874
875 GET_SCRIPT(GameObjectScript, go->GetScriptId(), tmpscript);
876 tmpscript->OnLootStateChanged(go, state, unit);
877}
878
880{
881 ASSERT(go);
882
883 GET_SCRIPT(GameObjectScript, go->GetScriptId(), tmpscript);
884 tmpscript->OnGameObjectStateChanged(go, state);
885}
886
888{
889 ASSERT(go);
890
891 GET_SCRIPT(GameObjectScript, go->GetScriptId(), tmpscript);
892 tmpscript->OnUpdate(go, diff);
893}
894
895bool ScriptMgr::OnDummyEffect(Unit* caster, uint32 spellId, SpellEffIndex effIndex, GameObject* target)
896{
897 ASSERT(caster);
898 ASSERT(target);
899
900 GET_SCRIPT_RET(GameObjectScript, target->GetScriptId(), tmpscript, false);
901 return tmpscript->OnDummyEffect(caster, spellId, effIndex, target);
902}
903
905{
906 ASSERT(player);
907 ASSERT(trigger);
908
909 GET_SCRIPT_RET(AreaTriggerScript, sObjectMgr->GetAreaTriggerScriptId(trigger->id), tmpscript, false);
910 return tmpscript->OnTrigger(player, trigger);
911}
912
914{
916 ASSERT(false);
917 return NULL;
918}
919
921{
922 ASSERT(data);
923
924 GET_SCRIPT_RET(OutdoorPvPScript, data->ScriptId, tmpscript, NULL);
925 return tmpscript->GetOutdoorPvP();
926}
927
928std::vector<ChatCommand> ScriptMgr::GetChatCommands()
929{
930 std::vector<ChatCommand> table;
931
933 {
934 std::vector<ChatCommand> cmds = itr->second->GetCommands();
935 table.insert(table.end(), cmds.begin(), cmds.end());
936 }
937
938 return table;
939}
940
941void ScriptMgr::OnWeatherChange(Weather* weather, WeatherState state, float grade)
942{
943 ASSERT(weather);
944
945 GET_SCRIPT(WeatherScript, weather->GetScriptId(), tmpscript);
946 tmpscript->OnChange(weather, state, grade);
947}
948
950{
951 ASSERT(weather);
952
953 GET_SCRIPT(WeatherScript, weather->GetScriptId(), tmpscript);
954 tmpscript->OnUpdate(weather, diff);
955}
956
958{
959 ASSERT(ah);
960 ASSERT(entry);
961
962 FOREACH_SCRIPT(AuctionHouseScript)->OnAuctionAdd(ah, entry);
963}
964
966{
967 ASSERT(ah);
968 ASSERT(entry);
969
970 FOREACH_SCRIPT(AuctionHouseScript)->OnAuctionRemove(ah, entry);
971}
972
974{
975 ASSERT(ah);
976 ASSERT(entry);
977
978 FOREACH_SCRIPT(AuctionHouseScript)->OnAuctionSuccessful(ah, entry);
979}
980
982{
983 ASSERT(ah);
984 ASSERT(entry);
985
986 FOREACH_SCRIPT(AuctionHouseScript)->OnAuctionExpire(ah, entry);
987}
988
990{
991 ASSERT(condition);
992
993 GET_SCRIPT_RET(ConditionScript, condition->ScriptId, tmpscript, true);
994 return tmpscript->OnConditionCheck(condition, sourceInfo);
995}
996
998{
999 ASSERT(veh);
1001
1002 GET_SCRIPT(VehicleScript, veh->GetBase()->ToCreature()->GetScriptId(), tmpscript);
1003 tmpscript->OnInstall(veh);
1004}
1005
1007{
1008 ASSERT(veh);
1010
1011 GET_SCRIPT(VehicleScript, veh->GetBase()->ToCreature()->GetScriptId(), tmpscript);
1012 tmpscript->OnUninstall(veh);
1013}
1014
1016{
1017 ASSERT(veh);
1019
1020 GET_SCRIPT(VehicleScript, veh->GetBase()->ToCreature()->GetScriptId(), tmpscript);
1021 tmpscript->OnReset(veh);
1022}
1023
1025{
1026 ASSERT(veh);
1028 ASSERT(accessory);
1029
1030 GET_SCRIPT(VehicleScript, veh->GetBase()->ToCreature()->GetScriptId(), tmpscript);
1031 tmpscript->OnInstallAccessory(veh, accessory);
1032}
1033
1034void ScriptMgr::OnAddPassenger(Vehicle* veh, Unit* passenger, int8 seatId)
1035{
1036 ASSERT(veh);
1038 ASSERT(passenger);
1039
1040 GET_SCRIPT(VehicleScript, veh->GetBase()->ToCreature()->GetScriptId(), tmpscript);
1041 tmpscript->OnAddPassenger(veh, passenger, seatId);
1042}
1043
1045{
1046 ASSERT(veh);
1048 ASSERT(passenger);
1049
1050 GET_SCRIPT(VehicleScript, veh->GetBase()->ToCreature()->GetScriptId(), tmpscript);
1051 tmpscript->OnRemovePassenger(veh, passenger);
1052}
1053
1055{
1056 ASSERT(dynobj);
1057
1059 itr->second->OnUpdate(dynobj, diff);
1060}
1061
1063{
1064 ASSERT(transport);
1065 ASSERT(player);
1066
1067 GET_SCRIPT(TransportScript, transport->GetScriptId(), tmpscript);
1068 tmpscript->OnAddPassenger(transport, player);
1069}
1070
1072{
1073 ASSERT(transport);
1074 ASSERT(creature);
1075
1076 GET_SCRIPT(TransportScript, transport->GetScriptId(), tmpscript);
1077 tmpscript->OnAddCreaturePassenger(transport, creature);
1078}
1079
1081{
1082 ASSERT(transport);
1083 ASSERT(player);
1084
1085 GET_SCRIPT(TransportScript, transport->GetScriptId(), tmpscript);
1086 tmpscript->OnRemovePassenger(transport, player);
1087}
1088
1090{
1091 ASSERT(transport);
1092
1093 GET_SCRIPT(TransportScript, transport->GetScriptId(), tmpscript);
1094 tmpscript->OnUpdate(transport, diff);
1095}
1096
1097void ScriptMgr::OnRelocate(Transport* transport, uint32 waypointId, uint32 mapId, float x, float y, float z)
1098{
1099 GET_SCRIPT(TransportScript, transport->GetScriptId(), tmpscript);
1100 tmpscript->OnRelocate(transport, waypointId, mapId, x, y, z);
1101}
1102
1104{
1105 FOREACH_SCRIPT(WorldScript)->OnStartup();
1106}
1107
1109{
1110 FOREACH_SCRIPT(WorldScript)->OnShutdown();
1111}
1112
1113bool ScriptMgr::OnCriteriaCheck(uint32 scriptId, Player* source, Unit* target)
1114{
1115 ASSERT(source);
1116 // target can be NULL.
1117
1118 GET_SCRIPT_RET(AchievementCriteriaScript, scriptId, tmpscript, false);
1119 return tmpscript->OnCheck(source, target);
1120}
1121
1122// Player
1123void ScriptMgr::OnPVPKill(Player* killer, Player* killed)
1124{
1125 FOREACH_SCRIPT(PlayerScript)->OnPVPKill(killer, killed);
1126}
1127
1129{
1130 FOREACH_SCRIPT(PlayerScript)->OnCreatureKill(killer, killed);
1131}
1132
1134{
1135 FOREACH_SCRIPT(PlayerScript)->OnPlayerKilledByCreature(killer, killed);
1136}
1137
1139{
1140 FOREACH_SCRIPT(PlayerScript)->OnLevelChanged(player, oldLevel);
1141}
1142
1144{
1145 FOREACH_SCRIPT(PlayerScript)->OnFreeTalentPointsChanged(player, points);
1146}
1147
1148void ScriptMgr::OnPlayerTalentsReset(Player* player, bool noCost)
1149{
1150 FOREACH_SCRIPT(PlayerScript)->OnTalentsReset(player, noCost);
1151}
1152
1154{
1155 FOREACH_SCRIPT(PlayerScript)->OnMoneyChanged(player, amount);
1156}
1157
1158void ScriptMgr::OnGivePlayerXP(Player* player, uint32& amount, Unit* victim)
1159{
1160 FOREACH_SCRIPT(PlayerScript)->OnGiveXP(player, amount, victim);
1161}
1162
1163void ScriptMgr::OnPlayerReputationChange(Player* player, uint32 factionID, int32& standing, bool incremental)
1164{
1165 FOREACH_SCRIPT(PlayerScript)->OnReputationChange(player, factionID, standing, incremental);
1166}
1167
1169{
1170 FOREACH_SCRIPT(PlayerScript)->OnDuelRequest(target, challenger);
1171}
1172
1174{
1175 FOREACH_SCRIPT(PlayerScript)->OnDuelStart(player1, player2);
1176}
1177
1179{
1180 FOREACH_SCRIPT(PlayerScript)->OnDuelEnd(winner, loser, type);
1181}
1182
1183void ScriptMgr::OnPlayerChat(Player* player, ChatMsg type, Language lang, std::string& msg)
1184{
1185 FOREACH_SCRIPT(PlayerScript)->OnChat(player, type, lang, msg);
1186}
1187
1188void ScriptMgr::OnPlayerChat(Player* player, ChatMsg type, Language lang, std::string& msg, Player* receiver)
1189{
1190 FOREACH_SCRIPT(PlayerScript)->OnChat(player, type, lang, msg, receiver);
1191}
1192
1193void ScriptMgr::OnPlayerChat(Player* player, ChatMsg type, Language lang, std::string& msg, Group* group)
1194{
1195 FOREACH_SCRIPT(PlayerScript)->OnChat(player, type, lang, msg, group);
1196}
1197
1198void ScriptMgr::OnPlayerChat(Player* player, ChatMsg type, Language lang, std::string& msg, Guild* guild)
1199{
1200 FOREACH_SCRIPT(PlayerScript)->OnChat(player, type, lang, msg, guild);
1201}
1202
1203void ScriptMgr::OnPlayerChat(Player* player, ChatMsg type, Language lang, std::string& msg, Channel* channel)
1204{
1205 FOREACH_SCRIPT(PlayerScript)->OnChat(player, type, lang, msg, channel);
1206}
1207
1209{
1210 FOREACH_SCRIPT(PlayerScript)->OnEmote(player, emote);
1211}
1212
1213void ScriptMgr::OnPlayerTextEmote(Player* player, uint32 textEmote, uint32 emoteNum, uint64 guid)
1214{
1215 FOREACH_SCRIPT(PlayerScript)->OnTextEmote(player, textEmote, emoteNum, guid);
1216}
1217
1218void ScriptMgr::OnPlayerSpellCast(Player* player, Spell* spell, bool skipCheck)
1219{
1220 FOREACH_SCRIPT(PlayerScript)->OnSpellCast(player, spell, skipCheck);
1221}
1222
1223void ScriptMgr::OnPlayerLogin(Player* player, bool firstLogin)
1224{
1225 FOREACH_SCRIPT(PlayerScript)->OnLogin(player, firstLogin);
1226}
1227
1229{
1230 FOREACH_SCRIPT(PlayerScript)->OnLogout(player);
1231}
1232
1234{
1235 FOREACH_SCRIPT(PlayerScript)->OnCreate(player);
1236}
1237
1239{
1240 FOREACH_SCRIPT(PlayerScript)->OnDelete(guid);
1241}
1242
1244{
1245 FOREACH_SCRIPT(PlayerScript)->OnSave(player);
1246}
1247
1248void ScriptMgr::OnPlayerBindToInstance(Player* player, DifficultyID difficulty, uint32 mapid, bool permanent)
1249{
1250 FOREACH_SCRIPT(PlayerScript)->OnBindToInstance(player, difficulty, mapid, permanent);
1251}
1252
1253void ScriptMgr::OnPlayerUpdateZone(Player* player, uint32 newZone, uint32 newArea)
1254{
1255 FOREACH_SCRIPT(PlayerScript)->OnUpdateZone(player, newZone, newArea);
1256}
1257
1258// Guild
1259void ScriptMgr::OnGuildAddMember(Guild* guild, Player* player, uint8& plRank)
1260{
1261 FOREACH_SCRIPT(GuildScript)->OnAddMember(guild, player, plRank);
1262}
1263
1264void ScriptMgr::OnGuildRemoveMember(Guild* guild, Player* player, bool isDisbanding, bool isKicked)
1265{
1266 FOREACH_SCRIPT(GuildScript)->OnRemoveMember(guild, player, isDisbanding, isKicked);
1267}
1268
1269void ScriptMgr::OnGuildMOTDChanged(Guild* guild, const std::string& newMotd)
1270{
1271 FOREACH_SCRIPT(GuildScript)->OnMOTDChanged(guild, newMotd);
1272}
1273
1274void ScriptMgr::OnGuildInfoChanged(Guild* guild, const std::string& newInfo)
1275{
1276 FOREACH_SCRIPT(GuildScript)->OnInfoChanged(guild, newInfo);
1277}
1278
1279void ScriptMgr::OnGuildCreate(Guild* guild, Player* leader, const std::string& name)
1280{
1281 FOREACH_SCRIPT(GuildScript)->OnCreate(guild, leader, name);
1282}
1283
1285{
1286 FOREACH_SCRIPT(GuildScript)->OnDisband(guild);
1287}
1288
1289void ScriptMgr::OnGuildMemberWitdrawMoney(Guild* guild, Player* player, uint64& amount, bool isRepair)
1290{
1291 FOREACH_SCRIPT(GuildScript)->OnMemberWitdrawMoney(guild, player, amount, isRepair);
1292}
1293
1295{
1296 FOREACH_SCRIPT(GuildScript)->OnMemberDepositMoney(guild, player, amount);
1297}
1298
1299void ScriptMgr::OnGuildItemMove(Guild* guild, Player* player, Item* pItem, bool isSrcBank, uint8 srcContainer, uint8 srcSlotId,
1300 bool isDestBank, uint8 destContainer, uint8 destSlotId)
1301{
1302 FOREACH_SCRIPT(GuildScript)->OnItemMove(guild, player, pItem, isSrcBank, srcContainer, srcSlotId, isDestBank, destContainer, destSlotId);
1303}
1304
1305void ScriptMgr::OnGuildEvent(Guild* guild, uint8 eventType, uint32 playerGuid1, uint32 playerGuid2, uint8 newRank)
1306{
1307 FOREACH_SCRIPT(GuildScript)->OnEvent(guild, eventType, playerGuid1, playerGuid2, newRank);
1308}
1309
1310void ScriptMgr::OnGuildBankEvent(Guild* guild, uint8 eventType, uint8 tabId, uint32 playerGuid, uint32 itemOrMoney, uint16 itemStackCount, uint8 destTabId)
1311{
1312 FOREACH_SCRIPT(GuildScript)->OnBankEvent(guild, eventType, tabId, playerGuid, itemOrMoney, itemStackCount, destTabId);
1313}
1314
1315// Group
1317{
1318 ASSERT(group);
1319 FOREACH_SCRIPT(GroupScript)->OnAddMember(group, guid);
1320}
1321
1323{
1324 ASSERT(group);
1325 FOREACH_SCRIPT(GroupScript)->OnInviteMember(group, guid);
1326}
1327
1328void ScriptMgr::OnGroupRemoveMember(Group* group, uint64 guid, RemoveMethod method, uint64 kicker, const char* reason)
1329{
1330 ASSERT(group);
1331 FOREACH_SCRIPT(GroupScript)->OnRemoveMember(group, guid, method, kicker, reason);
1332}
1333
1334void ScriptMgr::OnGroupChangeLeader(Group* group, uint64 newLeaderGuid, uint64 oldLeaderGuid)
1335{
1336 ASSERT(group);
1337 FOREACH_SCRIPT(GroupScript)->OnChangeLeader(group, newLeaderGuid, oldLeaderGuid);
1338}
1339
1341{
1342 ASSERT(group);
1343 FOREACH_SCRIPT(GroupScript)->OnDisband(group);
1344}
1345
1346// Unit
1347void ScriptMgr::OnHeal(Unit* healer, Unit* reciever, uint32& gain)
1348{
1349 FOREACH_SCRIPT(UnitScript)->OnHeal(healer, reciever, gain);
1350}
1351
1352void ScriptMgr::OnDamage(Unit* attacker, Unit* victim, uint32& damage)
1353{
1354 FOREACH_SCRIPT(UnitScript)->OnDamage(attacker, victim, damage);
1355}
1356
1358{
1359 FOREACH_SCRIPT(UnitScript)->ModifyPeriodicDamageAurasTick(target, attacker, damage);
1360}
1361
1362void ScriptMgr::ModifyMeleeDamage(Unit* target, Unit* attacker, uint32& damage)
1363{
1364 FOREACH_SCRIPT(UnitScript)->ModifyMeleeDamage(target, attacker, damage);
1365}
1366
1367void ScriptMgr::ModifySpellDamageTaken(Unit* target, Unit* attacker, int32& damage)
1368{
1369 FOREACH_SCRIPT(UnitScript)->ModifySpellDamageTaken(target, attacker, damage);
1370}
1371
1377
1379 : ScriptObject(name)
1380{
1382}
1383
1385 : ScriptObject(name)
1386{
1388}
1389
1391 : ScriptObject(name)
1392{
1394}
1395
1396UnitScript::UnitScript(const char* name, bool addToScripts)
1397 : ScriptObject(name)
1398{
1399 if (addToScripts)
1401}
1402
1404 : ScriptObject(name), MapScript<Map>(mapId)
1405{
1406 if (GetEntry() && !GetEntry()->IsWorldMap())
1407 SF_LOG_ERROR("scripts", "WorldMapScript for map %u is invalid.", mapId);
1408
1410}
1411
1413 : ScriptObject(name), MapScript<InstanceMap>(mapId)
1414{
1415 if (GetEntry() && !GetEntry()->IsInstance())
1416 SF_LOG_ERROR("scripts", "InstanceMapScript for map %u is invalid.", mapId);
1417
1419}
1420
1422 : ScriptObject(name), MapScript<BattlegroundMap>(mapId)
1423{
1424 if (GetEntry() && !GetEntry()->IsBattleground())
1425 SF_LOG_ERROR("scripts", "BattlegroundMapScript for map %u is invalid.", mapId);
1426
1428}
1429
1430ItemScript::ItemScript(const char* name)
1431 : ScriptObject(name)
1432{
1434}
1435
1437 : UnitScript(name, false)
1438{
1440}
1441
1447
1453
1459
1465
1467 : ScriptObject(name)
1468{
1470}
1471
1473 : ScriptObject(name)
1474{
1476}
1477
1483
1489
1491 : ScriptObject(name)
1492{
1494}
1495
1501
1507
1513
1515 : UnitScript(name, false)
1516{
1518}
1519
1521 : ScriptObject(name)
1522{
1524}
1525
1527 : ScriptObject(name)
1528{
1530}
1531
1532// Instantiate static members of ScriptRegistry.
1533template<class TScript> std::map<uint32, TScript*> ScriptRegistry<TScript>::ScriptPointerList;
1535
1536// Specialize for each script type class like so:
1538template class ScriptRegistry<ServerScript>;
1539template class ScriptRegistry<WorldScript>;
1540template class ScriptRegistry<FormulaScript>;
1541template class ScriptRegistry<WorldMapScript>;
1544template class ScriptRegistry<ItemScript>;
1545template class ScriptRegistry<CreatureScript>;
1550template class ScriptRegistry<CommandScript>;
1551template class ScriptRegistry<WeatherScript>;
1553template class ScriptRegistry<ConditionScript>;
1554template class ScriptRegistry<VehicleScript>;
1556template class ScriptRegistry<TransportScript>;
1558template class ScriptRegistry<PlayerScript>;
1559template class ScriptRegistry<GuildScript>;
1560template class ScriptRegistry<GroupScript>;
1561template class ScriptRegistry<UnitScript>;
1562
1563// Undefine utility macros.
1564#undef GET_SCRIPT_RET
1565#undef GET_SCRIPT
1566#undef FOREACH_SCRIPT
1567#undef FOR_SCRIPTS_RET
1568#undef FOR_SCRIPTS
1569#undef SCR_REG_LST
1570#undef SCR_REG_ITR
1571#undef SCR_REG_MAP
const AuthHandler table[]
@ SELECT_TARGET_ANY_FRIEND
Definition CreatureAI.h:35
@ SELECT_TARGET_AOE_FRIEND
Definition CreatureAI.h:34
@ SELECT_TARGET_ANY_ENEMY
Definition CreatureAI.h:31
@ SELECT_TARGET_SINGLE_FRIEND
Definition CreatureAI.h:33
@ SELECT_TARGET_SINGLE_ENEMY
Definition CreatureAI.h:29
@ SELECT_TARGET_SELF
Definition CreatureAI.h:27
@ SELECT_TARGET_AOE_ENEMY
Definition CreatureAI.h:30
@ SELECT_EFFECT_AURA
Definition CreatureAI.h:44
@ SELECT_EFFECT_HEALING
Definition CreatureAI.h:43
@ SELECT_EFFECT_DAMAGE
Definition CreatureAI.h:42
DifficultyID
Definition DBCEnums.h:330
ContentLevels
Definition DBCStores.h:37
#define MAX_SPELL_EFFECTS
std::int32_t int32
Definition Define.h:73
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
std::int8_t int8
Definition Define.h:75
std::uint64_t uint64
Definition Define.h:76
std::int64_t int64
Definition Define.h:72
std::uint16_t uint16
Definition Define.h:78
#define ASSERT
Definition Errors.h:29
#define SF_LOG_ERROR(filterType__,...)
Definition Log.h:143
#define SF_LOG_INFO(filterType__,...)
Definition Log.h:137
@ TYPEID_UNIT
Definition Object.h:54
std::pair< SpellScriptsContainer::iterator, SpellScriptsContainer::iterator > SpellScriptsBounds
Definition ObjectMgr.h:382
#define sObjectMgr
Definition ObjectMgr.h:1617
void AddScripts()
#define FOREACH_SCRIPT(T)
#define FOR_SCRIPTS_RET(T, C, E, R)
#define SCR_CLEAR(T)
#define SCR_MAP_END
#define SCR_MAP_BGN(M, V, I, E, C, T)
#define GET_SCRIPT_RET(T, I, V, R)
#define GET_SCRIPT(T, I, V)
#define FOR_SCRIPTS(T, C, E)
#define sScriptMgr
Definition ScriptMgr.h:764
#define sScriptSystemMgr
struct TSpellSummary * SpellSummary
SpellEffIndex
ChatMsg
@ SPELL_EFFECT_HEALTH_LEECH
@ SPELL_EFFECT_HEAL
@ SPELL_EFFECT_HEAL_MAX_HEALTH
@ SPELL_EFFECT_HEAL_MECHANICAL
@ SPELL_EFFECT_ENVIRONMENTAL_DAMAGE
@ SPELL_EFFECT_SCHOOL_DAMAGE
@ SPELL_EFFECT_INSTAKILL
@ SPELL_EFFECT_APPLY_AURA
Language
@ TARGET_UNIT_TARGET_PARTY
@ TARGET_DEST_DYNOBJ_ENEMY
@ TARGET_UNIT_CASTER_AREA_PARTY
@ TARGET_UNIT_DEST_AREA_ENEMY
@ TARGET_UNIT_TARGET_ALLY
@ TARGET_UNIT_SRC_AREA_ENEMY
@ TARGET_UNIT_TARGET_PARTY_TARGET_RAID
@ TARGET_DEST_TARGET_ENEMY
@ TARGET_UNIT_TARGET_ENEMY
@ TARGET_UNIT_LASTTARGET_AREA_PARTY
@ TARGET_UNIT_CASTER
@ TARGET_SRC_CASTER
RemoveMethod
DuelCompleteType
XPColorChar
BattlegroundTypeId
#define sSpellMgr
Definition SpellMgr.h:744
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition Timer.h:22
uint32 getMSTime()
Definition Timer.h:12
virtual void _Init(std::string const *scriptname, uint32 spellId)
AchievementCriteriaScript(const char *name)
AreaTriggerScript(const char *name)
AuctionHouseScript(const char *name)
BattlegroundMapScript(const char *name, uint32 mapId)
BattlegroundScript(const char *name)
CommandScript(const char *name)
ConditionScript(const char *name)
uint32 GetScriptId() const
CreatureScript(const char *name)
DynamicObjectScript(const char *name)
FormulaScript(const char *name)
virtual uint32 GetScriptId() const
Definition GameObject.h:823
GameObjectScript(const char *name)
Definition Map.h:148
Definition Group.h:147
GroupScript(const char *name)
Definition Guild.h:324
GuildScript(const char *name)
uint32 GetScriptId() const
Definition Map.h:646
InstanceMapScript(const char *name, uint32 mapId)
Definition Item.h:202
uint32 GetScriptId() const
Definition Item.h:345
ItemScript(const char *name)
Definition Map.h:238
MapScript(uint32 mapId)
Definition ScriptMgr.h:278
MapEntry const * GetEntry()
Definition ScriptMgr.h:287
TypeID GetTypeId() const
Definition Object.h:131
Creature * ToCreature()
Definition Object.h:207
OutdoorPvPScript(const char *name)
PlayerMenu * PlayerTalkClass
Definition Player.h:2680
void ClearMenus()
PlayerScript(const char *name)
bool OnItemUse(Player *player, Item *item, SpellCastTargets const &targets)
bool OnGossipHello(Player *player, Creature *creature)
void OnPlayerLogin(Player *player, bool firstLogin)
void OnPlayerCreate(Player *player)
void OnBaseGainCalculation(uint32 &gain, uint8 playerLevel, uint8 mobLevel, ContentLevels content)
void OnPlayerTalentsReset(Player *player, bool noCost)
void OnGuildAddMember(Guild *guild, Player *player, uint8 &plRank)
void OnOpenStateChange(bool open)
uint32 GetDialogStatus(Player *player, Creature *creature)
void OnShutdownCancel()
void OnGuildEvent(Guild *guild, uint8 eventType, uint32 playerGuid1, uint32 playerGuid2, uint8 newRank)
void OnPlayerTextEmote(Player *player, uint32 textEmote, uint32 emoteNum, uint64 guid)
void OnGroupChangeLeader(Group *group, uint64 newLeaderGuid, uint64 oldLeaderGuid)
void OnAuctionSuccessful(AuctionHouseObject *ah, AuctionEntry *entry)
void OnShutdown()
void OnPlayerChat(Player *player, ChatMsg type, Language lang, std::string &msg)
void OnPlayerFreeTalentPointsChanged(Player *player, uint32 newPoints)
void OnLoadGridMap(Map *map, GridMap *gmap, uint32 gx, uint32 gy)
void ModifyPeriodicDamageAurasTick(Unit *target, Unit *attacker, uint32 &damage)
bool OnQuestAccept(Player *player, Item *item, Quest const *quest)
void OnHonorCalculation(float &honor, uint8 level, float multiplier)
void OnGameObjectDestroyed(GameObject *go, Player *player)
void FillSpellSummary()
void OnUnknownPacketReceive(WorldSocket *socket, WorldPacket packet)
void OnDestroyMap(Map *map)
void OnGrayLevelCalculation(uint8 &grayLevel, uint8 playerLevel)
Battleground * CreateBattleground(BattlegroundTypeId typeId)
uint32 GetScriptCount() const
Definition ScriptMgr.h:784
void OnGameObjectLootStateChanged(GameObject *go, uint32 state, Unit *unit)
void OnHeal(Unit *healer, Unit *reciever, uint32 &gain)
void OnUninstall(Vehicle *veh)
void OnPlayerLeaveMap(Map *map, Player *player)
void CreateAuraScripts(uint32 spellId, std::list< AuraScript * > &scriptVector)
void OnDynamicObjectUpdate(DynamicObject *dynobj, uint32 diff)
void OnGuildDisband(Guild *guild)
bool OnCriteriaCheck(uint32 scriptId, Player *source, Unit *target)
void OnRemovePassenger(Vehicle *veh, Unit *passenger)
std::vector< ChatCommand > GetChatCommands()
bool OnGossipSelect(Player *player, Creature *creature, uint32 sender, uint32 action)
void Initialize()
void OnAuctionExpire(AuctionHouseObject *ah, AuctionEntry *entry)
void OnPlayerMoneyChanged(Player *player, int64 &amount)
void ModifyMeleeDamage(Unit *target, Unit *attacker, uint32 &damage)
void OnMotdChange(std::string &newMotd)
virtual ~ScriptMgr()
void OnSocketClose(WorldSocket *socket, bool wasNew)
void OnGuildItemMove(Guild *guild, Player *player, Item *pItem, bool isSrcBank, uint8 srcContainer, uint8 srcSlotId, bool isDestBank, uint8 destContainer, uint8 destSlotId)
void OnTransportUpdate(Transport *transport, uint32 diff)
void CreateSpellScripts(uint32 spellId, std::list< SpellScript * > &scriptVector)
void OnGuildRemoveMember(Guild *guild, Player *player, bool isDisbanding, bool isKicked)
bool OnQuestReward(Player *player, Creature *creature, Quest const *quest, uint32 opt)
void OnGroupRemoveMember(Group *group, uint64 guid, RemoveMethod method, uint64 kicker, const char *reason)
void OnPlayerDuelEnd(Player *winner, Player *loser, DuelCompleteType type)
void OnPlayerReputationChange(Player *player, uint32 factionID, int32 &standing, bool incremental)
void OnPlayerSpellCast(Player *player, Spell *spell, bool skipCheck)
bool OnQuestSelect(Player *player, Creature *creature, Quest const *quest)
void OnGroupAddMember(Group *group, uint64 guid)
void OnPVPKill(Player *killer, Player *killed)
void OnCreatureUpdate(Creature *creature, uint32 diff)
void OnWorldUpdate(uint32 diff)
void ModifySpellDamageTaken(Unit *target, Unit *attacker, int32 &damage)
void OnGroupRateCalculation(float &rate, uint32 count, bool isRaid)
GameObjectAI * GetGameObjectAI(GameObject *go)
void OnNetworkStop()
void OnReset(Vehicle *veh)
bool OnGossipSelectCode(Player *player, Creature *creature, uint32 sender, uint32 action, const char *code)
void Unload()
bool OnAreaTrigger(Player *player, AreaTriggerEntry const *trigger)
void OnPlayerDelete(uint64 guid)
void OnGroupDisband(Group *group)
void OnZeroDifferenceCalculation(uint8 &diff, uint8 playerLevel)
void OnPacketSend(WorldSocket *socket, WorldPacket packet)
bool OnDummyEffect(Unit *caster, uint32 spellId, SpellEffIndex effIndex, Item *target)
void OnInstallAccessory(Vehicle *veh, Creature *accessory)
void OnGuildMOTDChanged(Guild *guild, const std::string &newMotd)
void OnDamage(Unit *attacker, Unit *victim, uint32 &damage)
void OnShutdownInitiate(ShutdownExitCode code, ShutdownMask mask)
void OnGuildInfoChanged(Guild *guild, const std::string &newInfo)
void OnPlayerKilledByCreature(Creature *killer, Player *killed)
void OnGainCalculation(uint32 &gain, Player *player, Unit *unit)
void OnPlayerLevelChanged(Player *player, uint8 oldLevel)
void OnPlayerSave(Player *player)
void OnGuildBankEvent(Guild *guild, uint8 eventType, uint8 tabId, uint32 playerGuid, uint32 itemOrMoney, uint16 itemStackCount, uint8 destTabId)
void OnGameObjectDamaged(GameObject *go, Player *player)
void OnGroupInviteMember(Group *group, uint64 guid)
void OnPacketReceive(WorldSocket *socket, WorldPacket packet)
void OnGuildMemberDepositMoney(Guild *guild, Player *player, uint64 &amount)
void OnPlayerLogout(Player *player)
void OnGivePlayerXP(Player *player, uint32 &amount, Unit *victim)
void OnPlayerEmote(Player *player, uint32 emote)
void OnPlayerDuelRequest(Player *target, Player *challenger)
void OnConfigLoad(bool reload)
void OnMapUpdate(Map *map, uint32 diff)
CreatureAI * GetCreatureAI(Creature *creature)
void LoadDatabase()
void OnUnloadGridMap(Map *map, GridMap *gmap, uint32 gx, uint32 gy)
void OnPlayerEnterMap(Map *map, Player *player)
void OnInstall(Vehicle *veh)
OutdoorPvP * CreateOutdoorPvP(OutdoorPvPData const *data)
InstanceScript * CreateInstanceData(InstanceMap *map)
bool OnConditionCheck(Condition *condition, ConditionSourceInfo &sourceInfo)
void CreateSpellScriptLoaders(uint32 spellId, std::vector< std::pair< SpellScriptLoader *, std::multimap< uint32, uint32 >::iterator > > &scriptVector)
void OnGameObjectUpdate(GameObject *go, uint32 diff)
void OnWeatherUpdate(Weather *weather, uint32 diff)
bool OnQuestComplete(Player *player, Creature *creature, Quest const *quest)
uint32 _scriptCount
Definition ScriptMgr.h:978
void OnColorCodeCalculation(XPColorChar &color, uint8 playerLevel, uint8 mobLevel)
std::atomic< long > _scheduledScripts
Definition ScriptMgr.h:981
void OnPlayerUpdateZone(Player *player, uint32 newZone, uint32 newArea)
void OnRelocate(Transport *transport, uint32 waypointId, uint32 mapId, float x, float y, float z)
void OnStartup()
void OnPlayerBindToInstance(Player *player, DifficultyID difficulty, uint32 mapid, bool permanent)
void OnCreatureKill(Player *killer, Creature *killed)
void OnGuildCreate(Guild *guild, Player *leader, const std::string &name)
void OnAuctionAdd(AuctionHouseObject *ah, AuctionEntry *entry)
void OnAddCreaturePassenger(Transport *transport, Creature *creature)
void OnPlayerDuelStart(Player *player1, Player *player2)
void OnGuildMemberWitdrawMoney(Guild *guild, Player *player, uint64 &amount, bool isRepair)
void OnAuctionRemove(AuctionHouseObject *ah, AuctionEntry *entry)
void OnGameObjectStateChanged(GameObject *go, uint32 state)
void OnSocketOpen(WorldSocket *socket)
void OnNetworkStart()
void OnWeatherChange(Weather *weather, WeatherState state, float grade)
bool OnItemExpire(Player *player, ItemTemplate const *proto)
void OnCreateMap(Map *map)
void OnAddPassenger(Vehicle *veh, Unit *passenger, int8 seatId)
const std::string & GetName() const
Definition ScriptMgr.h:146
ScriptObject(const char *name)
Definition ScriptMgr.h:149
std::map< uint32, TScript * > ScriptMap
Definition ScriptMgr.cpp:35
static TScript * GetScriptById(uint32 id)
static uint32 _scriptIdCounter
static ScriptMap ScriptPointerList
Definition ScriptMgr.cpp:40
ScriptMap::iterator ScriptMapIterator
Definition ScriptMgr.cpp:36
static void AddScript(TScript *const script)
Definition ScriptMgr.cpp:42
ServerScript(const char *name)
uint32 ApplyAuraName
Definition SpellInfo.h:90
SpellImplicitTargetInfo TargetA
Definition SpellInfo.h:102
Definition Spell.h:289
SpellEffectInfo Effects[MAX_SPELL_EFFECTS]
Definition SpellInfo.h:255
SpellScriptLoader(const char *name)
virtual SpellScript * GetSpellScript() const
Definition ScriptMgr.h:176
virtual AuraScript * GetAuraScript() const
Definition ScriptMgr.h:179
TransportScript(const char *name)
static void FillAISpellInfo()
Definition UnitAI.cpp:186
static AISpellInfoType * AISpellInfo
Definition UnitAI.h:242
Definition Unit.h:1367
UnitScript(const char *name, bool addToScripts=true)
Unit * GetBase() const
May be called from scripts.
Definition Vehicle.h:38
VehicleScript(const char *name)
Weather for one zone.
Definition Weather.h:53
WeatherScript(const char *name)
WorldMapScript(const char *name, uint32 mapId)
WorldScript(const char *name)
Handler that can communicate over stream sockets.
Definition WorldSocket.h:51
uint32 GetScriptId() const
Definition Weather.h:67
ShutdownMask
Definition World.h:57
WeatherState
Definition Weather.h:34
ShutdownExitCode
Definition World.h:63
uint32 id
uint32 ScriptId