From 1a7f63ce051dba7e9ec65e6516b1805c587d1c58 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 19 Apr 2024 10:32:36 -0400 Subject: [PATCH] lastNegativeId moved to ItemManager --- src/engine/db/handlers/dbContractHandler.java | 4 ++-- src/engine/gameManager/ForgeManager.java | 2 +- src/engine/gameManager/ItemManager.java | 17 +++++++++++++++++ src/engine/objects/MobBase.java | 3 ++- src/engine/objects/MobLoot.java | 7 ++----- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/engine/db/handlers/dbContractHandler.java b/src/engine/db/handlers/dbContractHandler.java index 5cdb69f5..223417dd 100644 --- a/src/engine/db/handlers/dbContractHandler.java +++ b/src/engine/db/handlers/dbContractHandler.java @@ -10,10 +10,10 @@ package engine.db.handlers; import engine.gameManager.DbManager; +import engine.gameManager.ItemManager; import engine.mbEnums; import engine.objects.Contract; import engine.objects.Item; -import engine.objects.MobLoot; import org.pmw.tinylog.Logger; import java.sql.Connection; @@ -66,7 +66,7 @@ public class dbContractHandler extends dbHandlerBase { int templateID = rs.getInt("templateID"); Item item = new Item(templateID); - item.objectUUID = MobLoot.lastNegativeID.decrementAndGet(); + item.objectUUID = ItemManager.lastNegativeID.decrementAndGet(); contract.getSellInventory().add(item); } diff --git a/src/engine/gameManager/ForgeManager.java b/src/engine/gameManager/ForgeManager.java index e57db32f..dc74b877 100644 --- a/src/engine/gameManager/ForgeManager.java +++ b/src/engine/gameManager/ForgeManager.java @@ -291,7 +291,7 @@ public enum ForgeManager implements Runnable { // Item gets a negative id; a virtual in-memory only item // which is not persisted or added to the game cache. - forgedItem.objectUUID = MobLoot.lastNegativeID.getAndDecrement(); + forgedItem.objectUUID = ItemManager.lastNegativeID.getAndDecrement(); forgedItem.containerType = mbEnums.ItemContainerType.FORGE; forgedItem.ownerID = workOrder.vendor.getObjectUUID(); diff --git a/src/engine/gameManager/ItemManager.java b/src/engine/gameManager/ItemManager.java index 149aa121..1e1d23f7 100644 --- a/src/engine/gameManager/ItemManager.java +++ b/src/engine/gameManager/ItemManager.java @@ -2,10 +2,13 @@ package engine.gameManager; import engine.mbEnums; import engine.objects.*; +import engine.powers.EffectsBase; +import engine.powers.poweractions.AbstractPowerAction; import org.pmw.tinylog.Logger; import java.util.EnumSet; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ @@ -17,6 +20,8 @@ import java.util.concurrent.ConcurrentHashMap; public enum ItemManager { ITEMMANAGER; + public static final AtomicInteger lastNegativeID = new AtomicInteger(0); + public static Boolean ValidRace(Item item, mbEnums.MonsterType race) { if (item.template.item_race_req.isEmpty() && item.template.item_race_res.isEmpty()) @@ -220,4 +225,16 @@ public enum ItemManager { return true; } + + public static void addPrefixOrSuffix(Item item, int token) { + + EffectsBase effectsBase = PowersManager.getEffectByToken(token); + AbstractPowerAction apa = PowersManager.getPowerActionByIDString(effectsBase.getIDString()); + + if (apa == null) + return; + + apa.applyEffectForItem(item, 0); + item.getEffectNames().add(effectsBase.getIDString()); + } } diff --git a/src/engine/objects/MobBase.java b/src/engine/objects/MobBase.java index fe573a4a..ee54309b 100644 --- a/src/engine/objects/MobBase.java +++ b/src/engine/objects/MobBase.java @@ -10,6 +10,7 @@ package engine.objects; import engine.gameManager.DbManager; +import engine.gameManager.ItemManager; import engine.gameManager.LootManager; import engine.loot.BootySetEntry; import engine.mbEnums; @@ -126,7 +127,7 @@ public class MobBase extends AbstractGameObject { for (BootySetEntry equipmentSetEntry : equipList) { Item item = new Item(equipmentSetEntry.templateID); - item.objectUUID = MobLoot.lastNegativeID.decrementAndGet(); + item.objectUUID = ItemManager.lastNegativeID.decrementAndGet(); item.drop_chance = equipmentSetEntry.dropChance; item.equipSlot = item.template.item_eq_slots_or.iterator().next(); equip.put(item.equipSlot, item); diff --git a/src/engine/objects/MobLoot.java b/src/engine/objects/MobLoot.java index b24a8798..db718610 100644 --- a/src/engine/objects/MobLoot.java +++ b/src/engine/objects/MobLoot.java @@ -10,6 +10,7 @@ package engine.objects; import engine.gameManager.DbManager; +import engine.gameManager.ItemManager; import engine.gameManager.PowersManager; import engine.mbEnums; import engine.mbEnums.ItemType; @@ -17,8 +18,6 @@ import engine.mbEnums.OwnerType; import engine.powers.poweractions.AbstractPowerAction; import org.pmw.tinylog.Logger; -import java.util.concurrent.atomic.AtomicInteger; - /** * An immutable, non-persistant implementation of Item * @@ -26,8 +25,6 @@ import java.util.concurrent.atomic.AtomicInteger; */ public final class MobLoot extends Item { - public static final AtomicInteger lastNegativeID = new AtomicInteger(0); - private boolean isDeleted = false; private boolean noSteal; private String prefix = ""; @@ -77,7 +74,7 @@ public final class MobLoot extends Item { * @return Id number */ private static int generateId() { - int id = lastNegativeID.decrementAndGet(); + int id = ItemManager.lastNegativeID.decrementAndGet(); //TODO Add a way to reclaim disposed IDs if this becomes a problem if (id == (-10000))