1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-02 08:57:44 +00:00

somewhat working action lut stuff

This commit is contained in:
NotAdam 2019-06-02 02:30:54 +10:00
parent 90d1fbc3ea
commit d755ea2a32
14 changed files with 44 additions and 227 deletions

View file

@ -1,23 +0,0 @@
#include <Script/NativeScriptApi.h>
#include <ScriptObject.h>
#include <Actor/Player.h>
#include <Action/Action.h>
class ActionHeavyShot97 :
public Sapphire::ScriptAPI::ActionScript
{
public:
ActionHeavyShot97() :
Sapphire::ScriptAPI::ActionScript( 97 )
{
}
void onExecute( Sapphire::World::Action::Action& action ) override
{
if( auto player = action.getSourceChara()->getAsPlayer() )
player->sendDebug( "Imagine you just hit an enemy for 150 potency. Incredible, right?" );
}
};
EXPOSE_SCRIPT( ActionHeavyShot97 );

View file

@ -1,22 +0,0 @@
#include <Script/NativeScriptApi.h>
#include <ScriptObject.h>
#include <Actor/Player.h>
#include <Action/Action.h>
class ActionCure120 :
public Sapphire::ScriptAPI::ActionScript
{
public:
ActionCure120() :
Sapphire::ScriptAPI::ActionScript( 120 )
{
}
void onExecute( Sapphire::World::Action::Action& action ) override
{
}
};
EXPOSE_SCRIPT( ActionCure120 );

View file

@ -1,24 +0,0 @@
#include <Script/NativeScriptApi.h>
#include <ScriptObject.h>
#include <Actor/Player.h>
#include <Action/Action.h>
class ActionAbyssalDrain3641 :
public Sapphire::ScriptAPI::ActionScript
{
public:
ActionAbyssalDrain3641() :
Sapphire::ScriptAPI::ActionScript( 3641 )
{
}
void onExecute( Sapphire::World::Action::Action& action ) override
{
for( auto& chara : action.getHitCharas() )
{
chara->takeDamage( chara->getMaxHp() * 0.5f );
}
}
};
EXPOSE_SCRIPT( ActionAbyssalDrain3641 );

View file

@ -1,23 +0,0 @@
#include <Script/NativeScriptApi.h>
#include <ScriptObject.h>
#include <Actor/Player.h>
#include <Action/Action.h>
class ActionHardSlash3617 :
public Sapphire::ScriptAPI::ActionScript
{
public:
ActionHardSlash3617() :
Sapphire::ScriptAPI::ActionScript( 3617 )
{
}
void onExecute( Sapphire::World::Action::Action& action ) override
{
auto chara = action.getHitChara();
chara->takeDamage( chara->getMaxHp() * 0.34f );
}
};
EXPOSE_SCRIPT( ActionHardSlash3617 );

View file

@ -1,22 +0,0 @@
#include <Script/NativeScriptApi.h>
#include <ScriptObject.h>
#include <Actor/Player.h>
#include <Action/Action.h>
class ActionPowerSlash3627 :
public Sapphire::ScriptAPI::ActionScript
{
public:
ActionPowerSlash3627() :
Sapphire::ScriptAPI::ActionScript( 3627 )
{
}
void onExecute( Sapphire::World::Action::Action& action ) override
{
}
};
EXPOSE_SCRIPT( ActionPowerSlash3627 );

View file

@ -1,22 +0,0 @@
#include <Script/NativeScriptApi.h>
#include <ScriptObject.h>
#include <Actor/Player.h>
#include <Action/Action.h>
class ActionSpinningSlash3619 :
public Sapphire::ScriptAPI::ActionScript
{
public:
ActionSpinningSlash3619() :
Sapphire::ScriptAPI::ActionScript( 3619 )
{
}
void onExecute( Sapphire::World::Action::Action& action ) override
{
}
};
EXPOSE_SCRIPT( ActionSpinningSlash3619 );

View file

@ -1,22 +0,0 @@
#include <Script/NativeScriptApi.h>
#include <ScriptObject.h>
#include <Actor/Player.h>
#include <Action/Action.h>
class ActionSyphonStrike3623 :
public Sapphire::ScriptAPI::ActionScript
{
public:
ActionSyphonStrike3623() :
Sapphire::ScriptAPI::ActionScript( 3623 )
{
}
void onExecute( Sapphire::World::Action::Action& action ) override
{
}
};
EXPOSE_SCRIPT( ActionSyphonStrike3623 );

View file

@ -1,24 +0,0 @@
#include <Script/NativeScriptApi.h>
#include <ScriptObject.h>
#include <Actor/Player.h>
#include <Action/Action.h>
class ActionUnleash3621 :
public Sapphire::ScriptAPI::ActionScript
{
public:
ActionUnleash3621() :
Sapphire::ScriptAPI::ActionScript( 3621 )
{
}
void onExecute( Sapphire::World::Action::Action& action ) override
{
for( auto& chara : action.getHitCharas() )
{
chara->takeDamage( chara->getMaxHp() * 0.34f );
}
}
};
EXPOSE_SCRIPT( ActionUnleash3621 );

View file

@ -1,22 +0,0 @@
#include <Script/NativeScriptApi.h>
#include <ScriptObject.h>
#include <Actor/Player.h>
#include <Action/Action.h>
class ActionAsylum3569 :
public Sapphire::ScriptAPI::ActionScript
{
public:
ActionAsylum3569() :
Sapphire::ScriptAPI::ActionScript( 3569 )
{
}
void onExecute( Sapphire::World::Action::Action& action ) override
{
}
};
EXPOSE_SCRIPT( ActionAsylum3569 );

View file

@ -239,17 +239,16 @@ void Action::start()
player->queuePacket( actionStartPkt ); player->queuePacket( actionStartPkt );
auto pScriptMgr = m_pFw->get< Scripting::ScriptMgr >(); auto pScriptMgr = m_pFw->get< Scripting::ScriptMgr >();
if( !pScriptMgr->onStart( *this ) )
{
// check the lut initially and see if we have something usable, otherwise cancel the cast
// Sapphire::World::Action::ActionLut::validEntryExists( getId() );
// script not implemented // check the lut too and see if we have something usable, otherwise cancel the cast
if( !pScriptMgr->onStart( *this ) && !ActionLut::validEntryExists( getId() ) )
{
// script not implemented and insufficient lut data (no potencies)
interrupt(); interrupt();
if( player ) if( player )
{ {
player->sendUrgent( "Action not implemented, missing script for action#{0}", getId() ); player->sendUrgent( "Action not implemented, missing script/lut entry for action#{0}", getId() );
player->setCurrentAction( nullptr ); player->setCurrentAction( nullptr );
} }
@ -335,7 +334,17 @@ void Action::execute()
if( !m_hitActors.empty() ) if( !m_hitActors.empty() )
{ {
// only call script if actors are hit // only call script if actors are hit
pScriptMgr->onExecute( *this ); if( !pScriptMgr->onExecute( *this ) && ActionLut::validEntryExists( getId() ) )
{
auto lutEntry = ActionLut::getEntry( getId() );
// no script exists but we have a valid lut entry
if( auto player = getSourceChara()->getAsPlayer() )
{
player->sendDebug( "Hit target: pot: {} (f: {}, r: {}), heal pot: {}",
lutEntry.potency, lutEntry.flankPotency, lutEntry.rearPotency, lutEntry.curePotency );
}
}
} }
} }
else if( auto player = m_pSource->getAsPlayer() ) else if( auto player = m_pSource->getAsPlayer() )
@ -352,18 +361,18 @@ void Action::execute()
} }
} }
bool Action::precheck() bool Action::preCheck()
{ {
if( auto player = m_pSource->getAsPlayer() ) if( auto player = m_pSource->getAsPlayer() )
{ {
if( !playerPrecheck( *player ) ) if( !playerPreCheck( *player ) )
return false; return false;
} }
return true; return true;
} }
bool Action::playerPrecheck( Entity::Player& player ) bool Action::playerPreCheck( Entity::Player& player )
{ {
// lol // lol
if( !player.isAlive() ) if( !player.isAlive() )
@ -393,17 +402,18 @@ bool Action::playerPrecheck( Entity::Player& player )
return false; return false;
} }
// reset target on actions that can only be casted on yourself while having a target set if( !m_actionData->canTargetSelf && getTargetId() == m_pSource->getId() )
// todo: check what actions send when targeting an enemy return false;
// if( m_actionData->canTargetSelf &&
// !m_actionData->canTargetFriendly &&
// !m_actionData->canTargetHostile &&
// !m_actionData->canTargetParty )
// {
// setTargetId( getSourceChara() );
// }
// todo: party/enemy validation // todo: does this need to check for party/alliance stuff or it's just same type?
// todo: m_pTarget doesn't exist at this stage because we only fill it when we snapshot targets
// if( !m_actionData->canTargetFriendly && m_pSource->getObjKind() == m_pTarget->getObjKind() )
// return false;
//
// if( !m_actionData->canTargetHostile && m_pSource->getObjKind() != m_pTarget->getObjKind() )
// return false;
// todo: party/dead validation
// validate range // validate range

View file

@ -75,7 +75,7 @@ namespace Sapphire::World::Action
* @brief Tests if an action is castable by the current source chara * @brief Tests if an action is castable by the current source chara
* @return true if castable, false if the caster doesn't meet the requirements * @return true if castable, false if the caster doesn't meet the requirements
*/ */
bool precheck(); bool preCheck();
/*! /*!
* @brief Snapshots characters affected by a cast. * @brief Snapshots characters affected by a cast.
@ -135,7 +135,7 @@ namespace Sapphire::World::Action
bool primaryCostCheck( bool subtractCosts ); bool primaryCostCheck( bool subtractCosts );
bool secondaryCostCheck( bool subtractCosts ); bool secondaryCostCheck( bool subtractCosts );
bool playerPrecheck( Entity::Player& player ); bool playerPreCheck( Entity::Player& player );
bool preFilterActor( Entity::Actor& actor ) const; bool preFilterActor( Entity::Actor& actor ) const;

View file

@ -1,3 +1,4 @@
#include <cassert>
#include "ActionLut.h" #include "ActionLut.h"
using namespace Sapphire::World::Action; using namespace Sapphire::World::Action;
@ -15,3 +16,12 @@ bool ActionLut::validEntryExists( uint16_t actionId )
return entry.potency != 0 || entry.comboPotency != 0 || entry.flankPotency != 0 || entry.frontPotency != 0 || return entry.potency != 0 || entry.comboPotency != 0 || entry.flankPotency != 0 || entry.frontPotency != 0 ||
entry.rearPotency != 0 || entry.curePotency != 0; entry.rearPotency != 0 || entry.curePotency != 0;
} }
const ActionEntry& ActionLut::getEntry( uint16_t actionId )
{
auto it = m_actionLut.find( actionId );
assert( it != m_actionLut.end() );
return it->second;
}

View file

@ -22,6 +22,7 @@ namespace Sapphire::World::Action
using Lut = std::unordered_map< uint16_t, ActionEntry >; using Lut = std::unordered_map< uint16_t, ActionEntry >;
static bool validEntryExists( uint16_t actionId ); static bool validEntryExists( uint16_t actionId );
static const ActionEntry& getEntry( uint16_t actionId );
static Lut m_actionLut; static Lut m_actionLut;
}; };

View file

@ -90,7 +90,7 @@ void World::Manager::ActionMgr::bootstrapAction( Entity::Player& player,
Action::ActionPtr currentAction, Action::ActionPtr currentAction,
Data::Action& actionData ) Data::Action& actionData )
{ {
if( !currentAction->precheck() ) if( !currentAction->preCheck() )
{ {
// forcefully interrupt the action and reset the cooldown // forcefully interrupt the action and reset the cooldown
currentAction->interrupt(); currentAction->interrupt();