diff options
author | megamage <none@none> | 2009-05-25 13:17:41 -0500 |
---|---|---|
committer | megamage <none@none> | 2009-05-25 13:17:41 -0500 |
commit | b96dea29c7432b776f7874ca536070682e9e426b (patch) | |
tree | 02100dfe87b40abb4ac1ff5cb01c9f3e90d0909c /src/bindings/interface/ScriptMgr.cpp | |
parent | a2f8a735aeec5517a1e28dd9202f241966be7691 (diff) | |
parent | 1efdaa89601f5b617b6abfc8b023ccac8e915ff6 (diff) |
*Merge.
--HG--
branch : trunk
Diffstat (limited to 'src/bindings/interface/ScriptMgr.cpp')
-rw-r--r-- | src/bindings/interface/ScriptMgr.cpp | 109 |
1 files changed, 48 insertions, 61 deletions
diff --git a/src/bindings/interface/ScriptMgr.cpp b/src/bindings/interface/ScriptMgr.cpp index c5d4652d5e6..397bfd2bb70 100644 --- a/src/bindings/interface/ScriptMgr.cpp +++ b/src/bindings/interface/ScriptMgr.cpp @@ -26,11 +26,8 @@ #include "Map.h" #include "ObjectMgr.h" -//uint8 loglevel = 0; -int nrscripts; +int num_sc_scripts; Script *m_scripts[MAX_SCRIPTS]; -InstanceDataScript* m_instance_scripts[MAX_INSTANCE_SCRIPTS]; -int num_inst_scripts; // -- Scripts to be added -- extern void AddSC_default(); @@ -39,26 +36,18 @@ extern void AddSC_default(); TRINITY_DLL_EXPORT void ScriptsFree() { // Free resources before library unload - for(int i=0;i<nrscripts;i++) + for(int i = 0; i < num_sc_scripts; i++) delete m_scripts[i]; - for(int i=0;i<num_inst_scripts;i++) - delete m_instance_scripts[i]; - - nrscripts = 0; - num_inst_scripts = 0; + num_sc_scripts = 0; } TRINITY_DLL_EXPORT void ScriptsInit(char const* cfg_file = "trinitycore.conf") { - nrscripts = 0; - num_inst_scripts = 0; + num_sc_scripts = 0; for(int i=0;i<MAX_SCRIPTS;i++) - { - m_scripts[i]=NULL; - m_instance_scripts[i]=NULL; - } + m_scripts[i]=NULL; // -- Inicialize the Scripts to be Added -- AddSC_default(); @@ -78,6 +67,19 @@ Script* GetScriptByName(std::string Name) return NULL; } +//********************************* +//*** Functions used internally *** + +void Script::RegisterSelf() +{ + int id = GetScriptId(Name.c_str()); + if(id) + { + m_scripts[id] = this; + ++num_sc_scripts; + } +} + //******************************** //*** Functions to be Exported *** @@ -86,6 +88,7 @@ char const* ScriptsVersion() { return "Default Trinity scripting library"; } + TRINITY_DLL_EXPORT bool GossipHello ( Player * player, Creature *_Creature ) { @@ -121,6 +124,34 @@ bool GossipSelectWithCode( Player *player, Creature *_Creature, uint32 sender, u } TRINITY_DLL_EXPORT +bool GOSelect( Player *player, GameObject *_GO, uint32 sender, uint32 action ) +{ + if(!_GO) + return false; + debug_log("TSCR: Gossip selection, sender: %d, action: %d",sender, action); + + Script *tmpscript = m_scripts[_GO->GetGOInfo()->ScriptId]; + if(!tmpscript || !tmpscript->pGOSelect) return false; + + player->PlayerTalkClass->ClearMenus(); + return tmpscript->pGOSelect(player,_GO,sender,action); +} + +TRINITY_DLL_EXPORT +bool GOSelectWithCode( Player *player, GameObject *_GO, uint32 sender, uint32 action, const char* sCode ) +{ + if(!_GO) + return false; + debug_log("TSCR: Gossip selection, sender: %d, action: %d",sender, action); + + Script *tmpscript = m_scripts[_GO->GetGOInfo()->ScriptId]; + if(!tmpscript || !tmpscript->pGOSelectWithCode) return false; + + player->PlayerTalkClass->ClearMenus(); + return tmpscript->pGOSelectWithCode(player,_GO,sender,action,sCode); +} + +TRINITY_DLL_EXPORT bool QuestAccept( Player *player, Creature *_Creature, Quest const *_Quest ) { Script *tmpscript = m_scripts[_Creature->GetScriptId()]; @@ -266,7 +297,7 @@ bool ReceiveEmote( Player *player, Creature *_Creature, uint32 emote ) return tmpscript->pReceiveEmote(player, _Creature, emote); } -/*TRINITY_DLL_EXPORT +TRINITY_DLL_EXPORT InstanceData* CreateInstanceData(Map *map) { if (!map->IsDungeon()) return NULL; @@ -277,47 +308,3 @@ InstanceData* CreateInstanceData(Map *map) return tmpscript->GetInstanceData(map); } -void ScriptedAI::UpdateAI(const uint32) -{ - //Check if we have a current target - if( m_creature->isAlive() && m_creature->SelectHostilTarget() && m_creature->getVictim()) - { - //If we are within range melee the target - if( m_creature->IsWithinDistInMap(m_creature->getVictim(), ATTACK_DISTANCE)) - { - if( m_creature->isAttackReady() ) - { - m_creature->AttackerStateUpdate(m_creature->getVictim()); - m_creature->resetAttackTimer(); - } - } - } -} - -void ScriptedAI::EnterEvadeMode() -{ - if( m_creature->isAlive() ) - DoGoHome(); -} - -void ScriptedAI::DoStartAttack(Unit* victim) -{ - if( m_creature->Attack(victim, true) ) - m_creature->GetMotionMaster()->MoveChase(victim); -} - -void ScriptedAI::DoStopAttack() -{ - if( m_creature->getVictim() != NULL ) - { - m_creature->AttackStop(); - } -} - -void ScriptedAI::DoGoHome() -{ - if( !m_creature->getVictim() && m_creature->isAlive() ) - m_creature->GetMotionMaster()->MoveTargetedHome(); -} -*/ - |