mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-05-01 16:37:45 +00:00
StatusEffect script bindings
This commit is contained in:
parent
4ae193ad7f
commit
f4e8798fe0
3 changed files with 73 additions and 0 deletions
|
@ -396,6 +396,69 @@ bool Core::Scripting::ScriptManager::onCastFinish( Entity::PlayerPtr pPlayer, En
|
||||||
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 );
|
||||||
|
|
||||||
|
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 )
|
||||||
|
{
|
||||||
|
pActor->getAsPlayer()->sendUrgent( e.what() );
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Core::Scripting::ScriptManager::onStatusTick( Entity::ActorPtr pActor, uint32_t effectId )
|
||||||
|
{
|
||||||
|
std::string eventName = "onTick";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
auto obj = m_pChaiHandler->eval( "statusDef_" + std::to_string( effectId ) );
|
||||||
|
std::string objName = "statusDef_" + std::to_string( effectId );
|
||||||
|
|
||||||
|
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 )
|
||||||
|
{
|
||||||
|
pActor->getAsPlayer()->sendUrgent( e.what() );
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 );
|
||||||
|
|
||||||
|
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 )
|
||||||
|
{
|
||||||
|
pActor->getAsPlayer()->sendUrgent( e.what() );
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool Core::Scripting::ScriptManager::onZoneInit( ZonePtr pZone )
|
bool Core::Scripting::ScriptManager::onZoneInit( ZonePtr pZone )
|
||||||
{
|
{
|
||||||
std::string eventName = "onZoneInit_" + pZone->getInternalName();
|
std::string eventName = "onZoneInit_" + pZone->getInternalName();
|
||||||
|
|
|
@ -52,6 +52,10 @@ namespace Core
|
||||||
|
|
||||||
bool onCastFinish( Entity::PlayerPtr pPlayer, Entity::ActorPtr pTarget, uint32_t actionId );
|
bool onCastFinish( Entity::PlayerPtr pPlayer, Entity::ActorPtr pTarget, uint32_t actionId );
|
||||||
|
|
||||||
|
bool onStatusReceive( Entity::ActorPtr pActor, uint32_t effectId );
|
||||||
|
bool onStatusTick( Entity::ActorPtr pActor, uint32_t effectId );
|
||||||
|
bool onStatusTimeOut( Entity::ActorPtr pActor, uint32_t effectId );
|
||||||
|
|
||||||
bool onZoneInit( ZonePtr pZone );
|
bool onZoneInit( ZonePtr pZone );
|
||||||
|
|
||||||
bool onEventHandlerReturn( Entity::PlayerPtr pPlayer, uint32_t eventId, uint16_t subEvent, uint16_t param1, uint16_t param2, uint16_t param3 );
|
bool onEventHandlerReturn( Entity::PlayerPtr pPlayer, uint32_t eventId, uint16_t subEvent, uint16_t param1, uint16_t param2, uint16_t param3 );
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "Actor.h"
|
#include "Actor.h"
|
||||||
|
|
||||||
#include "StatusEffect.h"
|
#include "StatusEffect.h"
|
||||||
|
#include "ScriptManager.h"
|
||||||
|
|
||||||
extern Core::Logger g_log;
|
extern Core::Logger g_log;
|
||||||
extern Core::Data::ExdData g_exdData;
|
extern Core::Data::ExdData g_exdData;
|
||||||
|
@ -17,6 +18,8 @@ extern Core::Data::ExdData g_exdData;
|
||||||
using namespace Core::Common;
|
using namespace Core::Common;
|
||||||
using namespace Core::Network::Packets;
|
using namespace Core::Network::Packets;
|
||||||
using namespace Core::Network::Packets::Server;
|
using namespace Core::Network::Packets::Server;
|
||||||
|
extern Core::Scripting::ScriptManager g_scriptMgr;
|
||||||
|
|
||||||
|
|
||||||
Core::StatusEffect::StatusEffect::StatusEffect( uint32_t id, Entity::ActorPtr sourceActor, Entity::ActorPtr targetActor,
|
Core::StatusEffect::StatusEffect::StatusEffect( uint32_t id, Entity::ActorPtr sourceActor, Entity::ActorPtr targetActor,
|
||||||
uint32_t duration, uint32_t tickRate )
|
uint32_t duration, uint32_t tickRate )
|
||||||
|
@ -51,6 +54,7 @@ Core::StatusEffect::StatusEffect::~StatusEffect()
|
||||||
void Core::StatusEffect::StatusEffect::onTick()
|
void Core::StatusEffect::StatusEffect::onTick()
|
||||||
{
|
{
|
||||||
m_lastTick = Util::getTimeMs();
|
m_lastTick = Util::getTimeMs();
|
||||||
|
g_scriptMgr.onStatusTick( m_targetActor, m_id );
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Core::StatusEffect::StatusEffect::getSrcActorId() const
|
uint32_t Core::StatusEffect::StatusEffect::getSrcActorId() const
|
||||||
|
@ -86,11 +90,13 @@ void Core::StatusEffect::StatusEffect::applyStatus()
|
||||||
//m_sourceActor->sendToInRangeSet( effectPacket, true );
|
//m_sourceActor->sendToInRangeSet( effectPacket, true );
|
||||||
|
|
||||||
g_log.debug( "StatusEffect applied: " + m_name );
|
g_log.debug( "StatusEffect applied: " + m_name );
|
||||||
|
g_scriptMgr.onStatusReceive( m_targetActor, m_id );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::StatusEffect::StatusEffect::removeStatus()
|
void Core::StatusEffect::StatusEffect::removeStatus()
|
||||||
{
|
{
|
||||||
g_log.debug( "StatusEffect removed: " + m_name );
|
g_log.debug( "StatusEffect removed: " + m_name );
|
||||||
|
g_scriptMgr.onStatusTimeOut( m_targetActor, m_id );
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Core::StatusEffect::StatusEffect::getId() const
|
uint32_t Core::StatusEffect::StatusEffect::getId() const
|
||||||
|
|
Loading…
Add table
Reference in a new issue