Load vendor tables

This commit is contained in:
Gent 2020-09-13 18:54:47 -04:00
parent 9cc5f3e4d5
commit f55cc8f36d
4 changed files with 43 additions and 46 deletions

View File

@ -7,6 +7,8 @@
#include <string.h> // for memset() and memcmp() #include <string.h> // for memset() and memcmp()
#include <assert.h> #include <assert.h>
std::map<int32_t, std::vector<VendorListing>> ItemManager::VendorTables;
void ItemManager::init() { void ItemManager::init() {
REGISTER_SHARD_PACKET(P_CL2FE_REQ_ITEM_MOVE, itemMoveHandler); REGISTER_SHARD_PACKET(P_CL2FE_REQ_ITEM_MOVE, itemMoveHandler);
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_ITEM_DELETE, itemDeleteHandler); REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_ITEM_DELETE, itemDeleteHandler);

View File

@ -3,13 +3,20 @@
#include "CNShardServer.hpp" #include "CNShardServer.hpp"
#include "Player.hpp" #include "Player.hpp"
struct VendorListing {
int sort, type, iID, price;
};
namespace ItemManager { namespace ItemManager {
enum class SlotType { enum class SlotType {
EQUIP = 0, EQUIP = 0,
INVENTORY = 1, INVENTORY = 1,
BANK = 3 BANK = 3
}; };
void init(); // hopefully this is fine since it's never modified after load
extern std::map<int32_t, std::vector<VendorListing>> VendorTables;
void init();
void itemMoveHandler(CNSocket* sock, CNPacketData* data); void itemMoveHandler(CNSocket* sock, CNPacketData* data);
void itemDeleteHandler(CNSocket* sock, CNPacketData* data); void itemDeleteHandler(CNSocket* sock, CNPacketData* data);

View File

@ -102,56 +102,33 @@ void NPCManager::npcVendorTable(CNSocket* sock, CNPacketData* data) {
if (data->size != sizeof(sP_CL2FE_REQ_PC_VENDOR_TABLE_UPDATE)) if (data->size != sizeof(sP_CL2FE_REQ_PC_VENDOR_TABLE_UPDATE))
return; // malformed packet return; // malformed packet
//sP_CL2FE_REQ_PC_VENDOR_TABLE_UPDATE* req = (sP_CL2FE_REQ_PC_VENDOR_TABLE_UPDATE*)data->buf; sP_CL2FE_REQ_PC_VENDOR_TABLE_UPDATE* req = (sP_CL2FE_REQ_PC_VENDOR_TABLE_UPDATE*)data->buf;
if (req->iVendorID != req->iNPC_ID || ItemManager::VendorTables.find(req->iNPC_ID) == ItemManager::VendorTables.end())
return;
std::vector<VendorListing> listings = ItemManager::VendorTables[req->iNPC_ID]; // maybe use iVendorID instead...?
INITSTRUCT(sP_FE2CL_REP_PC_VENDOR_TABLE_UPDATE_SUCC, resp); INITSTRUCT(sP_FE2CL_REP_PC_VENDOR_TABLE_UPDATE_SUCC, resp);
// TODO: data needs to be read from shopkeeper tabledata
// check req->iVendorID and req->iNPC_ID
// Exaple Items for (int i = 0; i < 20; i++) { // 20 is the max
// shirt
sItemBase base1;
base1.iID = 60;
base1.iOpt = 0;
// expire date
base1.iTimeLimit = 0;
base1.iType = 1;
sItemVendor item1; if (i < listings.size()) { // check to make sure listing exists first
item1.item = base1; sItemBase base;
item1.iSortNum = 0; base.iID = listings[i].iID;
item1.iVendorID = 1; base.iOpt = 0;
// cost amount in float? (doesn't work rn, need to figure out) base.iTimeLimit = 0;
item1.fBuyCost = 100.0; base.iType = listings[i].type;
// pants sItemVendor vItem;
sItemBase base2; vItem.item = base;
base2.iID = 61; vItem.iSortNum = listings[i].sort;
base2.iOpt = 0; vItem.iVendorID = req->iVendorID;
base2.iTimeLimit = 0; vItem.fBuyCost = listings[i].price;
base2.iType = 2;
sItemVendor item2; resp.item[i] = vItem;
item2.item = base2; }
item2.iSortNum = 1; }
item2.iVendorID = 1;
item2.fBuyCost = 250.0;
// shoes
sItemBase base3;
base3.iID = 51;
base3.iOpt = 0;
base3.iTimeLimit = 0;
base3.iType = 3;
sItemVendor item3;
item3.item = base3;
item3.iSortNum = 2;
item3.iVendorID = 1;
item3.fBuyCost = 350.0;
resp.item[0] = item1;
resp.item[1] = item2;
resp.item[2] = item3;
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_VENDOR_TABLE_UPDATE_SUCC, sizeof(sP_FE2CL_REP_PC_VENDOR_TABLE_UPDATE_SUCC)); sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_VENDOR_TABLE_UPDATE_SUCC, sizeof(sP_FE2CL_REP_PC_VENDOR_TABLE_UPDATE_SUCC));
} }

View File

@ -1,6 +1,7 @@
#include "TableData.hpp" #include "TableData.hpp"
#include "NPCManager.hpp" #include "NPCManager.hpp"
#include "TransportManager.hpp" #include "TransportManager.hpp"
#include "ItemManager.hpp"
#include "settings.hpp" #include "settings.hpp"
#include "MissionManager.hpp" #include "MissionManager.hpp"
@ -119,6 +120,16 @@ void TableData::init() {
} }
std::cout << "[INFO] Loaded mission-related data" << std::endl; std::cout << "[INFO] Loaded mission-related data" << std::endl;
// load vendor listings
nlohmann::json listings = xdtData["m_pVendorTable"]["m_pItemData"];
for (nlohmann::json::iterator listing = listings.begin(); listing != listings.end(); listing++) {
VendorListing vListing = {listing.value()["m_iSortNumber"], listing.value()["m_iItemType"], listing.value()["m_iitemID"], listing.value()["m_iSellCost"]};
ItemManager::VendorTables[listing.value()["m_iNpcNumber"]].push_back(vListing);
}
std::cout << "[INFO] Loaded " << ItemManager::VendorTables.size() << " vendor tables" << std::endl;
} }
catch (const std::exception& err) { catch (const std::exception& err) {
std::cerr << "[WARN] Malformed xdt.json file! Reason:" << err.what() << std::endl; std::cerr << "[WARN] Malformed xdt.json file! Reason:" << err.what() << std::endl;