26 typedef std::set<ScriptObject*> ExampleScriptContainer;
27 ExampleScriptContainer ExampleScripts;
31template<
class TScript>
50 if (it->second == script)
52 SF_LOG_ERROR(
"scripts",
"Script '%s' has same memory pointer as '%s'.",
53 script->GetName().c_str(), it->second->GetName().c_str());
59 if (script->IsDatabaseBound())
67 bool existing =
false;
71 if (it->second->GetName() == script->GetName())
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());
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());
102 ExampleScripts.insert(script);
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
134#define FOR_SCRIPTS(T, C, E) \
135 if (SCR_REG_LST(T).empty()) \
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()) \
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) \
149#define GET_SCRIPT(T, I, V) \
150 T* V = ScriptRegistry<T>::GetScriptById(I); \
153#define GET_SCRIPT_RET(T, I, V, R) \
154 T* V = ScriptRegistry<T>::GetScriptById(I); \
171 SF_LOG_INFO(
"server.loading",
"Loading C++ scripts");
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();
215 for (ExampleScriptContainer::iterator itr = ExampleScripts.begin(); itr != ExampleScripts.end(); ++itr)
217 ExampleScripts.clear();
320 for (SpellScriptsContainer::iterator itr = bounds.first; itr != bounds.second; ++itr)
333 scriptVector.push_back(script);
341 for (SpellScriptsContainer::iterator itr = bounds.first; itr != bounds.second; ++itr)
354 scriptVector.push_back(script);
361 scriptVector.reserve(std::distance(bounds.first, bounds.second));
363 for (SpellScriptsContainer::iterator itr = bounds.first; itr != bounds.second; ++itr)
369 scriptVector.push_back(std::make_pair(tmpscript, itr));
486#define SCR_MAP_BGN(M, V, I, E, C, T) \
487 if (V->GetEntry() && V->GetEntry()->T()) \
489 FOR_SCRIPTS(M, I, E) \
491 MapEntry const* C = I->second->GetEntry(); \
494 if (C->MapID == V->GetId()) \
507 itr->second->OnCreate(map);
524 itr->second->OnDestroy(map);
542 itr->second->OnLoadGridMap(map, gmap, gx, gy);
546 itr->second->OnLoadGridMap((
InstanceMap*)map, gmap, gx, gy);
560 itr->second->OnUnloadGridMap(map, gmap, gx, gy);
564 itr->second->OnUnloadGridMap((
InstanceMap*)map, gmap, gx, gy);
580 itr->second->OnPlayerEnter(map, player);
584 itr->second->OnPlayerEnter((
InstanceMap*)map, player);
598 itr->second->OnPlayerLeave(map, player);
602 itr->second->OnPlayerLeave((
InstanceMap*)map, player);
615 itr->second->OnUpdate(map, diff);
635 return tmpscript->GetInstanceScript(map);
644 return tmpscript->OnDummyEffect(caster, spellId, effIndex, target);
655 return tmpscript->OnQuestAccept(player, item, quest);
664 return tmpscript->OnUse(player, item, targets);
673 return tmpscript->OnExpire(player, proto);
682 return tmpscript->OnDummyEffect(caster, spellId, effIndex, target);
692 return tmpscript->OnGossipHello(player, creature);
701 return tmpscript->OnGossipSelect(player, creature, sender, action);
711 return tmpscript->OnGossipSelectCode(player, creature, sender, action, code);
722 return tmpscript->OnQuestAccept(player, creature, quest);
733 return tmpscript->OnQuestSelect(player, creature, quest);
744 return tmpscript->OnQuestComplete(player, creature, quest);
755 return tmpscript->OnQuestReward(player, creature, quest, opt);
766 return tmpscript->GetDialogStatus(player, creature);
774 return tmpscript->GetAI(creature);
782 return tmpscript->GetAI(gameobject);
790 tmpscript->OnUpdate(creature, diff);
800 return tmpscript->OnGossipHello(player, go);
809 return tmpscript->OnGossipSelect(player, go, sender, action);
819 return tmpscript->OnGossipSelectCode(player, go, sender, action, code);
830 return tmpscript->OnQuestAccept(player, go, quest);
841 return tmpscript->OnQuestReward(player, go, quest, opt);
852 return tmpscript->GetDialogStatus(player, go);
860 tmpscript->OnDestroyed(go, player);
868 tmpscript->OnDamaged(go, player);
876 tmpscript->OnLootStateChanged(go, state, unit);
884 tmpscript->OnGameObjectStateChanged(go, state);
892 tmpscript->OnUpdate(go, diff);
901 return tmpscript->OnDummyEffect(caster, spellId, effIndex, target);
910 return tmpscript->OnTrigger(player, trigger);
925 return tmpscript->GetOutdoorPvP();
930 std::vector<ChatCommand>
table;
934 std::vector<ChatCommand> cmds = itr->second->GetCommands();
935 table.insert(
table.end(), cmds.begin(), cmds.end());
946 tmpscript->OnChange(weather, state, grade);
954 tmpscript->OnUpdate(weather, diff);
994 return tmpscript->OnConditionCheck(condition, sourceInfo);
1003 tmpscript->OnInstall(veh);
1012 tmpscript->OnUninstall(veh);
1021 tmpscript->OnReset(veh);
1031 tmpscript->OnInstallAccessory(veh, accessory);
1041 tmpscript->OnAddPassenger(veh, passenger, seatId);
1051 tmpscript->OnRemovePassenger(veh, passenger);
1059 itr->second->OnUpdate(dynobj, diff);
1068 tmpscript->OnAddPassenger(transport, player);
1077 tmpscript->OnAddCreaturePassenger(transport, creature);
1086 tmpscript->OnRemovePassenger(transport, player);
1094 tmpscript->OnUpdate(transport, diff);
1100 tmpscript->OnRelocate(transport, waypointId, mapId, x, y, z);
1119 return tmpscript->OnCheck(source, target);
1300 bool isDestBank,
uint8 destContainer,
uint8 destSlotId)
1302 FOREACH_SCRIPT(
GuildScript)->OnItemMove(guild, player, pItem, isSrcBank, srcContainer, srcSlotId, isDestBank, destContainer, destSlotId);
1407 SF_LOG_ERROR(
"scripts",
"WorldMapScript for map %u is invalid.", mapId);
1416 SF_LOG_ERROR(
"scripts",
"InstanceMapScript for map %u is invalid.", mapId);
1425 SF_LOG_ERROR(
"scripts",
"BattlegroundMapScript for map %u is invalid.", mapId);
1564#undef GET_SCRIPT_RET
1566#undef FOREACH_SCRIPT
1567#undef FOR_SCRIPTS_RET
const AuthHandler table[]
@ SELECT_TARGET_ANY_FRIEND
@ SELECT_TARGET_AOE_FRIEND
@ SELECT_TARGET_ANY_ENEMY
@ SELECT_TARGET_SINGLE_FRIEND
@ SELECT_TARGET_SINGLE_ENEMY
@ SELECT_TARGET_AOE_ENEMY
#define MAX_SPELL_EFFECTS
#define SF_LOG_ERROR(filterType__,...)
#define SF_LOG_INFO(filterType__,...)
std::pair< SpellScriptsContainer::iterator, SpellScriptsContainer::iterator > SpellScriptsBounds
#define FOREACH_SCRIPT(T)
#define FOR_SCRIPTS_RET(T, C, E, R)
#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)
struct TSpellSummary * SpellSummary
@ SPELL_EFFECT_HEALTH_LEECH
@ SPELL_EFFECT_HEAL_MAX_HEALTH
@ SPELL_EFFECT_HEAL_MECHANICAL
@ SPELL_EFFECT_ENVIRONMENTAL_DAMAGE
@ SPELL_EFFECT_SCHOOL_DAMAGE
@ SPELL_EFFECT_APPLY_AURA
@ 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
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
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)
virtual uint32 GetScriptId() const
GameObjectScript(const char *name)
GroupScript(const char *name)
GuildScript(const char *name)
uint32 GetScriptId() const
InstanceMapScript(const char *name, uint32 mapId)
uint32 GetScriptId() const
ItemScript(const char *name)
MapEntry const * GetEntry()
OutdoorPvPScript(const char *name)
PlayerMenu * PlayerTalkClass
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 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 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 OnUnknownPacketReceive(WorldSocket *socket, WorldPacket packet)
void OnDestroyMap(Map *map)
void OnGrayLevelCalculation(uint8 &grayLevel, uint8 playerLevel)
Battleground * CreateBattleground(BattlegroundTypeId typeId)
uint32 GetScriptCount() const
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 OnAuctionExpire(AuctionHouseObject *ah, AuctionEntry *entry)
void OnPlayerMoneyChanged(Player *player, int64 &amount)
void ModifyMeleeDamage(Unit *target, Unit *attacker, uint32 &damage)
void OnMotdChange(std::string &newMotd)
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 OnReset(Vehicle *veh)
bool OnGossipSelectCode(Player *player, Creature *creature, uint32 sender, uint32 action, const char *code)
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 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)
void OnColorCodeCalculation(XPColorChar &color, uint8 playerLevel, uint8 mobLevel)
std::atomic< long > _scheduledScripts
void OnPlayerUpdateZone(Player *player, uint32 newZone, uint32 newArea)
void OnRelocate(Transport *transport, uint32 waypointId, uint32 mapId, float x, float y, float z)
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 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
ScriptObject(const char *name)
std::map< uint32, TScript * > ScriptMap
static TScript * GetScriptById(uint32 id)
static uint32 _scriptIdCounter
static ScriptMap ScriptPointerList
ScriptMap::iterator ScriptMapIterator
static void AddScript(TScript *const script)
ServerScript(const char *name)
SpellImplicitTargetInfo TargetA
Targets GetTarget() const
SpellEffectInfo Effects[MAX_SPELL_EFFECTS]
SpellScriptLoader(const char *name)
virtual SpellScript * GetSpellScript() const
virtual AuraScript * GetAuraScript() const
TransportScript(const char *name)
static void FillAISpellInfo()
static AISpellInfoType * AISpellInfo
UnitScript(const char *name, bool addToScripts=true)
Unit * GetBase() const
May be called from scripts.
VehicleScript(const char *name)
WeatherScript(const char *name)
WorldMapScript(const char *name, uint32 mapId)
WorldScript(const char *name)
Handler that can communicate over stream sockets.
uint32 GetScriptId() const