From a8d5521dd83c8ba771b4264ffe3397de54f73c3b Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 14 Apr 2024 13:51:37 -0400 Subject: [PATCH] Mobtype work related to ForgeManager --- src/engine/gameManager/ForgeManager.java | 51 +++++++++++++++++++++--- src/engine/objects/Item.java | 2 + 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/engine/gameManager/ForgeManager.java b/src/engine/gameManager/ForgeManager.java index 010164eb..9c57db89 100644 --- a/src/engine/gameManager/ForgeManager.java +++ b/src/engine/gameManager/ForgeManager.java @@ -8,15 +8,19 @@ package engine.gameManager; +import engine.loot.ModTableEntry; +import engine.loot.ModTypeTableEntry; import engine.loot.WorkOrder; import engine.mbEnums; import engine.objects.*; import engine.powers.EffectsBase; +import engine.powers.poweractions.AbstractPowerAction; import org.pmw.tinylog.Logger; import java.util.HashMap; import java.util.concurrent.BlockingQueue; import java.util.concurrent.DelayQueue; +import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @@ -254,12 +258,22 @@ public enum ForgeManager implements Runnable { public static Item forgeItem(WorkOrder workOrder) { + ItemTemplate template = ItemTemplate.templates.get(workOrder.templateID); + Item forgedItem = new Item(workOrder.templateID); forgedItem.objectUUID = MobLoot.lastNegativeID.getAndDecrement(); forgedItem.containerType = mbEnums.ItemContainerType.FORGE; forgedItem.ownerID = workOrder.vendor.getObjectUUID(); forgedItem.setDateToUpgrade(workOrder.completionTime); + // Give prefix and suffix to this item if random rolled + + if (workOrder.prefixToken == 0) + forgedItem.prefixToken = calcRandomMod(workOrder.vendor, mbEnums.ItemModType.PREFIX, template.modTable); + + if (workOrder.suffixToken == 0) + forgedItem.suffixToken = calcRandomMod(workOrder.vendor, mbEnums.ItemModType.SUFFIX, template.modTable); + // Forged random rolled items are unidentified until completed if (workOrder.prefixToken == 0 && workOrder.suffixToken == 0) @@ -282,14 +296,39 @@ public enum ForgeManager implements Runnable { } } - public static void calsRandomModType(NPC vendor, mbEnums.ItemModType itemModType, Item item) { + public static int calcRandomMod(NPC vendor, mbEnums.ItemModType itemModType, int modTable) { + + int modifier = 0; + ModTypeTableEntry modTypeTableEntry = null; + ModTableEntry modRollEntry = null; + int modifierRoll; + + switch (itemModType) { + case PREFIX: + modifier = vendor.getModTypeTable().get(vendor.getItemModTable().indexOf(modTable)); + modTypeTableEntry = ModTypeTableEntry.rollTable(modifier, ThreadLocalRandom.current().nextInt(1, 100 + 1)); + break; + case SUFFIX: + modifier = vendor.getModSuffixTable().get(vendor.getItemModTable().indexOf(modTable)); + modTypeTableEntry = ModTypeTableEntry.rollTable(modifier, ThreadLocalRandom.current().nextInt(1, 100 + 1)); + break; + } + + if (modTypeTableEntry == null) + return 0; - int modifier; + modifierRoll = ThreadLocalRandom.current().nextInt(1, 100 + 1); - if (itemModType.equals(mbEnums.ItemModType.PREFIX)) - modifier = vendor.getModTypeTable().get(vendor.getItemModTable().indexOf(item.template.modTable)); - else - modifier = vendor.getModTypeTable().get(vendor.getItemModTable().indexOf(item.template.modTable)); + if (modifierRoll < 80) { + modifierRoll = LootManager.TableRoll(vendor.getLevel(), false); + modRollEntry = ModTableEntry.rollTable(modTypeTableEntry.modTableID, modifierRoll); + } + + if (modRollEntry != null) { + AbstractPowerAction abstractPowerAction = PowersManager.getPowerActionByIDString(modRollEntry.action); + modifier = abstractPowerAction.getEffectsBase().getToken(); + } + return modifier; } } diff --git a/src/engine/objects/Item.java b/src/engine/objects/Item.java index 134d9e7d..d5b7ddd5 100644 --- a/src/engine/objects/Item.java +++ b/src/engine/objects/Item.java @@ -59,6 +59,8 @@ public class Item extends AbstractWorldObject { public int magicValue; public ItemTemplate template; public String name = ""; + public int prefixToken; // Forge support + public int suffixToken; // Forge support /** * In Memory constructor