mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-05 06:50:04 +00:00
drop format revision
This commit is contained in:
parent
30de9f668c
commit
1779d69078
@ -18,7 +18,7 @@ std::map<std::pair<int32_t, int32_t>, Items::Item> Items::ItemData;
|
|||||||
std::map<int32_t, CrocPotEntry> Items::CrocPotTable;
|
std::map<int32_t, CrocPotEntry> Items::CrocPotTable;
|
||||||
std::map<int32_t, std::vector<int32_t>> Items::RarityWeights;
|
std::map<int32_t, std::vector<int32_t>> Items::RarityWeights;
|
||||||
std::map<int32_t, Crate> Items::Crates;
|
std::map<int32_t, Crate> Items::Crates;
|
||||||
std::map<int32_t, DroppableItem> Items::DroppableItems;
|
std::map<int32_t, ItemReference> Items::ItemReferences;
|
||||||
std::map<std::string, std::vector<std::pair<int32_t, int32_t>>> Items::CodeItems;
|
std::map<std::string, std::vector<std::pair<int32_t, int32_t>>> Items::CodeItems;
|
||||||
|
|
||||||
std::map<int32_t, CrateDropChance> Items::CrateDropChances;
|
std::map<int32_t, CrateDropChance> Items::CrateDropChances;
|
||||||
@ -118,11 +118,11 @@ static int getRarity(int crateId, int itemSetTypeId) {
|
|||||||
|
|
||||||
// remember that rarities start from 1!
|
// remember that rarities start from 1!
|
||||||
std::set<int> rarityIndices;
|
std::set<int> rarityIndices;
|
||||||
for (int droppableItemId : Items::ItemSetTypes[itemSetTypeId].droppableItemIds) {
|
for (int itemReferenceId : Items::ItemSetTypes[itemSetTypeId].itemReferenceIds) {
|
||||||
if (Items::DroppableItems.find(droppableItemId) == Items::DroppableItems.end())
|
if (Items::ItemReferences.find(itemReferenceId) == Items::ItemReferences.end())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
rarityIndices.insert(Items::DroppableItems[droppableItemId].rarity - 1);
|
rarityIndices.insert(Items::ItemReferences[itemReferenceId].rarity - 1);
|
||||||
|
|
||||||
// shortcut
|
// shortcut
|
||||||
if (rarityIndices.size() == rarityWeights.size())
|
if (rarityIndices.size() == rarityWeights.size())
|
||||||
@ -144,37 +144,29 @@ static int getRarity(int crateId, int itemSetTypeId) {
|
|||||||
|
|
||||||
static int getCrateItem(sItemBase* result, int itemSetTypeId, int itemSetChanceId, int rarity, int playerGender) {
|
static int getCrateItem(sItemBase* result, int itemSetTypeId, int itemSetChanceId, int rarity, int playerGender) {
|
||||||
// (int, vector<int>)
|
// (int, vector<int>)
|
||||||
auto& [ignoreGender, droppableItemIds] = Items::ItemSetTypes[itemSetTypeId];
|
auto& [ignoreGender, itemReferenceIds] = Items::ItemSetTypes[itemSetTypeId];
|
||||||
|
|
||||||
// collect valid items that match the rarity and (if not ignored) gender
|
// collect valid items that match the rarity and (if not ignored) gender
|
||||||
std::vector<std::pair<int, DroppableItem*>> validItems;
|
std::vector<std::pair<int, ItemReference*>> validItems;
|
||||||
for (int i = 0; i < droppableItemIds.size(); i++) {
|
for (int i = 0; i < itemReferenceIds.size(); i++) {
|
||||||
int droppableItemId = droppableItemIds[i];
|
int itemReferenceId = itemReferenceIds[i];
|
||||||
|
|
||||||
if (Items::DroppableItems.find(droppableItemId) == Items::DroppableItems.end()) {
|
if (Items::ItemReferences.find(itemReferenceId) == Items::ItemReferences.end()) {
|
||||||
std::cout << "[WARN] Droppable item " << droppableItemId << " was not found, skipping..." << std::endl;
|
std::cout << "[WARN] Item reference " << itemReferenceId << " in item set type "
|
||||||
|
<< itemSetTypeId << " was not found, skipping..." << std::endl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
DroppableItem* droppableItem = &Items::DroppableItems[droppableItemId];
|
ItemReference* item = &Items::ItemReferences[itemReferenceId];
|
||||||
|
|
||||||
if (droppableItem->rarity != rarity)
|
if (item->rarity != rarity)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto key = std::make_pair(droppableItem->itemId, droppableItem->type);
|
|
||||||
|
|
||||||
if (Items::ItemData.find(key) == Items::ItemData.end()) {
|
|
||||||
std::cout << "[WARN] Item-Type pair (" << key.first << ", " << key.second << ") specified by droppable item "
|
|
||||||
<< droppableItemId << " was not found, skipping..." << std::endl;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if gender is incorrect, exclude item
|
// if gender is incorrect, exclude item
|
||||||
int itemGender = Items::ItemData[key].gender;
|
if (!ignoreGender && item->gender != 0 && item->gender != playerGender)
|
||||||
if (!ignoreGender && itemGender != 0 && itemGender != playerGender)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
validItems.push_back(std::make_pair(i, droppableItem));
|
validItems.push_back(std::make_pair(i, item));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (validItems.empty()) {
|
if (validItems.empty()) {
|
||||||
@ -184,20 +176,19 @@ static int getCrateItem(sItemBase* result, int itemSetTypeId, int itemSetChanceI
|
|||||||
}
|
}
|
||||||
|
|
||||||
// (int, map<int, int>)
|
// (int, map<int, int>)
|
||||||
auto& [defaultWeight, specialWeights] = Items::ItemSetChances[itemSetChanceId];
|
auto& [defaultWeight, indexWeightMap] = Items::ItemSetChances[itemSetChanceId];
|
||||||
|
|
||||||
// initialize all weights as the default weight for all item slots
|
// initialize all weights as the default weight for all item slots
|
||||||
std::vector<int> itemWeights(validItems.size(), defaultWeight);
|
std::vector<int> itemWeights(validItems.size(), defaultWeight);
|
||||||
|
|
||||||
if (!specialWeights.empty()) {
|
if (!indexWeightMap.empty()) {
|
||||||
for (int i = 0; i < validItems.size(); i++) {
|
for (int i = 0; i < validItems.size(); i++) {
|
||||||
// (int, DroppableItem*)
|
int dropIndex = validItems[i].first;
|
||||||
auto& [dropIndex, droppableItem] = validItems[i];
|
|
||||||
|
|
||||||
if (specialWeights.find(dropIndex) == specialWeights.end())
|
if (indexWeightMap.find(dropIndex) == indexWeightMap.end())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int weight = specialWeights[dropIndex];
|
int weight = indexWeightMap[dropIndex];
|
||||||
// allow 0 weights for convenience
|
// allow 0 weights for convenience
|
||||||
if (weight > -1)
|
if (weight > -1)
|
||||||
itemWeights[i] = weight;
|
itemWeights[i] = weight;
|
||||||
@ -205,7 +196,7 @@ static int getCrateItem(sItemBase* result, int itemSetTypeId, int itemSetChanceI
|
|||||||
}
|
}
|
||||||
|
|
||||||
int chosenIndex = Rand::randWeighted(itemWeights);
|
int chosenIndex = Rand::randWeighted(itemWeights);
|
||||||
DroppableItem* item = validItems[chosenIndex].second;
|
ItemReference* item = validItems[chosenIndex].second;
|
||||||
|
|
||||||
result->iID = item->itemId;
|
result->iID = item->itemId;
|
||||||
result->iType = item->type;
|
result->iType = item->type;
|
||||||
@ -866,7 +857,7 @@ void Items::giveMobDrop(CNSocket *sock, Mob* mob, int rolledBoosts, int rolledPo
|
|||||||
sock->sendPacket((void*)respbuf, P_FE2CL_REP_REWARD_ITEM, sizeof(sP_FE2CL_REP_REWARD_ITEM));
|
sock->sendPacket((void*)respbuf, P_FE2CL_REP_REWARD_ITEM, sizeof(sP_FE2CL_REP_REWARD_ITEM));
|
||||||
} else {
|
} else {
|
||||||
// item reward
|
// item reward
|
||||||
getMobDrop(&item->sItem, crateDropChance.crateWeights, crateDropType, rolledCrateType);
|
getMobDrop(&item->sItem, crateDropChance.crateTypeDropWeights, crateDropType, rolledCrateType);
|
||||||
item->iSlotNum = slot;
|
item->iSlotNum = slot;
|
||||||
item->eIL = 1; // Inventory Location. 1 means player inventory.
|
item->eIL = 1; // Inventory Location. 1 means player inventory.
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ struct Crate {
|
|||||||
|
|
||||||
struct CrateDropChance {
|
struct CrateDropChance {
|
||||||
int dropChance, dropChanceTotal;
|
int dropChance, dropChanceTotal;
|
||||||
std::vector<int> crateWeights;
|
std::vector<int> crateTypeDropWeights;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MiscDropChance {
|
struct MiscDropChance {
|
||||||
@ -43,18 +43,19 @@ struct MobDrop {
|
|||||||
|
|
||||||
struct ItemSetType {
|
struct ItemSetType {
|
||||||
bool ignoreGender;
|
bool ignoreGender;
|
||||||
std::vector<int> droppableItemIds;
|
std::vector<int> itemReferenceIds;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ItemSetChance {
|
struct ItemSetChance {
|
||||||
int defaultItemWeight;
|
int defaultItemWeight;
|
||||||
std::map<int, int> specialItemWeights;
|
std::map<int, int> indexWeightMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DroppableItem {
|
struct ItemReference {
|
||||||
int itemId;
|
int itemId;
|
||||||
int rarity;
|
|
||||||
int type;
|
int type;
|
||||||
|
int rarity;
|
||||||
|
int gender;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace Items {
|
namespace Items {
|
||||||
@ -76,7 +77,7 @@ namespace Items {
|
|||||||
extern std::map<int32_t, CrocPotEntry> CrocPotTable; // level gap -> entry
|
extern std::map<int32_t, CrocPotEntry> CrocPotTable; // level gap -> entry
|
||||||
extern std::map<int32_t, std::vector<int32_t>> RarityWeights;
|
extern std::map<int32_t, std::vector<int32_t>> RarityWeights;
|
||||||
extern std::map<int32_t, Crate> Crates;
|
extern std::map<int32_t, Crate> Crates;
|
||||||
extern std::map<int32_t, DroppableItem> DroppableItems;
|
extern std::map<int32_t, ItemReference> ItemReferences;
|
||||||
extern std::map<std::string, std::vector<std::pair<int32_t, int32_t>>> CodeItems; // code -> vector of <id, type>
|
extern std::map<std::string, std::vector<std::pair<int32_t, int32_t>>> CodeItems; // code -> vector of <id, type>
|
||||||
|
|
||||||
// mob drops
|
// mob drops
|
||||||
|
@ -213,7 +213,7 @@ static void loadDrops() {
|
|||||||
|
|
||||||
nlohmann::json crateWeights = crateDropChance["CrateTypeDropWeights"];
|
nlohmann::json crateWeights = crateDropChance["CrateTypeDropWeights"];
|
||||||
for (nlohmann::json::iterator _crateWeight = crateWeights.begin(); _crateWeight != crateWeights.end(); _crateWeight++)
|
for (nlohmann::json::iterator _crateWeight = crateWeights.begin(); _crateWeight != crateWeights.end(); _crateWeight++)
|
||||||
toAdd.crateWeights.push_back((int)_crateWeight.value());
|
toAdd.crateTypeDropWeights.push_back((int)_crateWeight.value());
|
||||||
|
|
||||||
Items::CrateDropChances[(int)crateDropChance["CrateDropChanceID"]] = toAdd;
|
Items::CrateDropChances[(int)crateDropChance["CrateDropChanceID"]] = toAdd;
|
||||||
}
|
}
|
||||||
@ -295,9 +295,9 @@ static void loadDrops() {
|
|||||||
|
|
||||||
toAdd.ignoreGender = (bool)itemSetType["IgnoreGender"];
|
toAdd.ignoreGender = (bool)itemSetType["IgnoreGender"];
|
||||||
|
|
||||||
nlohmann::json droppableItemIds = itemSetType["DroppableItemIDs"];
|
nlohmann::json itemReferenceIds = itemSetType["ItemReferenceIDs"];
|
||||||
for (nlohmann::json::iterator _droppableItemId = droppableItemIds.begin(); _droppableItemId != droppableItemIds.end(); _droppableItemId++)
|
for (nlohmann::json::iterator itemReferenceId = itemReferenceIds.begin(); itemReferenceId != itemReferenceIds.end(); itemReferenceId++)
|
||||||
toAdd.droppableItemIds.push_back((int)_droppableItemId.value());
|
toAdd.itemReferenceIds.push_back((int)itemReferenceId.value());
|
||||||
|
|
||||||
Items::ItemSetTypes[(int)itemSetType["ItemSetTypeID"]] = toAdd;
|
Items::ItemSetTypes[(int)itemSetType["ItemSetTypeID"]] = toAdd;
|
||||||
}
|
}
|
||||||
@ -310,12 +310,9 @@ static void loadDrops() {
|
|||||||
|
|
||||||
toAdd.defaultItemWeight = (int)itemSetChanceObject["DefaultItemWeight"];
|
toAdd.defaultItemWeight = (int)itemSetChanceObject["DefaultItemWeight"];
|
||||||
|
|
||||||
nlohmann::json specialItemWeightIndices = itemSetChanceObject["SpecialItemWeightIndices"];
|
nlohmann::json indexWeightMap = itemSetChanceObject["IndexWeightMap"];
|
||||||
nlohmann::json specialItemWeightVector = itemSetChanceObject["SpecialItemWeights"];
|
for (nlohmann::json::iterator _indexWeightMapEntry = indexWeightMap.begin(); _indexWeightMapEntry != indexWeightMap.end(); _indexWeightMapEntry++)
|
||||||
for (nlohmann::json::iterator _specialItemWeightIndex = specialItemWeightIndices.begin(), _specialItemWeight = specialItemWeightVector.begin();
|
toAdd.indexWeightMap[std::atoi(_indexWeightMapEntry.key().c_str())] = (int)_indexWeightMapEntry.value();
|
||||||
_specialItemWeightIndex != specialItemWeightIndices.end() && _specialItemWeight != specialItemWeightVector.end();
|
|
||||||
_specialItemWeightIndex++, _specialItemWeight++)
|
|
||||||
toAdd.specialItemWeights[(int)_specialItemWeightIndex.value()] = (int)_specialItemWeight.value();
|
|
||||||
|
|
||||||
Items::ItemSetChances[(int)itemSetChanceObject["ItemSetChanceID"]] = toAdd;
|
Items::ItemSetChances[(int)itemSetChanceObject["ItemSetChanceID"]] = toAdd;
|
||||||
}
|
}
|
||||||
@ -332,15 +329,29 @@ static void loadDrops() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// DroppableItems
|
// ItemReferences
|
||||||
nlohmann::json droppableItems = dropData["DroppableItems"];
|
nlohmann::json itemReferences = dropData["ItemReferences"];
|
||||||
for (nlohmann::json::iterator _droppableItem = droppableItems.begin(); _droppableItem != droppableItems.end(); _droppableItem++) {
|
for (nlohmann::json::iterator _itemReference = itemReferences.begin(); _itemReference != itemReferences.end(); _itemReference++) {
|
||||||
auto droppableItem = _droppableItem.value();
|
auto itemReference = _itemReference.value();
|
||||||
|
|
||||||
Items::DroppableItems[(int)droppableItem["DroppableItemID"]] = {
|
int itemReferenceId = (int)itemReference["ItemReferenceID"];
|
||||||
(int)droppableItem["ItemID"],
|
int itemId = (int)itemReference["ItemID"];
|
||||||
(int)droppableItem["Rarity"],
|
int type = (int)itemReference["Type"];
|
||||||
(int)droppableItem["Type"]
|
|
||||||
|
// validate and fetch relevant fields as they're loaded
|
||||||
|
auto key = std::make_pair(itemId, type);
|
||||||
|
if (Items::ItemData.find(key) == Items::ItemData.end()) {
|
||||||
|
std::cout << "[WARN] Item-Type pair (" << key.first << ", " << key.second << ") specified by item reference "
|
||||||
|
<< itemReferenceId << " was not found, skipping..." << std::endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Items::Item& item = Items::ItemData[key];
|
||||||
|
|
||||||
|
Items::ItemReferences[itemReferenceId] = {
|
||||||
|
itemId,
|
||||||
|
type,
|
||||||
|
item.rarity,
|
||||||
|
item.gender
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -405,15 +416,27 @@ static void loadDrops() {
|
|||||||
std::string codeStr = code["Code"];
|
std::string codeStr = code["Code"];
|
||||||
std::vector<std::pair<int32_t, int32_t>> itemVector;
|
std::vector<std::pair<int32_t, int32_t>> itemVector;
|
||||||
|
|
||||||
nlohmann::json items = code["Items"];
|
nlohmann::json itemReferenceIds = code["ItemReferenceIDs"];
|
||||||
for (nlohmann::json::iterator _item = items.begin(); _item != items.end(); _item++)
|
for (nlohmann::json::iterator _itemReferenceId = itemReferenceIds.begin(); _itemReferenceId != itemReferenceIds.end(); _itemReferenceId++) {
|
||||||
itemVector.push_back(std::make_pair((int)code["ItemID"], (int)code["Type"]));
|
int itemReferenceId = (int)_itemReferenceId.value();
|
||||||
|
|
||||||
|
// validate and convert here
|
||||||
|
if (Items::ItemReferences.find(itemReferenceId) == Items::ItemReferences.end()) {
|
||||||
|
std::cout << "[WARN] Item reference " << itemReferenceId << " for code "
|
||||||
|
<< codeStr << " was not found, skipping..." << std::endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// no need to further check whether this is a real item or not, we already did this!
|
||||||
|
ItemReference& itemReference = Items::ItemReferences[itemReferenceId];
|
||||||
|
itemVector.push_back(std::make_pair(itemReference.itemId, itemReference.type));
|
||||||
|
}
|
||||||
|
|
||||||
Items::CodeItems[codeStr] = itemVector;
|
Items::CodeItems[codeStr] = itemVector;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "[INFO] Loaded " << Items::Crates.size() << " Crates containing "
|
std::cout << "[INFO] Loaded " << Items::Crates.size() << " Crates containing "
|
||||||
<< Items::DroppableItems.size() << " unique items" << std::endl;
|
<< Items::ItemReferences.size() << " unique items" << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (const std::exception& err) {
|
catch (const std::exception& err) {
|
||||||
|
Loading…
Reference in New Issue
Block a user