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>
|
2018-11-24 15:17:18 +11:00
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
using namespace Sapphire;
|
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
|
|
|
|
|
|
|
return true;
|
2018-12-22 22:25:03 +01:00
|
|
|
}
|