mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-28 23:27:45 +00:00
refactor and simplify how actionscripts are called and used
This commit is contained in:
parent
8aeaa0c443
commit
c561b50058
9 changed files with 40 additions and 39 deletions
|
@ -1,6 +1,7 @@
|
||||||
#include <Script/NativeScriptApi.h>
|
#include <Script/NativeScriptApi.h>
|
||||||
#include <ScriptObject.h>
|
#include <ScriptObject.h>
|
||||||
#include <Actor/Player.h>
|
#include <Actor/Player.h>
|
||||||
|
#include <Action/Action.h>
|
||||||
|
|
||||||
class ActionReturn6 :
|
class ActionReturn6 :
|
||||||
public Sapphire::ScriptAPI::ActionScript
|
public Sapphire::ScriptAPI::ActionScript
|
||||||
|
@ -11,11 +12,11 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void onCastFinish( Sapphire::Entity::Chara& sourceActor, Sapphire::Action::Action& currentAction ) override
|
void onCastFinish( Sapphire::Action::Action& currentAction ) override
|
||||||
{
|
{
|
||||||
if( !sourceActor.isPlayer() )
|
if( !currentAction.getSourceChara()->isPlayer() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
sourceActor.getAsPlayer()->returnToHomepoint();
|
currentAction.getSourceChara()->getAsPlayer()->returnToHomepoint();
|
||||||
}
|
}
|
||||||
};
|
};
|
|
@ -1,5 +1,6 @@
|
||||||
#include <ScriptObject.h>
|
#include <ScriptObject.h>
|
||||||
#include <Actor/Player.h>
|
#include <Actor/Player.h>
|
||||||
|
#include <Action/Action.h>
|
||||||
|
|
||||||
class ActionSprint3 :
|
class ActionSprint3 :
|
||||||
public Sapphire::ScriptAPI::ActionScript
|
public Sapphire::ScriptAPI::ActionScript
|
||||||
|
@ -10,11 +11,13 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void onCastFinish( Sapphire::Entity::Chara& sourceActor, Sapphire::Action::Action& currentAction ) override
|
void onCastFinish( Sapphire::Action::Action& currentAction ) override
|
||||||
{
|
{
|
||||||
if( !sourceActor.isPlayer() )
|
auto sourceChara = currentAction.getSourceChara();
|
||||||
|
|
||||||
|
if( !sourceChara->isPlayer() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
sourceActor.getAsPlayer()->addStatusEffectByIdIfNotExist( 50, 20000, sourceActor, 30 );
|
sourceChara->getAsPlayer()->addStatusEffectByIdIfNotExist( 50, 20000, *sourceChara, 30 );
|
||||||
}
|
}
|
||||||
};
|
};
|
|
@ -12,14 +12,14 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void onCastFinish( Sapphire::Entity::Chara& source, Sapphire::Action::Action& currentAction ) override
|
void onCastFinish( Sapphire::Action::Action& currentAction ) override
|
||||||
{
|
{
|
||||||
if( auto player = source.getAsPlayer() )
|
auto source = currentAction.getSourceChara();
|
||||||
|
if( auto player = source->getAsPlayer() )
|
||||||
player->sendDebug( "cast finished" );
|
player->sendDebug( "cast finished" );
|
||||||
}
|
}
|
||||||
|
|
||||||
void onCharaHit( Sapphire::Entity::Chara& sourceActor, Sapphire::Entity::Chara& hitActor,
|
void onCharaHit( Sapphire::Action::Action& currentAction, Sapphire::Entity::Chara& hitActor ) override
|
||||||
Sapphire::Action::Action& currentAction ) override
|
|
||||||
{
|
{
|
||||||
currentAction.damageTarget( 150, hitActor );
|
currentAction.damageTarget( 150, hitActor );
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,7 +129,7 @@ bool Sapphire::Action::Action::hasCastTime() const
|
||||||
return m_castTime > 0;
|
return m_castTime > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Sapphire::Entity::CharaPtr Sapphire::Action::Action::getActionSource() const
|
Sapphire::Entity::CharaPtr Sapphire::Action::Action::getSourceChara() const
|
||||||
{
|
{
|
||||||
return m_pSource;
|
return m_pSource;
|
||||||
}
|
}
|
||||||
|
@ -194,7 +194,7 @@ void Sapphire::Action::Action::castStart()
|
||||||
}
|
}
|
||||||
|
|
||||||
auto pScriptMgr = m_pFw->get< Scripting::ScriptMgr >();
|
auto pScriptMgr = m_pFw->get< Scripting::ScriptMgr >();
|
||||||
if( !pScriptMgr->onCastStart( *m_pSource, *this ) )
|
if( !pScriptMgr->onCastStart( *this ) )
|
||||||
{
|
{
|
||||||
// script not implemented
|
// script not implemented
|
||||||
castInterrupt();
|
castInterrupt();
|
||||||
|
@ -249,7 +249,7 @@ void Sapphire::Action::Action::castInterrupt()
|
||||||
}
|
}
|
||||||
|
|
||||||
auto pScriptMgr = m_pFw->get< Scripting::ScriptMgr >();
|
auto pScriptMgr = m_pFw->get< Scripting::ScriptMgr >();
|
||||||
pScriptMgr->onCastInterrupt( *m_pSource, *this );
|
pScriptMgr->onCastInterrupt( *this );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sapphire::Action::Action::castFinish()
|
void Sapphire::Action::Action::castFinish()
|
||||||
|
@ -269,13 +269,13 @@ void Sapphire::Action::Action::castFinish()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pScriptMgr->onCastFinish( *m_pSource, *this );
|
pScriptMgr->onCastFinish( *this );
|
||||||
|
|
||||||
if( !hasResidentTarget() )
|
if( !hasResidentTarget() )
|
||||||
{
|
{
|
||||||
assert( m_pTarget );
|
assert( m_pTarget );
|
||||||
// todo: calculate final hit targets and call onCharaHit in action script
|
// todo: calculate final hit targets and call onCharaHit in action script
|
||||||
pScriptMgr->onCharaHit( *m_pSource, *m_pTarget, *this );
|
pScriptMgr->onCharaHit( *this, *m_pTarget );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -39,7 +39,7 @@ namespace Sapphire::Action
|
||||||
void setTargetChara( Entity::CharaPtr chara );
|
void setTargetChara( Entity::CharaPtr chara );
|
||||||
void setResidentTargetId( uint64_t targetId );
|
void setResidentTargetId( uint64_t targetId );
|
||||||
Entity::CharaPtr getTargetChara() const;
|
Entity::CharaPtr getTargetChara() const;
|
||||||
Entity::CharaPtr getActionSource() const;
|
Entity::CharaPtr getSourceChara() const;
|
||||||
|
|
||||||
bool isInterrupted() const;
|
bool isInterrupted() const;
|
||||||
void setInterrupted( Common::ActionInterruptType type );
|
void setInterrupted( Common::ActionInterruptType type );
|
||||||
|
|
|
@ -88,20 +88,19 @@ namespace Sapphire::ScriptAPI
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionScript::onCastStart( Entity::Chara& sourceActor, Sapphire::Action::Action& currentAction )
|
void ActionScript::onCastStart( Sapphire::Action::Action& currentAction )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionScript::onCastFinish( Entity::Chara& sourceActor, Sapphire::Action::Action& currentAction )
|
void ActionScript::onCastFinish( Sapphire::Action::Action& currentAction )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionScript::onCastInterrupt( Entity::Chara& sourceActor, Sapphire::Action::Action& currentAction )
|
void ActionScript::onCastInterrupt( Sapphire::Action::Action& currentAction )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionScript::onCharaHit( Sapphire::Entity::Chara& sourceActor, Sapphire::Entity::Chara& hitActor,
|
void ActionScript::onCharaHit( Sapphire::Action::Action& currentAction, Sapphire::Entity::Chara& hitActor )
|
||||||
Sapphire::Action::Action& currentAction )
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -140,14 +140,13 @@ namespace Sapphire::ScriptAPI
|
||||||
public:
|
public:
|
||||||
explicit ActionScript( uint32_t abilityId );
|
explicit ActionScript( uint32_t abilityId );
|
||||||
|
|
||||||
virtual void onCastStart( Sapphire::Entity::Chara& sourceActor, Sapphire::Action::Action& currentAction );
|
virtual void onCastStart( Sapphire::Action::Action& currentAction );
|
||||||
|
|
||||||
virtual void onCastFinish( Sapphire::Entity::Chara& sourceActor, Sapphire::Action::Action& currentAction );
|
virtual void onCastFinish( Sapphire::Action::Action& currentAction );
|
||||||
|
|
||||||
virtual void onCastInterrupt( Sapphire::Entity::Chara& sourceActor, Sapphire::Action::Action& currentAction );
|
virtual void onCastInterrupt( Sapphire::Action::Action& currentAction );
|
||||||
|
|
||||||
virtual void onCharaHit( Sapphire::Entity::Chara& sourceActor, Sapphire::Entity::Chara& hitActor,
|
virtual void onCharaHit( Sapphire::Action::Action& currentAction, Sapphire::Entity::Chara& hitActor );
|
||||||
Sapphire::Action::Action& currentAction );
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
|
@ -328,51 +328,50 @@ bool Sapphire::Scripting::ScriptMgr::onEObjHit( Sapphire::Entity::Player& player
|
||||||
return didCallScript;
|
return didCallScript;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Sapphire::Scripting::ScriptMgr::onCastFinish( Entity::Chara& sourceActor, Action::Action& currentAction )
|
bool Sapphire::Scripting::ScriptMgr::onCastFinish( Action::Action& currentAction )
|
||||||
{
|
{
|
||||||
auto script = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::ActionScript >( currentAction.getId() );
|
auto script = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::ActionScript >( currentAction.getId() );
|
||||||
|
|
||||||
if( script )
|
if( script )
|
||||||
{
|
{
|
||||||
script->onCastFinish( sourceActor, currentAction );
|
script->onCastFinish( currentAction );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Sapphire::Scripting::ScriptMgr::onCastInterrupt( Entity::Chara& sourceActor, Action::Action& currentAction )
|
bool Sapphire::Scripting::ScriptMgr::onCastInterrupt( Action::Action& currentAction )
|
||||||
{
|
{
|
||||||
auto script = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::ActionScript >( currentAction.getId() );
|
auto script = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::ActionScript >( currentAction.getId() );
|
||||||
|
|
||||||
if( script )
|
if( script )
|
||||||
{
|
{
|
||||||
script->onCastInterrupt( sourceActor, currentAction );
|
script->onCastInterrupt( currentAction );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Sapphire::Scripting::ScriptMgr::onCastStart( Entity::Chara& sourceActor, Action::Action& currentAction )
|
bool Sapphire::Scripting::ScriptMgr::onCastStart( Action::Action& currentAction )
|
||||||
{
|
{
|
||||||
auto script = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::ActionScript >( currentAction.getId() );
|
auto script = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::ActionScript >( currentAction.getId() );
|
||||||
|
|
||||||
if( script )
|
if( script )
|
||||||
{
|
{
|
||||||
script->onCastStart( sourceActor, currentAction );
|
script->onCastStart( currentAction );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Sapphire::Scripting::ScriptMgr::onCharaHit( Entity::Chara& sourceActor, Entity::Chara& hitActor,
|
bool Sapphire::Scripting::ScriptMgr::onCharaHit( Action::Action& currentAction, Entity::Chara& hitActor )
|
||||||
Action::Action& currentAction )
|
|
||||||
{
|
{
|
||||||
auto script = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::ActionScript >( currentAction.getId() );
|
auto script = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::ActionScript >( currentAction.getId() );
|
||||||
|
|
||||||
if( script )
|
if( script )
|
||||||
{
|
{
|
||||||
script->onCharaHit( sourceActor, hitActor, currentAction );
|
script->onCharaHit( currentAction, hitActor );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,10 +72,10 @@ namespace Sapphire::Scripting
|
||||||
|
|
||||||
bool onEObjHit( Entity::Player& player, uint64_t actorId );
|
bool onEObjHit( Entity::Player& player, uint64_t actorId );
|
||||||
|
|
||||||
bool onCastStart( Entity::Chara& sourceActor, Action::Action& currentAction );
|
bool onCastStart( Action::Action& currentAction );
|
||||||
bool onCastInterrupt( Entity::Chara& sourceActor, Action::Action& currentAction );
|
bool onCastInterrupt( Action::Action& currentAction );
|
||||||
bool onCastFinish( Entity::Chara& sourceActor, Action::Action& currentAction );
|
bool onCastFinish( Action::Action& currentAction );
|
||||||
bool onCharaHit( Entity::Chara& sourceActor, Entity::Chara& hitActor, Action::Action& currentAction );
|
bool onCharaHit( Action::Action& currentAction, Entity::Chara& hitActor );
|
||||||
|
|
||||||
bool onStatusReceive( Entity::CharaPtr pActor, uint32_t effectId );
|
bool onStatusReceive( Entity::CharaPtr pActor, uint32_t effectId );
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue