2019-06-02 20:45:18 +10:00
|
|
|
#include "ItemAction.h"
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
#include <Exd/ExdData.h>
|
|
|
|
#include <Exd/Structs.h>
|
2019-06-02 20:45:18 +10:00
|
|
|
|
|
|
|
#include <Actor/Player.h>
|
|
|
|
#include <Network/PacketWrappers/EffectPacket.h>
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
#include "Manager/PlayerMgr.h"
|
2023-02-17 15:34:51 +01:00
|
|
|
#include "Manager/MgrUtil.h"
|
2021-11-27 00:53:57 +01:00
|
|
|
|
2019-06-02 20:45:18 +10:00
|
|
|
using namespace Sapphire;
|
|
|
|
using namespace Sapphire::World::Action;
|
2023-02-17 15:34:51 +01:00
|
|
|
using namespace Sapphire::World::Manager;
|
2021-11-27 00:53:57 +01:00
|
|
|
using namespace Sapphire::Network::Packets::WorldPackets::Server;
|
2019-06-02 20:45:18 +10:00
|
|
|
|
|
|
|
ItemAction::ItemAction( Sapphire::Entity::CharaPtr source, uint32_t itemId,
|
2022-01-27 21:24:54 +01:00
|
|
|
std::shared_ptr< Excel::ExcelStruct< Excel::ItemAction > > itemActionData, uint16_t itemSourceSlot,
|
2020-03-01 01:00:57 +11:00
|
|
|
uint16_t itemSourceContainer ) :
|
2019-06-02 20:45:18 +10:00
|
|
|
m_itemAction( std::move( itemActionData ) ),
|
|
|
|
m_itemSourceSlot( itemSourceSlot ),
|
|
|
|
m_itemSourceContainer( itemSourceContainer )
|
|
|
|
{
|
|
|
|
m_id = itemId;
|
|
|
|
m_pSource = std::move( source );
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemAction::start()
|
|
|
|
{
|
|
|
|
if( !m_pSource->isPlayer() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// todo: check inv slot for item
|
|
|
|
|
|
|
|
// todo: can we just do this?
|
|
|
|
execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemAction::execute()
|
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
switch( m_itemAction->data().Action )
|
2019-06-02 20:45:18 +10:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
Manager::PlayerMgr::sendDebug( *getSourceChara()->getAsPlayer(), "ItemAction type {0} not supported.", m_itemAction->data().Action );
|
2019-06-02 20:45:18 +10:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Common::ItemActionType::ItemActionVFX:
|
|
|
|
case Common::ItemActionType::ItemActionVFX2:
|
|
|
|
{
|
|
|
|
handleVFXItem();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2022-01-16 22:48:55 +01:00
|
|
|
|
|
|
|
case Common::ItemActionType::ItemActionMount:
|
|
|
|
{
|
|
|
|
handleMountItem();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2023-01-23 21:39:12 +01:00
|
|
|
|
|
|
|
case Common::ItemActionType::ItemActionCompanion:
|
|
|
|
{
|
|
|
|
handleCompanionItem();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2024-01-10 20:35:02 -08:00
|
|
|
|
|
|
|
case Common::ItemActionType::ItemActionSong:
|
|
|
|
{
|
|
|
|
handleSongItem();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2019-06-02 20:45:18 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemAction::interrupt()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemAction::handleVFXItem()
|
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
Common::CalcResultParam effect{};
|
2023-03-15 15:21:03 +01:00
|
|
|
effect.Type = Common::CalcResultType::TypeCheckBarrier;
|
2021-11-27 00:53:57 +01:00
|
|
|
effect.Value = m_itemAction->data().Calcu0Arg[ 0 ];
|
2019-06-02 20:45:18 +10:00
|
|
|
|
2023-03-09 21:54:30 +01:00
|
|
|
auto effectPacket = std::make_shared< EffectPacket >( getSourceChara()->getId(), getSourceChara()->getId(), getId() );
|
|
|
|
effectPacket->setActionId( Common::ItemActionType::ItemActionVFX );
|
2019-06-02 20:45:18 +10:00
|
|
|
effectPacket->setDisplayType( Common::ActionEffectDisplayType::ShowItemName );
|
2022-01-10 19:31:21 -03:00
|
|
|
effectPacket->addTargetEffect( effect, static_cast< uint64_t >( getSourceChara()->getId() ) );
|
2023-02-17 15:34:51 +01:00
|
|
|
server().queueForPlayers( m_pSource->getInRangePlayerIds( true ), effectPacket );
|
2022-01-16 22:48:55 +01:00
|
|
|
}
|
|
|
|
|
2023-01-23 21:39:12 +01:00
|
|
|
void ItemAction::handleCompanionItem()
|
|
|
|
{
|
|
|
|
auto player = getSourceChara()->getAsPlayer();
|
|
|
|
|
|
|
|
player->unlockCompanion( m_itemAction->data().Calcu0Arg[ 0 ] );
|
2023-02-27 08:58:08 +01:00
|
|
|
player->dropInventoryItem( static_cast< Common::InventoryType >( m_itemSourceContainer ), static_cast< uint8_t >( m_itemSourceSlot ) );
|
2023-01-23 21:39:12 +01:00
|
|
|
}
|
|
|
|
|
2022-01-16 22:48:55 +01:00
|
|
|
void ItemAction::handleMountItem()
|
|
|
|
{
|
|
|
|
auto player = getSourceChara()->getAsPlayer();
|
|
|
|
|
|
|
|
player->unlockMount( m_itemAction->data().Calcu0Arg[ 0 ] );
|
2023-02-27 08:58:08 +01:00
|
|
|
player->dropInventoryItem( static_cast< Common::InventoryType >( m_itemSourceContainer ), static_cast< uint8_t >( m_itemSourceSlot ) );
|
2024-01-10 20:35:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ItemAction::handleSongItem()
|
|
|
|
{
|
|
|
|
auto player = getSourceChara()->getAsPlayer();
|
|
|
|
|
|
|
|
player->learnSong( m_itemAction->data().Calcu0Arg[ 0 ], m_id );
|
|
|
|
player->dropInventoryItem( static_cast< Common::InventoryType >( m_itemSourceContainer ), static_cast< uint8_t >( m_itemSourceSlot ) );
|
2019-06-02 20:45:18 +10:00
|
|
|
}
|