From 79080df72a61c3a5949863c85d4ae492643887e6 Mon Sep 17 00:00:00 2001 From: GokuWeedLord Date: Sat, 9 Dec 2017 17:28:51 +1100 Subject: [PATCH 01/75] fix build failures how does CI even work? witchcraft? --- src/servers/Server_Zone/Actor/Actor.h | 2 +- src/servers/Server_Zone/Actor/Player.h | 4 ++-- src/servers/Server_Zone/StatusEffect/StatusEffect.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/servers/Server_Zone/Actor/Actor.h b/src/servers/Server_Zone/Actor/Actor.h index 35547b01..5eade547 100644 --- a/src/servers/Server_Zone/Actor/Actor.h +++ b/src/servers/Server_Zone/Actor/Actor.h @@ -4,7 +4,7 @@ #include #include -#include "Forwards.h" +#include "../Forwards.h" #include #include #include diff --git a/src/servers/Server_Zone/Actor/Player.h b/src/servers/Server_Zone/Actor/Player.h index a7b7400b..8a95cf97 100644 --- a/src/servers/Server_Zone/Actor/Player.h +++ b/src/servers/Server_Zone/Actor/Player.h @@ -1,12 +1,12 @@ #ifndef _PLAYER_H #define _PLAYER_H -#include "Forwards.h" +#include "../Forwards.h" #include #include "Actor.h" -#include "Inventory/Inventory.h" +#include "../Inventory/Inventory.h" #include #include diff --git a/src/servers/Server_Zone/StatusEffect/StatusEffect.h b/src/servers/Server_Zone/StatusEffect/StatusEffect.h index 070bfb44..97706856 100644 --- a/src/servers/Server_Zone/StatusEffect/StatusEffect.h +++ b/src/servers/Server_Zone/StatusEffect/StatusEffect.h @@ -3,7 +3,7 @@ #include -#include "Forwards.h" +#include "../Forwards.h" namespace Core { From d0dc716b2d2676c7decfa0484ff4b8619407dd5c Mon Sep 17 00:00:00 2001 From: GokuWeedLord Date: Sat, 9 Dec 2017 23:02:23 +1100 Subject: [PATCH 02/75] Revert "fix build failures" This reverts commit 79080df72a61c3a5949863c85d4ae492643887e6. --- src/servers/Server_Zone/Actor/Actor.h | 2 +- src/servers/Server_Zone/Actor/Player.h | 4 ++-- src/servers/Server_Zone/StatusEffect/StatusEffect.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/servers/Server_Zone/Actor/Actor.h b/src/servers/Server_Zone/Actor/Actor.h index 5eade547..35547b01 100644 --- a/src/servers/Server_Zone/Actor/Actor.h +++ b/src/servers/Server_Zone/Actor/Actor.h @@ -4,7 +4,7 @@ #include #include -#include "../Forwards.h" +#include "Forwards.h" #include #include #include diff --git a/src/servers/Server_Zone/Actor/Player.h b/src/servers/Server_Zone/Actor/Player.h index 8a95cf97..a7b7400b 100644 --- a/src/servers/Server_Zone/Actor/Player.h +++ b/src/servers/Server_Zone/Actor/Player.h @@ -1,12 +1,12 @@ #ifndef _PLAYER_H #define _PLAYER_H -#include "../Forwards.h" +#include "Forwards.h" #include #include "Actor.h" -#include "../Inventory/Inventory.h" +#include "Inventory/Inventory.h" #include #include diff --git a/src/servers/Server_Zone/StatusEffect/StatusEffect.h b/src/servers/Server_Zone/StatusEffect/StatusEffect.h index 97706856..070bfb44 100644 --- a/src/servers/Server_Zone/StatusEffect/StatusEffect.h +++ b/src/servers/Server_Zone/StatusEffect/StatusEffect.h @@ -3,7 +3,7 @@ #include -#include "../Forwards.h" +#include "Forwards.h" namespace Core { From bb7ea6740d75f29fd7e8600f5b031d0a7c565811 Mon Sep 17 00:00:00 2001 From: GokuWeedLord Date: Sun, 10 Dec 2017 01:52:03 +1100 Subject: [PATCH 03/75] oh my god it finally fucking builds without issue --- .../Server_Common/Script/ChaiscriptStdLib.cpp | 16 - .../Server_Common/Script/ChaiscriptStdLib.h | 19 - src/servers/Server_Zone/Forwards.h | 1 + .../Server_Zone/Script/NativeScript.cpp | 63 +++ src/servers/Server_Zone/Script/NativeScript.h | 50 ++ .../Server_Zone/Script/NativeScriptApi.h | 129 +++++ .../Server_Zone/Script/ScriptManager.cpp | 510 ++++++++---------- .../Server_Zone/Script/ScriptManager.h | 8 +- .../Server_Zone/Script/ScriptManagerInit.cpp | 207 ------- src/servers/Server_Zone/ServerZone.cpp | 6 +- 10 files changed, 472 insertions(+), 537 deletions(-) delete mode 100644 src/servers/Server_Common/Script/ChaiscriptStdLib.cpp delete mode 100644 src/servers/Server_Common/Script/ChaiscriptStdLib.h create mode 100644 src/servers/Server_Zone/Script/NativeScript.cpp create mode 100644 src/servers/Server_Zone/Script/NativeScript.h create mode 100644 src/servers/Server_Zone/Script/NativeScriptApi.h delete mode 100644 src/servers/Server_Zone/Script/ScriptManagerInit.cpp diff --git a/src/servers/Server_Common/Script/ChaiscriptStdLib.cpp b/src/servers/Server_Common/Script/ChaiscriptStdLib.cpp deleted file mode 100644 index 282d4ecb..00000000 --- a/src/servers/Server_Common/Script/ChaiscriptStdLib.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include -#include "ChaiscriptStdLib.h" -#include - -std::shared_ptr< chaiscript::Module > Core::Scripting::create_chaiscript_stdlib() -{ - return chaiscript::Std_Lib::library(); -} - -boost::shared_ptr< chaiscript::ChaiScript > Core::Scripting::create_chaiscript() -{ - auto chai = boost::make_shared< chaiscript::ChaiScript >(); - //create_chaiscript_bindings( chai ); - return chai; -} \ No newline at end of file diff --git a/src/servers/Server_Common/Script/ChaiscriptStdLib.h b/src/servers/Server_Common/Script/ChaiscriptStdLib.h deleted file mode 100644 index f3e346d8..00000000 --- a/src/servers/Server_Common/Script/ChaiscriptStdLib.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef CHAISCRIPT_STDLIB -#define CHAISCRIPT_STDLIB - -#include - -namespace chaiscript -{ - class Module; - class ChaiScript; -} - -namespace Core { namespace Scripting { - -std::shared_ptr create_chaiscript_stdlib(); -boost::shared_ptr< chaiscript::ChaiScript > create_chaiscript(); - -} } - -#endif diff --git a/src/servers/Server_Zone/Forwards.h b/src/servers/Server_Zone/Forwards.h index 2eaaa75e..3c75c40b 100644 --- a/src/servers/Server_Zone/Forwards.h +++ b/src/servers/Server_Zone/Forwards.h @@ -70,6 +70,7 @@ namespace Core namespace Scripting { + class NativeScript; typedef std::function< void( Entity::Player&, uint32_t, uint16_t, uint16_t, uint16_t ) > EventReturnCallback; } diff --git a/src/servers/Server_Zone/Script/NativeScript.cpp b/src/servers/Server_Zone/Script/NativeScript.cpp new file mode 100644 index 00000000..0181d82c --- /dev/null +++ b/src/servers/Server_Zone/Script/NativeScript.cpp @@ -0,0 +1,63 @@ +#include "NativeScript.h" + +namespace Core { + namespace Scripting { + + NativeScript::NativeScript( ) + { } + + StatusEffectScript* NativeScript::getStatusEffectScript( uint32_t statusId ) + { + return m_statusEffectScripts.at( statusId ); + } + + AbilityScript* NativeScript::getAbilityScript( uint32_t abilityId ) + { + return m_abilityScripts.at( abilityId ); + } + + QuestScript* NativeScript::getQuestScript( uint32_t questId ) + { + return m_questScripts.at( questId ); + } + + BattleNpcScript* NativeScript::getBattleNpcScript( uint32_t npcId ) + { + return m_battleNpcScripts.at( npcId ); + } + + ZoneScript* NativeScript::getZoneScript( uint32_t zoneId ) + { + return m_zoneScripts.at( zoneId ); + } + + void NativeScript::removeStatusEffectScript( uint32_t statusId ) + { + m_statusEffectScripts.erase( statusId ); + } + + void NativeScript::removeAbilityScript( uint32_t abilityId ) + { + m_abilityScripts.erase( abilityId ); + } + + void NativeScript::removeQuestScript( uint32_t questId ) + { + m_questScripts.erase( questId ); + } + + void NativeScript::removeBattleNpcScript( uint32_t npcId ) + { + m_battleNpcScripts.erase( npcId ); + } + + + + + + boost::shared_ptr< NativeScript > create_script_engine( ) + { + return boost::make_shared< NativeScript >( ); + } + } +} diff --git a/src/servers/Server_Zone/Script/NativeScript.h b/src/servers/Server_Zone/Script/NativeScript.h new file mode 100644 index 00000000..ae21e0fb --- /dev/null +++ b/src/servers/Server_Zone/Script/NativeScript.h @@ -0,0 +1,50 @@ +#ifndef NATIVE_SCRIPT_H +#define NATIVE_SCRIPT_H + +#include + +#include +#include +#include + +#include + +#include "NativeScriptApi.h" + +namespace Core { + namespace Scripting { + + class NativeScript + { + protected: + std::unordered_map< uint32_t, StatusEffectScript* > m_statusEffectScripts; + std::unordered_map< uint32_t, AbilityScript* > m_abilityScripts; + std::unordered_map< uint32_t, QuestScript* > m_questScripts; + std::unordered_map< uint32_t, BattleNpcScript* > m_battleNpcScripts; + std::unordered_map< uint32_t, ZoneScript* > m_zoneScripts; + + public: + NativeScript( ); + + StatusEffectScript* getStatusEffectScript( uint32_t statusId ); + AbilityScript* getAbilityScript( uint32_t abilityId ); + QuestScript* getQuestScript( uint32_t questId ); + BattleNpcScript* getBattleNpcScript( uint32_t npcId ); + ZoneScript* getZoneScript( uint32_t zoneId ); + + void removeStatusEffectScript( uint32_t statusId ); + void removeAbilityScript( uint32_t abilityId ); + void removeQuestScript( uint32_t questId ); + void removeBattleNpcScript( uint32_t npcId ); + + + void clearAllScripts(); + }; + + + + boost::shared_ptr< NativeScript > create_script_engine( ); + } } + + +#endif \ No newline at end of file diff --git a/src/servers/Server_Zone/Script/NativeScriptApi.h b/src/servers/Server_Zone/Script/NativeScriptApi.h new file mode 100644 index 00000000..d694e30a --- /dev/null +++ b/src/servers/Server_Zone/Script/NativeScriptApi.h @@ -0,0 +1,129 @@ +#ifndef NATIVE_SCRIPT_API +#define NATIVE_SCRIPT_API + +#include +#include +#include +#include + +#define EXPORT_SCRIPTOBJECT( type, base ) \ +extern "C" __declspec( dllexport ) __cdecl base* get##base() \ +{ return static_cast< base* >( new type ); } + +#define EXPORT_STATUSEFFECTSCRIPT( type ) EXPORT_SCRIPTOBJECT( type, StatusEffectScript ) +#define EXPORT_ABILITYSCRIPT( type ) EXPORT_SCRIPTOBJECT( type, AbilityScript ) +#define EXPORT_QUESTSCRIPT( type ) EXPORT_SCRIPTOBJECT( type, QuestScript ) +#define EXPORT_BATTLENPCSCRIPT( type ) EXPORT_SCRIPTOBJECT( type, BattleNpcScript ) +#define EXPORT_ZONESCRIPT( type ) EXPORT_SCRIPTOBJECT( type, ZoneScript ) + +class ScriptObject +{ +protected: + const std::string m_scriptName; + +public: + ScriptObject( std::string name ) : + m_scriptName( name ) + { } + + std::string getName() const + { + return m_scriptName; + } + + virtual void onScriptUnload( ) { } +}; + + +class StatusEffectScript : ScriptObject +{ +protected: + const uint32_t m_effectId; + const uint32_t m_baseDuration; +public: + StatusEffectScript( std::string name, uint32_t effectId, uint32_t duration ) : + ScriptObject( name ), + m_effectId( effectId ), + m_baseDuration( duration ) + { } + + uint32_t getEffectId( ) const + { + return m_effectId; + } + + uint32_t getBaseDuration( ) const + { + return m_baseDuration; + } + + virtual Core::StatusEffect::StatusEffect applyEffect( Core::Entity::Actor sourceActor, Core::Entity::Actor targetActor ) { } + virtual void onTick(Core::Entity::ActorPtr actor) { } + virtual void onApply(Core::Entity::ActorPtr actor) { } + virtual void onRemove( Core::Entity::Actor actor ) { } + virtual void onExpire(Core::Entity::ActorPtr actor) { } + virtual void onPlayerCollision( Core::Entity::Actor actor, Core::Entity::Actor actorHit ) { } + virtual void onPlayerFinishCast( Core::Entity::Actor actor ) { } + virtual void onPlayerDamaged( Core::Entity::Actor actor ) { } + virtual bool onPlayerDeath( Core::Entity::Actor actor ) { } +}; + + +class AbilityScript : ScriptObject +{ +protected: + uint32_t m_abilityId; + +public: + AbilityScript( std::string name, uint32_t abilityId ) : + ScriptObject( name ), + m_abilityId( abilityId ) + { } + + uint32_t GetAbilityId( ) + { + return m_abilityId; + } + + virtual void onStart( Core::Entity::Actor sourceActor, Core::Entity::Actor targetActor ) { } + virtual bool onCastFinish(Core::Entity::Player player, Core::Entity::ActorPtr targetActor) { } + virtual void onInterrupt( Core::Entity::Actor sourceActor/*, Core::Entity::Actor targetActor*/ ) { } +}; + + +class QuestScript : ScriptObject +{ +protected: + uint32_t QuestId; +public: + QuestScript( std::string name, uint32_t questId ) : + ScriptObject( name ), + QuestId( questId ) + { } + + virtual void onTalk(uint32_t eventId, Core::Entity::Player player, uint64_t actorId) { } + virtual void onNpcKill( uint32_t npcId, Core::Entity::Player player ) { } + virtual void onEmote( uint64_t actorId, uint32_t eventId, uint32_t emoteId, Core::Entity::Player player ) { } +}; + + +class BattleNpcScript : ScriptObject +{ +public: + BattleNpcScript( std::string name ) : + ScriptObject( name ) + { } +}; + +class ZoneScript : ScriptObject +{ +public: + ZoneScript( std::string name ) : + ScriptObject( name ) + { } + + virtual void onZoneInit() { } + virtual void onEnterZone( Core::Entity::Player pPlayer, uint32_t eventId, uint16_t param1, uint16_t param2 ) { } +}; + +#endif \ No newline at end of file diff --git a/src/servers/Server_Zone/Script/ScriptManager.cpp b/src/servers/Server_Zone/Script/ScriptManager.cpp index 7ee72a52..316ddf63 100644 --- a/src/servers/Server_Zone/Script/ScriptManager.cpp +++ b/src/servers/Server_Zone/Script/ScriptManager.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include "NativeScript.h" #include "Zone/Zone.h" #include "Actor/Player.h" @@ -26,7 +26,7 @@ extern Core::ServerZone g_serverZone; Core::Scripting::ScriptManager::ScriptManager() { - m_pChaiHandler = create_chaiscript(); + m_nativeScriptHandler = create_script_engine(); } Core::Scripting::ScriptManager::~ScriptManager() @@ -44,28 +44,28 @@ void Core::Scripting::ScriptManager::loadDir( std::string dirname, std::set& Core::Scripting::ScriptManager::getHandler() const -{ - return m_pChaiHandler; -} - - bool Core::Scripting::ScriptManager::onTalk( Entity::Player& player, uint64_t actorId, uint32_t eventId ) { std::string eventName = "onTalk"; @@ -102,23 +96,138 @@ bool Core::Scripting::ScriptManager::onTalk( Entity::Player& player, uint64_t ac uint16_t eventType = eventId >> 16; - try + auto script = m_nativeScriptHandler->getQuestScript( eventId ); + if( script ) { - // Get object from engine - auto obj = m_pChaiHandler->eval( objName ); player.sendDebug( "Calling: " + objName + "." + eventName ); player.eventStart( actorId, eventId, Event::Event::Talk, 0, 0 ); - auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, - uint32_t, Entity::Player&, uint64_t ) > >( eventName ); - fn( obj, eventId, player, actorId ); + script->onTalk( eventId, player, actorId ); player.checkEvent( eventId ); } - catch( std::exception& e ) + else { - player.sendDebug( e.what( ) ); + if ( eventType == Common::EventType::Quest ) + { + auto questInfo = g_exdData.getQuestInfo( eventId ); + if ( questInfo ) + { + player.sendUrgent( "Quest not implemented: " + questInfo->name ); + return false; + } + } + } + + return true; +} + +bool Core::Scripting::ScriptManager::onEnterTerritory( Entity::Player& player, uint32_t eventId, + uint16_t param1, uint16_t param2 ) +{ + std::string eventName = "onEnterTerritory"; + std::string objName = Event::getEventName( eventId ); + + auto script = m_nativeScriptHandler->getZoneScript( player.getZoneId() ); + if( script ) + { + player.sendDebug( "Calling: " + objName + "." + eventName ); + + player.eventStart( player.getId(), eventId, Event::Event::EnterTerritory, 0, player.getZoneId() ); + + script->onEnterZone( player, eventId, param1, param2 ); + + player.checkEvent( eventId ); + + return true; + } + + return false; +} + +bool Core::Scripting::ScriptManager::onWithinRange( Entity::Player& player, uint32_t eventId, uint32_t param1, + float x, float y, float z ) +{ +// std::string eventName = "onWithinRange"; +// std::string objName = Event::getEventName( eventId ); +// +// try +// { +// // Get object from engine +// auto obj = m_pChaiHandler->eval( Event::getEventName( eventId ) ); +// +// player.sendDebug( "Calling: " + objName + "." + eventName ); +// +// player.eventStart( player.getId(), eventId, Event::Event::WithinRange, 1, param1 ); +// +// auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, uint32_t, Entity::Player&, uint32_t, +// float, float, float ) > >( eventName ); +// fn( obj, eventId, player, param1, x, y, z ); +// +// player.checkEvent( eventId ); +// } +// catch( std::exception& e ) +// { +// player.sendDebug( e.what() ); +// return false; +// } +// return true; + + return false; +} + +bool Core::Scripting::ScriptManager::onOutsideRange( Entity::Player& player, uint32_t eventId, uint32_t param1, + float x, float y, float z ) +{ +// std::string eventName = "onOutsideRange"; +// std::string objName = Event::getEventName( eventId ); +// +// try +// { +// // Get object from engine +// auto obj = m_pChaiHandler->eval( Event::getEventName( eventId ) ); +// +// player.sendDebug( "Calling: " + objName + "." + eventName ); +// +// player.eventStart( player.getId(), eventId, Event::Event::OutsideRange, 1, param1 ); +// +// auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, uint32_t, Entity::Player&, uint32_t, +// float, float, float ) > >( eventName ); +// fn( obj, eventId, player, param1, x, y, z ); +// +// player.checkEvent( eventId ); +// } +// catch( std::exception& e ) +// { +// player.sendDebug( e.what() ); +// return false; +// } +// return true; + + return false; +} + +bool Core::Scripting::ScriptManager::onEmote( Entity::Player& player, uint64_t actorId, + uint32_t eventId, uint8_t emoteId ) +{ + std::string eventName = "onEmote"; + std::string objName = Event::getEventName( eventId ); + + auto script = m_nativeScriptHandler->getQuestScript( eventId ); + if( script ) + { + player.sendDebug( "Calling: " + objName + "." + eventName ); + + player.eventStart( actorId, eventId, Event::Event::Emote, 0, emoteId ); + + script->onEmote( actorId, eventId, emoteId, player ); + + player.checkEvent( eventId ); + } + else + { + uint16_t eventType = eventId >> 16; if( eventType == Common::EventType::Quest ) { @@ -129,134 +238,9 @@ bool Core::Scripting::ScriptManager::onTalk( Entity::Player& player, uint64_t ac return false; } } - return false; } - return true; -} -bool Core::Scripting::ScriptManager::onEnterTerritory( Entity::Player& player, uint32_t eventId, - uint16_t param1, uint16_t param2 ) -{ - std::string eventName = "onEnterTerritory"; - std::string objName = Event::getEventName( eventId ); - - try - { - // Get object from engine - auto obj = m_pChaiHandler->eval( objName ); - - player.sendDebug( "Calling: " + objName + "." + eventName ); - - player.eventStart( player.getId(), eventId, Event::Event::EnterTerritory, 0, player.getZoneId() ); - - auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, uint32_t, - Entity::Player&, uint16_t, uint16_t ) > >( eventName ); - fn( obj, eventId, player, param1, param2 ); - - player.checkEvent( eventId ); - } - catch( std::exception& e ) - { - player.sendDebug( e.what() ); - return false; - } - return true; -} - -bool Core::Scripting::ScriptManager::onWithinRange( Entity::Player& player, uint32_t eventId, uint32_t param1, - float x, float y, float z ) -{ - std::string eventName = "onWithinRange"; - std::string objName = Event::getEventName( eventId ); - - try - { - // Get object from engine - auto obj = m_pChaiHandler->eval( Event::getEventName( eventId ) ); - - player.sendDebug( "Calling: " + objName + "." + eventName ); - - player.eventStart( player.getId(), eventId, Event::Event::WithinRange, 1, param1 ); - - auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, uint32_t, Entity::Player&, uint32_t, - float, float, float ) > >( eventName ); - fn( obj, eventId, player, param1, x, y, z ); - - player.checkEvent( eventId ); - } - catch( std::exception& e ) - { - player.sendDebug( e.what() ); - return false; - } - return true; -} - -bool Core::Scripting::ScriptManager::onOutsideRange( Entity::Player& player, uint32_t eventId, uint32_t param1, - float x, float y, float z ) -{ - std::string eventName = "onOutsideRange"; - std::string objName = Event::getEventName( eventId ); - - try - { - // Get object from engine - auto obj = m_pChaiHandler->eval( Event::getEventName( eventId ) ); - - player.sendDebug( "Calling: " + objName + "." + eventName ); - - player.eventStart( player.getId(), eventId, Event::Event::OutsideRange, 1, param1 ); - - auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, uint32_t, Entity::Player&, uint32_t, - float, float, float ) > >( eventName ); - fn( obj, eventId, player, param1, x, y, z ); - - player.checkEvent( eventId ); - } - catch( std::exception& e ) - { - player.sendDebug( e.what() ); - return false; - } - return true; -} - -bool Core::Scripting::ScriptManager::onEmote( Entity::Player& player, uint64_t actorId, - uint32_t eventId, uint8_t emoteId ) -{ - std::string eventName = "onEmote"; - std::string objName = Event::getEventName( eventId ); - - try - { - auto obj = m_pChaiHandler->eval( Event::getEventName( eventId ) ); - - player.sendDebug( "Calling: " + objName + "." + eventName ); - - player.eventStart( actorId, eventId, Event::Event::Emote, 0, emoteId ); - - auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, uint32_t, Entity::Player&, - uint64_t, uint8_t ) > >( eventName ); - fn( obj, eventId, player, actorId, emoteId ); - - player.checkEvent( eventId ); - } - catch( std::exception& e ) - { - uint16_t eventType = eventId >> 16; - - if( eventType == Common::EventType::Quest ) - { - auto questInfo = g_exdData.getQuestInfo( eventId ); - if( questInfo ) - { - player.sendDebug( "Quest not implemented: " + questInfo->name + "\n" + e.what() ); - return false; - } - } - return false; - } return true; } @@ -290,7 +274,7 @@ bool Core::Scripting::ScriptManager::onEventHandlerReturn( Entity::Player& playe else pEvent->setPlayedScene( false ); } - // else, finish the event. + // else, finish the event. else player.eventFinish( eventId, 1 ); } @@ -307,55 +291,57 @@ bool Core::Scripting::ScriptManager::onEventHandlerReturn( Entity::Player& playe bool Core::Scripting::ScriptManager::onEventHandlerTradeReturn( Entity::Player& player, uint32_t eventId, uint16_t subEvent, uint16_t param, uint32_t catalogId ) { - std::string eventName = Event::getEventName( eventId ) + "_TRADE"; +// std::string eventName = Event::getEventName( eventId ) + "_TRADE"; +// +// try +// { +// auto fn = m_pChaiHandler->eval< std::function< void( Entity::Player&, uint32_t, +// uint16_t, uint16_t, uint32_t ) > >( eventName ); +// fn( player, eventId, subEvent, param, catalogId ); +// } +// catch( ... ) +// { +// return false; +// } +// +// return true; - try - { - auto fn = m_pChaiHandler->eval< std::function< void( Entity::Player&, uint32_t, - uint16_t, uint16_t, uint32_t ) > >( eventName ); - fn( player, eventId, subEvent, param, catalogId ); - } - catch( ... ) - { - return false; - } - - return true; + return false; } bool Core::Scripting::ScriptManager::onEventItem( Entity::Player& player, uint32_t eventItemId, uint32_t eventId, uint32_t castTime, uint64_t targetId ) { - std::string eventName = "onEventItem"; - std::string objName = Event::getEventName( eventId ); - - try - { - auto obj = m_pChaiHandler->eval( Event::getEventName( eventId ) ); - - player.sendDebug( "Calling: " + objName + "." + eventName ); - - player.eventStart( targetId, eventId, Event::Event::Item, 0, 0 ); - - auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, uint32_t, Entity::Player&, - uint32_t, uint32_t, uint64_t ) > >( eventName ); - fn( obj, eventId, player, eventItemId, castTime, targetId ); - } - catch( std::exception& e ) - { - player.sendNotice( e.what() ); - return false; - } - - return true; - +// std::string eventName = "onEventItem"; +// std::string objName = Event::getEventName( eventId ); +// +// try +// { +// auto obj = m_pChaiHandler->eval( Event::getEventName( eventId ) ); +// +// player.sendDebug( "Calling: " + objName + "." + eventName ); +// +// player.eventStart( targetId, eventId, Event::Event::Item, 0, 0 ); +// +// auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, uint32_t, Entity::Player&, +// uint32_t, uint32_t, uint64_t ) > >( eventName ); +// fn( obj, eventId, player, eventItemId, castTime, targetId ); +// } +// catch( std::exception& e ) +// { +// player.sendNotice( e.what() ); +// return false; +// } +// +// return true; + return false; } bool Core::Scripting::ScriptManager::onMobKill( Entity::Player& player, uint16_t nameId ) { std::string eventName = "onBnpcKill_" + std::to_string( nameId ); - + // loop through all active quests and try to call available onMobKill callbacks for( size_t i = 0; i < 30; i++ ) { @@ -364,23 +350,15 @@ bool Core::Scripting::ScriptManager::onMobKill( Entity::Player& player, uint16_t continue; uint16_t questId = activeQuests->c.questId; - if( questId != 0 ) + + auto script = m_nativeScriptHandler->getQuestScript( questId ); + if( script ) { - auto obj = m_pChaiHandler->eval( Event::getEventName( 0x00010000 | questId ) ); std::string objName = Event::getEventName( 0x00010000 | questId ); player.sendDebug("Calling: " + objName + "." + eventName); - try - { - auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, Entity::Player& ) > >(eventName); - fn( obj, player ); - } - catch( std::exception& e ) - { - g_log.info( e.what() ); - } - + script->onNpcKill( nameId, player ); } } @@ -389,115 +367,71 @@ bool Core::Scripting::ScriptManager::onMobKill( Entity::Player& player, uint16_t bool Core::Scripting::ScriptManager::onCastFinish( Entity::Player& player, Entity::ActorPtr pTarget, uint32_t actionId ) { - std::string eventName = "onFinish"; + auto script = m_nativeScriptHandler->getAbilityScript( actionId ); - try - { - auto obj = m_pChaiHandler->eval( "skillDef_" + std::to_string( actionId ) ); - std::string objName = "skillDef_" + std::to_string( actionId ); + if( script ) + script->onCastFinish( player, pTarget ); - player.sendDebug( "Calling: " + objName + "." + eventName ); - auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, Entity::Player&, - Entity::Actor& ) > >( eventName ); - fn( obj, player, *pTarget ); - } - catch( std::exception& e ) - { - player.sendUrgent( e.what() ); - } - - return true; + return true; } bool Core::Scripting::ScriptManager::onStatusReceive( Entity::ActorPtr pActor, uint32_t effectId ) { - std::string eventName = "onReceive"; - - try - { - auto obj = m_pChaiHandler->eval( "statusDef_" + std::to_string( effectId ) ); - std::string objName = "statusDef_" + std::to_string( effectId ); - - if( pActor->isPlayer() ) - pActor->getAsPlayer()->sendDebug( "Calling: " + objName + "." + eventName ); - - auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, Entity::Actor&) > >( eventName ); - fn( obj, *pActor ); - } - catch( std::exception& e ) + auto script = m_nativeScriptHandler->getStatusEffectScript( effectId ); + if( script ) { if( pActor->isPlayer() ) - pActor->getAsPlayer()->sendUrgent( e.what() ); + pActor->getAsPlayer()->sendDebug( "Calling status recieve for statusid: " + effectId ); + + script->onApply( pActor ); + + return true; } - return true; + return false; } bool Core::Scripting::ScriptManager::onStatusTick( Entity::ActorPtr pActor, Core::StatusEffect::StatusEffect& effect ) { - std::string eventName = "onTick"; - - try - { - auto obj = m_pChaiHandler->eval( "statusDef_" + std::to_string( effect.getId() ) ); - std::string objName = "statusDef_" + std::to_string( effect.getId() ); - - if( pActor->isPlayer() ) - pActor->getAsPlayer()->sendDebug( "Calling: " + objName + "." + eventName ); - - auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, Entity::Actor&, - StatusEffect::StatusEffect& ) > >( eventName ); - fn( obj, *pActor, effect ); - } - catch( std::exception& e ) + auto script = m_nativeScriptHandler->getStatusEffectScript( effect.getId() ); + if( script ) { if( pActor->isPlayer() ) - pActor->getAsPlayer()->sendUrgent( e.what() ); + pActor->getAsPlayer()->sendDebug( "Calling status tick for statusid: " + effect.getId() ); + + script->onTick( pActor ); + + return true; } - return true; + return false; } bool Core::Scripting::ScriptManager::onStatusTimeOut( Entity::ActorPtr pActor, uint32_t effectId ) { - std::string eventName = "onTimeOut"; - - try - { - auto obj = m_pChaiHandler->eval( "statusDef_" + std::to_string( effectId ) ); - std::string objName = "statusDef_" + std::to_string( effectId ); - - if( pActor->isPlayer() ) - pActor->getAsPlayer()->sendDebug( "Calling: " + objName + "." + eventName ); - - auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, Entity::Actor& ) > >( eventName ); - fn( obj, *pActor ); - } - catch( std::exception& e ) + auto script = m_nativeScriptHandler->getStatusEffectScript( effectId ); + if( script ) { if( pActor->isPlayer() ) - pActor->getAsPlayer()->sendUrgent( e.what() ); + pActor->getAsPlayer()->sendDebug( "Calling status tick for statusid: " + effectId ); + + script->onExpire( pActor ); + + return true; } - return true; + return false; } bool Core::Scripting::ScriptManager::onZoneInit( ZonePtr pZone ) { - std::string eventName = "onZoneInit_" + pZone->getInternalName(); + auto script = m_nativeScriptHandler->getZoneScript( pZone->getId() ); + if( script ) + { + script->onZoneInit(); - try - { - auto fn = m_pChaiHandler->eval< std::function< void( Zone& ) > >( eventName ); - fn( *pZone ); - } - catch( std::exception& e ) - { - g_log.info( e.what() ); - return false; + return true; } - return true; - + return false; } - diff --git a/src/servers/Server_Zone/Script/ScriptManager.h b/src/servers/Server_Zone/Script/ScriptManager.h index 2e66f3cf..2695e33b 100644 --- a/src/servers/Server_Zone/Script/ScriptManager.h +++ b/src/servers/Server_Zone/Script/ScriptManager.h @@ -23,7 +23,7 @@ namespace Core { private: - boost::shared_ptr< chaiscript::ChaiScript > m_pChaiHandler; + boost::shared_ptr< NativeScript > m_nativeScriptHandler; std::function< std::string( Entity::Player& ) > m_onFirstEnterWorld; // auto fn = m_pChaiHandler->eval< std::function >( "onFirstEnterWorld" ); @@ -57,14 +57,14 @@ namespace Core bool onStatusTimeOut( Entity::ActorPtr pActor, uint32_t effectId ); bool onZoneInit( ZonePtr pZone ); - + bool onEventHandlerReturn( Entity::Player& player, uint32_t eventId, uint16_t subEvent, uint16_t param1, uint16_t param2, uint16_t param3 ); bool onEventHandlerTradeReturn( Entity::Player& player, uint32_t eventId, uint16_t subEvent, uint16_t param, uint32_t catalogId ); - + void loadDir( std::string dirname, std::set& chaiFiles ); - + }; } } diff --git a/src/servers/Server_Zone/Script/ScriptManagerInit.cpp b/src/servers/Server_Zone/Script/ScriptManagerInit.cpp deleted file mode 100644 index dbf76194..00000000 --- a/src/servers/Server_Zone/Script/ScriptManagerInit.cpp +++ /dev/null @@ -1,207 +0,0 @@ -#include - -#include -#include -#include - -#include "ServerZone.h" - -#include "Script/ScriptManager.h" - -#include "Zone/Zone.h" -#include "Actor/Player.h" -#include "Actor/BattleNpc.h" -#include "Event/Event.h" -#include "Event/EventHelper.h" -#include "Network/PacketWrappers/ServerNoticePacket.h" -#include "StatusEffect/StatusEffect.h" - -#include - -extern Core::Logger g_log; -extern Core::ServerZone g_serverZone; - -int Core::Scripting::ScriptManager::init() -{ - // ACTOR / PLAYER BINDINGS - ///////////////////////////////////////////////////////////////////////////////////////////// - m_pChaiHandler->add( chaiscript::fun( &Entity::Actor::getName ), "getName" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Actor::getId ), "getId" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Actor::getHp ), "getHp" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Actor::getMp ), "getMp" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Actor::getTp ), "getTp" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Actor::getLevel ), "getLevel" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Actor::getTargetId ), "getTargetId" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Actor::addStatusEffect ), "addStatusEffect" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Actor::addStatusEffectById ), "addStatusEffectById" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Actor::addStatusEffectByIdIfNotExist ), "addStatusEffectByIdIfNotExist" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Actor::takeDamage ), "takeDamage" ); - - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::forceZoneing ), "setZone" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getClassAsInt ), "getClass" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getRace ), "getRace" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getGender ), "getGender" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::gainExp ), "gainExp" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::unlock ), "unlock" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::registerAetheryte ), "aetheryteRegister" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::learnAction ), "learnAction" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getHomepoint ), "getHomepoint" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setHomepoint ), "setHomepoint" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::returnToHomepoint ), "returnToHomepoint" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::teleport ), "teleport" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::prepareZoning ), "prepareZoning" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::isInCombat ), "isInCombat" ); - - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getCurrency ), "getCurrency" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::addCurrency ), "addCurrency" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::removeCurrency ), "removeCurrency" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getCrystal ), "getCrystals" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::addCrystal ), "addCrystals" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::removeCrystal ), "removeCrystals" ); - - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::updateQuest ), "questUpdate" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::finishQuest ), "questFinish" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::sendQuestMessage ), "questMessage" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestSeq ), "questGetSeq" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::hasQuest ), "hasQuest" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getZoneId ), "getZoneId" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::handleScriptSkill ), "handleScriptSkill" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getOpeningSequence ), "getOpeningSequence" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setOpeningSequence ), "setOpeningSequence" ); - - m_pChaiHandler->add( chaiscript::fun( &Core::Event::mapEventActorToRealActor ), "mapActor" ); - - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestUI8A ), "getQuestUI8A" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestUI8B ), "getQuestUI8B" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestUI8C ), "getQuestUI8C" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestUI8D ), "getQuestUI8D" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestUI8E ), "getQuestUI8E" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestUI8F ), "getQuestUI8F" ); - - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestUI8AH ), "getQuestUI8AH" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestUI8BH ), "getQuestUI8BH" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestUI8CH ), "getQuestUI8CH" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestUI8DH ), "getQuestUI8DH" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestUI8EH ), "getQuestUI8EH" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestUI8FH ), "getQuestUI8FH" ); - - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestUI8AL ), "getQuestUI8AL" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestUI8BL ), "getQuestUI8BL" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestUI8CL ), "getQuestUI8CL" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestUI8DL ), "getQuestUI8DL" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestUI8EL ), "getQuestUI8EL" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestUI8FL ), "getQuestUI8FL" ); - - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestUI16A ), "getQuestUI16A" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestUI16B ), "getQuestUI16B" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestUI16C ), "getQuestUI16C" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestUI32A ), "getQuestUI32A" ); - - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestBitFlag8 ), "getQuestBitFlag8" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestBitFlag16 ), "getQuestBitFlag16" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestBitFlag24 ), "getQuestBitFlag24" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestBitFlag32 ), "getQuestBitFlag32" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestBitFlag40 ), "getQuestBitFlag40" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getQuestBitFlag48 ), "getQuestBitFlag48" ); - - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestUI8A ), "setQuestUI8A" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestUI8B ), "setQuestUI8B" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestUI8C ), "setQuestUI8C" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestUI8D ), "setQuestUI8D" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestUI8E ), "setQuestUI8E" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestUI8F ), "setQuestUI8F" ); - - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestUI8AH ), "setQuestUI8AH" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestUI8BH ), "setQuestUI8BH" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestUI8CH ), "setQuestUI8CH" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestUI8DH ), "setQuestUI8DH" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestUI8EH ), "setQuestUI8EH" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestUI8FH ), "setQuestUI8FH" ); - - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestUI8AL ), "setQuestUI8AL" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestUI8BL ), "setQuestUI8BL" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestUI8CL ), "setQuestUI8CL" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestUI8DL ), "setQuestUI8DL" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestUI8EL ), "setQuestUI8EL" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestUI8FL ), "setQuestUI8FL" ); - - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestUI16A ), "setQuestUI16A" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestUI16B ), "setQuestUI16B" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestUI16C ), "setQuestUI16C" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestUI32A ), "setQuestUI32A" ); - - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestBitFlag8 ), "setQuestBitFlag8" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestBitFlag16 ), "setQuestBitFlag16" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestBitFlag24 ), "setQuestBitFlag24" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestBitFlag32 ), "setQuestBitFlag32" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestBitFlag40 ), "setQuestBitFlag40" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestBitFlag48 ), "setQuestBitFlag48" ); - - m_pChaiHandler->add(chaiscript::fun(&Entity::Player::giveQuestRewards), "giveQuestRewards"); - - m_pChaiHandler->add( chaiscript::fun< void, Entity::Player, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t >( &Entity::Player::eventPlay ), "eventPlay" ); - m_pChaiHandler->add( chaiscript::fun< void, Entity::Player, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, EventReturnCallback >( &Entity::Player::eventPlay ), "eventPlay" ); - m_pChaiHandler->add( chaiscript::fun< void, Entity::Player, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, EventReturnCallback >( &Entity::Player::eventPlay ), "eventPlay" ); - m_pChaiHandler->add( chaiscript::fun< void, Entity::Player, uint32_t, uint32_t, uint32_t, EventReturnCallback >( &Entity::Player::eventPlay ), "eventPlay" ); - m_pChaiHandler->add( chaiscript::fun< void, Entity::Player, uint32_t, uint32_t, uint32_t >( &Entity::Player::eventPlay ), "eventPlay" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::eventActionStart ), "eventActionStart" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::eventItemActionStart ), "eventItemActionStart" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::changePosition ), "changePos" ); - - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::tryAddItem ), "tryAddItem" ); - - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::isAetheryteRegistered ), "isAetheryteRegistered" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Player::isActionLearned ), "isActionLearned" ); - - m_pChaiHandler->add( chaiscript::base_class< Entity::Actor, Entity::Player >() ); - m_pChaiHandler->add( chaiscript::base_class< Entity::Actor, Entity::BattleNpc >() ); - m_pChaiHandler->add( chaiscript::user_type< Entity::Actor >(), "Actor" ); - m_pChaiHandler->add( chaiscript::user_type< Entity::Player >(), "Player" ); - m_pChaiHandler->add( chaiscript::user_type< Entity::BattleNpc >(), "BattleNpc" ); - m_pChaiHandler->add( chaiscript::user_type< StatusEffect::StatusEffect >(), "StatusEffect" ); - - m_pChaiHandler->add( chaiscript::fun( &StatusEffect::StatusEffect::registerTickEffect ), "registerTickEffect" ); - - m_pChaiHandler->add( chaiscript::user_type< Zone >(), "Zone" ); - m_pChaiHandler->add( chaiscript::fun( &Zone::getName ), "getName" ); - - m_pChaiHandler->add( chaiscript::fun( ®isterBnpcTemplate ), "registerBnpcTemplate" ); - - // EVENT BINDINGS - ///////////////////////////////////////////////////////////////////////////////////////////// - - std::set< std::string > chaiFiles; - - loadDir( g_serverZone.getConfig()->getValue< std::string >( "Settings.General.ScriptPath", "../scripts/chai" ), chaiFiles ); - - uint16_t scriptCount = 0; - uint16_t errorCount = 0; - for( auto itr = chaiFiles.begin(); itr != chaiFiles.end(); ++itr ) - { - auto& fileName = *itr; - - try - { - m_pChaiHandler->eval_file( fileName ); - scriptCount++; - } - catch( std::exception& e ) - { - g_log.Log( LoggingSeverity::error, e.what() ); - errorCount++; - } - - } - - g_log.info( "\tloaded " + std::to_string( scriptCount ) + - " scripts, " + std::to_string( errorCount ) + " errors." ); - - std::function f = - m_pChaiHandler->eval< std::function >( "onFirstEnterWorld" ); - - m_onFirstEnterWorld = f; - - - return true; -} - diff --git a/src/servers/Server_Zone/ServerZone.cpp b/src/servers/Server_Zone/ServerZone.cpp index a863b06a..1c35aabd 100644 --- a/src/servers/Server_Zone/ServerZone.cpp +++ b/src/servers/Server_Zone/ServerZone.cpp @@ -64,7 +64,7 @@ size_t Core::ServerZone::getSessionCount() const return m_sessionMapById.size(); } -bool Core::ServerZone::registerBnpcTemplate( std::string templateName, uint32_t bnpcBaseId, +bool Core::ServerZone::registerBnpcTemplate( std::string templateName, uint32_t bnpcBaseId, uint32_t bnpcNameId, uint32_t modelId, std::string aiName ) { @@ -225,11 +225,11 @@ void Core::ServerZone::run( int32_t argc, char* argv[] ) g_log.info( "ZoneMgr: Setting up zones" ); g_zoneMgr.createZones(); - g_scriptMgr.init(); +// g_scriptMgr.init(); std::vector< std::thread > thread_list; thread_list.emplace_back( std::thread( std::bind( &Network::Hive::Run, hive.get() ) ) ); - + g_log.info( "Server listening on port: " + std::to_string( m_port ) ); g_log.info( "Ready for connections..." ); From 17daf26aa0611a169edde81d824bfc9a7d393932 Mon Sep 17 00:00:00 2001 From: GokuWeedLord Date: Sun, 10 Dec 2017 02:13:54 +1100 Subject: [PATCH 04/75] script api changes, fix indenting, some broken cmake shit --- CMakeLists.txt | 2 + scripts/native/CMakeLists.txt | 22 +++ scripts/native/ScriptObject.h | 9 ++ .../native/statuseffect/StatusEffect50.cpp | 15 ++ src/servers/Server_Zone/CMakeLists.txt | 1 + .../Server_Zone/Script/NativeScriptApi.h | 139 ++++++++++-------- 6 files changed, 125 insertions(+), 63 deletions(-) create mode 100644 scripts/native/CMakeLists.txt create mode 100644 scripts/native/ScriptObject.h create mode 100644 scripts/native/statuseffect/StatusEffect50.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 997abb3d..6f7b96f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,3 +66,5 @@ add_subdirectory("src/tools/exd_struct_gen") add_subdirectory("src/tools/exd_struct_test") add_subdirectory("src/tools/quest_parser") add_subdirectory("src/tools/pcb_reader") + +add_subdirectory("scripts/native") diff --git a/scripts/native/CMakeLists.txt b/scripts/native/CMakeLists.txt new file mode 100644 index 00000000..f431f0eb --- /dev/null +++ b/scripts/native/CMakeLists.txt @@ -0,0 +1,22 @@ +project(Sapphire_Script) + +file(GLOB SCRIPT_INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.h") + +file(GLOB_RECURSE SCRIPT_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp") +foreach(_sourcefile "${SCRIPT_FILES}") + get_filename_component(_file "${_sourcefile}" NAME_WE) + add_library("${_file}" MODULE "${_sourcefile}" "${SCRIPT_INCLUDE_FILES}") + + add_dependencies("${_file}" server_zone) + target_link_libraries("${_file}" server_zone) + + set_target_properties("${_file}" PROPERTIES + CXX_STANDARD 14 + CXX_STANDARD_REQUIRED ON + CXX_EXTENSIONS ON + RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/../../bin/compiledscripts/" + RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/../../bin/compiledscripts/" + RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_CURRENT_SOURCE_DIR}/../../bin/compiledscripts/" + RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_CURRENT_SOURCE_DIR}/../../bin/compiledscripts/" + ) +endforeach(_sourcefile "${SCRIPT_FILES}") \ No newline at end of file diff --git a/scripts/native/ScriptObject.h b/scripts/native/ScriptObject.h new file mode 100644 index 00000000..8d639251 --- /dev/null +++ b/scripts/native/ScriptObject.h @@ -0,0 +1,9 @@ +#ifndef SAPPHIRE_SCRIPTOBJECT_H +#define SAPPHIRE_SCRIPTOBJECT_H + +#include +#include +#include + + +#endif //SAPPHIRE_SCRIPTOBJECT_H diff --git a/scripts/native/statuseffect/StatusEffect50.cpp b/scripts/native/statuseffect/StatusEffect50.cpp new file mode 100644 index 00000000..e03a20d5 --- /dev/null +++ b/scripts/native/statuseffect/StatusEffect50.cpp @@ -0,0 +1,15 @@ +#include + +class StatusEffect50 : StatusEffectScript +{ +public: + StatusEffect50() : StatusEffectScript( "StatusEffect50", 50 ) + {} + + virtual void onTick( Core::Entity::ActorPtr actor ) + { + + } +}; + +EXPORT_STATUSEFFECTSCRIPT( StatusEffect50 ) \ No newline at end of file diff --git a/src/servers/Server_Zone/CMakeLists.txt b/src/servers/Server_Zone/CMakeLists.txt index 308f3ab7..60dc0ef4 100644 --- a/src/servers/Server_Zone/CMakeLists.txt +++ b/src/servers/Server_Zone/CMakeLists.txt @@ -46,6 +46,7 @@ set_target_properties(server_zone PROPERTIES CXX_STANDARD 14 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS ON + ENABLE_EXPORTS ON RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/../../../bin/" RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/../../../bin/" RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_CURRENT_SOURCE_DIR}/../../../bin/" diff --git a/src/servers/Server_Zone/Script/NativeScriptApi.h b/src/servers/Server_Zone/Script/NativeScriptApi.h index d694e30a..6d71c1e8 100644 --- a/src/servers/Server_Zone/Script/NativeScriptApi.h +++ b/src/servers/Server_Zone/Script/NativeScriptApi.h @@ -19,19 +19,17 @@ extern "C" __declspec( dllexport ) __cdecl base* get##base() \ class ScriptObject { protected: - const std::string m_scriptName; + const std::string m_scriptName; public: - ScriptObject( std::string name ) : - m_scriptName( name ) - { } + ScriptObject( std::string name ) : + m_scriptName( name ) + { } - std::string getName() const - { - return m_scriptName; - } - - virtual void onScriptUnload( ) { } + const std::string getName() + { + return m_scriptName; + } }; @@ -39,91 +37,106 @@ class StatusEffectScript : ScriptObject { protected: const uint32_t m_effectId; - const uint32_t m_baseDuration; + public: - StatusEffectScript( std::string name, uint32_t effectId, uint32_t duration ) : - ScriptObject( name ), - m_effectId( effectId ), - m_baseDuration( duration ) - { } + StatusEffectScript( std::string name, uint32_t effectId ) : + ScriptObject( name ), + m_effectId( effectId ) + { } - uint32_t getEffectId( ) const - { - return m_effectId; - } + const uint32_t getEffectId( ) + { + return m_effectId; + } - uint32_t getBaseDuration( ) const - { - return m_baseDuration; - } - virtual Core::StatusEffect::StatusEffect applyEffect( Core::Entity::Actor sourceActor, Core::Entity::Actor targetActor ) { } - virtual void onTick(Core::Entity::ActorPtr actor) { } - virtual void onApply(Core::Entity::ActorPtr actor) { } - virtual void onRemove( Core::Entity::Actor actor ) { } - virtual void onExpire(Core::Entity::ActorPtr actor) { } - virtual void onPlayerCollision( Core::Entity::Actor actor, Core::Entity::Actor actorHit ) { } - virtual void onPlayerFinishCast( Core::Entity::Actor actor ) { } - virtual void onPlayerDamaged( Core::Entity::Actor actor ) { } - virtual bool onPlayerDeath( Core::Entity::Actor actor ) { } + virtual Core::StatusEffect::StatusEffect applyEffect( Core::Entity::Actor sourceActor, Core::Entity::Actor targetActor ) { } + virtual void onTick(Core::Entity::ActorPtr actor) { } + virtual void onApply(Core::Entity::ActorPtr actor) { } + virtual void onRemove( Core::Entity::Actor actor ) { } + virtual void onExpire(Core::Entity::ActorPtr actor) { } + virtual void onPlayerCollision( Core::Entity::Actor actor, Core::Entity::Actor actorHit ) { } + virtual void onPlayerFinishCast( Core::Entity::Actor actor ) { } + virtual void onPlayerDamaged( Core::Entity::Actor actor ) { } + virtual bool onPlayerDeath( Core::Entity::Actor actor ) { } }; class AbilityScript : ScriptObject { protected: - uint32_t m_abilityId; + const uint32_t m_abilityId; public: - AbilityScript( std::string name, uint32_t abilityId ) : - ScriptObject( name ), - m_abilityId( abilityId ) - { } + AbilityScript( std::string name, uint32_t abilityId ) : + ScriptObject( name ), + m_abilityId( abilityId ) + { } - uint32_t GetAbilityId( ) - { - return m_abilityId; - } + const uint32_t GetAbilityId( ) + { + return m_abilityId; + } - virtual void onStart( Core::Entity::Actor sourceActor, Core::Entity::Actor targetActor ) { } - virtual bool onCastFinish(Core::Entity::Player player, Core::Entity::ActorPtr targetActor) { } - virtual void onInterrupt( Core::Entity::Actor sourceActor/*, Core::Entity::Actor targetActor*/ ) { } + virtual void onStart( Core::Entity::Actor sourceActor, Core::Entity::Actor targetActor ) { } + virtual bool onCastFinish(Core::Entity::Player player, Core::Entity::ActorPtr targetActor) { } + virtual void onInterrupt( Core::Entity::Actor sourceActor/*, Core::Entity::Actor targetActor*/ ) { } }; class QuestScript : ScriptObject { protected: - uint32_t QuestId; -public: - QuestScript( std::string name, uint32_t questId ) : - ScriptObject( name ), - QuestId( questId ) - { } + const uint32_t m_questId; - virtual void onTalk(uint32_t eventId, Core::Entity::Player player, uint64_t actorId) { } - virtual void onNpcKill( uint32_t npcId, Core::Entity::Player player ) { } - virtual void onEmote( uint64_t actorId, uint32_t eventId, uint32_t emoteId, Core::Entity::Player player ) { } +public: + QuestScript( std::string name, uint32_t questId ) : + ScriptObject( name ), + m_questId( questId ) + { } + + const uint32_t getQuestId() + { + return m_questId; + } + + virtual void onTalk(uint32_t eventId, Core::Entity::Player player, uint64_t actorId) { } + virtual void onNpcKill( uint32_t npcId, Core::Entity::Player player ) { } + virtual void onEmote( uint64_t actorId, uint32_t eventId, uint32_t emoteId, Core::Entity::Player player ) { } }; class BattleNpcScript : ScriptObject { +protected: + const uint32_t m_npcId; + public: - BattleNpcScript( std::string name ) : - ScriptObject( name ) - { } + BattleNpcScript( std::string name, uint32_t npcId ) : + ScriptObject( name ), + m_npcId( npcId ) + { } + + const uint32_t getNpcId() + { + return m_npcId; + } }; class ZoneScript : ScriptObject { -public: - ZoneScript( std::string name ) : - ScriptObject( name ) - { } +protected: + const uint32_t m_zoneId; - virtual void onZoneInit() { } - virtual void onEnterZone( Core::Entity::Player pPlayer, uint32_t eventId, uint16_t param1, uint16_t param2 ) { } +public: + ZoneScript( std::string name, uint32_t zoneId ) : + ScriptObject( name ), + m_zoneId( zoneId ) + { } + + + virtual void onZoneInit() { } + virtual void onEnterZone( Core::Entity::Player pPlayer, uint32_t eventId, uint16_t param1, uint16_t param2 ) { } }; #endif \ No newline at end of file From 0f962abe09860f5025859f71435b747b814c42b0 Mon Sep 17 00:00:00 2001 From: GokuWeedLord Date: Sun, 10 Dec 2017 02:49:22 +1100 Subject: [PATCH 05/75] building finally works :sweat_drops: :sweat_drops: :sweat_drops: --- CMakeLists.txt | 1 - scripts/native/CMakeLists.txt | 9 +++++++-- scripts/native/ScriptObject.h | 7 ++++--- scripts/native/statuseffect/StatusEffect50.cpp | 16 +++++++++------- src/servers/Server_Zone/CMakeLists.txt | 1 - src/servers/Server_Zone/Script/NativeScriptApi.h | 6 +++--- src/servers/Server_Zone/Script/ScriptManager.cpp | 16 +++++++--------- src/servers/Server_Zone/Script/ScriptManager.h | 2 -- 8 files changed, 30 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f7b96f6..45c443c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,7 +42,6 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/servers/Server_Common/Version.cp ########################################################################## # Common include folders -include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/libraries/external/ChaiScript-6.0.0/include/") include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/libraries/sapphire/datReader/") include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/libraries/sapphire/mysqlConnector/") include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src") diff --git a/scripts/native/CMakeLists.txt b/scripts/native/CMakeLists.txt index f431f0eb..3637a8a6 100644 --- a/scripts/native/CMakeLists.txt +++ b/scripts/native/CMakeLists.txt @@ -1,14 +1,19 @@ +cmake_minimum_required(VERSION 2.6) project(Sapphire_Script) file(GLOB SCRIPT_INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.h") - file(GLOB_RECURSE SCRIPT_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp") + +include_directories("../../src/servers/") +include_directories("../../src/servers/Server_Zone/") + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../../bin/compiledscripts/") + foreach(_sourcefile "${SCRIPT_FILES}") get_filename_component(_file "${_sourcefile}" NAME_WE) add_library("${_file}" MODULE "${_sourcefile}" "${SCRIPT_INCLUDE_FILES}") add_dependencies("${_file}" server_zone) - target_link_libraries("${_file}" server_zone) set_target_properties("${_file}" PROPERTIES CXX_STANDARD 14 diff --git a/scripts/native/ScriptObject.h b/scripts/native/ScriptObject.h index 8d639251..108b8df0 100644 --- a/scripts/native/ScriptObject.h +++ b/scripts/native/ScriptObject.h @@ -1,9 +1,10 @@ #ifndef SAPPHIRE_SCRIPTOBJECT_H #define SAPPHIRE_SCRIPTOBJECT_H -#include -#include -#include +#include