From 31557f52f8a3bbce533146bef311f03be1e26548 Mon Sep 17 00:00:00 2001 From: Mordred Date: Sun, 12 Mar 2023 20:46:27 +0100 Subject: [PATCH] Fixe for target and statuseffect issues, cleanup of gambits --- src/world/Action/Action.cpp | 5 ++++ src/world/Action/Action.h | 2 ++ src/world/Actor/BNpc.cpp | 15 ++++------- src/world/Actor/Chara.cpp | 2 +- src/world/Actor/Player.cpp | 27 +------------------- src/world/ForwardsZone.h | 3 +++ src/world/Manager/ActionMgr.cpp | 27 ++++++++++---------- src/world/Manager/ActionMgr.h | 9 +++---- src/world/Network/Handlers/ActionHandler.cpp | 8 +++--- src/world/Task/ActionIntegrityTask.cpp | 6 ++--- 10 files changed, 41 insertions(+), 63 deletions(-) diff --git a/src/world/Action/Action.cpp b/src/world/Action/Action.cpp index 3de95214..cb93cd63 100644 --- a/src/world/Action/Action.cpp +++ b/src/world/Action/Action.cpp @@ -71,6 +71,11 @@ uint32_t Action::Action::getResultId() const return m_resultId; } +std::shared_ptr< Excel::ExcelStruct< Excel::Action > > Action::Action::getActionData() const +{ + return m_actionData; +} + bool Action::Action::init() { if( !m_actionData ) diff --git a/src/world/Action/Action.h b/src/world/Action/Action.h index e5285b32..90b49198 100644 --- a/src/world/Action/Action.h +++ b/src/world/Action/Action.h @@ -55,6 +55,8 @@ namespace Sapphire::World::Action uint64_t getCastTimeRest() const; + std::shared_ptr< Excel::ExcelStruct< Excel::Action > > getActionData() const; + /*! * @brief Checks if a chara has enough resources available to cast the action (tp/mp/etc) * @return true if they have the required resources diff --git a/src/world/Actor/BNpc.cpp b/src/world/Actor/BNpc.cpp index 2224e089..4a9c95e6 100644 --- a/src/world/Actor/BNpc.cpp +++ b/src/world/Actor/BNpc.cpp @@ -982,7 +982,7 @@ void BNpc::autoAttack( CharaPtr pTarget ) pTarget->onActionHostile( getAsChara() ); m_lastAttack = tick; srand( static_cast< uint32_t >( tick ) ); - actionMgr.handleTargetedAction( *this, 7, exdData.getRow< Excel::Action >( 7 ), pTarget->getId(), 0 ); + actionMgr.handleTargetedAction( *this, 7, pTarget->getId(), 0 ); } } @@ -1051,16 +1051,12 @@ uint32_t BNpc::getLayoutId() const void BNpc::init() { - auto& exdData = Common::Service< Data::ExdData >::ref(); m_maxHp = Math::CalcStats::calculateMaxHp( *getAsChara() ); m_hp = m_maxHp; //setup a test gambit - auto testGambitRule = std::make_shared< AI::GambitRule >( std::make_shared< AI::TopHateTargetCondition >(), - Action::make_Action( getAsChara(), 88, 0, exdData.getRow< Excel::Action >( 88 ) ), 5000 ); - - auto testGambitRule1 = std::make_shared< AI::GambitRule >( std::make_shared< AI::HPSelfPctLessThan >( 50 ), - Action::make_Action( getAsChara(), 120, 0, exdData.getRow< Excel::Action >( 120 ) ), 5000 ); + auto testGambitRule = AI::make_GambitRule( AI::make_TopHateTargetCondition(), Action::make_Action( getAsChara(), 88, 0 ), 5000 ); + auto testGambitRule1 = AI::make_GambitRule( AI::make_HPSelfPctLessThan( 50 ), Action::make_Action( getAsChara(), 120, 0 ), 5000 ); m_gambits.push_back( testGambitRule ); m_gambits.push_back( testGambitRule1 ); @@ -1068,7 +1064,6 @@ void BNpc::init() void BNpc::processGambits( uint64_t tickCount ) { - auto& exdData = Common::Service< Data::ExdData >::ref(); auto& actionMgr = Common::Service< World::Manager::ActionMgr >::ref(); for( auto& gambitRule : m_gambits ) { @@ -1081,8 +1076,8 @@ void BNpc::processGambits( uint64_t tickCount ) continue; gambitRule->setLastExecutionMs( tickCount ); - actionMgr.handleTargetedAction( *this, gambitRule->getActionPtr()->getId(), exdData.getRow< Excel::Action >( gambitRule->getActionPtr()->getId() ), - gambitRule->getGambitTargetCondition()->getTarget()->getId(), 0 ); + actionMgr.handleTargetedAction( *this, gambitRule->getActionPtr()->getId(), gambitRule->getGambitTargetCondition()->getTarget()->getId(), 0 ); + break; } } diff --git a/src/world/Actor/Chara.cpp b/src/world/Actor/Chara.cpp index 3301846b..80922377 100644 --- a/src/world/Actor/Chara.cpp +++ b/src/world/Actor/Chara.cpp @@ -365,7 +365,7 @@ Change the current target and propagate to in range players void Chara::changeTarget( uint64_t targetId ) { setTargetId( targetId ); - Network::Util::Packet::sendActorControlTarget( getInRangePlayerIds(), getId(), ToggleWeapon, SetTarget, 0, 0, 0, 0, targetId ); + Network::Util::Packet::sendActorControlTarget( getInRangePlayerIds(), getId(), SetTarget, 0, 0, 0, 0, targetId ); } /*! diff --git a/src/world/Actor/Player.cpp b/src/world/Actor/Player.cpp index e89b25a7..c667fe39 100644 --- a/src/world/Actor/Player.cpp +++ b/src/world/Actor/Player.cpp @@ -1285,33 +1285,8 @@ void Player::autoAttack( CharaPtr pTarget ) auto& RNGMgr = Common::Service< World::Manager::RNGMgr >::ref(); auto variation = static_cast< uint32_t >( RNGMgr.getRandGenerator< float >( 0, 3 ).next() ); - actionMgr.handleTargetedAction( *this, 7, exdData.getRow< Excel::Action >( 7 ), pTarget->getId(), 0 ); + actionMgr.handleTargetedAction( *this, 7, pTarget->getId(), 0 ); -/* auto damage = Math::CalcStats::calcAutoAttackDamage( *this ); - - auto effectPacket = std::make_shared< EffectPacket1 >( getId(), pTarget->getId(), 7 ); - - Common::CalcResultParam entry{}; - - entry.Value = static_cast< int16_t >( damage.first ); - entry.Type = Common::ActionEffectType::CALC_RESULT_TYPE_DAMAGE_HP; - entry.Arg0 = 2; - entry.Arg1 = 7; - - if( getClass() == ClassJob::Machinist || getClass() == ClassJob::Bard || getClass() == ClassJob::Archer ) - effectPacket->setActionId( 8 ); - - auto resultId = pZone->getNextActionResultId(); - effectPacket->setResultId( resultId ); - effectPacket->setRotation( Util::floatToUInt16Rot( getRot() ) ); - effectPacket->addTargetEffect( entry ); - - server().queueForPlayers( getInRangePlayerIds( true ), effectPacket ); - - pTarget->takeDamage( static_cast< uint32_t >( damage.first ) ); - - auto& taskMgr = Common::Service< TaskMgr >::ref();*/ - //taskMgr.queueTask( Sapphire::World::makeActionIntegrityTask( resultId, pTarget, 500 ) ); } diff --git a/src/world/ForwardsZone.h b/src/world/ForwardsZone.h index a6040794..02bbc8a6 100644 --- a/src/world/ForwardsZone.h +++ b/src/world/ForwardsZone.h @@ -50,6 +50,9 @@ TYPE_FORWARD( HousingInteriorTerritory ); namespace World::AI { TYPE_FORWARD( GambitTargetCondition ); + TYPE_FORWARD( TopHateTargetCondition ); + TYPE_FORWARD( HPSelfPctLessThan ); + TYPE_FORWARD( GambitRule ); } diff --git a/src/world/Manager/ActionMgr.cpp b/src/world/Manager/ActionMgr.cpp index 5faf4d22..db74754e 100644 --- a/src/world/Manager/ActionMgr.cpp +++ b/src/world/Manager/ActionMgr.cpp @@ -23,19 +23,20 @@ bool ActionMgr::cacheActionLut() return Action::ActionLutData::cacheActions(); } -void ActionMgr::handlePlacedPlayerAction( Entity::Player& player, uint32_t actionId, - Excel::ExcelStructPtr< Excel::Action > actionData, Common::FFXIVARR_POSITION3 pos, - uint16_t sequence ) +void ActionMgr::handlePlacedAction( Entity::Chara& chara, uint32_t actionId, Common::FFXIVARR_POSITION3 pos, uint16_t requestId ) { - PlayerMgr::sendDebug( player, "got aoe act: {0}", actionData->getString( actionData->data().Text.Name ) ); - - auto action = Action::make_Action( player.getAsPlayer(), actionId, sequence, actionData ); + auto action = Action::make_Action( chara.getAsChara(), actionId, requestId ); action->setPos( pos ); if( !action->init() ) return; + auto actionData = action->getActionData(); + + if( chara.isPlayer() ) + PlayerMgr::sendDebug( *chara.getAsPlayer(), "got aoe act: {0}", actionData->getString( actionData->data().Text.Name ) ); + if( !actionData->data().EffectRange ) { // not an action that has an aoe, cancel it @@ -43,13 +44,12 @@ void ActionMgr::handlePlacedPlayerAction( Entity::Player& player, uint32_t actio return; } - bootstrapAction( player, action, actionData ); + bootstrapAction( chara, action, actionData ); } -void ActionMgr::handleItemManipulationAction( Entity::Player& player, uint32_t actionId, - Excel::ExcelStructPtr< Excel::Action > actionData, uint16_t sequence ) +void ActionMgr::handleItemManipulationAction( Entity::Player& player, uint32_t actionId, uint16_t sequence ) { - auto action = Action::make_ItemManipulationAction( player.getAsPlayer(), actionId, sequence, actionData, 2500 ); // todo: maybe the delay can be retrieved from data + auto action = Action::make_ItemManipulationAction( player.getAsPlayer(), actionId, sequence, nullptr, 2500 ); // todo: maybe the delay can be retrieved from data player.setCurrentAction( action ); @@ -59,10 +59,9 @@ void ActionMgr::handleItemManipulationAction( Entity::Player& player, uint32_t a action->start(); } -void ActionMgr::handleTargetedAction( Entity::Chara& src, uint32_t actionId, - Excel::ExcelStructPtr< Excel::Action > actionData, uint64_t targetId, uint16_t requestId ) +void ActionMgr::handleTargetedAction( Entity::Chara& src, uint32_t actionId, uint64_t targetId, uint16_t requestId ) { - auto action = Action::make_Action( src.getAsChara(), actionId, requestId, actionData ); + auto action = Action::make_Action( src.getAsChara(), actionId, requestId ); action->setTargetId( targetId ); action->setPos( src.getPos() ); @@ -70,6 +69,8 @@ void ActionMgr::handleTargetedAction( Entity::Chara& src, uint32_t actionId, if( !action->init() ) return; + auto actionData = action->getActionData(); + // cancel any aoe actions casted with this packet if( actionData->data().EffectRange ) { diff --git a/src/world/Manager/ActionMgr.h b/src/world/Manager/ActionMgr.h index f92f5df1..8268c35a 100644 --- a/src/world/Manager/ActionMgr.h +++ b/src/world/Manager/ActionMgr.h @@ -22,12 +22,9 @@ namespace Sapphire::World::Manager bool cacheActionLut(); - void handleItemManipulationAction( Entity::Player& player, uint32_t actionId, Excel::ExcelStructPtr< Excel::Action > actionData, uint16_t sequence ); - - void handleTargetedAction( Entity::Chara& chara, uint32_t actionId, - std::shared_ptr< Excel::ExcelStruct< Excel::Action > > actionData, uint64_t targetId, uint16_t requestId ); - void handlePlacedPlayerAction( Entity::Player& player, uint32_t actionId, - std::shared_ptr< Excel::ExcelStruct< Excel::Action > > actionData, Common::FFXIVARR_POSITION3 pos, uint16_t sequence ); + void handleItemManipulationAction( Entity::Player& player, uint32_t actionId, uint16_t requestId ); + void handleTargetedAction( Entity::Chara& chara, uint32_t actionId, uint64_t targetId, uint16_t requestId ); + void handlePlacedAction( Entity::Chara& chara, uint32_t actionId, Common::FFXIVARR_POSITION3 pos, uint16_t requestId ); void handleItemAction( Entity::Player& player, uint32_t itemId, std::shared_ptr< Excel::ExcelStruct< Excel::ItemAction > > itemActionData, uint16_t itemSourceSlot, uint16_t itemSourceContainer ); diff --git a/src/world/Network/Handlers/ActionHandler.cpp b/src/world/Network/Handlers/ActionHandler.cpp index cfc0c9c4..4465f64d 100644 --- a/src/world/Network/Handlers/ActionHandler.cpp +++ b/src/world/Network/Handlers/ActionHandler.cpp @@ -50,9 +50,9 @@ void Sapphire::Network::GameConnection::actionRequest( const Packets::FFXIVARR_P auto category = static_cast< Common::ActionCategory >( action->data().Category ); if( category == Common::ActionCategory::ItemManipulation ) - actionMgr.handleItemManipulationAction( player, actionId, action, requestId ); + actionMgr.handleItemManipulationAction( player, actionId, requestId ); else - actionMgr.handleTargetedAction( player, actionId, action, targetId, requestId ); + actionMgr.handleTargetedAction( player, actionId, targetId, requestId ); break; } @@ -111,7 +111,7 @@ void Sapphire::Network::GameConnection::selectGroundActionRequest( const Packets return; } - PlayerMgr::sendDebug( player, "Skill type: {0}, sequence: {1}, actionId: {2}, x:{3}, y:{4}, z:{5}", + PlayerMgr::sendDebug( player, "Skill type: {0}, requestId: {1}, actionId: {2}, x:{3}, y:{4}, z:{5}", type, requestId, actionId, pos.x, pos.y, pos.z ); auto& exdData = Common::Service< Data::ExdData >::ref(); @@ -123,5 +123,5 @@ void Sapphire::Network::GameConnection::selectGroundActionRequest( const Packets return; auto& actionMgr = Common::Service< World::Manager::ActionMgr >::ref(); - actionMgr.handlePlacedPlayerAction( player, actionId, action, pos, requestId ); + actionMgr.handlePlacedAction( player, actionId, pos, requestId ); } diff --git a/src/world/Task/ActionIntegrityTask.cpp b/src/world/Task/ActionIntegrityTask.cpp index 40a75c46..10406e5e 100644 --- a/src/world/Task/ActionIntegrityTask.cpp +++ b/src/world/Task/ActionIntegrityTask.cpp @@ -49,6 +49,9 @@ void ActionIntegrityTask::execute() int statusIdx = 0; for( auto& actionResult : m_results ) { + if( actionResult && actionResult->getTarget() ) + actionResult->execute(); + if( actionResult->getCalcResultParam().Type == Common::CALC_RESULT_TYPE_SET_STATUS ) { auto& status = data.Status[ statusIdx++ ]; @@ -59,9 +62,6 @@ void ActionIntegrityTask::execute() status.Slot = static_cast< uint8_t >( pEffect->getSlot() ); status.SystemParam = static_cast< int16_t >( pEffect->getParam() ); } - - if( actionResult && actionResult->getTarget() ) - actionResult->execute(); } data.Hp = m_pTarget->getHp();