mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-19 08:55:32 +01:00
Re-commit 262 due to EOL issues. (no difference from 262)
--HG-- branch : trunk
This commit is contained in:
@@ -17,7 +17,8 @@
|
||||
#endif _TRINITY_SCRIPT_CONFIG
|
||||
|
||||
//*** Global data ***
|
||||
int nrscripts;
|
||||
int num_db_scripts;
|
||||
int num_sc_scripts;
|
||||
Script *m_scripts[MAX_SCRIPTS];
|
||||
|
||||
DatabaseType TScriptDB;
|
||||
@@ -47,7 +48,6 @@ enum ChatType
|
||||
// Text Maps
|
||||
UNORDERED_MAP<int32, StringTextData> TextMap;
|
||||
|
||||
|
||||
//*** End Global data ***
|
||||
|
||||
//*** EventAI data ***
|
||||
@@ -1180,15 +1180,16 @@ struct TSpellSummary {
|
||||
|
||||
TRINITY_DLL_EXPORT
|
||||
void ScriptsFree()
|
||||
{
|
||||
{
|
||||
// Free Spell Summary
|
||||
delete []SpellSummary;
|
||||
|
||||
// Free resources before library unload
|
||||
for(int i=0;i<nrscripts;i++)
|
||||
for(int i=0;i<num_db_scripts;i++)
|
||||
delete m_scripts[i];
|
||||
|
||||
nrscripts = 0;
|
||||
num_db_scripts = 0;
|
||||
num_sc_scripts = 0;
|
||||
}
|
||||
|
||||
TRINITY_DLL_EXPORT
|
||||
@@ -1239,12 +1240,13 @@ void ScriptsInit()
|
||||
if (CanLoadDB)
|
||||
LoadDatabase();
|
||||
|
||||
num_db_scripts = GetScriptNames().size();
|
||||
|
||||
outstring_log("TSCR: Loading C++ scripts");
|
||||
barGoLink bar(1);
|
||||
bar.step();
|
||||
outstring_log("");
|
||||
|
||||
nrscripts = 0;
|
||||
for(int i=0;i<MAX_SCRIPTS;i++)
|
||||
m_scripts[i]=NULL;
|
||||
|
||||
@@ -1775,8 +1777,7 @@ void ScriptsInit()
|
||||
|
||||
// -------------------
|
||||
|
||||
outstring_log("TSCR: Loaded %u C++ Scripts", nrscripts);
|
||||
outstring_log("");
|
||||
outstring_log(">> Loaded %i C++ Scripts (of %i ScriptNames defined in Mangos database)", num_sc_scripts, num_db_scripts);
|
||||
}
|
||||
|
||||
//*********************************
|
||||
@@ -1848,32 +1849,29 @@ void DoScriptText(int32 textEntry, WorldObject* pSource, Unit* target)
|
||||
//*********************************
|
||||
//*** Functions used internally ***
|
||||
|
||||
TRINITY_DLL_EXPORT
|
||||
char const* ScriptsVersion()
|
||||
void Script::RegisterSelf()
|
||||
{
|
||||
return "Default Trinity scripting library";
|
||||
}
|
||||
|
||||
Script* GetScriptByName(std::string Name)
|
||||
{
|
||||
if (Name.empty())
|
||||
return NULL;
|
||||
|
||||
for(int i=0;i<MAX_SCRIPTS;i++)
|
||||
int id = GetScriptId(Name.c_str());
|
||||
if (id != 0)
|
||||
{
|
||||
if (m_scripts[i] && m_scripts[i]->Name == Name)
|
||||
return m_scripts[i];
|
||||
}
|
||||
return NULL;
|
||||
m_scripts[id] = this;
|
||||
++num_sc_scripts;
|
||||
} else
|
||||
debug_log("SD2: RegisterSelf, but script named %s does not have ScriptName assigned in database.",(this)->Name.c_str());
|
||||
}
|
||||
|
||||
//********************************
|
||||
//*** Functions to be Exported ***
|
||||
|
||||
TRINITY_DLL_EXPORT
|
||||
char const* ScriptsVersion()
|
||||
{
|
||||
return "Default Trinity scripting library";
|
||||
}
|
||||
TRINITY_DLL_EXPORT
|
||||
bool GossipHello ( Player * player, Creature *_Creature )
|
||||
{
|
||||
Script *tmpscript = GetScriptByName(_Creature->GetScriptName());
|
||||
Script *tmpscript = m_scripts[_Creature->GetScriptId()];
|
||||
if (!tmpscript || !tmpscript->pGossipHello) return false;
|
||||
|
||||
player->PlayerTalkClass->ClearMenus();
|
||||
@@ -1885,7 +1883,7 @@ bool GossipSelect( Player *player, Creature *_Creature, uint32 sender, uint32 ac
|
||||
{
|
||||
debug_log("TSCR: Gossip selection, sender: %d, action: %d",sender, action);
|
||||
|
||||
Script *tmpscript = GetScriptByName(_Creature->GetScriptName());
|
||||
Script *tmpscript = m_scripts[_Creature->GetScriptId()];
|
||||
if (!tmpscript || !tmpscript->pGossipSelect) return false;
|
||||
|
||||
player->PlayerTalkClass->ClearMenus();
|
||||
@@ -1897,7 +1895,7 @@ bool GossipSelectWithCode( Player *player, Creature *_Creature, uint32 sender, u
|
||||
{
|
||||
debug_log("TSCR: Gossip selection with code, sender: %d, action: %d",sender, action);
|
||||
|
||||
Script *tmpscript = GetScriptByName(_Creature->GetScriptName());
|
||||
Script *tmpscript = m_scripts[_Creature->GetScriptId()];
|
||||
if (!tmpscript || !tmpscript->pGossipSelectWithCode) return false;
|
||||
|
||||
player->PlayerTalkClass->ClearMenus();
|
||||
@@ -1907,7 +1905,7 @@ bool GossipSelectWithCode( Player *player, Creature *_Creature, uint32 sender, u
|
||||
TRINITY_DLL_EXPORT
|
||||
bool QuestAccept( Player *player, Creature *_Creature, Quest const *_Quest )
|
||||
{
|
||||
Script *tmpscript = GetScriptByName(_Creature->GetScriptName());
|
||||
Script *tmpscript = m_scripts[_Creature->GetScriptId()];
|
||||
if (!tmpscript || !tmpscript->pQuestAccept) return false;
|
||||
|
||||
player->PlayerTalkClass->ClearMenus();
|
||||
@@ -1917,7 +1915,7 @@ bool QuestAccept( Player *player, Creature *_Creature, Quest const *_Quest )
|
||||
TRINITY_DLL_EXPORT
|
||||
bool QuestSelect( Player *player, Creature *_Creature, Quest const *_Quest )
|
||||
{
|
||||
Script *tmpscript = GetScriptByName(_Creature->GetScriptName());
|
||||
Script *tmpscript = m_scripts[_Creature->GetScriptId()];
|
||||
if (!tmpscript || !tmpscript->pQuestSelect) return false;
|
||||
|
||||
player->PlayerTalkClass->ClearMenus();
|
||||
@@ -1927,7 +1925,7 @@ bool QuestSelect( Player *player, Creature *_Creature, Quest const *_Quest )
|
||||
TRINITY_DLL_EXPORT
|
||||
bool QuestComplete( Player *player, Creature *_Creature, Quest const *_Quest )
|
||||
{
|
||||
Script *tmpscript = GetScriptByName(_Creature->GetScriptName());
|
||||
Script *tmpscript = m_scripts[_Creature->GetScriptId()];
|
||||
if (!tmpscript || !tmpscript->pQuestComplete) return false;
|
||||
|
||||
player->PlayerTalkClass->ClearMenus();
|
||||
@@ -1937,7 +1935,7 @@ bool QuestComplete( Player *player, Creature *_Creature, Quest const *_Quest )
|
||||
TRINITY_DLL_EXPORT
|
||||
bool ChooseReward( Player *player, Creature *_Creature, Quest const *_Quest, uint32 opt )
|
||||
{
|
||||
Script *tmpscript = GetScriptByName(_Creature->GetScriptName());
|
||||
Script *tmpscript = m_scripts[_Creature->GetScriptId()];
|
||||
if (!tmpscript || !tmpscript->pChooseReward) return false;
|
||||
|
||||
player->PlayerTalkClass->ClearMenus();
|
||||
@@ -1947,7 +1945,7 @@ bool ChooseReward( Player *player, Creature *_Creature, Quest const *_Quest, uin
|
||||
TRINITY_DLL_EXPORT
|
||||
uint32 NPCDialogStatus( Player *player, Creature *_Creature )
|
||||
{
|
||||
Script *tmpscript = GetScriptByName(_Creature->GetScriptName());
|
||||
Script *tmpscript = m_scripts[_Creature->GetScriptId()];
|
||||
if (!tmpscript || !tmpscript->pNPCDialogStatus) return 100;
|
||||
|
||||
player->PlayerTalkClass->ClearMenus();
|
||||
@@ -1957,8 +1955,8 @@ uint32 NPCDialogStatus( Player *player, Creature *_Creature )
|
||||
TRINITY_DLL_EXPORT
|
||||
uint32 GODialogStatus( Player *player, GameObject *_GO )
|
||||
{
|
||||
Script *tmpscript = GetScriptByName(_GO->GetGOInfo()->ScriptName);
|
||||
if(!tmpscript || !tmpscript->pGODialogStatus) return 100;
|
||||
Script *tmpscript = m_scripts[_GO->GetGOInfo()->ScriptId];
|
||||
if (!tmpscript || !tmpscript->pGODialogStatus) return 100;
|
||||
|
||||
player->PlayerTalkClass->ClearMenus();
|
||||
return tmpscript->pGODialogStatus(player,_GO);
|
||||
@@ -1967,7 +1965,7 @@ uint32 GODialogStatus( Player *player, GameObject *_GO )
|
||||
TRINITY_DLL_EXPORT
|
||||
bool ItemHello( Player *player, Item *_Item, Quest const *_Quest )
|
||||
{
|
||||
Script *tmpscript = GetScriptByName(_Item->GetProto()->ScriptName);
|
||||
Script *tmpscript = m_scripts[_Item->GetProto()->ScriptId];
|
||||
if (!tmpscript || !tmpscript->pItemHello) return false;
|
||||
|
||||
player->PlayerTalkClass->ClearMenus();
|
||||
@@ -1977,7 +1975,7 @@ bool ItemHello( Player *player, Item *_Item, Quest const *_Quest )
|
||||
TRINITY_DLL_EXPORT
|
||||
bool ItemQuestAccept( Player *player, Item *_Item, Quest const *_Quest )
|
||||
{
|
||||
Script *tmpscript = GetScriptByName(_Item->GetProto()->ScriptName);
|
||||
Script *tmpscript = m_scripts[_Item->GetProto()->ScriptId];
|
||||
if (!tmpscript || !tmpscript->pItemQuestAccept) return false;
|
||||
|
||||
player->PlayerTalkClass->ClearMenus();
|
||||
@@ -1987,7 +1985,7 @@ bool ItemQuestAccept( Player *player, Item *_Item, Quest const *_Quest )
|
||||
TRINITY_DLL_EXPORT
|
||||
bool GOHello( Player *player, GameObject *_GO )
|
||||
{
|
||||
Script *tmpscript = GetScriptByName(_GO->GetGOInfo()->ScriptName);
|
||||
Script *tmpscript = m_scripts[_GO->GetGOInfo()->ScriptId];
|
||||
if (!tmpscript || !tmpscript->pGOHello) return false;
|
||||
|
||||
player->PlayerTalkClass->ClearMenus();
|
||||
@@ -1997,7 +1995,7 @@ bool GOHello( Player *player, GameObject *_GO )
|
||||
TRINITY_DLL_EXPORT
|
||||
bool GOQuestAccept( Player *player, GameObject *_GO, Quest const *_Quest )
|
||||
{
|
||||
Script *tmpscript = GetScriptByName(_GO->GetGOInfo()->ScriptName);
|
||||
Script *tmpscript = m_scripts[_GO->GetGOInfo()->ScriptId];
|
||||
if (!tmpscript || !tmpscript->pGOQuestAccept) return false;
|
||||
|
||||
player->PlayerTalkClass->ClearMenus();
|
||||
@@ -2007,7 +2005,7 @@ bool GOQuestAccept( Player *player, GameObject *_GO, Quest const *_Quest )
|
||||
TRINITY_DLL_EXPORT
|
||||
bool GOChooseReward( Player *player, GameObject *_GO, Quest const *_Quest, uint32 opt )
|
||||
{
|
||||
Script *tmpscript = GetScriptByName(_GO->GetGOInfo()->ScriptName);
|
||||
Script *tmpscript = m_scripts[_GO->GetGOInfo()->ScriptId];
|
||||
if (!tmpscript || !tmpscript->pGOChooseReward) return false;
|
||||
|
||||
player->PlayerTalkClass->ClearMenus();
|
||||
@@ -2017,9 +2015,7 @@ bool GOChooseReward( Player *player, GameObject *_GO, Quest const *_Quest, uint3
|
||||
TRINITY_DLL_EXPORT
|
||||
bool AreaTrigger( Player *player, AreaTriggerEntry * atEntry)
|
||||
{
|
||||
Script *tmpscript = NULL;
|
||||
|
||||
tmpscript = GetScriptByName(GetAreaTriggerScriptNameById(atEntry->id));
|
||||
Script *tmpscript = m_scripts[GetAreaTriggerScriptId(atEntry->id)];
|
||||
if (!tmpscript || !tmpscript->pAreaTrigger) return false;
|
||||
|
||||
return tmpscript->pAreaTrigger(player, atEntry);
|
||||
@@ -2028,16 +2024,16 @@ bool AreaTrigger( Player *player, AreaTriggerEntry * atEntry)
|
||||
TRINITY_DLL_EXPORT
|
||||
CreatureAI* GetAI(Creature *_Creature)
|
||||
{
|
||||
Script *tmpscript = GetScriptByName(_Creature->GetScriptName());
|
||||
|
||||
Script *tmpscript = m_scripts[_Creature->GetScriptId()];
|
||||
if (!tmpscript || !tmpscript->GetAI) return NULL;
|
||||
|
||||
return tmpscript->GetAI(_Creature);
|
||||
}
|
||||
|
||||
TRINITY_DLL_EXPORT
|
||||
bool ItemUse( Player *player, Item* _Item, SpellCastTargets const& targets)
|
||||
{
|
||||
Script *tmpscript = GetScriptByName(_Item->GetProto()->ScriptName);
|
||||
Script *tmpscript = m_scripts[_Item->GetProto()->ScriptId];
|
||||
if (!tmpscript || !tmpscript->pItemUse) return false;
|
||||
|
||||
return tmpscript->pItemUse(player,_Item,targets);
|
||||
@@ -2046,7 +2042,7 @@ bool ItemUse( Player *player, Item* _Item, SpellCastTargets const& targets)
|
||||
TRINITY_DLL_EXPORT
|
||||
bool ReceiveEmote( Player *player, Creature *_Creature, uint32 emote )
|
||||
{
|
||||
Script *tmpscript = GetScriptByName(_Creature->GetScriptName());
|
||||
Script *tmpscript = m_scripts[_Creature->GetScriptId()];
|
||||
if (!tmpscript || !tmpscript->pReceiveEmote) return false;
|
||||
|
||||
return tmpscript->pReceiveEmote(player, _Creature, emote);
|
||||
@@ -2055,12 +2051,10 @@ bool ReceiveEmote( Player *player, Creature *_Creature, uint32 emote )
|
||||
TRINITY_DLL_EXPORT
|
||||
InstanceData* CreateInstanceData(Map *map)
|
||||
{
|
||||
Script *tmpscript = NULL;
|
||||
if (!map->IsDungeon()) return NULL;
|
||||
|
||||
if (!map->IsDungeon()) return false;
|
||||
|
||||
tmpscript = GetScriptByName(((InstanceMap*)map)->GetScript());
|
||||
if (!tmpscript || !tmpscript->GetInstanceData) return false;
|
||||
Script *tmpscript = m_scripts[((InstanceMap*)map)->GetScriptId()];
|
||||
if (!tmpscript || !tmpscript->GetInstanceData) return NULL;
|
||||
|
||||
return tmpscript->GetInstanceData(map);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user