From 458235685a59b4224dfd44d52fa17008f86d081f Mon Sep 17 00:00:00 2001 From: NotAdam Date: Sat, 9 Feb 2019 21:48:42 +1100 Subject: [PATCH] VFX ItemAction handling --- src/common/Common.h | 5 +++ src/world/Action/Action.cpp | 20 +++++++++++ src/world/Manager/ActionMgr.cpp | 36 +++++++++++++++++-- src/world/Manager/ActionMgr.h | 8 ++++- src/world/Network/Handlers/ActionHandler.cpp | 9 +++-- .../Network/PacketWrappers/EffectPacket.h | 5 +++ 6 files changed, 78 insertions(+), 5 deletions(-) diff --git a/src/common/Common.h b/src/common/Common.h index 0abe0ac9..55d4c5d9 100644 --- a/src/common/Common.h +++ b/src/common/Common.h @@ -592,6 +592,11 @@ namespace Sapphire::Common CritDirectHitDamage = 3 }; + enum ItemActionType : uint16_t + { + ItemActionVFX = 944, + }; + enum ActionEffectDisplayType : uint8_t { HideActionName = 0, diff --git a/src/world/Action/Action.cpp b/src/world/Action/Action.cpp index 1ce77f9e..2718d72f 100644 --- a/src/world/Action/Action.cpp +++ b/src/world/Action/Action.cpp @@ -113,6 +113,9 @@ void Sapphire::Action::Action::calculateMPCost() cost = 0.2313f * ( level * level ) - 26.98f * level + 875.21f; break; } + + default: + return; } // m_cost is the base cost, cost is the multiplier for the current player level @@ -121,7 +124,24 @@ void Sapphire::Action::Action::calculateMPCost() void Sapphire::Action::Action::subtractCostFromCaster() { + if( !m_pSource->isPlayer() ) + return; + auto player = m_pSource->getAsPlayer(); + + switch( m_costType ) + { + case Common::ActionCostType::MagicPoints: + { + + break; + } + case Common::ActionCostType::TacticsPoints: + { + + break; + } + } } void Sapphire::Action::Action::setPos( Sapphire::Common::FFXIVARR_POSITION3 pos ) diff --git a/src/world/Manager/ActionMgr.cpp b/src/world/Manager/ActionMgr.cpp index 0de84b90..0e690cf2 100644 --- a/src/world/Manager/ActionMgr.cpp +++ b/src/world/Manager/ActionMgr.cpp @@ -8,6 +8,8 @@ #include #include "Framework.h" +#include + using namespace Sapphire; World::Manager::ActionMgr::ActionMgr( Sapphire::FrameworkPtr pFw ) : @@ -37,9 +39,22 @@ void World::Manager::ActionMgr::handleTargetedPlayerAction( Entity::Player& play bootstrapAction( player, action, *actionData ); } -void World::Manager::ActionMgr::handleItemAction( Sapphire::Entity::Player& player, uint32_t itemActionId ) +void World::Manager::ActionMgr::handleItemAction( Sapphire::Entity::Player& player, uint32_t itemId, Data::ItemActionPtr itemActionData ) { - player.sendDebug( "got item act: {0}", itemActionId ); + player.sendDebug( "got item act: {0}", itemId ); + + switch( itemActionData->type ) + { + default: + return; + + case Common::ItemActionType::ItemActionVFX: + { + handleItemActionVFX( player, itemId, itemActionData->data[ 0 ] ); + + break; + } + } } void World::Manager::ActionMgr::bootstrapAction( Entity::Player& player, @@ -100,4 +115,21 @@ bool World::Manager::ActionMgr::canPlayerUseAction( Entity::Player& player, // todo: script callback for action conditionals? return true; +} + +void World::Manager::ActionMgr::handleItemActionVFX( Sapphire::Entity::Player& player, uint32_t itemId, uint16_t vfxId ) +{ + // todo: check we have item & remove item from inventory + + Common::EffectEntry effect{}; + effect.effectType = Common::ActionEffectType::VFX; + effect.value = vfxId; + + auto effectPacket = std::make_shared< Network::Packets::Server::EffectPacket >( player.getId(), player.getId(), itemId ); + effectPacket->setTargetActor( player.getId() ); + effectPacket->setAnimationId( Common::ItemActionType::ItemActionVFX ); + effectPacket->setDisplayType( Common::ActionEffectDisplayType::ShowItemName ); + effectPacket->addEffect( effect ); + + player.sendToInRangeSet( effectPacket, true ); } \ No newline at end of file diff --git a/src/world/Manager/ActionMgr.h b/src/world/Manager/ActionMgr.h index 77e7118d..6a61fc5c 100644 --- a/src/world/Manager/ActionMgr.h +++ b/src/world/Manager/ActionMgr.h @@ -8,6 +8,9 @@ namespace Sapphire::Data { struct Action; using ActionPtr = std::shared_ptr< Action >; + + struct ItemAction; + using ItemActionPtr = std::shared_ptr< ItemAction >; } namespace Sapphire::World::Manager @@ -23,11 +26,14 @@ namespace Sapphire::World::Manager void handleAoEPlayerAction( Entity::Player& player, uint32_t actionId, Data::ActionPtr actionData, Common::FFXIVARR_POSITION3 pos ); - void handleItemAction( Entity::Player& player, uint32_t itemActionId ); + void handleItemAction( Entity::Player& player, uint32_t itemId, Data::ItemActionPtr itemActionData ); private: void bootstrapAction( Entity::Player& player, Action::ActionPtr currentAction, Data::Action& actionData ); bool canPlayerUseAction( Entity::Player& player, Action::Action& currentAction, Data::Action& actionData ); + + // item action handlers + void handleItemActionVFX( Entity::Player& player, uint32_t itemId, uint16_t vfxId ); }; } diff --git a/src/world/Network/Handlers/ActionHandler.cpp b/src/world/Network/Handlers/ActionHandler.cpp index a945d943..21324e73 100644 --- a/src/world/Network/Handlers/ActionHandler.cpp +++ b/src/world/Network/Handlers/ActionHandler.cpp @@ -30,6 +30,8 @@ void Sapphire::Network::GameConnection::actionHandler( FrameworkPtr pFw, auto exdData = m_pFw->get< Data::ExdDataGenerated >(); assert( exdData ); + auto actionMgr = pFw->get< World::Manager::ActionMgr >(); + switch( type ) { default: @@ -44,7 +46,6 @@ void Sapphire::Network::GameConnection::actionHandler( FrameworkPtr pFw, if( !action ) return; - auto actionMgr = pFw->get< World::Manager::ActionMgr >(); actionMgr->handleTargetedPlayerAction( player, actionId, action, targetId ); break; } @@ -58,7 +59,11 @@ void Sapphire::Network::GameConnection::actionHandler( FrameworkPtr pFw, if( item->itemAction == 0 ) return; - player.sendDebug( "Got itemaction for act: {0}", item->itemAction ); + auto itemAction = exdData->get< Data::ItemAction >( item->itemAction ); + if( !itemAction ) + return; + + actionMgr->handleItemAction( player, actionId, itemAction ); break; } diff --git a/src/world/Network/PacketWrappers/EffectPacket.h b/src/world/Network/PacketWrappers/EffectPacket.h index 7c265c9f..3be90b37 100644 --- a/src/world/Network/PacketWrappers/EffectPacket.h +++ b/src/world/Network/PacketWrappers/EffectPacket.h @@ -41,6 +41,11 @@ namespace Sapphire::Network::Packets::Server m_data.actionAnimationId = animationId; } + void setDisplayType( Common::ActionEffectDisplayType displayType ) + { + m_data.effectDisplayType = displayType; + } + void setEffectFlags( uint32_t effectFlags ) { m_data.effectFlags = effectFlags;