From f692c7bccf1ebad11a6eeb9b97af8c235f155b0e Mon Sep 17 00:00:00 2001 From: NotAdam Date: Sun, 17 Feb 2019 16:55:00 +1100 Subject: [PATCH] minor refactoring, fix adventurer actions not working --- src/world/Action/Action.cpp | 8 ++++---- src/world/Action/Action.h | 4 ++-- src/world/Actor/Player.h | 8 ++++---- src/world/Actor/PlayerEvent.cpp | 8 ++++---- src/world/ForwardsZone.h | 4 ++-- src/world/Manager/ActionMgr.cpp | 25 ++++++++++++++++++++++--- 6 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/world/Action/Action.cpp b/src/world/Action/Action.cpp index 48c49a10..2f8c472d 100644 --- a/src/world/Action/Action.cpp +++ b/src/world/Action/Action.cpp @@ -318,7 +318,7 @@ void Sapphire::Action::Action::buildEffectPackets() } } -void Sapphire::Action::Action::damageTarget( uint32_t potency, Entity::Chara& chara ) +void Sapphire::Action::Action::damageTarget( uint16_t potency, Entity::Chara& chara ) { // todo: scale potency into damage from stats @@ -335,7 +335,7 @@ void Sapphire::Action::Action::damageTarget( uint32_t potency, Entity::Chara& ch { entry.value = static_cast< int16_t >( potency / 10 ); // todo: rename this? need to confirm how it works again - entry.bonusPercent = 1; + entry.valueMultiplier = 1; } else entry.value = static_cast< int16_t >( potency ); @@ -371,7 +371,7 @@ void Sapphire::Action::Action::damageTarget( uint32_t potency, Entity::Chara& ch m_effects[ EffectPacketIdentity::DamageEffect ].m_hitActors.emplace_back( chara.getId() ); } -void Sapphire::Action::Action::healTarget( uint32_t potency, Entity::Chara& chara ) +void Sapphire::Action::Action::healTarget( uint16_t potency, Entity::Chara& chara ) { // todo: scale potency into healing from stats @@ -387,7 +387,7 @@ void Sapphire::Action::Action::healTarget( uint32_t potency, Entity::Chara& char { entry.value = static_cast< int16_t >( potency / 10 ); // todo: rename this? need to confirm how it works again - entry.bonusPercent = 1; + entry.valueMultiplier = 1; } else entry.value = static_cast< int16_t >( potency ); diff --git a/src/world/Action/Action.h b/src/world/Action/Action.h index 031a5dbd..66b2bd93 100644 --- a/src/world/Action/Action.h +++ b/src/world/Action/Action.h @@ -68,14 +68,14 @@ namespace Sapphire::Action * @param potency The amount of damage the target takes * @param chara The chara to inflict damage upon */ - void damageTarget( uint32_t potency, Entity::Chara& chara ); + void damageTarget( uint16_t potency, Entity::Chara& chara ); /*! * @brief Heals a target and adds the effect entry * @param potency Amount of healing to apply * @param chara Chara to receive healing */ - void healTarget( uint32_t potency, Entity::Chara& chara ); + void healTarget( uint16_t potency, Entity::Chara& chara ); /*! * @brief Starts the cast. Finishes it immediately if there is no cast time (weaponskills). diff --git a/src/world/Actor/Player.h b/src/world/Actor/Player.h index 9633b7a7..d4cea395 100644 --- a/src/world/Actor/Player.h +++ b/src/world/Actor/Player.h @@ -52,12 +52,12 @@ namespace Sapphire::Entity // EventHandlers ////////////////////////////////////////////////////////////////////////////////////////////////////// /*! start an event action */ - void eventActionStart( uint32_t eventId, uint32_t action, ActionCallback finishCallback, - ActionCallback interruptCallback, uint64_t additional ); + void eventActionStart( uint32_t eventId, uint32_t action, Action::ActionCallback finishCallback, + Action::ActionCallback interruptCallback, uint64_t additional ); /*! start an event item action */ - void eventItemActionStart( uint32_t eventId, uint32_t action, ActionCallback finishCallback, - ActionCallback interruptCallback, uint64_t additional ); + void eventItemActionStart( uint32_t eventId, uint32_t action, Action::ActionCallback finishCallback, + Action::ActionCallback interruptCallback, uint64_t additional ); /*! start/register a normal event */ void diff --git a/src/world/Actor/PlayerEvent.cpp b/src/world/Actor/PlayerEvent.cpp index 83fb5276..e4c27afc 100644 --- a/src/world/Actor/PlayerEvent.cpp +++ b/src/world/Actor/PlayerEvent.cpp @@ -278,8 +278,8 @@ void Sapphire::Entity::Player::eventFinish( uint32_t eventId, uint32_t freePlaye void Sapphire::Entity::Player::eventActionStart( uint32_t eventId, uint32_t action, - ActionCallback finishCallback, - ActionCallback interruptCallback, + Action::ActionCallback finishCallback, + Action::ActionCallback interruptCallback, uint64_t additional ) { auto pEventAction = Action::make_EventAction( getAsChara(), eventId, action, @@ -309,8 +309,8 @@ void Sapphire::Entity::Player::eventActionStart( uint32_t eventId, void Sapphire::Entity::Player::eventItemActionStart( uint32_t eventId, uint32_t action, - ActionCallback finishCallback, - ActionCallback interruptCallback, + Action::ActionCallback finishCallback, + Action::ActionCallback interruptCallback, uint64_t additional ) { // Action::ActionPtr pEventItemAction = Action::make_EventItemAction( getAsChara(), eventId, action, diff --git a/src/world/ForwardsZone.h b/src/world/ForwardsZone.h index b73f47e8..8504922e 100644 --- a/src/world/ForwardsZone.h +++ b/src/world/ForwardsZone.h @@ -85,6 +85,8 @@ namespace Action { TYPE_FORWARD( Action ); TYPE_FORWARD( EventAction ); + +using ActionCallback = std::function< void( Entity::Player&, uint32_t, uint64_t ) >; } namespace Network @@ -113,8 +115,6 @@ namespace Scripting class NativeScriptMgr; } -typedef std::function< void( Entity::Player&, uint32_t, uint64_t ) > ActionCallback; - } diff --git a/src/world/Manager/ActionMgr.cpp b/src/world/Manager/ActionMgr.cpp index c8576bbf..3e26105b 100644 --- a/src/world/Manager/ActionMgr.cpp +++ b/src/world/Manager/ActionMgr.cpp @@ -48,7 +48,11 @@ void World::Manager::ActionMgr::handleTargetedPlayerAction( Entity::Player& play return; } - if( targetId != player.getId() ) + if( targetId == 0 ) + { + action->setTargetChara( player.getAsChara() ); + } + else if( targetId != player.getId() ) { auto target = player.lookupTargetById( targetId ); if( !target ) @@ -127,13 +131,16 @@ bool World::Manager::ActionMgr::canPlayerUseAction( Entity::Player& player, if( player.getLevel() < actionData.classJobLevel ) return false; - if( player.getClass() != static_cast< Common::ClassJob >( actionData.classJob ) ) + auto currentClass = player.getClass(); + auto actionClass = static_cast< Common::ClassJob >( actionData.classJob ); + + if( actionClass != Common::ClassJob::Adventurer && currentClass != actionClass ) { // check if not a base class action auto exdData = framework()->get< Data::ExdDataGenerated >(); assert( exdData ); - auto classJob = exdData->get< Data::ClassJob >( static_cast< uint8_t >( player.getClass() ) ); + auto classJob = exdData->get< Data::ClassJob >( static_cast< uint8_t >( currentClass ) ); if( !classJob ) return false; @@ -141,6 +148,18 @@ bool World::Manager::ActionMgr::canPlayerUseAction( Entity::Player& player, return false; } + // reset target on actions that can only be casted on yourself while having a target set + // todo: check what actions send when targeting an enemy + if( actionData.canTargetSelf && + !actionData.canTargetFriendly && + !actionData.canTargetHostile && + !actionData.canTargetParty ) + { + currentAction.setTargetChara( currentAction.getSourceChara() ); + } + + // todo: party/enemy validation + // validate range