From edd1c0e9a6a7c6c6c81fcbfd1d1c4e5d705ecda5 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 23 Apr 2023 09:30:29 -0400 Subject: [PATCH] Name/level saved to disk when slotting mobiles. --- src/engine/db/handlers/dbMobHandler.java | 6 +-- src/engine/gameManager/BuildingManager.java | 2 +- src/engine/objects/Mob.java | 51 +++++++++++++-------- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/engine/db/handlers/dbMobHandler.java b/src/engine/db/handlers/dbMobHandler.java index 8a73b01e..2f748592 100644 --- a/src/engine/db/handlers/dbMobHandler.java +++ b/src/engine/db/handlers/dbMobHandler.java @@ -9,7 +9,6 @@ package engine.db.handlers; -import engine.gameManager.NPCManager; import engine.objects.Mob; import engine.objects.Zone; import engine.server.MBServerStatics; @@ -27,9 +26,9 @@ public class dbMobHandler extends dbHandlerBase { this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); } - public Mob ADD_MOB(Mob toAdd, boolean isMob) + public Mob ADD_MOB(Mob toAdd) { - prepareCallable("CALL `mob_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"); + prepareCallable("CALL `mob_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"); setLong(1, toAdd.getParentZoneID()); setInt(2, toAdd.getMobBaseID()); setInt(3, toAdd.getGuildUUID()); @@ -45,6 +44,7 @@ public class dbMobHandler extends dbHandlerBase { setInt(10, 0); setInt(11, toAdd.getBuildingID()); setInt(12, toAdd.getLevel()); + setString(13, toAdd.getFirstName()); int objectUUID = (int) getUUID(); if (objectUUID > 0) return GET_MOB(objectUUID); diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index 58ac5edd..b023f7b9 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -470,7 +470,7 @@ public enum BuildingManager { NPC npc = null; if (NPC.ISWallArcher(contractID.getContractID())) { - mob = Mob.createMob( contractID.getMobbaseID(), NpcLoc, contractOwner.getGuild(), true, zone, building, contractID.getContractID(), pirateName, 1); + mob = Mob.createMob( contractID.getMobbaseID(), NpcLoc, contractOwner.getGuild(), true, zone, building, contractID.getContractID(), pirateName, rank); if (mob == null) return false; diff --git a/src/engine/objects/Mob.java b/src/engine/objects/Mob.java index 6f41918e..ac10aa5c 100644 --- a/src/engine/objects/Mob.java +++ b/src/engine/objects/Mob.java @@ -126,10 +126,10 @@ public class Mob extends AbstractIntelligenceAgent { if (building != null) this.buildingID = building.getObjectUUID(); else this.buildingID = 0; - if (contractID == 0) this.contract = null; - else this.contract = DbManager.ContractQueries.GET_CONTRACT(contractID); - - if (this.contract != null) this.level = 10; + if (contractID == 0) + this.contract = null; + else + this.contract = DbManager.ContractQueries.GET_CONTRACT(contractID); clearStatic(); } @@ -223,8 +223,10 @@ public class Mob extends AbstractIntelligenceAgent { int contractID = rs.getInt("mob_contractID"); - if (contractID == 0) this.contract = null; - else this.contract = DbManager.ContractQueries.GET_CONTRACT(contractID); + if (contractID == 0) + this.contract = null; + else + this.contract = DbManager.ContractQueries.GET_CONTRACT(contractID); if (this.contract != null) if (NPC.ISGuardCaptain(contract.getContractID())) { this.spawnTime = 60 * 15; @@ -235,15 +237,18 @@ public class Mob extends AbstractIntelligenceAgent { int guildID = rs.getInt("mob_guildUID"); - if (this.building != null) this.guild = this.building.getGuild(); - else this.guild = Guild.getGuild(guildID); + if (this.building != null) + this.guild = this.building.getGuild(); + else + this.guild = Guild.getGuild(guildID); if (this.guild == null) this.guild = Guild.getErrantGuild(); java.util.Date sqlDateTime; sqlDateTime = rs.getTimestamp("upgradeDate"); - if (sqlDateTime != null) upgradeDateTime = new DateTime(sqlDateTime); + if (sqlDateTime != null) + upgradeDateTime = new DateTime(sqlDateTime); else upgradeDateTime = null; // Submit upgrade job if NPC is currently set to rank. @@ -254,23 +259,30 @@ public class Mob extends AbstractIntelligenceAgent { this.setObjectTypeMask(MBServerStatics.MASK_MOB | this.getTypeMasks()); - if (this.mobBase != null && this.spawnTime == 0) this.spawnTime = this.mobBase.getSpawnTime(); + if (this.mobBase != null && this.spawnTime == 0) + this.spawnTime = this.mobBase.getSpawnTime(); this.bindLoc = new Vector3fImmutable(this.statLat, this.statAlt, this.statLon); this.setParentZone(ZoneManager.getZoneByUUID(this.parentZoneID)); - this.equipmentSetID = rs.getInt("equipmentSet"); this.runeSet = rs.getInt("runeSet"); this.bootySet = rs.getInt("bootySet"); this.notEnemy = EnumBitSet.asEnumBitSet(rs.getLong("notEnemy"), Enum.MonsterType.class); this.enemy = EnumBitSet.asEnumBitSet(rs.getLong("enemy"), Enum.MonsterType.class); - if (this.contract != null) this.equipmentSetID = this.contract.getEquipmentSet(); + if (this.contract != null) { + this.equipmentSetID = this.contract.getEquipmentSet(); + this.nameOverride = rs.getString("npc_name") + " the " + this.getContract().getName(); + } else { + this.equipmentSetID = rs.getInt("equipmentSet"); + this.nameOverride = rs.getString("mob_name"); + } + + if (rs.getString("fsm").length() > 1) + this.BehaviourType = MobBehaviourType.valueOf(rs.getString("fsm")); - this.nameOverride = rs.getString("mob_name"); - if (rs.getString("fsm").length() > 1) this.BehaviourType = MobBehaviourType.valueOf(rs.getString("fsm")); } catch (Exception e) { Logger.error(currentID + ""); } @@ -503,16 +515,20 @@ 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 rank) { - Mob mobWithoutID = new Mob("", "", (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 (parent != null) mobWithoutID.setRelPos(parent, spawn.x - parent.absX, spawn.y - parent.absY, spawn.z - parent.absZ); + if (mobWithoutID.mobBase == null) + return null; + + mobWithoutID.level = (short) (rank * 10); - if (mobWithoutID.mobBase == null) return null; Mob mob; + try { - mob = DbManager.MobQueries.ADD_MOB(mobWithoutID, isMob); + mob = DbManager.MobQueries.ADD_MOB(mobWithoutID); mob.setObjectTypeMask(MBServerStatics.MASK_MOB | mob.getTypeMasks()); mob.setMob(); mob.setParentZone(parent); @@ -522,7 +538,6 @@ public class Mob extends AbstractIntelligenceAgent { mob.setLoc(buildingWorldLoc); mob.region = AbstractWorldObject.GetRegionByWorldObject(mob); MovementManager.translocate(mob, buildingWorldLoc, mob.region); - mob.nameOverride = NPC.getPirateName(mob.getMobBaseID()) + " the " + mob.getContract().getName(); mob.runAfterLoad(); } catch (Exception e) { Logger.error("SQLException:" + e.getMessage());