2018-12-31 23:20:36 +11:00
|
|
|
#include "MarketMgr.h"
|
|
|
|
|
2019-01-01 11:51:48 +11:00
|
|
|
#include <Exd/ExdDataGenerated.h>
|
|
|
|
#include <Framework.h>
|
|
|
|
#include <Logging/Logger.h>
|
|
|
|
|
|
|
|
#include <Network/CommonNetwork.h>
|
|
|
|
#include <Network/GamePacketNew.h>
|
|
|
|
#include <Network/PacketDef/Zone/ServerZoneDef.h>
|
|
|
|
|
|
|
|
#include "Actor/Player.h"
|
|
|
|
|
2019-01-01 14:19:44 +11:00
|
|
|
#include <algorithm>
|
|
|
|
|
2019-01-01 11:51:48 +11:00
|
|
|
using namespace Sapphire::Network::Packets;
|
|
|
|
|
2018-12-31 23:20:36 +11:00
|
|
|
Sapphire::World::Manager::MarketMgr::MarketMgr( Sapphire::FrameworkPtr pFw ) :
|
|
|
|
BaseManager( pFw )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Sapphire::World::Manager::MarketMgr::init()
|
|
|
|
{
|
2019-01-01 11:51:48 +11:00
|
|
|
Logger::info( "MarketMgr: warming up marketable item cache..." );
|
|
|
|
|
|
|
|
// build item cache
|
|
|
|
auto exdData = framework()->get< Sapphire::Data::ExdDataGenerated >();
|
|
|
|
auto idList = exdData->getItemIdList();
|
|
|
|
|
|
|
|
for( auto id : idList )
|
|
|
|
{
|
|
|
|
auto item = exdData->get< Sapphire::Data::Item >( id );
|
|
|
|
if( !item )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( item->isUntradable )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
MarketableItem cacheEntry {};
|
|
|
|
cacheEntry.catalogId = id;
|
|
|
|
cacheEntry.itemSearchCategory = item->itemSearchCategory;
|
|
|
|
cacheEntry.maxEquipLevel = item->levelEquip;
|
|
|
|
cacheEntry.name = item->name;
|
|
|
|
cacheEntry.classJob = item->classJobUse;
|
2019-01-01 14:19:44 +11:00
|
|
|
cacheEntry.itemLevel = item->levelItem;
|
2019-01-01 11:51:48 +11:00
|
|
|
|
|
|
|
m_marketItemCache.push_back( std::move( cacheEntry ) );
|
|
|
|
}
|
|
|
|
|
2019-01-01 14:19:44 +11:00
|
|
|
std::sort( m_marketItemCache.begin(), m_marketItemCache.end(), []( const MarketableItem& a, const MarketableItem& b )
|
|
|
|
{
|
|
|
|
return a.itemLevel > b.itemLevel;
|
|
|
|
} );
|
|
|
|
|
2019-01-01 11:51:48 +11:00
|
|
|
Logger::info( "MarketMgr: Cached " + std::to_string( m_marketItemCache.size() ) + " marketable items" );
|
|
|
|
|
2018-12-31 23:20:36 +11:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-01 17:29:06 +11:00
|
|
|
void Sapphire::World::Manager::MarketMgr::requestItemListingInfo( Sapphire::Entity::Player& player, uint32_t catalogId,
|
|
|
|
uint32_t requestId )
|
2019-01-01 11:51:48 +11:00
|
|
|
{
|
|
|
|
auto countPkt = makeZonePacket< Server::FFFXIVIpcMarketBoardItemListingCount >( player.getId() );
|
2019-01-01 17:29:06 +11:00
|
|
|
countPkt->data().quantity = 1 << 8;
|
2019-01-01 11:51:48 +11:00
|
|
|
countPkt->data().itemCatalogId = catalogId;
|
2019-01-01 17:29:06 +11:00
|
|
|
countPkt->data().requestId = requestId;
|
|
|
|
|
|
|
|
player.queuePacket( countPkt );
|
|
|
|
|
|
|
|
auto historyPkt = makeZonePacket< Server::FFXIVIpcMarketBoardItemListingHistory >( player.getId() );
|
|
|
|
historyPkt->data().itemCatalogId = catalogId;
|
|
|
|
historyPkt->data().itemCatalogId2 = catalogId;
|
|
|
|
|
|
|
|
memset( &historyPkt->data().listing, 0x0, sizeof( Server::FFXIVIpcMarketBoardItemListingHistory::MarketListing ) * 20 );
|
|
|
|
|
|
|
|
std::string name = "fix game";
|
|
|
|
|
|
|
|
for( int i = 0; i < 10; ++i )
|
|
|
|
{
|
|
|
|
auto& listing = historyPkt->data().listing[ i ];
|
|
|
|
|
|
|
|
listing.itemCatalogId = catalogId;
|
|
|
|
listing.quantity = i;
|
|
|
|
listing.purchaseTime = time( nullptr );
|
|
|
|
listing.salePrice = 500;
|
|
|
|
|
|
|
|
strcpy( listing.sellerName, name.c_str() );
|
|
|
|
}
|
|
|
|
|
|
|
|
player.queuePacket( historyPkt );
|
2019-01-01 11:51:48 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Sapphire::World::Manager::MarketMgr::searchMarketboard( Entity::Player& player, uint8_t itemSearchCategory,
|
|
|
|
uint8_t maxEquipLevel, uint8_t classJob,
|
|
|
|
const std::string_view& searchStr, uint32_t requestId,
|
|
|
|
uint32_t startIdx )
|
2018-12-31 23:20:36 +11:00
|
|
|
{
|
2019-01-01 11:51:48 +11:00
|
|
|
ItemSearchResultList resultList;
|
|
|
|
findItems( searchStr, itemSearchCategory, maxEquipLevel, classJob, resultList );
|
|
|
|
|
|
|
|
auto numResults = resultList.size();
|
|
|
|
|
|
|
|
if( startIdx > numResults )
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto endIdx = std::min< size_t >( startIdx + 20, numResults );
|
|
|
|
auto size = endIdx - startIdx;
|
|
|
|
|
|
|
|
auto resultPkt = makeZonePacket< Server::FFXIVIpcMarketBoardSearchResult >( player.getId() );
|
|
|
|
resultPkt->data().itemIndexStart = startIdx;
|
|
|
|
resultPkt->data().requestId = requestId;
|
|
|
|
|
2019-01-01 14:19:44 +11:00
|
|
|
for( auto i = 0; i < size; i++ )
|
2019-01-01 11:51:48 +11:00
|
|
|
{
|
|
|
|
auto& item = resultList.at( startIdx + i );
|
|
|
|
auto& data = resultPkt->data().items[ i ];
|
|
|
|
|
|
|
|
data.itemCatalogId = item.catalogId;
|
|
|
|
data.quantity = item.quantity;
|
|
|
|
data.demand = 69;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( size < 20 )
|
|
|
|
resultPkt->data().itemIndexEnd = 0;
|
|
|
|
else
|
|
|
|
resultPkt->data().itemIndexEnd = startIdx + 20;
|
|
|
|
|
|
|
|
player.queuePacket( resultPkt );
|
|
|
|
}
|
|
|
|
|
2019-01-01 17:29:06 +11:00
|
|
|
void Sapphire::World::Manager::MarketMgr::requestItemListings( Sapphire::Entity::Player& player, uint16_t catalogId )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-01-01 11:51:48 +11:00
|
|
|
void Sapphire::World::Manager::MarketMgr::findItems( const std::string_view& searchStr, uint8_t itemSearchCat,
|
|
|
|
uint8_t maxEquipLevel, uint8_t classJob,
|
|
|
|
Sapphire::World::Manager::MarketMgr::ItemSearchResultList& resultList )
|
|
|
|
{
|
|
|
|
for( const auto& item : m_marketItemCache )
|
|
|
|
{
|
|
|
|
if( item.itemSearchCategory != itemSearchCat )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( maxEquipLevel > 0 && item.maxEquipLevel > maxEquipLevel )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( classJob > 0 && item.classJob != classJob )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
resultList.push_back( { item.catalogId, 1 } );
|
|
|
|
}
|
2018-12-31 23:20:36 +11:00
|
|
|
}
|