2018-03-06 22:22:19 +01:00
|
|
|
#include <Common.h>
|
|
|
|
#include <Logging/Logger.h>
|
2021-11-27 00:53:57 +01:00
|
|
|
|
2018-10-26 09:40:47 +02:00
|
|
|
#include <algorithm>
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2019-07-21 22:33:33 +10:00
|
|
|
#include "Territory/Territory.h"
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2017-12-08 15:38:25 +01:00
|
|
|
#include "Inventory/Item.h"
|
2018-07-24 23:58:08 +02:00
|
|
|
#include "Inventory/ItemContainer.h"
|
2018-12-23 13:26:33 +01:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
#include <Exd/ExdData.h>
|
2018-07-24 23:58:08 +02:00
|
|
|
#include <Database/DatabaseDef.h>
|
|
|
|
|
|
|
|
#include "Actor/Player.h"
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
#include <Network/CommonActorControl.h>
|
|
|
|
#include "Network/PacketWrappers/ActorControlPacket.h"
|
2019-10-09 18:14:53 +02:00
|
|
|
#include "Network/PacketWrappers/ActorControlSelfPacket.h"
|
2021-11-27 00:53:57 +01:00
|
|
|
#include "Network/PacketWrappers/UpdateInventorySlotPacket.h"
|
|
|
|
#include <Network/PacketDef/Zone/ServerZoneDef.h>
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-12-18 22:59:01 +11:00
|
|
|
#include "Manager/InventoryMgr.h"
|
2018-12-23 13:26:33 +01:00
|
|
|
#include "Manager/ItemMgr.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"
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2020-03-01 01:00:57 +11:00
|
|
|
#include <Service.h>
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
using namespace Sapphire::Common;
|
2023-02-17 15:34:51 +01:00
|
|
|
using namespace Sapphire::World::Manager;
|
2018-11-29 16:55:48 +01:00
|
|
|
using namespace Sapphire::Network::Packets;
|
2021-11-27 00:53:57 +01:00
|
|
|
using namespace Sapphire::Network::Packets::WorldPackets::Server;
|
2018-11-29 16:55:48 +01:00
|
|
|
using namespace Sapphire::Network::ActorControl;
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
void Sapphire::Entity::Player::initInventory()
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
2021-12-03 10:53:13 +01:00
|
|
|
const uint8_t inventorySize = 25;
|
2018-08-29 21:40:59 +02:00
|
|
|
auto setupContainer = [ this ]( InventoryType type, uint8_t maxSize, const std::string& tableName,
|
|
|
|
bool isMultiStorage, bool isPersistentStorage = true )
|
2020-03-01 01:00:57 +11:00
|
|
|
{ m_storageMap[ type ] = make_ItemContainer( type, maxSize, tableName, isMultiStorage, isPersistentStorage ); };
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
// main bags
|
2021-12-03 10:53:13 +01:00
|
|
|
setupContainer( Bag0, inventorySize, "charaiteminventory", true );
|
|
|
|
setupContainer( Bag1, inventorySize, "charaiteminventory", true );
|
|
|
|
setupContainer( Bag2, inventorySize, "charaiteminventory", true );
|
|
|
|
setupContainer( Bag3, inventorySize, "charaiteminventory", true );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
// gear set
|
|
|
|
setupContainer( GearSet0, 13, "charaitemgearset", true );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
// gil contianer
|
|
|
|
setupContainer( Currency, 11, "charaiteminventory", true );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
// crystals??
|
|
|
|
setupContainer( Crystal, 11, "charaiteminventory", true );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
// armory weapons - 0
|
2021-12-03 10:53:13 +01:00
|
|
|
setupContainer( ArmoryMain, inventorySize, "charaiteminventory", true );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
// armory offhand - 1
|
2021-12-03 10:53:13 +01:00
|
|
|
setupContainer( ArmoryOff, inventorySize, "charaiteminventory", true );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
//armory head - 2
|
2021-12-03 10:53:13 +01:00
|
|
|
setupContainer( ArmoryHead, inventorySize, "charaiteminventory", true );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
//armory body - 3
|
2021-12-03 10:53:13 +01:00
|
|
|
setupContainer( ArmoryBody, inventorySize, "charaiteminventory", true );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
//armory hand - 4
|
2021-12-03 10:53:13 +01:00
|
|
|
setupContainer( ArmoryHand, inventorySize, "charaiteminventory", true );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
//armory waist - 5
|
2021-12-03 10:53:13 +01:00
|
|
|
setupContainer( ArmoryWaist, inventorySize, "charaiteminventory", true );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
//armory legs - 6
|
2021-12-03 10:53:13 +01:00
|
|
|
setupContainer( ArmoryLegs, inventorySize, "charaiteminventory", true );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
//armory feet - 7
|
2021-12-03 10:53:13 +01:00
|
|
|
setupContainer( ArmoryFeet, inventorySize, "charaiteminventory", true );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
//neck
|
2021-12-03 10:53:13 +01:00
|
|
|
setupContainer( ArmoryNeck, inventorySize, "charaiteminventory", true );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
//earring
|
2021-12-03 10:53:13 +01:00
|
|
|
setupContainer( ArmoryEar, inventorySize, "charaiteminventory", true );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
//wrist
|
2021-12-03 10:53:13 +01:00
|
|
|
setupContainer( ArmoryWrist, inventorySize, "charaiteminventory", true );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
//armory rings - 11
|
2021-12-03 10:53:13 +01:00
|
|
|
setupContainer( ArmoryRing, inventorySize, "charaiteminventory", true );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
//soul crystals - 13
|
2021-12-03 10:53:13 +01:00
|
|
|
setupContainer( ArmorySoulCrystal, inventorySize, "charaiteminventory", true );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
// item hand in container
|
|
|
|
// non-persistent container, will not save its contents
|
|
|
|
setupContainer( HandIn, 10, "", true, false );
|
2018-08-12 22:53:21 +10:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
loadInventory();
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2017-08-08 13:53:47 +02:00
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
void Sapphire::Entity::Player::sendItemLevel()
|
2017-11-16 00:03:36 -02:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
calculateEquippedGearItemLevel();
|
|
|
|
Service< World::Manager::PlayerMgr >::ref().onPlayerItemLevelUpdate( *this );
|
2017-11-16 00:03:36 -02:00
|
|
|
}
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
void Sapphire::Entity::Player::equipWeapon( const Item& item )
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
auto& exdData = Common::Service< Sapphire::Data::ExdData >::ref();
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2022-01-27 21:24:54 +01:00
|
|
|
auto itemInfo = exdData.getRow< Excel::Item >( item.getId() );
|
2021-11-27 00:53:57 +01:00
|
|
|
auto itemClassJob = itemInfo->data().Class;
|
2022-01-27 21:24:54 +01:00
|
|
|
auto classJobInfo = exdData.getRow< Excel::ClassJob >( static_cast< uint32_t >( getClass() ) );
|
2021-11-27 00:53:57 +01:00
|
|
|
auto currentParentClass = static_cast< ClassJob >( classJobInfo->data().MainClass );
|
2018-08-29 21:40:59 +02:00
|
|
|
auto newClassJob = static_cast< ClassJob >( itemClassJob );
|
2018-08-26 16:19:05 +10:00
|
|
|
|
2018-10-17 23:25:41 +03:00
|
|
|
if( ( isClassJobUnlocked( newClassJob ) ) && ( currentParentClass != newClassJob ) )
|
2018-10-18 20:59:04 +03:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
setClassJob( newClassJob );
|
2018-10-18 20:59:04 +03:00
|
|
|
}
|
2017-08-08 13:53:47 +02:00
|
|
|
}
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
void Sapphire::Entity::Player::equipSoulCrystal( const Item& item )
|
2018-10-20 14:20:39 +03:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
auto& exdData = Common::Service< Sapphire::Data::ExdData >::ref();
|
2018-10-20 14:20:39 +03:00
|
|
|
|
2022-01-27 21:24:54 +01:00
|
|
|
auto itemInfo = exdData.getRow< Excel::Item >( item.getId() );
|
2021-11-27 00:53:57 +01:00
|
|
|
auto itemClassJob = itemInfo->data().Class;
|
2018-10-20 14:20:39 +03:00
|
|
|
auto newClassJob = static_cast< ClassJob >( itemClassJob );
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
if( isClassJobUnlocked( newClassJob ) )
|
2018-10-20 14:20:39 +03:00
|
|
|
setClassJob( newClassJob );
|
|
|
|
}
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
void Sapphire::Entity::Player::updateModels( GearSetSlot equipSlotId, const Sapphire::Item& item )
|
2018-09-17 22:52:57 +02:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
uint64_t model = item.getModelId1();
|
|
|
|
uint64_t model2 = item.getModelId2();
|
|
|
|
uint64_t stain = item.getStain();
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
switch( equipSlotId )
|
|
|
|
{
|
2018-09-17 22:52:57 +02:00
|
|
|
case MainHand:
|
2019-04-13 22:41:29 +10:00
|
|
|
m_modelMainWeapon = model | ( stain << 48 );
|
2017-08-08 13:53:47 +02:00
|
|
|
m_modelSubWeapon = model2;
|
2019-04-13 22:41:29 +10:00
|
|
|
|
|
|
|
if( m_modelSubWeapon > 0 )
|
|
|
|
m_modelSubWeapon = m_modelSubWeapon | ( stain << 48 );
|
|
|
|
|
2017-08-08 13:53:47 +02:00
|
|
|
break;
|
|
|
|
|
2018-09-17 22:52:57 +02:00
|
|
|
case OffHand:
|
2019-04-13 22:41:29 +10:00
|
|
|
m_modelSubWeapon = model | ( stain << 48 );
|
2017-08-08 13:53:47 +02:00
|
|
|
break;
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
// these have no model
|
2018-09-17 22:52:57 +02:00
|
|
|
case SoulCrystal:
|
|
|
|
case Waist:
|
|
|
|
break;
|
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
default: // any other slot
|
2018-09-17 22:52:57 +02:00
|
|
|
auto modelSlot = equipSlotToModelSlot( equipSlotId );
|
|
|
|
if( modelSlot == GearModelSlot::ModelInvalid )
|
|
|
|
break;
|
2019-04-13 22:41:29 +10:00
|
|
|
|
|
|
|
model = model | stain << 24;
|
2018-09-17 22:52:57 +02:00
|
|
|
m_modelEquip[ static_cast< uint8_t >( modelSlot ) ] = static_cast< uint32_t >( model );
|
2017-08-08 13:53:47 +02:00
|
|
|
break;
|
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
2018-09-17 22:52:57 +02:00
|
|
|
}
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
Sapphire::Common::GearModelSlot Sapphire::Entity::Player::equipSlotToModelSlot( Common::GearSetSlot slot )
|
2018-09-17 22:52:57 +02:00
|
|
|
{
|
|
|
|
switch( slot )
|
2018-08-29 21:40:59 +02:00
|
|
|
{
|
2018-09-17 22:52:57 +02:00
|
|
|
case MainHand:
|
|
|
|
case OffHand:
|
|
|
|
case Waist:
|
|
|
|
case SoulCrystal:
|
|
|
|
default:
|
|
|
|
return GearModelSlot::ModelInvalid;
|
|
|
|
case Head:
|
|
|
|
return GearModelSlot::ModelHead;
|
|
|
|
case Body:
|
|
|
|
return GearModelSlot::ModelBody;
|
|
|
|
case Hands:
|
|
|
|
return GearModelSlot::ModelHands;
|
|
|
|
case Legs:
|
|
|
|
return GearModelSlot::ModelLegs;
|
|
|
|
case Feet:
|
|
|
|
return GearModelSlot::ModelFeet;
|
|
|
|
case Neck:
|
|
|
|
return GearModelSlot::ModelNeck;
|
|
|
|
case Ear:
|
|
|
|
return GearModelSlot::ModelEar;
|
|
|
|
case Wrist:
|
|
|
|
return GearModelSlot::ModelWrist;
|
|
|
|
case Ring1:
|
|
|
|
return GearModelSlot::ModelRing1;
|
|
|
|
case Ring2:
|
|
|
|
return GearModelSlot::ModelRing2;
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
2017-08-08 13:53:47 +02:00
|
|
|
}
|
|
|
|
|
2019-03-20 22:16:02 +01:00
|
|
|
// equip an item
|
2021-11-27 00:53:57 +01:00
|
|
|
void Sapphire::Entity::Player::equipItem( Common::GearSetSlot equipSlotId, Item& item, bool sendUpdate )
|
2019-03-20 22:16:02 +01:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
switch( equipSlotId )
|
2019-03-20 22:16:02 +01:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
case MainHand:
|
|
|
|
equipWeapon( item );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SoulCrystal:
|
|
|
|
equipSoulCrystal( item );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2019-03-20 22:16:02 +01:00
|
|
|
}
|
2019-03-21 18:06:48 +01:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
updateModels( equipSlotId, item );
|
|
|
|
|
2019-03-21 18:53:32 +01:00
|
|
|
calculateStats();
|
|
|
|
if( sendUpdate )
|
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
sendModel();
|
|
|
|
sendItemLevel();
|
2019-03-21 18:53:32 +01:00
|
|
|
sendStats();
|
|
|
|
sendStatusUpdate();
|
|
|
|
}
|
2019-03-20 22:16:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
void Sapphire::Entity::Player::unequipItem( Common::GearSetSlot equipSlotId, Item& item, bool sendUpdate )
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
2018-09-17 22:52:57 +02:00
|
|
|
auto modelSlot = equipSlotToModelSlot( equipSlotId );
|
|
|
|
if( modelSlot != GearModelSlot::ModelInvalid )
|
|
|
|
m_modelEquip[ static_cast< uint8_t >( modelSlot ) ] = 0;
|
2017-11-16 00:03:36 -02:00
|
|
|
|
2018-10-20 14:20:39 +03:00
|
|
|
if ( equipSlotId == SoulCrystal )
|
2021-11-27 00:53:57 +01:00
|
|
|
unequipSoulCrystal();
|
2019-03-21 18:06:48 +01:00
|
|
|
|
2019-03-21 18:53:32 +01:00
|
|
|
calculateStats();
|
|
|
|
|
2019-03-21 18:06:48 +01:00
|
|
|
if( sendUpdate )
|
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
sendModel();
|
|
|
|
sendItemLevel();
|
2019-03-21 18:06:48 +01:00
|
|
|
sendStats();
|
2019-03-21 18:53:32 +01:00
|
|
|
sendStatusUpdate();
|
2019-03-21 18:06:48 +01:00
|
|
|
}
|
2018-10-20 14:20:39 +03:00
|
|
|
}
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
void Sapphire::Entity::Player::unequipSoulCrystal()
|
2018-10-20 14:20:39 +03:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
auto& exdData = Common::Service< Sapphire::Data::ExdData >::ref();
|
2018-10-20 14:20:39 +03:00
|
|
|
|
2022-01-27 21:24:54 +01:00
|
|
|
auto currentClassJob = exdData.getRow< Excel::ClassJob >( static_cast< uint32_t >( getClass() ) );
|
2021-11-27 00:53:57 +01:00
|
|
|
auto parentClass = static_cast< ClassJob >( currentClassJob->data().MainClass );
|
2018-10-20 14:36:56 +03:00
|
|
|
setClassJob( parentClass );
|
2017-08-08 13:53:47 +02:00
|
|
|
}
|
|
|
|
|
2023-02-14 01:26:27 +01:00
|
|
|
uint32_t Sapphire::Entity::Player::currencyTypeToItem( Common::CurrencyType type ) const
|
|
|
|
{
|
|
|
|
switch( type )
|
|
|
|
{
|
|
|
|
case Common::CurrencyType::Gil:
|
|
|
|
return 1;
|
|
|
|
case Common::CurrencyType::StormSeal:
|
|
|
|
return 20;
|
|
|
|
case Common::CurrencyType::SerpentSeal:
|
|
|
|
return 21;
|
|
|
|
case Common::CurrencyType::FlameSeal:
|
|
|
|
return 22;
|
|
|
|
case Common::CurrencyType::TomestonePhilo:
|
|
|
|
return 23;
|
|
|
|
case Common::CurrencyType::TomestoneMytho:
|
|
|
|
return 24;
|
|
|
|
case Common::CurrencyType::WolfMark:
|
|
|
|
return 25;
|
|
|
|
case Common::CurrencyType::TomestoneSold:
|
|
|
|
return 26;
|
|
|
|
case Common::CurrencyType::AlliedSeal:
|
|
|
|
return 27;
|
|
|
|
case Common::CurrencyType::Mgp:
|
|
|
|
return 29;
|
|
|
|
case Common::CurrencyType::TomestonePoet:
|
|
|
|
return 28;
|
|
|
|
case Common::CurrencyType::TomestoneLaw:
|
|
|
|
return 30;
|
|
|
|
case Common::CurrencyType::TomestoneEso:
|
|
|
|
return 31;
|
|
|
|
case Common::CurrencyType::TomestoneLore:
|
|
|
|
return 32;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-08 13:53:47 +02:00
|
|
|
// TODO: these next functions are so similar that they could likely be simplified
|
2021-11-27 00:53:57 +01:00
|
|
|
void Sapphire::Entity::Player::addCurrency( CurrencyType type, uint32_t amount )
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
auto slot = static_cast< uint8_t >( static_cast< uint8_t >( type ) - 1 );
|
|
|
|
auto currItem = m_storageMap[ Currency ]->getItem( slot );
|
|
|
|
|
|
|
|
if( !currItem )
|
|
|
|
{
|
2023-02-14 01:26:27 +01:00
|
|
|
currItem = createItem( currencyTypeToItem( type ) );
|
2018-08-29 21:40:59 +02:00
|
|
|
m_storageMap[ Currency ]->setItem( slot, currItem );
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t currentAmount = currItem->getStackSize();
|
|
|
|
currItem->setStackSize( currentAmount + amount );
|
2023-01-06 22:18:29 -05:00
|
|
|
writeCurrencyItem( type );
|
2018-08-29 21:40:59 +02:00
|
|
|
|
|
|
|
updateContainer( Currency, slot, currItem );
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
auto seq = getNextInventorySequence();
|
|
|
|
|
|
|
|
auto invUpdate = makeZonePacket< FFXIVIpcItemOperation >( getId() );
|
|
|
|
invUpdate->data().contextId = seq;
|
|
|
|
invUpdate->data().srcStorageId = Common::InventoryType::Currency;
|
|
|
|
invUpdate->data().srcStack = currItem->getStackSize();
|
|
|
|
invUpdate->data().srcContainerIndex = static_cast< int16_t >( type ) - 1;
|
|
|
|
invUpdate->data().srcEntity = getId();
|
|
|
|
invUpdate->data().srcCatalogId = currItem->getId();
|
|
|
|
invUpdate->data().operationType = Common::ITEM_OPERATION_TYPE::ITEM_OPERATION_TYPE_UPDATEITEM;
|
|
|
|
|
2023-02-17 15:34:51 +01:00
|
|
|
server().queueForPlayer( getCharacterId(), invUpdate );
|
2020-05-12 02:30:21 +09:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
auto invTransFinPacket = makeZonePacket< FFXIVIpcItemOperationBatch >( getId() );
|
|
|
|
invTransFinPacket->data().contextId = seq;
|
|
|
|
invTransFinPacket->data().operationId = seq;
|
|
|
|
invTransFinPacket->data().operationType = Common::ITEM_OPERATION_TYPE::ITEM_OPERATION_TYPE_UPDATEITEM;
|
2020-05-12 02:30:21 +09:00
|
|
|
|
2023-02-17 15:34:51 +01:00
|
|
|
server().queueForPlayer( getCharacterId(), invTransFinPacket );
|
2017-08-08 13:53:47 +02:00
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
void Sapphire::Entity::Player::removeCurrency( Common::CurrencyType type, uint32_t amount )
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
auto currItem = m_storageMap[ Currency ]->getItem( static_cast< uint8_t >( type ) - 1 );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
if( !currItem )
|
|
|
|
return;
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
uint32_t currentAmount = currItem->getStackSize();
|
|
|
|
if( amount > currentAmount )
|
|
|
|
currItem->setStackSize( 0 );
|
|
|
|
else
|
|
|
|
currItem->setStackSize( currentAmount - amount );
|
2023-01-06 22:18:29 -05:00
|
|
|
writeCurrencyItem( type );
|
2021-11-27 00:53:57 +01:00
|
|
|
|
|
|
|
auto seq = getNextInventorySequence();
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
auto invUpdate = makeZonePacket< FFXIVIpcItemOperation >( getId() );
|
|
|
|
invUpdate->data().contextId = seq;
|
|
|
|
invUpdate->data().srcStorageId = Common::InventoryType::Currency;
|
|
|
|
invUpdate->data().srcStack = currItem->getStackSize();
|
|
|
|
invUpdate->data().srcContainerIndex = static_cast< int16_t >( type ) - 1;
|
|
|
|
invUpdate->data().srcCatalogId = currItem->getId();
|
|
|
|
invUpdate->data().operationType = Common::ITEM_OPERATION_TYPE::ITEM_OPERATION_TYPE_UPDATEITEM;
|
2023-02-17 15:34:51 +01:00
|
|
|
server().queueForPlayer( getCharacterId(), invUpdate );
|
2021-11-27 00:53:57 +01:00
|
|
|
|
|
|
|
auto invTransFinPacket = makeZonePacket< FFXIVIpcItemOperationBatch >( getId() );
|
|
|
|
invTransFinPacket->data().contextId = seq;
|
|
|
|
invTransFinPacket->data().operationId = seq;
|
|
|
|
invTransFinPacket->data().operationType = Common::ITEM_OPERATION_TYPE::ITEM_OPERATION_TYPE_UPDATEITEM;
|
2023-02-17 15:34:51 +01:00
|
|
|
server().queueForPlayer( getCharacterId(), invTransFinPacket );
|
2017-08-08 13:53:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
void Sapphire::Entity::Player::addCrystal( Common::CrystalType type, uint32_t amount )
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
auto currItem = m_storageMap[ Crystal ]->getItem( static_cast< uint8_t >( type ) - 1 );
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
if( !currItem )
|
|
|
|
{
|
|
|
|
// TODO: map currency type to itemid
|
2021-11-27 00:53:57 +01:00
|
|
|
currItem = createItem( static_cast< uint8_t >( type ) + 1 );
|
2018-08-29 21:40:59 +02:00
|
|
|
m_storageMap[ Crystal ]->setItem( static_cast< uint8_t >( type ) - 1, currItem );
|
|
|
|
}
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
uint32_t currentAmount = currItem->getStackSize();
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
currItem->setStackSize( currentAmount + amount );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
writeItem( currItem );
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
writeInventory( Crystal );
|
2018-07-26 23:12:02 +10:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
auto seq = getNextInventorySequence();
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
auto invUpdate = makeZonePacket< FFXIVIpcItemOperation >( getId() );
|
|
|
|
invUpdate->data().contextId = seq;
|
|
|
|
invUpdate->data().srcStorageId = Common::InventoryType::Currency;
|
|
|
|
invUpdate->data().srcStack = currItem->getStackSize();
|
|
|
|
invUpdate->data().srcContainerIndex = static_cast< int16_t >( type ) - 1;
|
|
|
|
invUpdate->data().srcEntity = getId();
|
|
|
|
invUpdate->data().srcCatalogId = currItem->getId();
|
|
|
|
invUpdate->data().operationType = Common::ITEM_OPERATION_TYPE::ITEM_OPERATION_TYPE_UPDATEITEM;
|
2023-02-17 15:34:51 +01:00
|
|
|
server().queueForPlayer( getCharacterId(), invUpdate );
|
2020-05-12 02:30:21 +09:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
auto invTransFinPacket = makeZonePacket< FFXIVIpcItemOperationBatch >( getId() );
|
|
|
|
invTransFinPacket->data().contextId = seq;
|
|
|
|
invTransFinPacket->data().operationId = seq;
|
|
|
|
invTransFinPacket->data().operationType = Common::ITEM_OPERATION_TYPE::ITEM_OPERATION_TYPE_UPDATEITEM;
|
2023-02-17 15:34:51 +01:00
|
|
|
server().queueForPlayer( getCharacterId(), invTransFinPacket );
|
|
|
|
server().queueForPlayer( getCharacterId(), makeActorControlSelf( getId(), ItemObtainIcon, static_cast< uint8_t >( type ) + 1, amount ) );
|
2017-08-08 13:53:47 +02:00
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
void Sapphire::Entity::Player::removeCrystal( Common::CrystalType type, uint32_t amount )
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
auto currItem = m_storageMap[ Crystal ]->getItem( static_cast< uint8_t >( type ) - 1 );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
if( !currItem )
|
|
|
|
return;
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
uint32_t currentAmount = currItem->getStackSize();
|
|
|
|
if( amount > currentAmount )
|
|
|
|
currItem->setStackSize( 0 );
|
|
|
|
else
|
|
|
|
currItem->setStackSize( currentAmount - amount );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
writeItem( currItem );
|
|
|
|
|
|
|
|
auto seq = getNextInventorySequence();
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
auto invUpdate = makeZonePacket< FFXIVIpcItemOperation >( getId() );
|
|
|
|
invUpdate->data().contextId = seq;
|
|
|
|
invUpdate->data().srcStorageId = Common::InventoryType::Currency;
|
|
|
|
invUpdate->data().srcStack = currItem->getStackSize();
|
|
|
|
invUpdate->data().srcContainerIndex = static_cast< int16_t >( type ) - 1;
|
|
|
|
invUpdate->data().srcEntity = getId();
|
|
|
|
invUpdate->data().srcCatalogId = currItem->getId();
|
|
|
|
invUpdate->data().operationType = Common::ITEM_OPERATION_TYPE::ITEM_OPERATION_TYPE_UPDATEITEM;
|
2023-02-17 15:34:51 +01:00
|
|
|
server().queueForPlayer( getCharacterId(), invUpdate );
|
2021-11-27 00:53:57 +01:00
|
|
|
|
|
|
|
auto invTransFinPacket = makeZonePacket< FFXIVIpcItemOperationBatch >( getId() );
|
|
|
|
invTransFinPacket->data().contextId = seq;
|
|
|
|
invTransFinPacket->data().operationId = seq;
|
|
|
|
invTransFinPacket->data().operationType = Common::ITEM_OPERATION_TYPE::ITEM_OPERATION_TYPE_UPDATEITEM;
|
2023-02-17 15:34:51 +01:00
|
|
|
server().queueForPlayer( getCharacterId(), invTransFinPacket );
|
2017-08-08 13:53:47 +02:00
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
void Sapphire::Entity::Player::sendInventory()
|
2018-07-24 23:58:08 +02:00
|
|
|
{
|
2020-03-01 01:00:57 +11:00
|
|
|
auto& invMgr = Common::Service< World::Manager::InventoryMgr >::ref();
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2023-01-17 08:28:06 +01:00
|
|
|
for( auto& it : m_storageMap )
|
2018-12-18 22:59:01 +11:00
|
|
|
{
|
2023-01-17 08:28:06 +01:00
|
|
|
invMgr.sendInventoryContainer( *this, it.second );
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
2018-07-24 23:58:08 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 21:07:20 +01:00
|
|
|
void Sapphire::Entity::Player::sendGearInventory()
|
|
|
|
{
|
|
|
|
auto& invMgr = Common::Service< World::Manager::InventoryMgr >::ref();
|
|
|
|
|
|
|
|
invMgr.sendInventoryContainer( *this, m_storageMap[ GearSet0 ] );
|
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
Sapphire::Entity::Player::InvSlotPairVec Sapphire::Entity::Player::getSlotsOfItemsInInventory( uint32_t catalogId )
|
2018-07-24 23:58:08 +02:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
InvSlotPairVec outVec;
|
|
|
|
for( auto i : { Bag0, Bag1, Bag2, Bag3 } )
|
|
|
|
{
|
|
|
|
auto inv = m_storageMap[ i ];
|
2023-01-17 08:28:06 +01:00
|
|
|
for( const auto& item : inv->getItemMap() )
|
2018-08-29 21:40:59 +02:00
|
|
|
{
|
|
|
|
if( item.second && item.second->getId() == catalogId )
|
|
|
|
outVec.push_back( std::make_pair( i, static_cast< int8_t >( item.first ) ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return outVec;
|
2018-07-24 23:58:08 +02:00
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
Sapphire::Entity::Player::InvSlotPair Sapphire::Entity::Player::getFreeBagSlot()
|
2018-07-24 23:58:08 +02:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
for( auto i : { Bag0, Bag1, Bag2, Bag3 } )
|
|
|
|
{
|
|
|
|
auto freeSlot = static_cast< int8_t >( m_storageMap[ i ]->getFreeSlot() );
|
|
|
|
|
|
|
|
if( freeSlot != -1 )
|
|
|
|
return std::make_pair( i, freeSlot );
|
|
|
|
}
|
|
|
|
// no room in inventory
|
|
|
|
return std::make_pair( 0, -1 );
|
2018-07-24 23:58:08 +02:00
|
|
|
}
|
|
|
|
|
2022-02-18 02:24:18 +01:00
|
|
|
Sapphire::Entity::Player::InvSlotPair Sapphire::Entity::Player::getFreeContainerSlot( uint32_t containerId )
|
|
|
|
{
|
2022-02-19 22:05:30 -03:00
|
|
|
auto freeSlot = static_cast< int8_t >( m_storageMap[ containerId ]->getFreeSlot() );
|
2022-02-18 02:24:18 +01:00
|
|
|
|
|
|
|
if( freeSlot != -1 )
|
|
|
|
return std::make_pair( containerId, freeSlot );
|
|
|
|
|
|
|
|
// no room in inventory
|
|
|
|
return std::make_pair( 0, -1 );
|
|
|
|
}
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
Sapphire::ItemPtr Sapphire::Entity::Player::getItemAt( uint16_t containerId, uint16_t slotId )
|
2018-07-24 23:58:08 +02:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
return m_storageMap[ containerId ]->getItem( slotId );
|
2018-07-24 23:58:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
uint32_t Sapphire::Entity::Player::getCurrency( CurrencyType type )
|
2018-07-24 23:58:08 +02:00
|
|
|
{
|
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
auto currItem = m_storageMap[ Currency ]->getItem( static_cast< uint8_t >( type ) - 1 );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
if( !currItem )
|
|
|
|
return 0;
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
return currItem->getStackSize();
|
2018-07-24 23:58:08 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
uint32_t Sapphire::Entity::Player::getCrystal( CrystalType type )
|
2018-07-24 23:58:08 +02:00
|
|
|
{
|
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
auto currItem = m_storageMap[ Crystal ]->getItem( static_cast< uint8_t >( type ) - 1 );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
if( !currItem )
|
|
|
|
return 0;
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
return currItem->getStackSize();
|
2018-07-24 23:58:08 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
void Sapphire::Entity::Player::writeInventory( InventoryType type )
|
2018-07-24 23:58:08 +02:00
|
|
|
{
|
2020-03-01 01:00:57 +11:00
|
|
|
auto& db = Common::Service< Db::DbWorkerPool< Db::ZoneDbConnection > >::ref();
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
auto storage = m_storageMap[ type ];
|
2018-07-26 23:40:46 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
if( !storage->isPersistentStorage() )
|
|
|
|
return;
|
2018-08-12 22:53:21 +10:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
std::string query = "UPDATE " + storage->getTableName() + " SET ";
|
2018-07-26 23:12:02 +10:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
for( int32_t i = 0; i <= storage->getMaxSize(); i++ )
|
|
|
|
{
|
|
|
|
auto currItem = storage->getItem( i );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
if( i > 0 )
|
|
|
|
query += ", ";
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2023-01-06 22:18:29 -05:00
|
|
|
query += "container_" + std::to_string( i ) + " = " + std::to_string( currItem ? currItem->getUId() : 0 );
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2021-12-02 00:08:33 +01:00
|
|
|
query += " WHERE CharacterId = " + std::to_string( getCharacterId() );
|
2018-07-26 23:40:46 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
if( storage->isMultiStorage() )
|
|
|
|
query += " AND storageId = " + std::to_string( static_cast< uint16_t >( type ) );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2020-03-01 01:00:57 +11:00
|
|
|
db.execute( query );
|
2017-08-08 13:53:47 +02:00
|
|
|
}
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
void Sapphire::Entity::Player::writeItem( Sapphire::ItemPtr pItem ) const
|
2018-07-24 23:58:08 +02:00
|
|
|
{
|
2020-03-01 01:00:57 +11:00
|
|
|
auto& db = Common::Service< Db::DbWorkerPool< Db::ZoneDbConnection > >::ref();
|
|
|
|
auto stmt = db.getPreparedStatement( Db::CHARA_ITEMGLOBAL_UP );
|
2018-08-31 23:25:53 +10:00
|
|
|
|
|
|
|
// todo: add more fields
|
|
|
|
stmt->setInt( 1, pItem->getStackSize() );
|
|
|
|
stmt->setInt( 2, pItem->getDurability() );
|
|
|
|
stmt->setInt( 3, pItem->getStain() );
|
2023-02-09 20:56:26 +01:00
|
|
|
stmt->setInt( 4, pItem->getPattern() );
|
2018-08-31 23:25:53 +10:00
|
|
|
|
2023-02-09 20:56:26 +01:00
|
|
|
stmt->setInt64( 5, pItem->getUId() );
|
2018-08-31 23:25:53 +10:00
|
|
|
|
2020-03-01 01:00:57 +11:00
|
|
|
db.directExecute( stmt );
|
2018-07-24 23:58:08 +02:00
|
|
|
}
|
|
|
|
|
2023-01-06 22:18:29 -05:00
|
|
|
void Sapphire::Entity::Player::writeCurrencyItem( CurrencyType type )
|
|
|
|
{
|
|
|
|
auto& db = Common::Service< Db::DbWorkerPool< Db::ZoneDbConnection > >::ref();
|
|
|
|
|
|
|
|
auto money = m_storageMap[ Currency ]->getItem( static_cast< uint16_t >( type ) - 1 )->getStackSize();
|
|
|
|
|
|
|
|
std::string query = fmt::format(
|
|
|
|
"UPDATE charaitemcurrency SET container_{0} = {1} WHERE CharacterId = {2};",
|
|
|
|
std::to_string( static_cast< int16_t >( type ) - 1 ), std::to_string( money ), std::to_string( getCharacterId() ) );
|
|
|
|
|
|
|
|
db.execute( query );
|
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
void Sapphire::Entity::Player::deleteItemDb( Sapphire::ItemPtr item ) const
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
2020-03-01 01:00:57 +11:00
|
|
|
auto& db = Common::Service< Db::DbWorkerPool< Db::ZoneDbConnection > >::ref();
|
|
|
|
auto stmt = db.getPreparedStatement( Db::CHARA_ITEMGLOBAL_DELETE );
|
2018-08-31 23:25:53 +10:00
|
|
|
|
|
|
|
stmt->setInt64( 1, item->getUId() );
|
|
|
|
|
2020-03-01 01:00:57 +11:00
|
|
|
db.directExecute( stmt );
|
2017-08-08 13:53:47 +02:00
|
|
|
}
|
|
|
|
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
bool Sapphire::Entity::Player::isObtainable( uint32_t catalogId, uint8_t quantity )
|
2018-07-24 23:58:08 +02:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
return true;
|
2018-07-24 23:58:08 +02:00
|
|
|
}
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
|
|
|
|
Sapphire::ItemPtr Sapphire::Entity::Player::addItem( uint32_t catalogId, uint32_t quantity, bool isHq, bool silent, bool canMerge )
|
2018-07-24 23:58:08 +02:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
auto& exdData = Common::Service< Data::ExdData >::ref();
|
2022-01-27 21:24:54 +01:00
|
|
|
auto itemInfo = exdData.getRow< Excel::Item >( catalogId );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
// if item data doesn't exist or it's a blank field
|
2021-11-27 00:53:57 +01:00
|
|
|
if( !itemInfo || itemInfo->data().EquipLevel == 0 )
|
2018-08-29 21:40:59 +02:00
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
quantity = std::min< uint32_t >( quantity, itemInfo->data().StackMax );
|
2018-08-25 00:15:26 +10:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
// used for item obtain notification
|
2021-11-27 00:53:57 +01:00
|
|
|
uint32_t originalQuantity = quantity;
|
2018-08-25 00:15:26 +10:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
std::pair< uint16_t, uint8_t > freeBagSlot;
|
|
|
|
bool foundFreeSlot = false;
|
2018-08-25 00:15:26 +10:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
std::vector< uint16_t > bags = { Bag0, Bag1, Bag2, Bag3 };
|
2021-11-27 00:53:57 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
// add the related armoury bag to the applicable bags and try and fill a free slot there before falling back to regular inventory
|
2021-11-27 00:53:57 +01:00
|
|
|
// EXD TODO: wtf...
|
2022-02-18 02:24:18 +01:00
|
|
|
if( itemInfo->data().Slot > 0 && getEquipDisplayFlags() & StoreNewItemsInArmouryChest )
|
2018-08-29 21:40:59 +02:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
auto bag = World::Manager::ItemMgr::getCharaEquipSlotCategoryToArmoryId( itemInfo->data().Slot );
|
2018-08-25 22:38:07 +10:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
bags.insert( bags.begin(), bag );
|
|
|
|
}
|
2018-08-25 22:38:07 +10:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
for( auto bag : bags )
|
|
|
|
{
|
|
|
|
auto storage = m_storageMap[ bag ];
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
for( uint16_t slot = 0; slot < storage->getMaxSize(); slot++ )
|
2018-08-29 21:40:59 +02:00
|
|
|
{
|
2020-02-24 18:23:43 +09:00
|
|
|
if( !canMerge && foundFreeSlot )
|
|
|
|
break;
|
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
auto item = storage->getItem( slot );
|
|
|
|
|
|
|
|
// add any items that are stackable
|
2022-02-18 02:37:04 +01:00
|
|
|
if( canMerge && item && item->getMaxStackSize() > 0 && item->getId() == catalogId )
|
2018-08-25 00:15:26 +10:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
uint32_t count = item->getStackSize();
|
|
|
|
uint32_t maxStack = item->getMaxStackSize();
|
|
|
|
|
|
|
|
// if slot is full, skip it
|
|
|
|
if( count >= maxStack )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// check slot is same quality
|
2021-11-27 00:53:57 +01:00
|
|
|
if( item->isHq() != isHq )
|
2018-08-29 21:40:59 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// update stack
|
2021-11-27 00:53:57 +01:00
|
|
|
uint32_t newStackSize = count + quantity;
|
2018-08-29 21:40:59 +02:00
|
|
|
if( newStackSize > maxStack )
|
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
quantity = newStackSize - maxStack;
|
2018-08-29 21:40:59 +02:00
|
|
|
newStackSize = maxStack;
|
|
|
|
}
|
2020-01-03 01:07:42 +09:00
|
|
|
else
|
2021-11-27 00:53:57 +01:00
|
|
|
quantity = 0;
|
2018-08-29 21:40:59 +02:00
|
|
|
|
|
|
|
item->setStackSize( newStackSize );
|
2021-11-27 00:53:57 +01:00
|
|
|
writeItem( item );
|
2018-08-29 21:40:59 +02:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
auto seq = getNextInventorySequence();
|
|
|
|
|
|
|
|
auto slotUpdate = std::make_shared< UpdateInventorySlotPacket >( getId(), slot, bag, *item, seq );
|
2023-02-17 15:34:51 +01:00
|
|
|
server().queueForPlayer( getCharacterId(), slotUpdate );
|
2021-11-27 00:53:57 +01:00
|
|
|
|
|
|
|
auto invTransFinPacket = makeZonePacket< FFXIVIpcItemOperationBatch >( getId() );
|
|
|
|
invTransFinPacket->data().contextId = seq;
|
|
|
|
invTransFinPacket->data().operationId = seq;
|
|
|
|
invTransFinPacket->data().operationType = Common::ITEM_OPERATION_TYPE::ITEM_OPERATION_TYPE_UPDATEITEM;
|
2023-02-17 15:34:51 +01:00
|
|
|
server().queueForPlayer( getCharacterId(), invTransFinPacket );
|
2018-08-29 21:40:59 +02:00
|
|
|
|
|
|
|
// return existing stack if we have no overflow - items fit into a preexisting stack
|
2021-11-27 00:53:57 +01:00
|
|
|
if( quantity == 0 )
|
2018-08-29 21:40:59 +02:00
|
|
|
{
|
2023-02-17 15:34:51 +01:00
|
|
|
server().queueForPlayer( getCharacterId(), makeActorControlSelf( getId(), ItemObtainIcon, catalogId, originalQuantity ) );
|
2018-08-29 21:40:59 +02:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else if( !item && !foundFreeSlot )
|
|
|
|
{
|
|
|
|
freeBagSlot = { bag, slot };
|
|
|
|
foundFreeSlot = true;
|
2018-08-12 22:30:18 +10:00
|
|
|
}
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
|
|
|
}
|
2018-08-12 22:30:18 +10:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
// couldn't find a free slot and we still have some quantity of items left, shits fucked
|
|
|
|
if( !foundFreeSlot )
|
|
|
|
return nullptr;
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
auto item = createItem( catalogId, quantity );
|
|
|
|
item->setHq( isHq );
|
2020-06-28 09:27:00 +09:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
auto storage = m_storageMap[ freeBagSlot.first ];
|
2021-11-27 00:53:57 +01:00
|
|
|
storage->setItem( freeBagSlot.second, item );
|
2018-08-25 00:15:26 +10:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
writeInventory( static_cast< InventoryType >( freeBagSlot.first ) );
|
2018-08-25 00:15:26 +10:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
if( !silent )
|
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
auto seq = getNextInventorySequence();
|
|
|
|
|
|
|
|
// send inv update
|
|
|
|
auto invTransPacket = makeZonePacket< FFXIVIpcItemOperation >( getId() );
|
|
|
|
invTransPacket->data().contextId = seq;
|
|
|
|
invTransPacket->data().dstEntity = getId();
|
|
|
|
invTransPacket->data().dstStorageId = freeBagSlot.first;
|
|
|
|
invTransPacket->data().dstCatalogId = item->getId();
|
|
|
|
invTransPacket->data().dstStack = item->getStackSize();
|
|
|
|
invTransPacket->data().dstContainerIndex = freeBagSlot.second;
|
|
|
|
invTransPacket->data().operationType = Common::ITEM_OPERATION_TYPE::ITEM_OPERATION_TYPE_CREATEITEM;
|
2023-02-17 15:34:51 +01:00
|
|
|
server().queueForPlayer( getCharacterId(), invTransPacket );
|
2021-11-27 00:53:57 +01:00
|
|
|
|
|
|
|
auto invTransFinPacket = makeZonePacket< FFXIVIpcItemOperationBatch >( getId() );
|
|
|
|
invTransFinPacket->data().contextId = seq;
|
|
|
|
invTransFinPacket->data().operationId = seq;
|
|
|
|
invTransFinPacket->data().operationType = Common::ITEM_OPERATION_TYPE::ITEM_OPERATION_TYPE_CREATEITEM;
|
2023-02-17 15:34:51 +01:00
|
|
|
server().queueForPlayer( getCharacterId(), invTransFinPacket );
|
|
|
|
server().queueForPlayer( getCharacterId(), makeActorControlSelf( getId(), ItemObtainIcon, catalogId, originalQuantity ) );
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
return item;
|
2018-07-24 23:58:08 +02:00
|
|
|
}
|
|
|
|
|
2023-02-08 21:44:51 +01:00
|
|
|
bool Sapphire::Entity::Player::removeItem( uint32_t catalogId, uint32_t quantity, bool isHq )
|
|
|
|
{
|
|
|
|
std::vector< uint16_t > bags = { Bag0, Bag1, Bag2, Bag3 };
|
|
|
|
|
|
|
|
for( auto bag : bags )
|
|
|
|
{
|
|
|
|
auto storage = m_storageMap[ bag ];
|
|
|
|
|
|
|
|
for( uint16_t slot = 0; slot < storage->getMaxSize(); slot++ )
|
|
|
|
{
|
|
|
|
if( quantity == 0 )
|
|
|
|
break;
|
|
|
|
|
|
|
|
auto item = storage->getItem( slot );
|
|
|
|
|
|
|
|
// remove any matching items
|
|
|
|
if( item && item->getId() == catalogId )
|
|
|
|
{
|
|
|
|
uint32_t count = item->getStackSize();
|
|
|
|
uint32_t maxStack = item->getMaxStackSize();
|
|
|
|
|
|
|
|
// check slot is same quality
|
|
|
|
if( item->isHq() != isHq )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// update stack
|
|
|
|
int32_t newStackSize = count - quantity;
|
|
|
|
if( newStackSize <= 0 )
|
|
|
|
{
|
|
|
|
quantity = std::abs( newStackSize );
|
|
|
|
discardItem( bag, slot );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
quantity = 0;
|
|
|
|
item->setStackSize( newStackSize );
|
|
|
|
|
|
|
|
insertInventoryItem( static_cast< Sapphire::Common::InventoryType >( bag ), slot, item );
|
|
|
|
|
|
|
|
writeItem( item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return quantity == 0;
|
|
|
|
}
|
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
void
|
2021-11-27 00:53:57 +01:00
|
|
|
Sapphire::Entity::Player::moveItem( uint16_t fromInventoryId, uint16_t fromSlotId, uint16_t toInventoryId, uint16_t toSlot )
|
2018-07-24 23:58:08 +02:00
|
|
|
{
|
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
auto tmpItem = m_storageMap[ fromInventoryId ]->getItem( fromSlotId );
|
|
|
|
auto& itemMap = m_storageMap[ fromInventoryId ]->getItemMap();
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
if( tmpItem == nullptr )
|
|
|
|
return;
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
itemMap[ fromSlotId ].reset();
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
m_storageMap[ toInventoryId ]->setItem( toSlot, tmpItem );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
writeInventory( static_cast< InventoryType >( toInventoryId ) );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
if( fromInventoryId != toInventoryId )
|
|
|
|
writeInventory( static_cast< InventoryType >( fromInventoryId ) );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
if( static_cast< InventoryType >( toInventoryId ) == GearSet0 )
|
2021-11-27 00:53:57 +01:00
|
|
|
equipItem( static_cast< GearSetSlot >( toSlot ), *tmpItem, true );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
if( static_cast< InventoryType >( fromInventoryId ) == GearSet0 )
|
2021-11-27 00:53:57 +01:00
|
|
|
unequipItem( static_cast< GearSetSlot >( fromSlotId ), *tmpItem, true );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2020-01-05 17:41:38 +09:00
|
|
|
if( static_cast< InventoryType >( toInventoryId ) == GearSet0 ||
|
|
|
|
static_cast< InventoryType >( fromInventoryId ) == GearSet0 )
|
|
|
|
sendStatusEffectUpdate(); // send if any equip is changed
|
2018-07-24 23:58:08 +02:00
|
|
|
}
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
bool Sapphire::Entity::Player::updateContainer( uint16_t storageId, uint16_t slotId, ItemPtr pItem )
|
2018-07-24 23:58:08 +02:00
|
|
|
{
|
2018-12-23 13:26:33 +01:00
|
|
|
auto containerType = World::Manager::ItemMgr::getContainerType( storageId );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2019-03-21 18:06:48 +01:00
|
|
|
auto pOldItem = getItemAt( storageId, slotId );
|
2018-08-29 21:40:59 +02:00
|
|
|
m_storageMap[ storageId ]->setItem( slotId, pItem );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
switch( containerType )
|
|
|
|
{
|
|
|
|
case Armory:
|
|
|
|
case Bag:
|
|
|
|
case CurrencyCrystal:
|
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
writeInventory( static_cast< InventoryType >( storageId ) );
|
2018-08-29 21:40:59 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
case GearSet:
|
|
|
|
{
|
|
|
|
if( pItem )
|
2019-03-21 18:06:48 +01:00
|
|
|
{
|
|
|
|
if( pOldItem )
|
2021-11-27 00:53:57 +01:00
|
|
|
unequipItem( static_cast< GearSetSlot >( slotId ), *pOldItem, false );
|
|
|
|
equipItem( static_cast< GearSetSlot >( slotId ), *pItem, true );
|
2019-03-21 18:06:48 +01:00
|
|
|
}
|
2018-08-29 21:40:59 +02:00
|
|
|
else
|
2021-11-27 00:53:57 +01:00
|
|
|
unequipItem( static_cast< GearSetSlot >( slotId ), *pItem, true );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
writeInventory( static_cast< InventoryType >( storageId ) );
|
2018-08-29 21:40:59 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
return true;
|
2018-07-24 23:58:08 +02:00
|
|
|
}
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
void Sapphire::Entity::Player::splitItem( uint16_t fromInventoryId, uint16_t fromSlotId,
|
|
|
|
uint16_t toInventoryId, uint16_t toSlot, uint16_t itemCount )
|
2018-07-24 23:58:08 +02:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
if( itemCount == 0 )
|
|
|
|
return;
|
2018-08-12 22:30:18 +10:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
auto fromItem = m_storageMap[ fromInventoryId ]->getItem( fromSlotId );
|
|
|
|
if( !fromItem )
|
|
|
|
return;
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
// check we have enough items in the origin slot
|
|
|
|
// nb: don't let the client 'split' a whole stack into another slot
|
|
|
|
if( fromItem->getStackSize() < itemCount )
|
|
|
|
// todo: correct the invalid item split? does retail do this or does it just ignore it?
|
|
|
|
return;
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
// make sure toInventoryId & toSlot are actually free so we don't orphan an item
|
|
|
|
if( m_storageMap[ toInventoryId ]->getItem( toSlot ) )
|
|
|
|
// todo: correct invalid move? again, not sure what retail does here
|
|
|
|
return;
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2020-02-24 18:23:43 +09:00
|
|
|
auto newItem = addItem( fromItem->getId(), itemCount, fromItem->isHq(), true, false );
|
2018-08-29 21:40:59 +02:00
|
|
|
if( !newItem )
|
|
|
|
return;
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
fromItem->setStackSize( fromItem->getStackSize() - itemCount );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
updateContainer( fromInventoryId, fromSlotId, fromItem );
|
2018-08-29 21:40:59 +02:00
|
|
|
updateContainer( toInventoryId, toSlot, newItem );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
writeItem( fromItem );
|
2018-07-24 23:58:08 +02:00
|
|
|
}
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
void Sapphire::Entity::Player::mergeItem( uint16_t fromInventoryId, uint16_t fromSlotId,
|
|
|
|
uint16_t toInventoryId, uint16_t toSlot )
|
2018-07-24 23:58:08 +02:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
auto fromItem = m_storageMap[ fromInventoryId ]->getItem( fromSlotId );
|
|
|
|
auto toItem = m_storageMap[ toInventoryId ]->getItem( toSlot );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
if( !fromItem || !toItem )
|
|
|
|
return;
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
if( fromItem->getId() != toItem->getId() )
|
|
|
|
return;
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
uint32_t stackSize = fromItem->getStackSize() + toItem->getStackSize();
|
|
|
|
uint32_t stackOverflow = stackSize - std::min< uint32_t >( fromItem->getMaxStackSize(), stackSize );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
// we can destroy the original stack if there's no overflow
|
|
|
|
if( stackOverflow == 0 )
|
|
|
|
{
|
|
|
|
m_storageMap[ fromInventoryId ]->removeItem( fromSlotId );
|
|
|
|
deleteItemDb( fromItem );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fromItem->setStackSize( stackOverflow );
|
2021-11-27 00:53:57 +01:00
|
|
|
writeItem( fromItem );
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
2018-07-24 23:58:08 +02:00
|
|
|
|
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
toItem->setStackSize( stackSize );
|
2021-11-27 00:53:57 +01:00
|
|
|
writeItem( toItem );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
updateContainer( fromInventoryId, fromSlotId, fromItem );
|
2018-08-29 21:40:59 +02:00
|
|
|
updateContainer( toInventoryId, toSlot, toItem );
|
2018-07-24 23:58:08 +02:00
|
|
|
}
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
void Sapphire::Entity::Player::swapItem( uint16_t fromInventoryId, uint16_t fromSlotId,
|
|
|
|
uint16_t toInventoryId, uint16_t toSlot )
|
2018-07-24 23:58:08 +02:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
auto fromItem = m_storageMap[ fromInventoryId ]->getItem( fromSlotId );
|
|
|
|
auto toItem = m_storageMap[ toInventoryId ]->getItem( toSlot );
|
|
|
|
auto& itemMap = m_storageMap[ fromInventoryId ]->getItemMap();
|
|
|
|
|
|
|
|
if( fromItem == nullptr || toItem == nullptr )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// An item is being moved from bag0-3 to equippment, meaning
|
|
|
|
// the swapped out item will be placed in the matching armory.
|
2018-12-23 13:26:33 +01:00
|
|
|
if( World::Manager::ItemMgr::isEquipment( toInventoryId )
|
|
|
|
&& !World::Manager::ItemMgr::isEquipment( fromInventoryId )
|
|
|
|
&& !World::Manager::ItemMgr::isArmory( fromInventoryId ) )
|
2018-08-29 21:40:59 +02:00
|
|
|
{
|
|
|
|
updateContainer( fromInventoryId, fromSlotId, nullptr );
|
2022-02-18 02:24:18 +01:00
|
|
|
auto& exdData = Common::Service< Data::ExdData >::ref();
|
|
|
|
auto itemInfo = exdData.getRow< Excel::Item >( toItem->getId() );
|
|
|
|
fromInventoryId = World::Manager::ItemMgr::getCharaEquipSlotCategoryToArmoryId( static_cast< Common::EquipSlotCategory >( itemInfo->data().Slot ) );
|
2018-08-29 21:40:59 +02:00
|
|
|
fromSlotId = static_cast < uint8_t >( m_storageMap[ fromInventoryId ]->getFreeSlot() );
|
|
|
|
}
|
|
|
|
|
2018-12-23 13:26:33 +01:00
|
|
|
auto containerTypeFrom = World::Manager::ItemMgr::getContainerType( fromInventoryId );
|
|
|
|
auto containerTypeTo = World::Manager::ItemMgr::getContainerType( toInventoryId );
|
2018-08-29 21:40:59 +02:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
updateContainer( toInventoryId, toSlot, fromItem );
|
2018-08-29 21:40:59 +02:00
|
|
|
updateContainer( fromInventoryId, fromSlotId, toItem );
|
2020-01-05 17:41:38 +09:00
|
|
|
|
|
|
|
if( static_cast< InventoryType >( toInventoryId ) == GearSet0 ||
|
|
|
|
static_cast< InventoryType >( fromInventoryId ) == GearSet0 )
|
|
|
|
sendStatusEffectUpdate(); // send if any equip is changed
|
2018-07-24 23:58:08 +02:00
|
|
|
}
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
void Sapphire::Entity::Player::discardItem( uint16_t fromInventoryId, uint16_t fromSlotId )
|
2018-07-24 23:58:08 +02:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
// i am not entirely sure how this should be generated or if it even is important for us...
|
2019-02-09 22:59:14 +11:00
|
|
|
uint32_t sequence = getNextInventorySequence();
|
2018-08-29 21:40:59 +02:00
|
|
|
|
|
|
|
auto fromItem = m_storageMap[ fromInventoryId ]->getItem( fromSlotId );
|
|
|
|
|
|
|
|
deleteItemDb( fromItem );
|
|
|
|
|
|
|
|
m_storageMap[ fromInventoryId ]->removeItem( fromSlotId );
|
|
|
|
updateContainer( fromInventoryId, fromSlotId, nullptr );
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
auto invTransPacket = makeZonePacket< FFXIVIpcItemOperation >( getId() );
|
|
|
|
invTransPacket->data().contextId = sequence;
|
|
|
|
invTransPacket->data().srcEntity = getId();
|
|
|
|
invTransPacket->data().srcStorageId = fromInventoryId;
|
|
|
|
invTransPacket->data().srcCatalogId = fromItem->getId();
|
|
|
|
invTransPacket->data().srcStack = fromItem->getStackSize();
|
|
|
|
invTransPacket->data().srcContainerIndex = fromSlotId;
|
|
|
|
invTransPacket->data().operationType = Common::ITEM_OPERATION_TYPE::ITEM_OPERATION_TYPE_DELETEITEM;
|
2023-02-17 15:34:51 +01:00
|
|
|
server().queueForPlayer( getCharacterId(), invTransPacket );
|
2018-08-29 21:40:59 +02:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
auto invTransFinPacket = makeZonePacket< FFXIVIpcItemOperationBatch >( getId() );
|
|
|
|
invTransFinPacket->data().contextId = sequence;
|
|
|
|
invTransFinPacket->data().operationId = sequence;
|
|
|
|
invTransFinPacket->data().operationType = Common::ITEM_OPERATION_TYPE::ITEM_OPERATION_TYPE_DELETEITEM;
|
2023-02-17 15:34:51 +01:00
|
|
|
server().queueForPlayer( getCharacterId(), invTransFinPacket );
|
2018-07-24 23:58:08 +02:00
|
|
|
}
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
uint16_t Sapphire::Entity::Player::calculateEquippedGearItemLevel()
|
2018-07-24 23:58:08 +02:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
uint32_t iLvlResult = 0;
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
auto gearSetMap = m_storageMap[ GearSet0 ]->getItemMap();
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
auto it = gearSetMap.begin();
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
while( it != gearSetMap.end() )
|
|
|
|
{
|
|
|
|
auto currItem = it->second;
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2019-04-25 18:26:35 +10:00
|
|
|
if( currItem && currItem->getCategory() != Common::ItemUICategory::SoulCrystal )
|
2018-08-29 21:40:59 +02:00
|
|
|
{
|
|
|
|
iLvlResult += currItem->getItemLevel();
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
// If item is weapon and isn't one-handed
|
2018-12-23 13:26:33 +01:00
|
|
|
if( currItem->isWeapon() && !World::Manager::ItemMgr::isOneHandedWeapon( currItem->getCategory() ) )
|
2018-08-29 21:40:59 +02:00
|
|
|
{
|
|
|
|
iLvlResult += currItem->getItemLevel();
|
2018-07-24 23:58:08 +02:00
|
|
|
}
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
it++;
|
|
|
|
}
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
uint16_t ilvl = static_cast< uint16_t >( std::min( static_cast< int32_t >( iLvlResult / 13 ), 9999 ) );
|
|
|
|
|
|
|
|
m_itemLevel = ilvl;
|
|
|
|
return ilvl;
|
2018-07-24 23:58:08 +02:00
|
|
|
}
|
|
|
|
|
2023-02-10 17:14:09 -03:00
|
|
|
void Sapphire::Entity::Player::calculateBonusStats()
|
|
|
|
{
|
|
|
|
m_bonusStats.fill( 0 );
|
|
|
|
|
|
|
|
auto gearSetMap = m_storageMap[ GearSet0 ]->getItemMap();
|
|
|
|
|
|
|
|
auto it = gearSetMap.begin();
|
|
|
|
|
|
|
|
while( it != gearSetMap.end() )
|
|
|
|
{
|
|
|
|
auto pItem = it->second;
|
|
|
|
|
|
|
|
if( pItem && pItem->getCategory() != Common::ItemUICategory::SoulCrystal )
|
|
|
|
{
|
|
|
|
auto baseParams = pItem->getBaseParams();
|
|
|
|
for( auto i = 0; i < 6; ++i )
|
|
|
|
{
|
|
|
|
auto itemBaseParam = baseParams[ i ].baseParam;
|
|
|
|
auto itemBaseVal = baseParams[ i ].value;
|
|
|
|
if( itemBaseParam != static_cast< uint8_t >( Common::BaseParam::None ) )
|
|
|
|
m_bonusStats[ itemBaseParam ] += itemBaseVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_bonusStats[ static_cast< uint8_t >( Common::BaseParam::Defense ) ] += pItem->getDefense();
|
|
|
|
m_bonusStats[ static_cast< uint8_t >( Common::BaseParam::MagicDefense ) ] += pItem->getDefenseMag();
|
|
|
|
}
|
|
|
|
|
|
|
|
it++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-24 23:25:07 +10:00
|
|
|
Sapphire::ItemPtr Sapphire::Entity::Player::getEquippedWeapon()
|
|
|
|
{
|
|
|
|
return m_storageMap[ GearSet0 ]->getItem( GearSetSlot::MainHand );
|
|
|
|
}
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
uint16_t Sapphire::Entity::Player::getFreeSlotsInBags()
|
2018-07-24 23:58:08 +02:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
uint16_t slots = 0;
|
2018-08-29 21:40:59 +02:00
|
|
|
for( uint8_t container : { Bag0, Bag1, Bag2, Bag3 } )
|
|
|
|
{
|
|
|
|
const auto& storage = m_storageMap[ container ];
|
|
|
|
slots += ( storage->getMaxSize() - storage->getEntryCount() );
|
|
|
|
}
|
|
|
|
return slots;
|
2018-07-24 23:58:08 +02:00
|
|
|
}
|
2018-08-31 22:57:33 +10:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
bool Sapphire::Entity::Player::collectHandInItems( std::vector< uint32_t > itemIds )
|
2018-08-31 22:57:33 +10:00
|
|
|
{
|
|
|
|
// todo: figure out how the game gets the required stack count
|
2018-09-01 14:36:04 +10:00
|
|
|
const auto& container = m_storageMap[ HandIn ];
|
2018-08-31 22:57:33 +10:00
|
|
|
|
|
|
|
std::vector< uint8_t > foundItems;
|
|
|
|
|
|
|
|
auto itemMap = container->getItemMap();
|
|
|
|
|
|
|
|
for( auto& item : itemMap )
|
|
|
|
{
|
|
|
|
for( auto needle : itemIds )
|
|
|
|
{
|
|
|
|
if( item.second->getId() == needle )
|
|
|
|
{
|
|
|
|
foundItems.push_back( item.first );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// couldn't find all the items required
|
|
|
|
if( foundItems.size() != itemIds.size() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// remove items
|
|
|
|
for( auto item : foundItems )
|
|
|
|
{
|
|
|
|
container->removeItem( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-12-20 20:41:16 +11:00
|
|
|
|
|
|
|
uint32_t Sapphire::Entity::Player::getNextInventorySequence()
|
|
|
|
{
|
|
|
|
return m_inventorySequence++;
|
|
|
|
}
|
2018-12-26 18:11:18 +11:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
Sapphire::ItemPtr Sapphire::Entity::Player::dropInventoryItem( Sapphire::Common::InventoryType storageId, uint8_t slotId )
|
2018-12-26 18:11:18 +11:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
auto& container = m_storageMap[ storageId ];
|
2018-12-26 18:11:18 +11:00
|
|
|
|
|
|
|
auto item = container->getItem( slotId );
|
|
|
|
if( !item )
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
// unlink item
|
2018-12-29 21:51:43 +11:00
|
|
|
container->removeItem( slotId, false );
|
2021-11-27 00:53:57 +01:00
|
|
|
updateContainer( storageId, slotId, nullptr );
|
2020-05-11 06:25:25 +09:00
|
|
|
|
2018-12-26 18:11:18 +11:00
|
|
|
auto seq = getNextInventorySequence();
|
|
|
|
|
|
|
|
// send inv update
|
2021-11-27 00:53:57 +01:00
|
|
|
auto invTransPacket = makeZonePacket< FFXIVIpcItemOperation >( getId() );
|
|
|
|
invTransPacket->data().contextId = seq;
|
|
|
|
invTransPacket->data().dstEntity = getId();
|
|
|
|
invTransPacket->data().dstStorageId = storageId;
|
|
|
|
invTransPacket->data().dstCatalogId = item->getId();
|
|
|
|
invTransPacket->data().dstStack = item->getStackSize();
|
|
|
|
invTransPacket->data().dstContainerIndex = slotId;
|
|
|
|
invTransPacket->data().operationType = Common::ITEM_OPERATION_TYPE::ITEM_OPERATION_TYPE_DELETEITEM;
|
2023-02-17 15:34:51 +01:00
|
|
|
server().queueForPlayer( getCharacterId(), invTransPacket );
|
2018-12-26 18:11:18 +11:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
auto invTransFinPacket = makeZonePacket< FFXIVIpcItemOperationBatch >( getId() );
|
|
|
|
invTransFinPacket->data().contextId = seq;
|
|
|
|
invTransFinPacket->data().operationId = seq;
|
|
|
|
invTransFinPacket->data().operationType = Common::ITEM_OPERATION_TYPE::ITEM_OPERATION_TYPE_DELETEITEM;
|
2023-02-17 15:34:51 +01:00
|
|
|
server().queueForPlayer( getCharacterId(), invTransFinPacket );
|
2018-12-26 18:11:18 +11:00
|
|
|
|
|
|
|
return item;
|
2018-12-28 02:17:29 +11:00
|
|
|
}
|
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
void Sapphire::Entity::Player::addSoldItem( uint32_t itemId, uint8_t stackSize )
|
|
|
|
{
|
|
|
|
if( m_soldItems.size() > 10 )
|
|
|
|
m_soldItems.pop_back();
|
2023-01-17 08:28:06 +01:00
|
|
|
m_soldItems.emplace_front( itemId, stackSize );
|
2021-11-27 00:53:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::deque< std::pair< uint32_t, uint8_t > > *Sapphire::Entity::Player::getSoldItems()
|
|
|
|
{
|
|
|
|
return &m_soldItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sapphire::Entity::Player::clearSoldItems()
|
|
|
|
{
|
|
|
|
m_soldItems.clear();
|
|
|
|
}
|
|
|
|
|
2018-12-28 11:49:12 +11:00
|
|
|
bool Sapphire::Entity::Player::getFreeInventoryContainerSlot( Inventory::InventoryContainerPair& containerPair ) const
|
2018-12-28 02:17:29 +11:00
|
|
|
{
|
|
|
|
for( auto bagId : { Bag0, Bag1, Bag2, Bag3 } )
|
|
|
|
{
|
|
|
|
auto needle = m_storageMap.find( bagId );
|
|
|
|
if( needle == m_storageMap.end() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
auto& container = needle->second;
|
|
|
|
|
2023-01-17 08:28:06 +01:00
|
|
|
for( uint16_t idx = 0; idx < container->getMaxSize(); idx++ )
|
2018-12-28 02:17:29 +11:00
|
|
|
{
|
|
|
|
auto item = container->getItem( idx );
|
|
|
|
if( !item )
|
|
|
|
{
|
|
|
|
containerPair = std::make_pair( bagId, idx );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sapphire::Entity::Player::insertInventoryItem( Sapphire::Common::InventoryType type, uint16_t slot,
|
|
|
|
const Sapphire::ItemPtr item )
|
|
|
|
{
|
2018-12-28 10:17:05 +11:00
|
|
|
updateContainer( type, slot, item );
|
2018-12-28 02:17:29 +11:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
auto seq = getNextInventorySequence();
|
|
|
|
|
|
|
|
auto slotUpdate = std::make_shared< UpdateInventorySlotPacket >( getId(), slot, type, *item, seq );
|
2023-02-17 15:34:51 +01:00
|
|
|
server().queueForPlayer( getCharacterId(), slotUpdate );
|
2018-12-28 10:17:05 +11:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
auto invTransFinPacket = makeZonePacket< FFXIVIpcItemOperationBatch >( getId() );
|
|
|
|
invTransFinPacket->data().contextId = seq;
|
|
|
|
invTransFinPacket->data().operationId = seq;
|
|
|
|
invTransFinPacket->data().operationType = Common::ITEM_OPERATION_TYPE::ITEM_OPERATION_TYPE_UPDATEITEM;
|
2023-02-17 15:34:51 +01:00
|
|
|
server().queueForPlayer( getCharacterId(), invTransFinPacket );
|
2018-12-30 17:44:03 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Sapphire::Entity::Player::findFirstItemWithId( uint32_t catalogId,
|
2022-02-12 00:58:52 +01:00
|
|
|
Inventory::InventoryContainerPair& location, std::initializer_list< InventoryType > bags )
|
2018-12-30 17:44:03 +11:00
|
|
|
{
|
2022-02-12 00:58:52 +01:00
|
|
|
for( auto bagId : bags )
|
2018-12-30 17:44:03 +11:00
|
|
|
{
|
|
|
|
auto& container = m_storageMap[ bagId ];
|
|
|
|
|
|
|
|
for( const auto& item : container->getItemMap() )
|
|
|
|
{
|
2022-02-12 19:20:13 +00:00
|
|
|
if( ( item.second && item.second->getId() != catalogId ) || !item.second )
|
2018-12-30 17:44:03 +11:00
|
|
|
continue;
|
|
|
|
|
|
|
|
location = std::make_pair( bagId, item.first );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2022-02-12 19:20:13 +00:00
|
|
|
}
|