From b21e9dc59e03d56bed7dfc59c1bde4e834b6844d Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 20 Aug 2023 16:38:10 -0400 Subject: [PATCH] Moving items out of constructor. --- src/engine/objects/AbstractCharacter.java | 15 ++++++++++----- src/engine/objects/AbstractIntelligenceAgent.java | 2 +- src/engine/objects/Mob.java | 4 ++++ src/engine/objects/NPC.java | 6 +++++- src/engine/objects/PlayerCharacter.java | 7 +++---- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/engine/objects/AbstractCharacter.java b/src/engine/objects/AbstractCharacter.java index 39b22377..e43da320 100644 --- a/src/engine/objects/AbstractCharacter.java +++ b/src/engine/objects/AbstractCharacter.java @@ -45,7 +45,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; public abstract class AbstractCharacter extends AbstractWorldObject { - protected final CharacterItemManager charItemManager; + protected CharacterItemManager charItemManager; private final ReentrantReadWriteLock healthLock = new ReentrantReadWriteLock(); public short level; public AbstractWorldObject combatTarget; @@ -122,6 +122,15 @@ public abstract class AbstractCharacter extends AbstractWorldObject { private boolean collided = false; private byte aoecntr = 0; + public AbstractCharacter() { + super(); + + this.powers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + this.skills = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + this.initializeCharacter(); + + } + /** * No Id Constructor */ @@ -136,7 +145,6 @@ public abstract class AbstractCharacter extends AbstractWorldObject { final short level, final int exp, final Vector3fImmutable bindLoc, - final Vector3fImmutable currentLoc, final Vector3fImmutable faceDir, final Guild guild, final byte runningTrains @@ -154,7 +162,6 @@ public abstract class AbstractCharacter extends AbstractWorldObject { this.exp = exp; this.walkMode = true; this.bindLoc = bindLoc; - ; this.faceDir = faceDir; this.guild = guild; this.runningTrains = runningTrains; @@ -162,8 +169,6 @@ public abstract class AbstractCharacter extends AbstractWorldObject { this.skills = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); this.initializeCharacter(); - // Dangerous to use THIS in a constructor!!! - this.charItemManager = new CharacterItemManager(this); } /** diff --git a/src/engine/objects/AbstractIntelligenceAgent.java b/src/engine/objects/AbstractIntelligenceAgent.java index 3c7c9635..580a3094 100644 --- a/src/engine/objects/AbstractIntelligenceAgent.java +++ b/src/engine/objects/AbstractIntelligenceAgent.java @@ -46,7 +46,7 @@ public abstract class AbstractIntelligenceAgent extends AbstractCharacter { Guild guild, byte runningTrains) { super(firstName, lastName, statStrCurrent, statDexCurrent, statConCurrent, statIntCurrent, statSpiCurrent, level, exp, bindLoc, - currentLoc, faceDir, guild, + faceDir, guild, runningTrains); } diff --git a/src/engine/objects/Mob.java b/src/engine/objects/Mob.java index f385d7b7..a7e26c1b 100644 --- a/src/engine/objects/Mob.java +++ b/src/engine/objects/Mob.java @@ -1928,6 +1928,10 @@ public class Mob extends AbstractIntelligenceAgent { @Override public void runAfterLoad() { + // Initialize inventory + + this.charItemManager = new CharacterItemManager(this); + try { if (this.equipmentSetID != 0) this.equip = MobBase.loadEquipmentSet(this.equipmentSetID); diff --git a/src/engine/objects/NPC.java b/src/engine/objects/NPC.java index d5705f4e..e93cce62 100644 --- a/src/engine/objects/NPC.java +++ b/src/engine/objects/NPC.java @@ -88,7 +88,7 @@ public class NPC extends AbstractCharacter { Vector3fImmutable currentLoc, Vector3fImmutable faceDir, short healthCurrent, short manaCurrent, short stamCurrent, Guild guild, byte runningTrains, int npcType, boolean isMob, Building building, int contractID, Zone parent) { super(name, "", statStrCurrent, statDexCurrent, statConCurrent, statIntCurrent, statSpiCurrent, level, exp, - bindLoc, currentLoc, faceDir, guild, runningTrains); + bindLoc, faceDir, guild, runningTrains); this.loadID = npcType; this.contract = DbManager.ContractQueries.GET_CONTRACT(contractID); @@ -1049,6 +1049,10 @@ public class NPC extends AbstractCharacter { if (wordCount(this.name) < 2 && this.contract != null) this.name += " the " + this.contract.getName(); + // Initialize inventory + + this.charItemManager = new CharacterItemManager(this); + // Configure parent zone adding this NPC to the // zone collection diff --git a/src/engine/objects/PlayerCharacter.java b/src/engine/objects/PlayerCharacter.java index 91b8d32a..ba0f4223 100644 --- a/src/engine/objects/PlayerCharacter.java +++ b/src/engine/objects/PlayerCharacter.java @@ -188,7 +188,7 @@ public class PlayerCharacter extends AbstractCharacter { short spiMod, Guild guild, byte runningTrains, Account account, Race race, BaseClass baseClass, byte skinColor, byte hairColor, byte beardColor, byte hairStyle, byte beardStyle) { super(firstName, lastName, (short) 1, (short) 1, (short) 1, (short) 1, (short) 1, (short) 1, 0, - Vector3fImmutable.ZERO, Vector3fImmutable.ZERO, Vector3fImmutable.ZERO, + Vector3fImmutable.ZERO, Vector3fImmutable.ZERO, guild, runningTrains); this.runes = new ArrayList<>(); @@ -4582,10 +4582,9 @@ public class PlayerCharacter extends AbstractCharacter { @Override public void runAfterLoad() { - // Create player bounds object + // Init inventory - // if ((MBServer.getApp() instanceof engine.server.world.WorldServer)) - // DbManager.GuildQueries.LOAD_GUILD_HISTORY_FOR_PLAYER(this); + this.charItemManager = new CharacterItemManager(this); Bounds playerBounds = Bounds.borrow(); playerBounds.setBounds(this.getLoc());