1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-03 17:27:47 +00:00

Split up NativeScriptApi

This commit is contained in:
root 2018-09-25 07:18:42 -04:00
parent 84e334d9bb
commit 64a9eec055
3 changed files with 207 additions and 123 deletions

View file

@ -6,6 +6,7 @@
#include <memory> #include <memory>
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
#include <vector> #include <vector>
#include "Common.h"
#define TYPE_FORWARD( x ) \ #define TYPE_FORWARD( x ) \
class x; \ class x; \

View file

@ -0,0 +1,167 @@
#include <string>
#include <typeinfo>
#include <typeindex>
#include <Event/EventHandler.h>
#include "NativeScriptApi.h"
#ifdef _MSC_VER
#define EXPORT __declspec( dllexport )
#else
#define EXPORT __attribute__((visibility("default")))
#endif
using namespace Core;
ScriptObject::ScriptObject( uint32_t id, std::size_t type ) :
m_id( id ),
m_type( type )
{
}
uint32_t ScriptObject::getId() const
{
return m_id;
}
std::size_t ScriptObject::getType() const
{
return m_type;
}
///////////////////////////////////////////////////////////////////
StatusEffectScript::StatusEffectScript( uint32_t effectId ) :
ScriptObject( effectId, typeid( StatusEffectScript ).hash_code() )
{
}
void StatusEffectScript::onTick( Entity::Chara& actor )
{
}
void StatusEffectScript::onApply( Entity::Chara& actor )
{
}
void StatusEffectScript::onRemove( Entity::Chara& actor )
{
}
void StatusEffectScript::onExpire( Entity::Chara& actor )
{
}
void StatusEffectScript::onPlayerCollision( Entity::Chara& actor, Entity::Chara& actorHit )
{
}
void StatusEffectScript::onPlayerFinishCast( Entity::Chara& actor )
{
}
void StatusEffectScript::onPlayerDamaged( Entity::Chara& actor )
{
}
void StatusEffectScript::onPlayerDeath( Entity::Chara& actor )
{
}
///////////////////////////////////////////////////////////////////
ActionScript::ActionScript( uint32_t abilityId ) :
ScriptObject( abilityId, typeid( ActionScript ).hash_code() )
{
}
void ActionScript::onStart( Entity::Chara& sourceActor, Entity::Chara& targetActor )
{
}
void ActionScript::onCastFinish( Entity::Player& player, Entity::Chara& targetActor )
{
}
void ActionScript::onInterrupt( Entity::Chara& sourceActor/*, Core::Entity::Chara targetActor*/ )
{
}
///////////////////////////////////////////////////////////////////
EventScript::EventScript( uint32_t questId ) :
ScriptObject( questId, typeid( EventScript ).hash_code() )
{
}
void EventScript::onTalk( uint32_t eventId, Entity::Player& player, uint64_t actorId )
{
}
void EventScript::onNpcKill( uint32_t npcId, Entity::Player& player )
{
}
void EventScript::onEmote( uint64_t actorId, uint32_t eventId, uint32_t emoteId, Entity::Player& player )
{
}
void EventScript::onEnterTerritory( Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2 )
{
}
void EventScript::onWithinRange( Entity::Player& player, uint32_t eventId, uint32_t param1, float x, float y, float z )
{
}
void EventScript::onOutsideRange( Entity::Player& player, uint32_t eventId, uint32_t param1, float x, float y, float z )
{
}
void
EventScript::onEventItem( Entity::Player& player, uint32_t eventItemId, uint32_t eventId, uint32_t castTime, uint64_t targetId )
{
}
void EventScript::onEventHandlerTradeReturn( Entity::Player& player, uint32_t eventId, uint16_t subEvent, uint16_t param,
uint32_t catalogId )
{
}
///////////////////////////////////////////////////////////////////
BattleNpcScript::BattleNpcScript( uint32_t npcId ) :
ScriptObject( npcId, typeid( BattleNpcScript ).hash_code() )
{
}
///////////////////////////////////////////////////////////////////
ZoneScript::ZoneScript( uint32_t zoneId ) :
ScriptObject( zoneId, typeid( ZoneScript ).hash_code() )
{
}
void ZoneScript::onZoneInit()
{
}
///////////////////////////////////////////////////////////////////
InstanceContentScript::InstanceContentScript( uint32_t instanceContentId ) :
ScriptObject( uint32_t{ 0x8003 } << 16 | instanceContentId, typeid( InstanceContentScript ).hash_code() )
{
}
void InstanceContentScript::onInit( InstanceContentPtr instance )
{
}
void InstanceContentScript::onUpdate( InstanceContentPtr instance, uint32_t currTime )
{
}
void InstanceContentScript::onEnterTerritory( InstanceContentPtr instance, Entity::Player& player, uint32_t eventId, uint16_t param1,
uint16_t param2 )
{
}

View file

@ -2,9 +2,6 @@
#define NATIVE_SCRIPT_API #define NATIVE_SCRIPT_API
#include <string> #include <string>
#include <typeinfo>
#include <typeindex>
#include <Event/EventHandler.h>
#include "ForwardsZone.h" #include "ForwardsZone.h"
#ifdef _MSC_VER #ifdef _MSC_VER
@ -34,81 +31,59 @@ public:
* @param id an ID which uniquely identifies this script in relation to it's type * @param id an ID which uniquely identifies this script in relation to it's type
* @param type The RTTI hash code of the implementing type to uniquely identify it * @param type The RTTI hash code of the implementing type to uniquely identify it
*/ */
ScriptObject( uint32_t id, std::size_t type ) : ScriptObject( uint32_t id, std::size_t type );
m_id( id ),
m_type( type )
{
}
/*! /*!
* @brief Gets the ID set for this script * @brief Gets the ID set for this script
* *
* @return The allocated ID of the script set during object construction * @return The allocated ID of the script set during object construction
*/ */
virtual uint32_t getId() const virtual uint32_t getId() const;
{
return m_id;
}
/*! /*!
* @brief Gets the unique identifier (hash_code) of the script * @brief Gets the unique identifier (hash_code) of the script
* *
* @return The hash_code of the script * @return The hash_code of the script
*/ */
virtual std::size_t getType() const virtual std::size_t getType() const;
{
return m_type;
}
}; };
/*! /*!
* @brief The base class for any scripts that implement behaviour related to status effects. * @brief The base class for any scripts that implement behaviour related to status effects.
*/ */
class StatusEffectScript : class StatusEffectScript : public ScriptObject
public ScriptObject
{ {
public: public:
explicit StatusEffectScript( uint32_t effectId ) : explicit StatusEffectScript( uint32_t effectId );
ScriptObject( effectId, typeid( StatusEffectScript ).hash_code() )
{
}
/*! /*!
* @brief Called on each tick that a status effect is active on an actor * @brief Called on each tick that a status effect is active on an actor
* *
* @param actor the actor the status effect is ticking on * @param actor the actor the status effect is ticking on
*/ */
virtual void onTick( Entity::Chara& actor ) virtual void onTick( Entity::Chara& actor );
{
}
/*! /*!
* @brief Called when the status effect is applied to an actor * @brief Called when the status effect is applied to an actor
* *
* @param actor the actor on which the status effect was applied to * @param actor the actor on which the status effect was applied to
*/ */
virtual void onApply( Entity::Chara& actor ) virtual void onApply( Entity::Chara& actor );
{
}
/*! /*!
* @brief Called when the actor (usually a player) removes the status effect by right clicking it * @brief Called when the actor (usually a player) removes the status effect by right clicking it
* *
* @param actor The actor on which the effect was removed from * @param actor The actor on which the effect was removed from
*/ */
virtual void onRemove( Entity::Chara& actor ) virtual void onRemove( Entity::Chara& actor );
{
}
/*! /*!
* @brief Called when the status effect expires * @brief Called when the status effect expires
* *
* @param actor The actor on which the efect expired on * @param actor The actor on which the efect expired on
*/ */
virtual void onExpire( Entity::Chara& actor ) virtual void onExpire( Entity::Chara& actor );
{
}
/*! /*!
* @brief Called when the player with the status effect collides with another player, eg. hot potato * @brief Called when the player with the status effect collides with another player, eg. hot potato
@ -116,175 +91,116 @@ public:
* @param actor The actor which has status effect * @param actor The actor which has status effect
* @param actorHit The actor who collided with the status effect owner * @param actorHit The actor who collided with the status effect owner
*/ */
virtual void onPlayerCollision( Entity::Chara& actor, Entity::Chara& actorHit ) virtual void onPlayerCollision( Entity::Chara& actor, Entity::Chara& actorHit );
{
}
/*! /*!
* @brief Called when the owner finishes a cast * @brief Called when the owner finishes a cast
* *
* @param actor The actor who finished a cast * @param actor The actor who finished a cast
*/ */
virtual void onPlayerFinishCast( Entity::Chara& actor ) virtual void onPlayerFinishCast( Entity::Chara& actor );
{
}
/*! /*!
* @brief Called when the status effect owner was damaged * @brief Called when the status effect owner was damaged
* *
* @param actor The actor that was damaged * @param actor The actor that was damaged
*/ */
virtual void onPlayerDamaged( Entity::Chara& actor ) virtual void onPlayerDamaged( Entity::Chara& actor );
{
}
/*! /*!
* @brief Called when the status effect owner dies * @brief Called when the status effect owner dies
* *
* @param actor The actor that died * @param actor The actor that died
*/ */
virtual void onPlayerDeath( Entity::Chara& actor ) virtual void onPlayerDeath( Entity::Chara& actor );
{
}
}; };
/*! /*!
* @brief The base class for any scripts that implement behaviour related to actions * @brief The base class for any scripts that implement behaviour related to actions
*/ */
class ActionScript : class ActionScript : public ScriptObject
public ScriptObject
{ {
public: public:
explicit ActionScript( uint32_t abilityId ) : explicit ActionScript( uint32_t abilityId );
ScriptObject( abilityId, typeid( ActionScript ).hash_code() )
{
}
virtual void onStart( Entity::Chara& sourceActor, Entity::Chara& targetActor ) virtual void onStart( Entity::Chara& sourceActor, Entity::Chara& targetActor );
{
}
virtual void onCastFinish( Entity::Player& player, Entity::Chara& targetActor ) virtual void onCastFinish( Entity::Player& player, Entity::Chara& targetActor );
{
}
virtual void onInterrupt( Entity::Chara& sourceActor/*, Core::Entity::Chara targetActor*/ ) virtual void onInterrupt( Entity::Chara& sourceActor/*, Core::Entity::Chara targetActor*/ );
{
}
}; };
/*! /*!
* @brief The base class for any scripts that implement behaviour related to the event system. * @brief The base class for any scripts that implement behaviour related to the event system.
* This includes but is not limited to: NPCs, shops, some world objects * This includes but is not limited to: NPCs, shops, some world objects
*/ */
class EventScript : class EventScript : public ScriptObject
public ScriptObject
{ {
protected: protected:
template< typename Ret, class Obj > template< typename Ret, class Obj >
inline Event::EventHandler::SceneChainCallback bindScene( Ret ( Obj::*f )( Entity::Player& ) ) inline std::function< void( Entity::Player& ) > bindScene( Ret ( Obj::*f )( Entity::Player& ) )
{ {
return std::bind( f, static_cast< Obj* >( this ), std::placeholders::_1 ); return std::bind( f, static_cast< Obj* >( this ), std::placeholders::_1 );
} }
public: public:
explicit EventScript( uint32_t questId ) : explicit EventScript( uint32_t questId );
ScriptObject( questId, typeid( EventScript ).hash_code() )
{
}
virtual void onTalk( uint32_t eventId, Entity::Player& player, uint64_t actorId ) virtual void onTalk( uint32_t eventId, Entity::Player& player, uint64_t actorId );
{
}
virtual void onNpcKill( uint32_t npcId, Entity::Player& player ) virtual void onNpcKill( uint32_t npcId, Entity::Player& player );
{
}
virtual void onEmote( uint64_t actorId, uint32_t eventId, uint32_t emoteId, Entity::Player& player ) virtual void onEmote( uint64_t actorId, uint32_t eventId, uint32_t emoteId, Entity::Player& player );
{
}
virtual void onEnterTerritory( Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2 ) virtual void onEnterTerritory( Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2 );
{
}
virtual void onWithinRange( Entity::Player& player, uint32_t eventId, uint32_t param1, float x, float y, float z ) virtual void onWithinRange( Entity::Player& player, uint32_t eventId, uint32_t param1, float x, float y, float z );
{
}
virtual void onOutsideRange( Entity::Player& player, uint32_t eventId, uint32_t param1, float x, float y, float z ) virtual void onOutsideRange( Entity::Player& player, uint32_t eventId, uint32_t param1, float x, float y, float z );
{
}
virtual void virtual void
onEventItem( Entity::Player& player, uint32_t eventItemId, uint32_t eventId, uint32_t castTime, uint64_t targetId ) onEventItem( Entity::Player& player, uint32_t eventItemId, uint32_t eventId, uint32_t castTime, uint64_t targetId );
{
}
virtual void onEventHandlerTradeReturn( Entity::Player& player, uint32_t eventId, uint16_t subEvent, uint16_t param, virtual void onEventHandlerTradeReturn( Entity::Player& player, uint32_t eventId, uint16_t subEvent, uint16_t param,
uint32_t catalogId ) uint32_t catalogId );
{
}
}; };
/*! /*!
* @brief The base class for any scripts that implement behaviour related to BattleNPCs * @brief The base class for any scripts that implement behaviour related to BattleNPCs
*/ */
class BattleNpcScript : class BattleNpcScript : public ScriptObject
public ScriptObject
{ {
public: public:
explicit BattleNpcScript( uint32_t npcId ) : explicit BattleNpcScript( uint32_t npcId );
ScriptObject( npcId, typeid( BattleNpcScript ).hash_code() )
{
}
}; };
/*! /*!
* @brief The base class for any scripts that implement behaviour related to zones * @brief The base class for any scripts that implement behaviour related to zones
*/ */
class ZoneScript : class ZoneScript : public ScriptObject
public ScriptObject
{ {
public: public:
explicit ZoneScript( uint32_t zoneId ) : explicit ZoneScript( uint32_t zoneId );
ScriptObject( zoneId, typeid( ZoneScript ).hash_code() )
{
}
virtual void onZoneInit() virtual void onZoneInit();
{
}
}; };
/*! /*!
* @brief The base class for any scripts that implement behaviour related to instance content zones * @brief The base class for any scripts that implement behaviour related to instance content zones
*/ */
class InstanceContentScript : class InstanceContentScript : public ScriptObject
public ScriptObject
{ {
public: public:
explicit InstanceContentScript( uint32_t instanceContentId ) : explicit InstanceContentScript( uint32_t instanceContentId );
ScriptObject( uint32_t{ 0x8003 } << 16 | instanceContentId, typeid( InstanceContentScript ).hash_code() )
{
}
virtual void onInit( InstanceContentPtr instance ) virtual void onInit( InstanceContentPtr instance );
{
}
virtual void onUpdate( InstanceContentPtr instance, uint32_t currTime ) virtual void onUpdate( InstanceContentPtr instance, uint32_t currTime );
{
}
virtual void onEnterTerritory( InstanceContentPtr instance, Entity::Player& player, uint32_t eventId, uint16_t param1, virtual void onEnterTerritory( InstanceContentPtr instance, Entity::Player& player, uint32_t eventId, uint16_t param1,
uint16_t param2 ) uint16_t param2 );
{
}
}; };
#endif #endif