2018-11-24 15:17:18 +11:00
|
|
|
#include "ShopMgr.h"
|
|
|
|
|
|
|
|
#include <Framework.h>
|
|
|
|
#include <Exd/ExdDataGenerated.h>
|
|
|
|
#include <Actor/Player.h>
|
|
|
|
#include <Common.h>
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
using namespace Sapphire;
|
2018-11-24 15:17:18 +11:00
|
|
|
|
2018-12-22 22:25:03 +01:00
|
|
|
Sapphire::World::Manager::ShopMgr::ShopMgr( FrameworkPtr pFw ) :
|
|
|
|
BaseManager( pFw )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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 )
|
|
|
|
{
|
2018-12-22 22:25:03 +01:00
|
|
|
auto exdData = framework()->get< Data::ExdDataGenerated >();
|
2018-11-24 15:17:18 +11:00
|
|
|
if( !exdData )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto gilShopItem = exdData->get< Data::GilShopItem >( shopId, itemId );
|
|
|
|
if( !gilShopItem )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto item = exdData->get< Data::Item >( gilShopItem->item );
|
|
|
|
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
|
|
|
}
|