Moving items out of constructor.

This commit is contained in:
2023-08-20 16:38:10 -04:00
parent 2c9fc405e9
commit b21e9dc59e
5 changed files with 23 additions and 11 deletions
+10 -5
View File
@@ -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);
}
/**
@@ -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);
}
+4
View File
@@ -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);
+5 -1
View File
@@ -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
+3 -4
View File
@@ -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());