Browse Source

lastNegativeId moved to ItemManager

combat-2
MagicBot 7 months ago
parent
commit
1a7f63ce05
  1. 4
      src/engine/db/handlers/dbContractHandler.java
  2. 2
      src/engine/gameManager/ForgeManager.java
  3. 17
      src/engine/gameManager/ItemManager.java
  4. 3
      src/engine/objects/MobBase.java
  5. 7
      src/engine/objects/MobLoot.java

4
src/engine/db/handlers/dbContractHandler.java

@ -10,10 +10,10 @@
package engine.db.handlers; package engine.db.handlers;
import engine.gameManager.DbManager; import engine.gameManager.DbManager;
import engine.gameManager.ItemManager;
import engine.mbEnums; import engine.mbEnums;
import engine.objects.Contract; import engine.objects.Contract;
import engine.objects.Item; import engine.objects.Item;
import engine.objects.MobLoot;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.sql.Connection; import java.sql.Connection;
@ -66,7 +66,7 @@ public class dbContractHandler extends dbHandlerBase {
int templateID = rs.getInt("templateID"); int templateID = rs.getInt("templateID");
Item item = new Item(templateID); Item item = new Item(templateID);
item.objectUUID = MobLoot.lastNegativeID.decrementAndGet(); item.objectUUID = ItemManager.lastNegativeID.decrementAndGet();
contract.getSellInventory().add(item); contract.getSellInventory().add(item);
} }

2
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 // Item gets a negative id; a virtual in-memory only item
// which is not persisted or added to the game cache. // 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.containerType = mbEnums.ItemContainerType.FORGE;
forgedItem.ownerID = workOrder.vendor.getObjectUUID(); forgedItem.ownerID = workOrder.vendor.getObjectUUID();

17
src/engine/gameManager/ItemManager.java

@ -2,10 +2,13 @@ package engine.gameManager;
import engine.mbEnums; import engine.mbEnums;
import engine.objects.*; import engine.objects.*;
import engine.powers.EffectsBase;
import engine.powers.poweractions.AbstractPowerAction;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
@ -17,6 +20,8 @@ import java.util.concurrent.ConcurrentHashMap;
public enum ItemManager { public enum ItemManager {
ITEMMANAGER; ITEMMANAGER;
public static final AtomicInteger lastNegativeID = new AtomicInteger(0);
public static Boolean ValidRace(Item item, mbEnums.MonsterType race) { public static Boolean ValidRace(Item item, mbEnums.MonsterType race) {
if (item.template.item_race_req.isEmpty() && item.template.item_race_res.isEmpty()) if (item.template.item_race_req.isEmpty() && item.template.item_race_res.isEmpty())
@ -220,4 +225,16 @@ public enum ItemManager {
return true; 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());
}
} }

3
src/engine/objects/MobBase.java

@ -10,6 +10,7 @@
package engine.objects; package engine.objects;
import engine.gameManager.DbManager; import engine.gameManager.DbManager;
import engine.gameManager.ItemManager;
import engine.gameManager.LootManager; import engine.gameManager.LootManager;
import engine.loot.BootySetEntry; import engine.loot.BootySetEntry;
import engine.mbEnums; import engine.mbEnums;
@ -126,7 +127,7 @@ public class MobBase extends AbstractGameObject {
for (BootySetEntry equipmentSetEntry : equipList) { for (BootySetEntry equipmentSetEntry : equipList) {
Item item = new Item(equipmentSetEntry.templateID); Item item = new Item(equipmentSetEntry.templateID);
item.objectUUID = MobLoot.lastNegativeID.decrementAndGet(); item.objectUUID = ItemManager.lastNegativeID.decrementAndGet();
item.drop_chance = equipmentSetEntry.dropChance; item.drop_chance = equipmentSetEntry.dropChance;
item.equipSlot = item.template.item_eq_slots_or.iterator().next(); item.equipSlot = item.template.item_eq_slots_or.iterator().next();
equip.put(item.equipSlot, item); equip.put(item.equipSlot, item);

7
src/engine/objects/MobLoot.java

@ -10,6 +10,7 @@
package engine.objects; package engine.objects;
import engine.gameManager.DbManager; import engine.gameManager.DbManager;
import engine.gameManager.ItemManager;
import engine.gameManager.PowersManager; import engine.gameManager.PowersManager;
import engine.mbEnums; import engine.mbEnums;
import engine.mbEnums.ItemType; import engine.mbEnums.ItemType;
@ -17,8 +18,6 @@ import engine.mbEnums.OwnerType;
import engine.powers.poweractions.AbstractPowerAction; import engine.powers.poweractions.AbstractPowerAction;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.util.concurrent.atomic.AtomicInteger;
/** /**
* An immutable, non-persistant implementation of Item * An immutable, non-persistant implementation of Item
* *
@ -26,8 +25,6 @@ import java.util.concurrent.atomic.AtomicInteger;
*/ */
public final class MobLoot extends Item { public final class MobLoot extends Item {
public static final AtomicInteger lastNegativeID = new AtomicInteger(0);
private boolean isDeleted = false; private boolean isDeleted = false;
private boolean noSteal; private boolean noSteal;
private String prefix = ""; private String prefix = "";
@ -77,7 +74,7 @@ public final class MobLoot extends Item {
* @return Id number * @return Id number
*/ */
private static int generateId() { 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 //TODO Add a way to reclaim disposed IDs if this becomes a problem
if (id == (-10000)) if (id == (-10000))

Loading…
Cancel
Save