2018-11-24 15:17:18 +11:00
|
|
|
#include "ShopMgr.h"
|
|
|
|
|
|
|
|
#include <Exd/ExdDataGenerated.h>
|
|
|
|
#include <Actor/Player.h>
|
|
|
|
#include <Common.h>
|
2020-03-01 01:00:57 +11:00
|
|
|
#include <Service.h>
|
2020-05-11 06:25:25 +09:00
|
|
|
#include <Network/GamePacket.h>
|
|
|
|
#include <Network/PacketDef/Zone/ServerZoneDef.h>
|
|
|
|
|
|
|
|
#include "Inventory/Item.h"
|
|
|
|
#include "Inventory/ItemContainer.h"
|
2018-11-24 15:17:18 +11:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
using namespace Sapphire;
|
2020-05-11 06:25:25 +09:00
|
|
|
using namespace Sapphire::Network::Packets;
|
|
|
|
using namespace Sapphire::Network::Packets::Server;
|
2018-11-24 15:17:18 +11:00
|
|
|
|
|
|
|
bool Sapphire::World::Manager::ShopMgr::purchaseGilShopItem( Entity::Player& player, uint32_t shopId, uint16_t itemId, uint32_t quantity )
|
|
|
|
{
|
2020-03-01 01:00:57 +11:00
|
|
|
auto& exdData = Common::Service< Data::ExdDataGenerated >::ref();
|
2018-11-24 15:17:18 +11:00
|
|
|
|
2020-03-01 01:00:57 +11:00
|
|
|
auto gilShopItem = exdData.get< Data::GilShopItem >( shopId, itemId );
|
2018-11-24 15:17:18 +11:00
|
|
|
if( !gilShopItem )
|
|
|
|
return false;
|
|
|
|
|
2020-03-01 01:00:57 +11:00
|
|
|
auto item = exdData.get< Data::Item >( gilShopItem->item );
|
2018-11-24 15:17:18 +11:00
|
|
|
if( !item )
|
|
|
|
return false;
|
|
|
|
|
2018-12-04 22:27:54 +11:00
|
|
|
auto price = item->priceMid * quantity;
|
|
|
|
|
|
|
|
if( player.getCurrency( Common::CurrencyType::Gil ) < price )
|
2018-11-24 15:17:18 +11:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if( !player.addItem( gilShopItem->item, quantity ) )
|
|
|
|
return false;
|
|
|
|
|
2018-12-04 22:27:54 +11:00
|
|
|
player.removeCurrency( Common::CurrencyType::Gil, price );
|
2018-11-24 15:17:18 +11:00
|
|
|
|
2020-05-11 06:25:25 +09:00
|
|
|
auto packet = makeZonePacket< FFXIVIpcShopMessage >( player.getId() );
|
|
|
|
packet->data().shopId = shopId;
|
|
|
|
packet->data().msgType = 1687;
|
|
|
|
packet->data().unknown2 = 3;
|
|
|
|
packet->data().itemId = gilShopItem->item;
|
|
|
|
packet->data().amount = quantity;
|
|
|
|
packet->data().price = price;
|
|
|
|
packet->data().unknown6 = 0;
|
|
|
|
packet->data().unknown7 = 0;
|
|
|
|
player.queuePacket( packet );
|
|
|
|
|
2018-11-24 15:17:18 +11:00
|
|
|
return true;
|
2018-12-22 22:25:03 +01:00
|
|
|
}
|
2020-05-11 06:25:25 +09:00
|
|
|
|
|
|
|
bool Sapphire::World::Manager::ShopMgr::shopSellItem( Sapphire::Entity::Player& player, uint32_t shopId, uint16_t containerId, uint16_t slotId )
|
|
|
|
{
|
|
|
|
auto item = player.getItemAt( containerId, slotId );
|
|
|
|
if( item )
|
|
|
|
{
|
|
|
|
auto& exdData = Common::Service< Data::ExdDataGenerated >::ref();
|
|
|
|
auto itemData = exdData.get< Data::Item >( item->getId() );
|
|
|
|
if( itemData && !itemData->isIndisposable )
|
|
|
|
{
|
|
|
|
auto value = itemData->priceLow * item->getStackSize();
|
|
|
|
player.dropInventoryItem( static_cast< Common::InventoryType >( containerId ), slotId );
|
|
|
|
player.addCurrency( Common::CurrencyType::Gil, value );
|
|
|
|
Entity::ShopBuyBackEntry entry =
|
|
|
|
{
|
|
|
|
item,
|
|
|
|
item->getStackSize(),
|
|
|
|
itemData->priceLow
|
|
|
|
};
|
|
|
|
player.addBuyBackItemForShop( shopId, entry );
|
|
|
|
auto packet = makeZonePacket< FFXIVIpcShopMessage >( player.getId() );
|
|
|
|
packet->data().shopId = shopId;
|
|
|
|
packet->data().msgType = 1688;
|
|
|
|
packet->data().unknown2 = 3;
|
|
|
|
packet->data().itemId = item->getId();
|
|
|
|
packet->data().amount = item->getStackSize();
|
|
|
|
packet->data().price = value;
|
|
|
|
packet->data().unknown6 = 0;
|
|
|
|
packet->data().unknown7 = 0;
|
|
|
|
player.queuePacket( packet );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Sapphire::World::Manager::ShopMgr::shopBuyBack( Sapphire::Entity::Player& player, uint32_t shopId, uint16_t index )
|
|
|
|
{
|
|
|
|
auto& buyBackList = player.getBuyBackListForShop( shopId );
|
|
|
|
if( buyBackList.size() > index )
|
|
|
|
{
|
|
|
|
auto& entry = buyBackList[ index ];
|
|
|
|
auto originalStack = entry.item->getStackSize();
|
2020-05-11 19:03:52 +09:00
|
|
|
auto price = entry.pricePerItem * originalStack;
|
|
|
|
if( player.getCurrency( Common::CurrencyType::Gil ) < price )
|
|
|
|
return false;
|
2020-05-11 06:25:25 +09:00
|
|
|
|
|
|
|
if( !player.addItem( entry.item ) )
|
|
|
|
return false;
|
|
|
|
|
2020-05-11 19:03:52 +09:00
|
|
|
player.removeCurrency( Common::CurrencyType::Gil, price );
|
2020-05-11 06:25:25 +09:00
|
|
|
|
|
|
|
buyBackList.erase( buyBackList.begin() + index );
|
|
|
|
|
|
|
|
auto packet = makeZonePacket< FFXIVIpcShopMessage >( player.getId() );
|
|
|
|
packet->data().shopId = shopId;
|
|
|
|
packet->data().msgType = 1689;
|
|
|
|
packet->data().unknown2 = 3;
|
|
|
|
packet->data().itemId = entry.item->getId();
|
|
|
|
packet->data().amount = originalStack;
|
2020-05-11 19:03:52 +09:00
|
|
|
packet->data().price = price;
|
2020-05-11 06:25:25 +09:00
|
|
|
packet->data().unknown6 = 0;
|
|
|
|
packet->data().unknown7 = 0;
|
|
|
|
player.queuePacket( packet );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|