Browse Source

Refactor towards new constructor.

combat-2
MagicBot 1 year ago
parent
commit
573cc531bf
  1. 2
      src/engine/db/handlers/dbMobHandler.java
  2. 25
      src/engine/objects/AbstractCharacter.java
  3. 31
      src/engine/objects/Mob.java

2
src/engine/db/handlers/dbMobHandler.java

@ -35,7 +35,7 @@ public class dbMobHandler extends dbHandlerBase {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("CALL `mob_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")) { PreparedStatement preparedStatement = connection.prepareStatement("CALL `mob_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")) {
preparedStatement.setLong(1, toAdd.getParentZoneID()); preparedStatement.setLong(1, toAdd.getParentZoneUUID());
preparedStatement.setInt(2, toAdd.getMobBaseID()); preparedStatement.setInt(2, toAdd.getMobBaseID());
preparedStatement.setInt(3, toAdd.getGuildUUID()); preparedStatement.setInt(3, toAdd.getGuildUUID());
preparedStatement.setFloat(4, toAdd.getSpawnX()); preparedStatement.setFloat(4, toAdd.getSpawnX());

25
src/engine/objects/AbstractCharacter.java

@ -119,14 +119,31 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
private long takeOffTime = 0; private long takeOffTime = 0;
private float hateValue = 0; private float hateValue = 0;
private long lastHateUpdate = 0; private long lastHateUpdate = 0;
private boolean collided = false;
private byte aoecntr = 0; private byte aoecntr = 0;
public AbstractCharacter() { public AbstractCharacter() {
super(); super();
this.firstName = "";
this.lastName = "";
this.powers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); this.statStrCurrent = (short) 0;
this.skills = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); this.statDexCurrent = (short) 0;
this.statConCurrent = (short) 0;
this.statIntCurrent = (short) 0;
this.statSpiCurrent = (short) 0;
this.unusedStatPoints = (short) 0;
this.level = (short) 0; // TODO get this from MobsBase later
this.exp = 1;
this.walkMode = true;
this.bindLoc = Vector3fImmutable.ZERO;
this.faceDir = Vector3fImmutable.ZERO;
this.runningTrains = (byte) 0;
this.skills = new ConcurrentHashMap<>();
this.powers = new ConcurrentHashMap<>();
this.initializeCharacter(); this.initializeCharacter();
} }
@ -291,8 +308,6 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
this.powers = new ConcurrentHashMap<>(); this.powers = new ConcurrentHashMap<>();
initializeCharacter(); initializeCharacter();
// Dangerous to use THIS in a constructor!!!
this.charItemManager = new CharacterItemManager(this);
} }
/** /**

31
src/engine/objects/Mob.java

@ -81,7 +81,7 @@ public class Mob extends AbstractIntelligenceAgent {
protected int loadID; protected int loadID;
protected float spawnRadius; protected float spawnRadius;
//used by static mobs //used by static mobs
protected int parentZoneID; protected int parentZoneUUID;
protected float statLat; protected float statLat;
protected float statLon; protected float statLon;
protected float statAlt; protected float statAlt;
@ -116,7 +116,7 @@ public class Mob extends AbstractIntelligenceAgent {
this.mobBase = MobBase.getMobBase(loadID); this.mobBase = MobBase.getMobBase(loadID);
this.dbID = MBServerStatics.NO_DB_ROW_ASSIGNED_YET; this.dbID = MBServerStatics.NO_DB_ROW_ASSIGNED_YET;
this.parentZone = parent; this.parentZone = parent;
this.parentZoneID = (parent != null) ? parent.getObjectUUID() : 0; this.parentZoneUUID = (parent != null) ? parent.getObjectUUID() : 0;
this.building = building; this.building = building;
if (building != null) if (building != null)
@ -143,7 +143,7 @@ public class Mob extends AbstractIntelligenceAgent {
this.loadID = mobBase.getObjectUUID(); this.loadID = mobBase.getObjectUUID();
this.mobBase = mobBase; this.mobBase = mobBase;
this.parentZone = parent; this.parentZone = parent;
this.parentZoneID = (parent != null) ? parent.getObjectUUID() : 0; this.parentZoneUUID = (parent != null) ? parent.getObjectUUID() : 0;
this.ownerUID = owner.getObjectUUID(); this.ownerUID = owner.getObjectUUID();
this.BehaviourType = Enum.MobBehaviourType.Pet; this.BehaviourType = Enum.MobBehaviourType.Pet;
clearStatic(); clearStatic();
@ -156,7 +156,7 @@ public class Mob extends AbstractIntelligenceAgent {
this.loadID = mobBase.getObjectUUID(); this.loadID = mobBase.getObjectUUID();
this.mobBase = mobBase; this.mobBase = mobBase;
this.parentZone = parent; this.parentZone = parent;
this.parentZoneID = (parent != null) ? parent.getObjectUUID() : 0; this.parentZoneUUID = (parent != null) ? parent.getObjectUUID() : 0;
this.ownerUID = 0; this.ownerUID = 0;
this.equip = new HashMap<>(); this.equip = new HashMap<>();
clearStatic(); clearStatic();
@ -181,7 +181,7 @@ public class Mob extends AbstractIntelligenceAgent {
this.localLoc = new Vector3fImmutable(this.statLat, this.statAlt, this.statLon); this.localLoc = new Vector3fImmutable(this.statLat, this.statAlt, this.statLon);
this.parentZoneID = rs.getInt("parent"); this.parentZoneUUID = rs.getInt("parent");
this.level = (short) rs.getInt("mob_level"); this.level = (short) rs.getInt("mob_level");
this.buildingUUID = rs.getInt("mob_buildingID"); this.buildingUUID = rs.getInt("mob_buildingID");
@ -469,6 +469,21 @@ public class Mob extends AbstractIntelligenceAgent {
public static Mob createMob(int loadID, Vector3fImmutable spawn, Guild guild, boolean isMob, Zone parent, Building building, int contractID, String pirateName, int level) { public static Mob createMob(int loadID, Vector3fImmutable spawn, Guild guild, boolean isMob, Zone parent, Building building, int contractID, String pirateName, int level) {
Mob mobile = new Mob();
mobile.dbID = MBServerStatics.NO_DB_ROW_ASSIGNED_YET;
mobile.loadID = loadID;
if (guild.isEmptyGuild())
mobile.guildUUID = 0;
else
mobile.guildUUID = guild.getObjectUUID();
mobile.parentZoneUUID = parent.getObjectUUID();
mobile.buildingUUID = building.getObjectUUID();
mobile.firstName = pirateName;
mobile.bindLoc = spawn;
Mob mobWithoutID = new Mob(pirateName, "", (short) 0, (short) 0, (short) 0, (short) 0, (short) 0, (short) 1, 0, false, false, false, spawn, spawn, Vector3fImmutable.ZERO, (short) 1, (short) 1, (short) 1, guild, (byte) 0, loadID, isMob, parent, building, contractID); Mob mobWithoutID = new Mob(pirateName, "", (short) 0, (short) 0, (short) 0, (short) 0, (short) 0, (short) 1, 0, false, false, false, spawn, spawn, Vector3fImmutable.ZERO, (short) 1, (short) 1, (short) 1, guild, (byte) 0, loadID, isMob, parent, building, contractID);
if (mobWithoutID.mobBase == null) if (mobWithoutID.mobBase == null)
@ -480,7 +495,7 @@ public class Mob extends AbstractIntelligenceAgent {
// refactor that out and just use the id. // refactor that out and just use the id.
mobWithoutID.parentZone = parent; mobWithoutID.parentZone = parent;
mobWithoutID.parentZoneID = parent.getObjectUUID(); mobWithoutID.parentZoneUUID = parent.getObjectUUID();
// NPC in a Building derives position from slot // NPC in a Building derives position from slot
@ -883,7 +898,7 @@ public class Mob extends AbstractIntelligenceAgent {
return this.parentZone; return this.parentZone;
} }
public int getParentZoneID() { public int getParentZoneUUID() {
if (this.parentZone != null) if (this.parentZone != null)
return this.parentZone.getObjectUUID(); return this.parentZone.getObjectUUID();
@ -1837,7 +1852,7 @@ public class Mob extends AbstractIntelligenceAgent {
// Configure parent zone adding this NPC to the // Configure parent zone adding this NPC to the
// zone collection // zone collection
this.parentZone = ZoneManager.getZoneByUUID(this.parentZoneID); this.parentZone = ZoneManager.getZoneByUUID(this.parentZoneUUID);
this.parentZone.zoneMobSet.remove(this); this.parentZone.zoneMobSet.remove(this);
this.parentZone.zoneMobSet.add(this); this.parentZone.zoneMobSet.add(this);

Loading…
Cancel
Save