2018-07-22 22:11:03 +10:00
|
|
|
#include <ScriptObject.h>
|
|
|
|
#include <Actor/Player.h>
|
|
|
|
|
2018-11-24 15:17:18 +11:00
|
|
|
#include <Manager/ShopMgr.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-10-28 21:53:21 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
class GilShop :
|
2018-11-13 21:34:44 +11:00
|
|
|
public Sapphire::ScriptAPI::EventScript
|
2018-07-22 22:11:03 +10:00
|
|
|
{
|
|
|
|
public:
|
2018-08-29 21:40:59 +02:00
|
|
|
GilShop() :
|
2018-11-20 22:52:57 +11:00
|
|
|
Sapphire::ScriptAPI::EventScript( 0x00040000 )
|
2018-08-29 21:40:59 +02:00
|
|
|
{
|
|
|
|
}
|
2018-07-22 22:11:03 +10:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
constexpr static auto SCENE_FLAGS = HIDE_HOTBAR | NO_DEFAULT_CAMERA;
|
2018-07-22 23:20:12 +10:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
void onTalk( uint32_t eventId, Entity::Player& player, uint64_t actorId ) override
|
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
eventMgr().playScene( player, eventId, 0, SCENE_FLAGS, { 2 }, std::bind( &GilShop::shopCallback, this, std::placeholders::_1, std::placeholders::_2 ) );
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
2018-07-23 00:05:44 +10:00
|
|
|
|
|
|
|
private:
|
2018-11-24 15:17:18 +11:00
|
|
|
void shopInteractionCallback( Entity::Player& player, const Event::SceneResult& result )
|
2018-08-29 21:40:59 +02:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
// item purchase
|
|
|
|
if( result.numOfResults == 255 )
|
2018-08-29 21:40:59 +02:00
|
|
|
{
|
|
|
|
// buy
|
2021-11-27 00:53:57 +01:00
|
|
|
if( result.getResult( 1 ) == 1 )
|
2018-07-22 22:11:03 +10:00
|
|
|
{
|
2020-03-01 01:00:57 +11:00
|
|
|
auto& shopMgr = Common::Service< Sapphire::World::Manager::ShopMgr >::ref();
|
2021-11-27 00:53:57 +01:00
|
|
|
shopMgr.purchaseGilShopItem( player, result.getResult( 4 ), result.getResult( 6 ), result.getResult( 5 ) );
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
2021-11-27 00:53:57 +01:00
|
|
|
|
2018-11-24 15:17:18 +11:00
|
|
|
// sell
|
2018-11-25 23:20:56 +11:00
|
|
|
// can't sell if the vendor is yourself (eg, housing permit shop)
|
2021-11-27 00:53:57 +01:00
|
|
|
else if( result.getResult( 1 ) == 2 && result.actorId != player.getId() )
|
2020-05-11 06:25:25 +09:00
|
|
|
{
|
|
|
|
auto& shopMgr = Common::Service< Sapphire::World::Manager::ShopMgr >::ref();
|
2021-11-27 00:53:57 +01:00
|
|
|
shopMgr.sellGilShopItem( player, result.getResult( 2 ), result.getResult( 3 ), result.getResult( 6 ), result.getResult( 5 ) );
|
2018-07-22 23:20:12 +10:00
|
|
|
}
|
2018-07-22 22:11:03 +10:00
|
|
|
|
2021-11-27 00:53:57 +01:00
|
|
|
eventMgr().playGilShop( player, result.eventId, SCENE_FLAGS, result.getResult( 0 ), [ & ]( Entity::Player& player, const Event::SceneResult& result )
|
|
|
|
{
|
|
|
|
shopInteractionCallback( player, result );
|
|
|
|
});
|
2018-08-29 21:40:59 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// exit
|
2021-11-27 00:53:57 +01:00
|
|
|
eventMgr().eventFinish( player, result.eventId, 1 );
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
|
|
|
|
2018-11-24 15:17:18 +11:00
|
|
|
void shopCallback( Entity::Player& player, const Event::SceneResult& result )
|
2018-08-29 21:40:59 +02:00
|
|
|
{
|
2021-11-27 00:53:57 +01:00
|
|
|
eventMgr().playGilShop( player, result.eventId, SCENE_FLAGS, 0, [ & ]( Entity::Player& player, const Event::SceneResult& result )
|
|
|
|
{
|
|
|
|
shopInteractionCallback( player, result );
|
|
|
|
});
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
2019-02-20 17:38:03 +11:00
|
|
|
};
|
|
|
|
|
|
|
|
EXPOSE_SCRIPT( GilShop );
|