1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-25 14:07:46 +00:00
sapphire/src/world/Manager/ShopMgr.cpp

36 lines
906 B
C++
Raw Normal View History

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>
extern Sapphire::Framework g_fw;
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 )
{
auto exdData = g_fw.get< Data::ExdDataGenerated >();
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;
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;
player.removeCurrency( Common::CurrencyType::Gil, price );
2018-11-24 15:17:18 +11:00
return true;
}