mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-28 15:17:46 +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 <ScriptObject.h>
|
||||
#include <Actor/Player.h>
|
||||
#include <Action/Action.h>
|
||||
|
||||
class ActionReturn6 :
|
||||
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;
|
||||
|
||||
sourceActor.getAsPlayer()->returnToHomepoint();
|
||||
currentAction.getSourceChara()->getAsPlayer()->returnToHomepoint();
|
||||
}
|
||||
};
|
|
@ -1,5 +1,6 @@
|
|||
#include <ScriptObject.h>
|
||||
#include <Actor/Player.h>
|
||||
#include <Action/Action.h>
|
||||
|
||||
class ActionSprint3 :
|
||||
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;
|
||||
|
||||
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" );
|
||||
}
|
||||
|
||||
void onCharaHit( Sapphire::Entity::Chara& sourceActor, Sapphire::Entity::Chara& hitActor,
|
||||
Sapphire::Action::Action& currentAction ) override
|
||||
void onCharaHit( Sapphire::Action::Action& currentAction, Sapphire::Entity::Chara& hitActor ) override
|
||||
{
|
||||
currentAction.damageTarget( 150, hitActor );
|
||||
}
|
||||
|
|
|
@ -129,7 +129,7 @@ bool Sapphire::Action::Action::hasCastTime() const
|
|||
return m_castTime > 0;
|
||||
}
|
||||
|
||||
Sapphire::Entity::CharaPtr Sapphire::Action::Action::getActionSource() const
|
||||
Sapphire::Entity::CharaPtr Sapphire::Action::Action::getSourceChara() const
|
||||
{
|
||||
return m_pSource;
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ void Sapphire::Action::Action::castStart()
|
|||
}
|
||||
|
||||
auto pScriptMgr = m_pFw->get< Scripting::ScriptMgr >();
|
||||
if( !pScriptMgr->onCastStart( *m_pSource, *this ) )
|
||||
if( !pScriptMgr->onCastStart( *this ) )
|
||||
{
|
||||
// script not implemented
|
||||
castInterrupt();
|
||||
|
@ -249,7 +249,7 @@ void Sapphire::Action::Action::castInterrupt()
|
|||
}
|
||||
|
||||
auto pScriptMgr = m_pFw->get< Scripting::ScriptMgr >();
|
||||
pScriptMgr->onCastInterrupt( *m_pSource, *this );
|
||||
pScriptMgr->onCastInterrupt( *this );
|
||||
}
|
||||
|
||||
void Sapphire::Action::Action::castFinish()
|
||||
|
@ -269,13 +269,13 @@ void Sapphire::Action::Action::castFinish()
|
|||
|
||||
}
|
||||
|
||||
pScriptMgr->onCastFinish( *m_pSource, *this );
|
||||
pScriptMgr->onCastFinish( *this );
|
||||
|
||||
if( !hasResidentTarget() )
|
||||
{
|
||||
assert( m_pTarget );
|
||||
// todo: calculate final hit targets and call onCharaHit in action script
|
||||
pScriptMgr->onCharaHit( *m_pSource, *m_pTarget, *this );
|
||||
pScriptMgr->onCharaHit( *this, *m_pTarget );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace Sapphire::Action
|
|||
void setTargetChara( Entity::CharaPtr chara );
|
||||
void setResidentTargetId( uint64_t targetId );
|
||||
Entity::CharaPtr getTargetChara() const;
|
||||
Entity::CharaPtr getActionSource() const;
|
||||
Entity::CharaPtr getSourceChara() const;
|
||||
|
||||
bool isInterrupted() const;
|
||||
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,
|
||||
Sapphire::Action::Action& currentAction )
|
||||
void ActionScript::onCharaHit( Sapphire::Action::Action& currentAction, Sapphire::Entity::Chara& hitActor )
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -140,14 +140,13 @@ namespace Sapphire::ScriptAPI
|
|||
public:
|
||||
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,
|
||||
Sapphire::Action::Action& currentAction );
|
||||
virtual void onCharaHit( Sapphire::Action::Action& currentAction, Sapphire::Entity::Chara& hitActor );
|
||||
};
|
||||
|
||||
/*!
|
||||
|
|
|
@ -328,51 +328,50 @@ bool Sapphire::Scripting::ScriptMgr::onEObjHit( Sapphire::Entity::Player& player
|
|||
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() );
|
||||
|
||||
if( script )
|
||||
{
|
||||
script->onCastFinish( sourceActor, currentAction );
|
||||
script->onCastFinish( currentAction );
|
||||
return true;
|
||||
}
|
||||
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() );
|
||||
|
||||
if( script )
|
||||
{
|
||||
script->onCastInterrupt( sourceActor, currentAction );
|
||||
script->onCastInterrupt( currentAction );
|
||||
return true;
|
||||
}
|
||||
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() );
|
||||
|
||||
if( script )
|
||||
{
|
||||
script->onCastStart( sourceActor, currentAction );
|
||||
script->onCastStart( currentAction );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Sapphire::Scripting::ScriptMgr::onCharaHit( Entity::Chara& sourceActor, Entity::Chara& hitActor,
|
||||
Action::Action& currentAction )
|
||||
bool Sapphire::Scripting::ScriptMgr::onCharaHit( Action::Action& currentAction, Entity::Chara& hitActor )
|
||||
{
|
||||
auto script = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::ActionScript >( currentAction.getId() );
|
||||
|
||||
if( script )
|
||||
{
|
||||
script->onCharaHit( sourceActor, hitActor, currentAction );
|
||||
script->onCharaHit( currentAction, hitActor );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -72,10 +72,10 @@ namespace Sapphire::Scripting
|
|||
|
||||
bool onEObjHit( Entity::Player& player, uint64_t actorId );
|
||||
|
||||
bool onCastStart( Entity::Chara& sourceActor, Action::Action& currentAction );
|
||||
bool onCastInterrupt( Entity::Chara& sourceActor, Action::Action& currentAction );
|
||||
bool onCastFinish( Entity::Chara& sourceActor, Action::Action& currentAction );
|
||||
bool onCharaHit( Entity::Chara& sourceActor, Entity::Chara& hitActor, Action::Action& currentAction );
|
||||
bool onCastStart( Action::Action& currentAction );
|
||||
bool onCastInterrupt( Action::Action& currentAction );
|
||||
bool onCastFinish( Action::Action& currentAction );
|
||||
bool onCharaHit( Action::Action& currentAction, Entity::Chara& hitActor );
|
||||
|
||||
bool onStatusReceive( Entity::CharaPtr pActor, uint32_t effectId );
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue