From a5ab912ffa4977a86ad4f8a9ef40e066b3ed8247 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 7 Aug 2023 13:36:16 -0400 Subject: [PATCH] Method for adjusted table rolls based on mpc level. --- src/engine/objects/ItemFactory.java | 33 +++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/engine/objects/ItemFactory.java b/src/engine/objects/ItemFactory.java index c54469d8..a4ca24aa 100644 --- a/src/engine/objects/ItemFactory.java +++ b/src/engine/objects/ItemFactory.java @@ -696,15 +696,22 @@ public class ItemFactory { return null; } - ModTypeTableEntry prefixTable = ModTypeTableEntry.rollTable(prefixMod, ThreadLocalRandom.current().nextInt(1, 100 + 1)); - ModTypeTableEntry suffixTable = ModTypeTableEntry.rollTable(suffixMod, ThreadLocalRandom.current().nextInt(1, 100 + 1)); + // Roll on the tables for this vendor + + ModTypeTableEntry prefixTypeTable = ModTypeTableEntry.rollTable(prefixMod, ThreadLocalRandom.current().nextInt(1, 100 + 1)); + ModTypeTableEntry suffixTypeTable = ModTypeTableEntry.rollTable(suffixMod, ThreadLocalRandom.current().nextInt(1, 100 + 1)); + + // Sanity check. + + if (prefixTypeTable == null || suffixTypeTable == null) + return null; int rollPrefix = ThreadLocalRandom.current().nextInt(1, 100 + 1); if (rollPrefix < 80) { - int randomPrefix = ThreadLocalRandom.current().nextInt(1, 100 + 1); - prefixEntry = ModTableEntry.rollTable(prefixTable.modTableID, randomPrefix); + int randomPrefix = getAdjustedRollForNPC((int) calculatedMobLevel, prefixTypeTable.minRoll, prefixTypeTable.maxRoll); + prefixEntry = ModTableEntry.rollTable(prefixTypeTable.modTableID, randomPrefix); if (prefixEntry != null) prefix = prefixEntry.action; @@ -715,8 +722,8 @@ public class ItemFactory { if (rollSuffix < 80) { - int randomSuffix = ThreadLocalRandom.current().nextInt(1, 100 + 1); - suffixEntry = ModTableEntry.rollTable(suffixTable.modTableID, randomSuffix); + int randomSuffix = getAdjustedRollForNPC((int) calculatedMobLevel, suffixTypeTable.minRoll, suffixTypeTable.maxRoll); + suffixEntry = ModTableEntry.rollTable(suffixTypeTable.modTableID, randomSuffix); if (suffixEntry != null) suffix = suffixEntry.action; @@ -763,6 +770,20 @@ public class ItemFactory { return toRoll; } + private static int getAdjustedRollForNPC(int npcLevel, int minRoll, int maxRoll) { + int randomRoll; + + int minValue = (npcLevel - 5) * 5; + int maxValue = (npcLevel + 15) * 5; + + minValue = Math.max(minRoll, Math.min(maxRoll, minValue)); + maxValue = Math.max(minRoll, Math.min(maxRoll, maxValue)); + + randomRoll = ThreadLocalRandom.current().nextInt(minValue, maxValue + 1); //Does not return Max, but does return min? + + return randomRoll; + } + public static MobLoot produceRandomRoll(NPC npc, PlayerCharacter pc, String prefixString, String suffixString, int itemID) { boolean useWarehouse = false;