diff --git a/scripts/native/statuseffect/Status50.cpp b/scripts/native/statuseffect/Status50.cpp index 4a078414..da9d6bd0 100644 --- a/scripts/native/statuseffect/Status50.cpp +++ b/scripts/native/statuseffect/Status50.cpp @@ -11,6 +11,19 @@ public: if( actor->isPlayer() ) actor->getAsPlayer()->sendDebug( "tick tock bitch" ); } + + virtual void onApply( Entity::ActorPtr actor ) + { + if( actor->isPlayer() ) + actor->getAsPlayer()->sendDebug( "status50 applied" ); + } + + virtual void onExpire( Entity::ActorPtr actor ) + { + if( actor->isPlayer() ) + actor->getAsPlayer()->sendDebug( "status50 timed out" ); + } + }; EXPORT_STATUSEFFECTSCRIPT( Status50 ) \ No newline at end of file diff --git a/src/servers/Server_Zone/Script/NativeScript.cpp b/src/servers/Server_Zone/Script/NativeScript.cpp index 3b3f08de..8fb34072 100644 --- a/src/servers/Server_Zone/Script/NativeScript.cpp +++ b/src/servers/Server_Zone/Script/NativeScript.cpp @@ -77,25 +77,25 @@ namespace Core { if( handle ) { // todo: this is shit - if( auto script = m_loader.getScriptObject< StatusEffectScript >( handle ) ) + if( auto script = m_loader.getScriptObject< StatusEffectScript >( handle, "StatusEffectScript" ) ) { - m_statusEffectScripts.insert( std::make_pair( script->getEffectId(), script ) ); + m_statusEffectScripts[ script->getId() ] = script; } - else if( auto script = m_loader.getScriptObject< ActionScript >( handle ) ) + else if( auto script = m_loader.getScriptObject< ActionScript >( handle, "ActionScript" ) ) { - m_actionScripts.insert( std::make_pair( script->getActionId(), script ) ); + m_actionScripts[ script->getId() ] = script; } - else if( auto script = m_loader.getScriptObject< QuestScript >( handle ) ) + else if( auto script = m_loader.getScriptObject< QuestScript >( handle, "QuestScript" ) ) { - m_questScripts.insert( std::make_pair( script->getQuestId(), script ) ); + m_questScripts[ script->getId() ] = script; } - else if( auto script = m_loader.getScriptObject< BattleNpcScript >( handle ) ) + else if( auto script = m_loader.getScriptObject< BattleNpcScript >( handle, "BattleNpcScript" ) ) { - m_battleNpcScripts.insert( std::make_pair( script->getNpcId(), script ) ); + m_battleNpcScripts[ script->getId() ] = script; } - else if( auto script = m_loader.getScriptObject< ZoneScript >( handle ) ) + else if( auto script = m_loader.getScriptObject< ZoneScript >( handle, "ZoneScript" ) ) { - m_zoneScripts.insert( std::make_pair( script->getZoneId(), script ) ); + m_zoneScripts[ script->getId() ] = script; } else { diff --git a/src/servers/Server_Zone/Script/NativeScriptApi.h b/src/servers/Server_Zone/Script/NativeScriptApi.h index 8b53e5fe..be766101 100644 --- a/src/servers/Server_Zone/Script/NativeScriptApi.h +++ b/src/servers/Server_Zone/Script/NativeScriptApi.h @@ -22,129 +22,93 @@ extern "C" EXPORT base* get##base() \ #define EXPORT_BATTLENPCSCRIPT( type ) EXPORT_SCRIPTOBJECT( type, BattleNpcScript ) #define EXPORT_ZONESCRIPT( type ) EXPORT_SCRIPTOBJECT( type, ZoneScript ) +using namespace Core; + class ScriptObject { protected: - const std::string m_scriptName; + std::string m_scriptName; + uint32_t m_id; public: - ScriptObject( std::string name ) : - m_scriptName( name ) + ScriptObject( std::string name, uint32_t id ) : + m_scriptName( name ), + m_id( id ) { } - const std::string getName() + virtual const std::string& getName() const { return m_scriptName; } + + virtual uint32_t getId() const + { + return m_id; + } }; class StatusEffectScript : public ScriptObject { -protected: - const uint32_t m_effectId; - public: StatusEffectScript( std::string name, uint32_t effectId ) : - ScriptObject( name ), - m_effectId( effectId ) + ScriptObject( name, effectId ) { } - const uint32_t getEffectId( ) - { - return m_effectId; - } - - virtual void onTick( Core::Entity::ActorPtr actor ) { } - virtual void onApply( Core::Entity::ActorPtr actor ) { } - virtual void onRemove( Core::Entity::ActorPtr actor ) { } - virtual void onExpire(Core::Entity::ActorPtr actor) { } - virtual void onPlayerCollision( Core::Entity::ActorPtr actor, Core::Entity::ActorPtr actorHit ) { } - virtual void onPlayerFinishCast( Core::Entity::ActorPtr actor ) { } - virtual void onPlayerDamaged( Core::Entity::ActorPtr actor ) { } - virtual void onPlayerDeath( Core::Entity::ActorPtr actor ) { } + virtual void onTick( Entity::ActorPtr actor ) { } + virtual void onApply( Entity::ActorPtr actor ) { } + virtual void onRemove( Entity::ActorPtr actor ) { } + virtual void onExpire(Entity::ActorPtr actor) { } + virtual void onPlayerCollision( Entity::ActorPtr actor, Entity::ActorPtr actorHit ) { } + virtual void onPlayerFinishCast( Entity::ActorPtr actor ) { } + virtual void onPlayerDamaged( Entity::ActorPtr actor ) { } + virtual void onPlayerDeath( Entity::ActorPtr actor ) { } }; class ActionScript : public ScriptObject { -protected: - const uint32_t m_actionId; - public: ActionScript( std::string name, uint32_t abilityId ) : - ScriptObject( name ), - m_actionId( abilityId ) + ScriptObject( name, abilityId ) { } - const uint32_t getActionId() - { - return m_actionId; - } - - virtual void onStart( Core::Entity::Actor sourceActor, Core::Entity::ActorPtr targetActor ) { } - virtual void onCastFinish( Core::Entity::Player player, Core::Entity::ActorPtr targetActor ) { } - virtual void onInterrupt( Core::Entity::Actor sourceActor/*, Core::Entity::Actor targetActor*/ ) { } + virtual void onStart( Entity::Actor sourceActor, Entity::ActorPtr targetActor ) { } + virtual void onCastFinish( Entity::Player& player, Entity::ActorPtr targetActor ) { } + virtual void onInterrupt( Entity::ActorPtr sourceActor/*, Core::Entity::Actor targetActor*/ ) { } }; class QuestScript : public ScriptObject { -protected: - const uint32_t m_questId; - public: QuestScript( std::string name, uint32_t questId ) : - ScriptObject( name ), - m_questId( questId ) + ScriptObject( name, 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 ) { } + virtual void onTalk(uint32_t eventId, Entity::Player& player, uint64_t actorId) { } + virtual void onNpcKill( uint32_t npcId, Entity::Player& player ) { } + virtual void onEmote( uint64_t actorId, uint32_t eventId, uint32_t emoteId, Entity::Player& player ) { } }; class BattleNpcScript : public ScriptObject { -protected: - const uint32_t m_npcId; - public: BattleNpcScript( std::string name, uint32_t npcId ) : - ScriptObject( name ), - m_npcId( npcId ) + ScriptObject( name, npcId ) { } - - const uint32_t getNpcId() - { - return m_npcId; - } }; class ZoneScript : public ScriptObject { -protected: - const uint32_t m_zoneId; - public: ZoneScript( std::string name, uint32_t zoneId ) : - ScriptObject( name ), - m_zoneId( zoneId ) + ScriptObject( name, zoneId ) { } - const uint32_t getZoneId() - { - return m_zoneId; - } - virtual void onZoneInit() { } - virtual void onEnterZone( Core::Entity::Player pPlayer, uint32_t eventId, uint16_t param1, uint16_t param2 ) { } + virtual void onEnterZone( 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/ScriptLoader.cpp b/src/servers/Server_Zone/Script/ScriptLoader.cpp index 8632a298..93c12881 100644 --- a/src/servers/Server_Zone/Script/ScriptLoader.cpp +++ b/src/servers/Server_Zone/Script/ScriptLoader.cpp @@ -60,12 +60,12 @@ ModuleHandle Core::Scripting::ScriptLoader::loadModule( std::string path ) return handle; } -ScriptObject* Core::Scripting::ScriptLoader::getScriptObject( ModuleHandle handle, std::string name ) +ScriptObject* Core::Scripting::ScriptLoader::getScriptObjectExport( ModuleHandle handle, std::string name ) { typedef ScriptObject* (*getScriptObjectType)(); auto fn = boost::str( boost::format( "get%1%" ) % name ); - g_log.info( "getting symbol: " + fn ); + g_log.debug( "getting symbol: " + fn ); #ifdef _WIN32 getScriptObjectType func = reinterpret_cast< getScriptObjectType >( GetProcAddress( handle, fn.c_str() ) ); @@ -74,7 +74,14 @@ ScriptObject* Core::Scripting::ScriptLoader::getScriptObject( ModuleHandle handl #endif if( func ) - return func(); + { + auto ptr = func(); + + g_log.debug( "got ScriptObject @ 0x" + boost::str( boost::format( "%|08X|" ) % ptr ) ); + g_log.debug( "script info -> name: " + std::string( ptr->getName() ) + ", id: " + std::to_string( ptr->getId() ) ); + + return ptr; + } else return nullptr; } diff --git a/src/servers/Server_Zone/Script/ScriptLoader.h b/src/servers/Server_Zone/Script/ScriptLoader.h index 3d422620..10b65727 100644 --- a/src/servers/Server_Zone/Script/ScriptLoader.h +++ b/src/servers/Server_Zone/Script/ScriptLoader.h @@ -30,12 +30,12 @@ namespace Scripting { bool unloadScript( std::string ); bool unloadScript( ModuleHandle ); - ScriptObject* getScriptObject( ModuleHandle handle, std::string name ); + ScriptObject* getScriptObjectExport( ModuleHandle handle, std::string name ); template< typename T > - T* getScriptObject( ModuleHandle handle ) + T* getScriptObject( ModuleHandle handle, std::string name ) { - return static_cast< T* >( getScriptObject( handle, typeid( T ).name() ) ); + return static_cast< T* >( getScriptObjectExport( handle, name ) ); } }; diff --git a/src/servers/Server_Zone/Script/ScriptManager.cpp b/src/servers/Server_Zone/Script/ScriptManager.cpp index 5d847045..9603554d 100644 --- a/src/servers/Server_Zone/Script/ScriptManager.cpp +++ b/src/servers/Server_Zone/Script/ScriptManager.cpp @@ -47,6 +47,8 @@ bool Core::Scripting::ScriptManager::init() auto& path = *itr; g_log.debug( "got module: " + path ); + + m_nativeScriptHandler->loadScript( path ); } return true;