From 4f535ef5fe53f99e5b03188b7a4a1a4d5351d5b7 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sat, 15 Jun 2024 19:44:37 -0500 Subject: [PATCH] loot manager for glass runes and contracts --- src/engine/gameManager/LootManager.java | 12 +++++------- src/engine/loot/ItemTableEntry.java | 13 +++++++++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/engine/gameManager/LootManager.java b/src/engine/gameManager/LootManager.java index f9b73bd6..1ce8136e 100644 --- a/src/engine/gameManager/LootManager.java +++ b/src/engine/gameManager/LootManager.java @@ -104,7 +104,7 @@ public enum LootManager { //1 in 1,000 chance to drop glass if(ThreadLocalRandom.current().nextInt(1,1000) == 500){ - int glassID = rollRandomItem(126,221); + int glassID = rollRandomItem(126); ItemBase glassItem = ItemBase.getItemBase(glassID); if(glassItem != null) { MobLoot toAdd = new MobLoot(mob, glassItem, false); @@ -193,12 +193,12 @@ public enum LootManager { if(ThreadLocalRandom.current().nextInt(1,101) < 91) return null; // cut down world drops rates of resources by 90% }else if(ItemBase.getItemBase(itemUUID).getType().equals(Enum.ItemType.RUNE)){ - int randomRune = rollRandomItem(itemTableId,75); + int randomRune = rollRandomItem(itemTableId); if(randomRune != 0) { itemUUID = randomRune; } } else if(ItemBase.getItemBase(itemUUID).getType().equals(Enum.ItemType.CONTRACT)){ - int randomContract = rollRandomItem(itemTableId,191); + int randomContract = rollRandomItem(itemTableId); if(randomContract != 0) { itemUUID = randomContract; } @@ -491,9 +491,7 @@ public enum LootManager { itemMan.updateInventory(); } - public static int rollRandomItem(int itemTable, int min){ - int roll = ThreadLocalRandom.current().nextInt(min,321); - ItemTableEntry ite = ItemTableEntry.rollTable(itemTable, roll); - return ite.cacheID; + public static int rollRandomItem(int itemTable){ + return ItemTableEntry.getRandomItem(itemTable); } } diff --git a/src/engine/loot/ItemTableEntry.java b/src/engine/loot/ItemTableEntry.java index 9147f217..012dfc54 100644 --- a/src/engine/loot/ItemTableEntry.java +++ b/src/engine/loot/ItemTableEntry.java @@ -13,6 +13,7 @@ import engine.gameManager.LootManager; import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; +import java.util.concurrent.ThreadLocalRandom; public class ItemTableEntry { public int minRoll; @@ -42,4 +43,16 @@ public class ItemTableEntry { return itemTableEntry; } + + public static Integer getRandomItem(int itemTable) { + + List itemTableEntryList; + + itemTableEntryList = LootManager._itemTables.get(itemTable); + + if(itemTableEntryList != null){ + return (itemTableEntryList.get(ThreadLocalRandom.current().nextInt(0,itemTableEntryList.size() - 1))).cacheID; + } + return 0; + } }