Add the static world ID counter and static flag
Static world objects take IDs from DbManager.nextStaticID(), counting down from -2 in a fixed load order (W2). Runtime negative IDs (loot, forged and contract items, pets and minions) now share ItemManager.lastNegativeID, which starts at -1,000,000; Mob.staticID is gone. Boot fails if the static counter reaches the runtime range. AbstractWorldObject gets a staticWorldObject flag for the factories to set. Nothing uses either yet. Value changes: runtime negative IDs start at -1,000,001 (-1,000,000 for forged items) instead of -1; pets and minions draw from the item counter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
740719aeb2
commit
c89bda35da
4 files changed
+31
-5
No files matched your search
@@ -23,10 +23,15 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.EnumMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public enum DbManager {
|
||||
DBMANAGER;
|
||||
|
||||
// Static world IDs count down from -2 (-1 means "not found"); runtime negative IDs start below them.
|
||||
public static final int RUNTIME_ID_START = -1_000_000;
|
||||
private static final AtomicInteger lastStaticID = new AtomicInteger(-1);
|
||||
|
||||
public static final dbAccountHandler AccountQueries = new dbAccountHandler();
|
||||
public static final dbBaneHandler BaneQueries = new dbBaneHandler();
|
||||
|
||||
@@ -70,6 +75,17 @@ public enum DbManager {
|
||||
public static Hasher hasher;
|
||||
private static HikariDataSource connectionPool = null;
|
||||
|
||||
// Only the static world factories may call this, in the fixed load order (W2); never renumber.
|
||||
public static int nextStaticID() {
|
||||
|
||||
int staticID = lastStaticID.decrementAndGet();
|
||||
|
||||
if (staticID <= RUNTIME_ID_START)
|
||||
throw new IllegalStateException("Static world ID " + staticID + " reached the runtime ID range at " + RUNTIME_ID_START);
|
||||
|
||||
return staticID;
|
||||
}
|
||||
|
||||
public static AbstractGameObject getObject(GameObjectType objectType, int objectUUID) {
|
||||
|
||||
AbstractGameObject outObject = null;
|
||||
|
||||
@@ -20,7 +20,8 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
public enum ItemManager {
|
||||
ITEMMANAGER;
|
||||
|
||||
public static final AtomicInteger lastNegativeID = new AtomicInteger(0);
|
||||
// Shared by every runtime object with a negative ID: loot, forged and contract items, pets and minions.
|
||||
public static final AtomicInteger lastNegativeID = new AtomicInteger(DbManager.RUNTIME_ID_START);
|
||||
|
||||
// restrict true: the set is a blacklist; false: a whitelist. An empty set allows everyone.
|
||||
|
||||
|
||||
@@ -59,6 +59,8 @@ public abstract class AbstractWorldObject extends AbstractGameObject {
|
||||
private Quaternion rotation = new Quaternion();
|
||||
private int objectTypeMask = 0;
|
||||
private Bounds bounds;
|
||||
// Built from world data with an ID from DbManager.nextStaticID(); never written to the DB.
|
||||
private boolean staticWorldObject = false;
|
||||
|
||||
/**
|
||||
* No Id Constructor
|
||||
@@ -594,6 +596,14 @@ public abstract class AbstractWorldObject extends AbstractGameObject {
|
||||
this.bounds = bounds;
|
||||
}
|
||||
|
||||
public boolean isStaticWorldObject() {
|
||||
return this.staticWorldObject;
|
||||
}
|
||||
|
||||
public void setStaticWorldObject(boolean staticWorldObject) {
|
||||
this.staticWorldObject = staticWorldObject;
|
||||
}
|
||||
|
||||
public float getAltitude() {
|
||||
return altitude;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,6 @@ import static java.lang.Math.toIntExact;
|
||||
|
||||
public class Mob extends AbstractIntelligenceAgent implements Delayed {
|
||||
|
||||
private static int staticID = 0;
|
||||
//mob specific
|
||||
public final ConcurrentHashMap<Integer, Float> playerAgroMap = new ConcurrentHashMap<>(); //key = Player value = hate value
|
||||
|
||||
@@ -466,7 +465,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed {
|
||||
Mob minionMobile;
|
||||
|
||||
minionMobile = new Mob();
|
||||
minionMobile.currentID = (--Mob.staticID);
|
||||
minionMobile.currentID = ItemManager.lastNegativeID.decrementAndGet();
|
||||
|
||||
minionMobile.level = level;
|
||||
minionMobile.loadID = guardCaptain.loadID;
|
||||
@@ -527,7 +526,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed {
|
||||
Mob siegeMinion;
|
||||
|
||||
siegeMinion = new Mob();
|
||||
siegeMinion.currentID = (--Mob.staticID);
|
||||
siegeMinion.currentID = ItemManager.lastNegativeID.decrementAndGet();
|
||||
|
||||
siegeMinion.level = 1;
|
||||
siegeMinion.loadID = loadID;
|
||||
@@ -559,7 +558,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed {
|
||||
|
||||
Mob petMinion = new Mob();
|
||||
|
||||
petMinion.currentID = (--Mob.staticID);
|
||||
petMinion.currentID = ItemManager.lastNegativeID.decrementAndGet();
|
||||
|
||||
petMinion.level = (short) (level + 20);
|
||||
petMinion.loadID = loadID;
|
||||
|
||||
Reference in new issue
Block a user