mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-22 05:20:05 +00:00
Clean up item loading from XDT.
This commit is contained in:
parent
856a90abcf
commit
794856a63c
@ -9,13 +9,13 @@
|
||||
#include <string.h> // for memset()
|
||||
#include <assert.h>
|
||||
|
||||
std::map<std::pair<int32_t, int32_t>, Item> ItemManager::ItemData;
|
||||
std::map<std::pair<int32_t, int32_t>, ItemManager::Item> ItemManager::ItemData;
|
||||
std::map<int32_t, std::vector<VendorListing>> ItemManager::VendorTables;
|
||||
std::map<int32_t, CrocPotEntry> ItemManager::CrocPotTable;
|
||||
std::map<int32_t, std::vector<int>> ItemManager::RarityRatios;
|
||||
std::map<int32_t, Crate> ItemManager::Crates;
|
||||
// pair Itemset, Rarity -> vector of pointers (map iterators) to records in ItemData
|
||||
std::map<std::pair<int32_t, int32_t>, std::vector<std::map<std::pair<int32_t, int32_t>, Item>::iterator>> ItemManager::CrateItems;
|
||||
std::map<std::pair<int32_t, int32_t>, std::vector<std::map<std::pair<int32_t, int32_t>, ItemManager::Item>::iterator>> ItemManager::CrateItems;
|
||||
|
||||
void ItemManager::init() {
|
||||
REGISTER_SHARD_PACKET(P_CL2FE_REQ_ITEM_MOVE, itemMoveHandler);
|
||||
@ -1012,9 +1012,9 @@ int ItemManager::findFreeSlot(Player *plr) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
Item* ItemManager::getItemData(int32_t id, int32_t type) {
|
||||
if(ItemData.find(std::pair<int32_t, int32_t>(id, type)) != ItemData.end())
|
||||
return &ItemData[std::pair<int32_t, int32_t>(id, type)];
|
||||
ItemManager::Item* ItemManager::getItemData(int32_t id, int32_t type) {
|
||||
if(ItemData.find(std::make_pair(id, type)) != ItemData.end())
|
||||
return &ItemData[std::make_pair(id, type)];
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -3,10 +3,6 @@
|
||||
#include "CNShardServer.hpp"
|
||||
#include "Player.hpp"
|
||||
|
||||
struct Item {
|
||||
bool tradeable, sellable;
|
||||
int buyPrice, sellPrice, stackSize, level, rarity, pointDamage, groupDamage, defense, gender; // TODO: implement more as needed
|
||||
};
|
||||
struct VendorListing {
|
||||
int sort, type, iID;
|
||||
};
|
||||
@ -25,6 +21,10 @@ namespace ItemManager {
|
||||
INVENTORY = 1,
|
||||
BANK = 3
|
||||
};
|
||||
struct Item {
|
||||
bool tradeable, sellable;
|
||||
int buyPrice, sellPrice, stackSize, level, rarity, pointDamage, groupDamage, defense, gender; // TODO: implement more as needed
|
||||
};
|
||||
// hopefully this is fine since it's never modified after load
|
||||
extern std::map<std::pair<int32_t, int32_t>, Item> ItemData; // <id, type> -> data
|
||||
extern std::map<int32_t, std::vector<VendorListing>> VendorTables;
|
||||
|
@ -120,7 +120,7 @@ void NPCManager::npcVendorBuy(CNSocket* sock, CNPacketData* data) {
|
||||
sP_CL2FE_REQ_PC_VENDOR_ITEM_BUY* req = (sP_CL2FE_REQ_PC_VENDOR_ITEM_BUY*)data->buf;
|
||||
Player *plr = PlayerManager::getPlayer(sock);
|
||||
|
||||
Item* item = ItemManager::getItemData(req->Item.iID, req->Item.iType);
|
||||
ItemManager::Item* item = ItemManager::getItemData(req->Item.iID, req->Item.iType);
|
||||
|
||||
if (item == nullptr) {
|
||||
std::cout << "[WARN] Item id " << req->Item.iID << " with type " << req->Item.iType << " not found (buy)" << std::endl;
|
||||
@ -178,7 +178,7 @@ void NPCManager::npcVendorSell(CNSocket* sock, CNPacketData* data) {
|
||||
}
|
||||
|
||||
sItemBase* item = &plr->Inven[req->iInvenSlotNum];
|
||||
Item* itemData = ItemManager::getItemData(item->iID, item->iType);
|
||||
ItemManager::Item* itemData = ItemManager::getItemData(item->iID, item->iType);
|
||||
|
||||
if (itemData == nullptr || !itemData->sellable) { // sanity + sellable check
|
||||
std::cout << "[WARN] Item id " << item->iID << " with type " << item->iType << " not found (sell)" << std::endl;
|
||||
@ -225,7 +225,7 @@ void NPCManager::npcVendorBuyback(CNSocket* sock, CNPacketData* data) {
|
||||
sP_CL2FE_REQ_PC_VENDOR_ITEM_RESTORE_BUY* req = (sP_CL2FE_REQ_PC_VENDOR_ITEM_RESTORE_BUY*)data->buf;
|
||||
Player* plr = PlayerManager::getPlayer(sock);
|
||||
|
||||
Item* item = ItemManager::getItemData(req->Item.iID, req->Item.iType);
|
||||
ItemManager::Item* item = ItemManager::getItemData(req->Item.iID, req->Item.iType);
|
||||
|
||||
if (item == nullptr) {
|
||||
std::cout << "[WARN] Item id " << req->Item.iID << " with type " << req->Item.iType << " not found (rebuy)" << std::endl;
|
||||
@ -364,8 +364,8 @@ void NPCManager::npcCombineItems(CNSocket* sock, CNPacketData* data) {
|
||||
|
||||
sItemBase* itemStats = &plr->Inven[req->iStatItemSlot];
|
||||
sItemBase* itemLooks = &plr->Inven[req->iCostumeItemSlot];
|
||||
Item* itemStatsDat = ItemManager::getItemData(itemStats->iID, itemStats->iType);
|
||||
Item* itemLooksDat = ItemManager::getItemData(itemLooks->iID, itemLooks->iType);
|
||||
ItemManager::Item* itemStatsDat = ItemManager::getItemData(itemStats->iID, itemStats->iType);
|
||||
ItemManager::Item* itemLooksDat = ItemManager::getItemData(itemLooks->iID, itemLooks->iType);
|
||||
|
||||
if (itemStatsDat == nullptr || itemLooksDat == nullptr
|
||||
|| ItemManager::CrocPotTable.find(abs(itemStatsDat->level - itemLooksDat->level)) == ItemManager::CrocPotTable.end()) { // sanity check 2
|
||||
|
@ -130,9 +130,23 @@ void TableData::init() {
|
||||
itemSet = xdtData[setNames[i]]["m_pItemData"];
|
||||
for (nlohmann::json::iterator _item = itemSet.begin(); _item != itemSet.end(); _item++) {
|
||||
auto item = _item.value();
|
||||
int itemID = item["m_iItemNumber"];
|
||||
int typeOverride = getItemType(i); // used for special cases where iEquipLoc doesn't indicate item type
|
||||
ItemManager::ItemData[std::pair<int32_t, int32_t>(item["m_iItemNumber"], typeOverride != -1 ? typeOverride : (int)item["m_iEquipLoc"])]
|
||||
= { item["m_iTradeAble"] == 1, item["m_iSellAble"] == 1, item["m_iItemPrice"], item["m_iItemSellPrice"], item["m_iStackNumber"], i > 9 ? 0 : (int)item["m_iMinReqLev"], i > 9 ? 1 : (int)item["m_iRarity"], i > 9 ? 0 : (int)item["m_iPointRat"], i > 9 ? 0 : (int)item["m_iGroupRat"], i > 9 ? 0 : (int)item["m_iDefenseRat"], i > 9 ? 0 : (int)item["m_iReqSex"] };
|
||||
INITSTRUCT(ItemManager::Item, itemData);
|
||||
itemData.tradeable = item["m_iTradeAble"] == 1;
|
||||
itemData.sellable = item["m_iSellAble"] == 1;
|
||||
itemData.buyPrice = item["m_iItemPrice"];
|
||||
itemData.sellPrice = item["m_iItemSellPrice"];
|
||||
itemData.stackSize = item["m_iStackNumber"];
|
||||
itemData.rarity = i > 9 ? 1 : (int)item["m_iRarity"];
|
||||
if (i <= 9) {
|
||||
itemData.level = item["m_iMinReqLev"];
|
||||
itemData.pointDamage = item["m_iPointRat"];
|
||||
itemData.groupDamage = item["m_iGroupRat"];
|
||||
itemData.defense = item["m_iDefenseRat"];
|
||||
itemData.gender = item["m_iReqSex"];
|
||||
}
|
||||
ItemManager::ItemData[std::make_pair(itemID, typeOverride != -1 ? typeOverride : (int)item["m_iEquipLoc"])] = itemData;
|
||||
}
|
||||
}
|
||||
|
||||
@ -478,11 +492,11 @@ void TableData::loadDrops() {
|
||||
throw TableException(std::string(buff));
|
||||
}
|
||||
|
||||
std::map<std::pair<int32_t, int32_t>, Item>::iterator toAdd = ItemManager::ItemData.find(itemDataKey);
|
||||
std::map<std::pair<int32_t, int32_t>, ItemManager::Item>::iterator toAdd = ItemManager::ItemData.find(itemDataKey);
|
||||
|
||||
// if item collection doesn't exist, start a new one
|
||||
if (ItemManager::CrateItems.find(itemSetkey) == ItemManager::CrateItems.end()) {
|
||||
std::vector<std::map<std::pair<int32_t, int32_t>, Item>::iterator> vector;
|
||||
std::vector<std::map<std::pair<int32_t, int32_t>, ItemManager::Item>::iterator> vector;
|
||||
vector.push_back(toAdd);
|
||||
ItemManager::CrateItems[itemSetkey] = vector;
|
||||
} else // else add a new element to existing collection
|
||||
|
Loading…
Reference in New Issue
Block a user