2018-12-23 13:26:33 +01:00
|
|
|
#include "ItemMgr.h"
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-12-23 13:26:33 +01:00
|
|
|
#include "Inventory/ItemContainer.h"
|
|
|
|
#include "Inventory/Item.h"
|
2018-07-24 23:58:08 +02:00
|
|
|
#include <Network/CommonActorControl.h>
|
|
|
|
|
|
|
|
#include <Exd/ExdDataGenerated.h>
|
|
|
|
#include <Logging/Logger.h>
|
|
|
|
#include <Database/DatabaseDef.h>
|
2020-03-01 01:00:57 +11:00
|
|
|
#include <Service.h>
|
2018-12-23 13:26:33 +01:00
|
|
|
|
|
|
|
bool Sapphire::World::Manager::ItemMgr::isArmory( uint16_t containerId )
|
2018-07-24 23:58:08 +02:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
return
|
|
|
|
containerId == Common::ArmoryBody ||
|
|
|
|
containerId == Common::ArmoryEar ||
|
|
|
|
containerId == Common::ArmoryFeet ||
|
|
|
|
containerId == Common::ArmoryHand ||
|
|
|
|
containerId == Common::ArmoryHead ||
|
|
|
|
containerId == Common::ArmoryLegs ||
|
|
|
|
containerId == Common::ArmoryMain ||
|
|
|
|
containerId == Common::ArmoryOff ||
|
|
|
|
containerId == Common::ArmoryRing ||
|
|
|
|
containerId == Common::ArmoryWaist ||
|
|
|
|
containerId == Common::ArmoryWrist ||
|
|
|
|
containerId == Common::ArmorySoulCrystal;
|
2018-07-24 23:58:08 +02:00
|
|
|
}
|
|
|
|
|
2018-12-23 13:26:33 +01:00
|
|
|
|
2020-05-12 00:18:45 +09:00
|
|
|
uint16_t Sapphire::World::Manager::ItemMgr::getCharaEquipSlotCategoryToArmoryId( Common::EquipSlotCategory slot )
|
2018-07-24 23:58:08 +02:00
|
|
|
{
|
2018-08-25 22:38:07 +10:00
|
|
|
|
2020-05-12 00:18:45 +09:00
|
|
|
switch( slot )
|
2018-08-29 21:40:59 +02:00
|
|
|
{
|
2021-02-16 23:51:42 +09:00
|
|
|
case Common::EquipSlotCategory::Head:
|
2018-08-29 21:40:59 +02:00
|
|
|
return Common::ArmoryHead;
|
2018-08-25 22:38:07 +10:00
|
|
|
|
2021-02-16 23:51:42 +09:00
|
|
|
case Common::EquipSlotCategory::Body:
|
|
|
|
case Common::EquipSlotCategory::BodyDisallowHead:
|
|
|
|
case Common::EquipSlotCategory::BodyDisallowHandsLegsFeet:
|
|
|
|
case Common::EquipSlotCategory::BodyDisallowAll:
|
|
|
|
case Common::EquipSlotCategory::BodyDisallowHands:
|
|
|
|
case Common::EquipSlotCategory::BodyDisallowLegsFeet:
|
2018-08-29 21:40:59 +02:00
|
|
|
return Common::ArmoryBody;
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2021-02-16 23:51:42 +09:00
|
|
|
case Common::EquipSlotCategory::Ears:
|
2018-08-29 21:40:59 +02:00
|
|
|
return Common::ArmoryEar;
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2021-02-16 23:51:42 +09:00
|
|
|
case Common::EquipSlotCategory::Feet:
|
2018-08-29 21:40:59 +02:00
|
|
|
return Common::ArmoryFeet;
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2021-02-16 23:51:42 +09:00
|
|
|
case Common::EquipSlotCategory::Hands:
|
2018-08-29 21:40:59 +02:00
|
|
|
return Common::ArmoryHand;
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2021-02-16 23:51:42 +09:00
|
|
|
case Common::EquipSlotCategory::Legs:
|
|
|
|
case Common::EquipSlotCategory::LegsDisallowFeet:
|
2018-08-29 21:40:59 +02:00
|
|
|
return Common::ArmoryLegs;
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2021-02-16 23:51:42 +09:00
|
|
|
case Common::EquipSlotCategory::MainHand:
|
|
|
|
case Common::EquipSlotCategory::MainTwoHandedWeapon:
|
2020-05-12 00:18:45 +09:00
|
|
|
//case Common::EquipSlotCategory::MainOrOffHand:
|
2018-08-29 21:40:59 +02:00
|
|
|
return Common::ArmoryMain;
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2021-02-16 23:51:42 +09:00
|
|
|
case Common::EquipSlotCategory::OffHand:
|
2018-08-29 21:40:59 +02:00
|
|
|
return Common::ArmoryOff;
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2021-02-16 23:51:42 +09:00
|
|
|
case Common::EquipSlotCategory::Ring:
|
2018-08-29 21:40:59 +02:00
|
|
|
return Common::ArmoryRing;
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2021-02-16 23:51:42 +09:00
|
|
|
case Common::EquipSlotCategory::Waist:
|
2018-08-29 21:40:59 +02:00
|
|
|
return Common::ArmoryWaist;
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2021-02-16 23:51:42 +09:00
|
|
|
case Common::EquipSlotCategory::Wrist:
|
2018-08-29 21:40:59 +02:00
|
|
|
return Common::ArmoryWrist;
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2021-02-16 23:51:42 +09:00
|
|
|
case Common::EquipSlotCategory::Neck:
|
2018-08-29 21:40:59 +02:00
|
|
|
return Common::ArmoryNeck;
|
2018-08-25 22:38:07 +10:00
|
|
|
|
2021-02-16 23:51:42 +09:00
|
|
|
case Common::EquipSlotCategory::SoulCrystal:
|
2018-08-29 21:40:59 +02:00
|
|
|
return Common::ArmorySoulCrystal;
|
2018-08-25 22:38:07 +10:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2018-07-24 23:58:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-23 13:26:33 +01:00
|
|
|
bool Sapphire::World::Manager::ItemMgr::isEquipment( uint16_t containerId )
|
2018-07-24 23:58:08 +02:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
return containerId == Common::GearSet0;
|
2018-07-24 23:58:08 +02:00
|
|
|
}
|
|
|
|
|
2018-12-23 13:26:33 +01:00
|
|
|
bool Sapphire::World::Manager::ItemMgr::isOneHandedWeapon( Common::ItemUICategory weaponCategory )
|
2018-07-24 23:58:08 +02:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
switch( weaponCategory )
|
|
|
|
{
|
|
|
|
case Common::ItemUICategory::AlchemistsPrimaryTool:
|
|
|
|
case Common::ItemUICategory::ArmorersPrimaryTool:
|
|
|
|
case Common::ItemUICategory::BotanistsPrimaryTool:
|
|
|
|
case Common::ItemUICategory::CulinariansPrimaryTool:
|
|
|
|
case Common::ItemUICategory::OnehandedConjurersArm:
|
|
|
|
case Common::ItemUICategory::CarpentersPrimaryTool:
|
|
|
|
case Common::ItemUICategory::FishersPrimaryTool:
|
|
|
|
case Common::ItemUICategory::GladiatorsArm:
|
|
|
|
case Common::ItemUICategory::GoldsmithsPrimaryTool:
|
|
|
|
case Common::ItemUICategory::LeatherworkersPrimaryTool:
|
|
|
|
case Common::ItemUICategory::MinersPrimaryTool:
|
|
|
|
case Common::ItemUICategory::OnehandedThaumaturgesArm:
|
|
|
|
case Common::ItemUICategory::WeaversPrimaryTool:
|
|
|
|
case Common::ItemUICategory::BlacksmithsPrimaryTool:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-24 23:58:08 +02:00
|
|
|
}
|
|
|
|
|
2018-12-23 13:26:33 +01:00
|
|
|
Sapphire::ItemPtr Sapphire::World::Manager::ItemMgr::loadItem( uint64_t uId )
|
2018-07-24 23:58:08 +02:00
|
|
|
{
|
2020-03-01 01:00:57 +11:00
|
|
|
auto& exdData = Common::Service< Data::ExdDataGenerated >::ref();
|
|
|
|
auto& db = Common::Service< Db::DbWorkerPool< Db::ZoneDbConnection > >::ref();
|
2019-04-13 22:41:29 +10:00
|
|
|
|
|
|
|
// 1 catalogId, 2 stack, 3 reservedFlag, 4 signatureId, 5 flags, 6 durability, 7 refine, 8 materia_0, 9 materia_1,
|
|
|
|
// 10 materia_2, 11 materia_3, 12 materia_4, 13 stain, 14 pattern, 15 buffer_0, 16 buffer_1, 17 buffer_2,
|
|
|
|
// 18 buffer_3, 19 buffer_4
|
2020-03-01 01:00:57 +11:00
|
|
|
auto query = db.getPreparedStatement( Db::CHARA_ITEMGLOBAL_SELECT );
|
2019-04-13 22:41:29 +10:00
|
|
|
query->setUInt64( 1, uId );
|
|
|
|
|
2020-03-01 01:00:57 +11:00
|
|
|
auto itemRes = db.query( query );
|
2018-08-29 21:40:59 +02:00
|
|
|
if( !itemRes->next() )
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2020-03-01 01:00:57 +11:00
|
|
|
auto itemInfo = exdData.get< Sapphire::Data::Item >( itemRes->getUInt( 1 ) );
|
2018-08-29 21:40:59 +02:00
|
|
|
bool isHq = itemRes->getUInt( 3 ) == 1;
|
|
|
|
|
|
|
|
ItemPtr pItem = make_Item( uId,
|
|
|
|
itemRes->getUInt( 1 ),
|
|
|
|
isHq );
|
|
|
|
|
|
|
|
pItem->setStackSize( itemRes->getUInt( 2 ) );
|
2019-04-13 22:41:29 +10:00
|
|
|
pItem->setStain( itemRes->getUInt16( 13 ) );
|
|
|
|
pItem->setDurability( itemRes->getInt16( 6 ) );
|
2018-08-29 21:40:59 +02:00
|
|
|
|
|
|
|
return pItem;
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-07-24 23:58:08 +02:00
|
|
|
}
|
|
|
|
|
2018-12-23 13:26:33 +01:00
|
|
|
|
|
|
|
Sapphire::Common::ContainerType Sapphire::World::Manager::ItemMgr::getContainerType( uint32_t containerId )
|
2018-07-24 23:58:08 +02:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
if( containerId < 5 )
|
|
|
|
{
|
|
|
|
return Common::Bag;
|
|
|
|
}
|
|
|
|
else if( containerId < 2000 )
|
|
|
|
{
|
|
|
|
return Common::GearSet;
|
|
|
|
}
|
|
|
|
else if( containerId < 3200 )
|
|
|
|
{
|
|
|
|
return Common::CurrencyCrystal;
|
|
|
|
}
|
|
|
|
else if( containerId < 3600 )
|
|
|
|
{
|
|
|
|
return Common::Armory;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return Common::Unknown;
|
|
|
|
}
|
2018-07-24 23:58:08 +02:00
|
|
|
}
|
|
|
|
|
2018-12-23 13:26:33 +01:00
|
|
|
uint32_t Sapphire::World::Manager::ItemMgr::getNextUId()
|
2018-07-24 23:58:08 +02:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
uint32_t charId = 0;
|
2020-03-01 01:00:57 +11:00
|
|
|
|
|
|
|
auto& db = Common::Service< Db::DbWorkerPool< Db::ZoneDbConnection > >::ref();
|
|
|
|
auto pQR = db.query( "SELECT MAX(ItemId) FROM charaglobalitem" );
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
if( !pQR->next() )
|
|
|
|
return 0x00500001;
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
charId = pQR->getUInt( 1 ) + 1;
|
|
|
|
if( charId < 0x00500001 )
|
|
|
|
return 0x00500001;
|
2018-07-24 23:58:08 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
return charId;
|
2018-07-24 23:58:08 +02:00
|
|
|
}
|