From 20b05a72a06fda1144d89824e553be1830cd4306 Mon Sep 17 00:00:00 2001 From: FinnHornhoover Date: Fri, 2 Apr 2021 23:34:20 -0700 Subject: [PATCH] added mob drop id lookup from mob id --- src/Items.cpp | 15 ++++++++++++--- src/Items.hpp | 1 + src/TableData.cpp | 8 ++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Items.cpp b/src/Items.cpp index ebfec41..7e91f2e 100644 --- a/src/Items.cpp +++ b/src/Items.cpp @@ -26,6 +26,7 @@ std::map> Items::CrateDropTypes; std::map Items::MiscDropChances; std::map Items::MiscDropTypes; std::map Items::MobDrops; +std::map Items::MobToDropMap; std::map Items::ItemSets; #ifdef ACADEMY @@ -770,12 +771,20 @@ void Items::giveMobDrop(CNSocket *sock, Mob* mob, int rolledBoosts, int rolledPo memset(respbuf, 0, resplen); // sanity check - if (MobDrops.find(mob->dropType) == MobDrops.end()) { - std::cout << "[WARN] Drop Type " << mob->dropType << " was not found" << std::endl; + if (Items::MobToDropMap.find(mob->appearanceData.iNPCType) == Items::MobToDropMap.end()) { + std::cout << "[WARN] Mob ID " << mob->appearanceData.iNPCType << " has no drops assigned" << std::endl; + return; + } + // find mob drop id + int dropType = Items::MobToDropMap[mob->appearanceData.iNPCType]; + + // sanity check + if (Items::MobDrops.find(dropType) == Items::MobDrops.end()) { + std::cout << "[WARN] Drop Type " << dropType << " was not found" << std::endl; return; } // find correct mob drop - MobDrop& drop = MobDrops[mob->dropType]; + MobDrop& drop = Items::MobDrops[dropType]; // use the keys to fetch data from other maps // sanity check diff --git a/src/Items.hpp b/src/Items.hpp index 36e01b7..991feb8 100644 --- a/src/Items.hpp +++ b/src/Items.hpp @@ -94,6 +94,7 @@ namespace Items { extern std::map MiscDropChances; extern std::map MiscDropTypes; extern std::map MobDrops; + extern std::map MobToDropMap; extern std::map ItemSets; void init(); diff --git a/src/TableData.cpp b/src/TableData.cpp index b0efadd..ee8f714 100644 --- a/src/TableData.cpp +++ b/src/TableData.cpp @@ -274,6 +274,14 @@ static void loadDrops() { }; } + // Mobs + nlohmann::json mobs = dropData["Mobs"]; + for (nlohmann::json::iterator _mob = mobs.begin(); _mob != mobs.end(); _mob++) { + auto mob = _mob.value(); + + Items::MobToDropMap[(int)mob["MobID"]] = (int)mob["MobDropID"]; + } + // RarityWeights nlohmann::json rarityWeights = dropData["RarityWeights"]; for (nlohmann::json::iterator _rarityWeightsObject = rarityWeights.begin(); _rarityWeightsObject != rarityWeights.end(); _rarityWeightsObject++) {