From 527ca817d56f5a168c6315d6bab1c3be54e78510 Mon Sep 17 00:00:00 2001 From: FinnHornhoover Date: Wed, 31 Mar 2021 23:34:36 -0700 Subject: [PATCH] revised getRarity set logic --- src/Items.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Items.cpp b/src/Items.cpp index c7ed5fd..35e033e 100644 --- a/src/Items.cpp +++ b/src/Items.cpp @@ -133,16 +133,15 @@ static int getRarity(int crateId, int itemSetId) { return -1; } - std::vector relevantWeights; - for (int index : rarityIndices) - relevantWeights.push_back(rarityWeights[index]); + std::vector relevantWeights(rarityWeights.size(), 0); + for (int index : rarityIndices) { + // sanity check + if (index >= 0 && index < rarityWeights.size()) + relevantWeights[index] = rarityWeights[index]; + } // now return a random rarity number (starting from 1) - int rarityChoice = Rand::randWeighted(relevantWeights); - - auto it = rarityIndices.begin(); - std::advance(it, rarityChoice); - return *it + 1; + return Rand::randWeighted(relevantWeights) + 1; } static int getCrateItem(sItemBase* result, int itemSetId, int rarity, int playerGender) {