From f7c76937fb66c20f93ec4c56617c7e80a83b577a Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 5 Apr 2024 09:18:12 -0400 Subject: [PATCH] Writing string of bitset for contracts. --- src/engine/db/handlers/dbContractHandler.java | 10 +++++----- src/engine/devcmd/cmds/InfoCmd.java | 6 ++++-- src/engine/devcmd/cmds/SlotNpcCmd.java | 12 ++++++------ src/engine/objects/Contract.java | 11 +++-------- src/engine/objects/Mob.java | 2 +- src/engine/objects/NPC.java | 5 +++-- 6 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/engine/db/handlers/dbContractHandler.java b/src/engine/db/handlers/dbContractHandler.java index 69fde2de..5cdb69f5 100644 --- a/src/engine/db/handlers/dbContractHandler.java +++ b/src/engine/db/handlers/dbContractHandler.java @@ -106,12 +106,12 @@ public class dbContractHandler extends dbHandlerBase { } } - public boolean updateAllowedBuildings(final Contract con, final long slotbitvalue) { + public boolean updateAllowedBuildings(final Contract con) { try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `static_npc_contract` SET `allowedBuildingTypeID`=? WHERE `contractID`=?")) { + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `static_npc_contract` SET `slotInBuildings`=? WHERE `contractID`=?")) { - preparedStatement.setLong(1, slotbitvalue); + preparedStatement.setString(1, mbEnums.asString(con.allowedBuildings)); preparedStatement.setInt(2, con.getContractID()); return (preparedStatement.executeUpdate() > 0); @@ -126,7 +126,7 @@ public class dbContractHandler extends dbHandlerBase { try (Connection connection = DbManager.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `static_npc_contract` SET `contractID`=?, `name`=?, " - + "`mobbaseID`=?, `classID`=?, vendorDialog=?, iconID=?, allowedBuildingTypeID=? WHERE `ID`=?")) { + + "`mobbaseID`=?, `classID`=?, vendorDialog=?, iconID=?, slotInBuildings=? WHERE `ID`=?")) { preparedStatement.setInt(1, con.getContractID()); preparedStatement.setString(2, con.getName()); @@ -135,7 +135,7 @@ public class dbContractHandler extends dbHandlerBase { preparedStatement.setInt(5, (con.getVendorDialog() != null) ? con.getVendorDialog().getObjectUUID() : 0); preparedStatement.setInt(6, con.getIconID()); preparedStatement.setInt(8, con.getObjectUUID()); - preparedStatement.setLong(7, mbEnums.toLong(con.getAllowedBuildings())); + preparedStatement.setString(7, mbEnums.asString(con.allowedBuildings)); return (preparedStatement.executeUpdate() > 0); diff --git a/src/engine/devcmd/cmds/InfoCmd.java b/src/engine/devcmd/cmds/InfoCmd.java index 6280d876..3d7fead5 100644 --- a/src/engine/devcmd/cmds/InfoCmd.java +++ b/src/engine/devcmd/cmds/InfoCmd.java @@ -369,7 +369,8 @@ public class InfoCmd extends AbstractDevCmd { output += newline; output += "InventorySet: " + targetNPC.getContract().inventorySet; output += newline; - output += targetNPC.getContract().getAllowedBuildings().toString(); + Contract contract1 = targetNPC.getContract(); + output += contract1.allowedBuildings.toString(); output += newline; output += "Extra Rune: " + targetNPC.getContract().getExtraRune(); @@ -383,7 +384,8 @@ public class InfoCmd extends AbstractDevCmd { output += newline; if (mobBase != null) { output += newline; - output += "Slottable: " + targetNPC.getContract().getAllowedBuildings().toString(); + Contract contract = targetNPC.getContract(); + output += "Slottable: " + contract.allowedBuildings.toString(); output += newline; output += "EquipSet: " + targetNPC.getEquipmentSetID(); output += newline; diff --git a/src/engine/devcmd/cmds/SlotNpcCmd.java b/src/engine/devcmd/cmds/SlotNpcCmd.java index e933cd92..576e0165 100644 --- a/src/engine/devcmd/cmds/SlotNpcCmd.java +++ b/src/engine/devcmd/cmds/SlotNpcCmd.java @@ -12,7 +12,6 @@ package engine.devcmd.cmds; import engine.devcmd.AbstractDevCmd; import engine.gameManager.ChatManager; import engine.gameManager.DbManager; -import engine.mbEnums; import engine.mbEnums.BuildingGroup; import engine.objects.*; import engine.util.StringUtils; @@ -93,7 +92,7 @@ public class SlotNpcCmd extends AbstractDevCmd { if (args[0].equalsIgnoreCase("LIST")) { - outString = "Current: " + contract.getAllowedBuildings(); + outString = "Current: " + contract.allowedBuildings; throwbackInfo(pc, outString); return; @@ -111,9 +110,9 @@ public class SlotNpcCmd extends AbstractDevCmd { switch (args[1].toUpperCase()) { case "ON": - contract.getAllowedBuildings().add(buildingGroup); + contract.allowedBuildings.add(buildingGroup); - if (!DbManager.ContractQueries.updateAllowedBuildings(contract, mbEnums.toLong(contract.getAllowedBuildings()))) { + if (!DbManager.ContractQueries.updateAllowedBuildings(contract)) { Logger.error("Failed to update Database for Contract Allowed buildings"); ChatManager.chatSystemError(pc, "Failed to update Database for Contract Allowed buildings. "); return; @@ -122,8 +121,9 @@ public class SlotNpcCmd extends AbstractDevCmd { throwbackInfo(pc, "SlotNpc " + buildingGroup.name() + " added to npc"); break; case "OFF": - contract.getAllowedBuildings().remove(buildingGroup); - if (!DbManager.ContractQueries.updateAllowedBuildings(contract, mbEnums.toLong(contract.getAllowedBuildings()))) { + contract.allowedBuildings.remove(buildingGroup); + + if (!DbManager.ContractQueries.updateAllowedBuildings(contract)) { Logger.error("Failed to update Database for Contract Allowed buildings"); ChatManager.chatSystemError(pc, "Failed to update Database for Contract Allowed buildings. "); return; diff --git a/src/engine/objects/Contract.java b/src/engine/objects/Contract.java index 53944489..d075656b 100644 --- a/src/engine/objects/Contract.java +++ b/src/engine/objects/Contract.java @@ -36,7 +36,7 @@ public class Contract extends AbstractGameObject { private ArrayList npcModSuffixTable = new ArrayList<>(); private ArrayList itemModTable = new ArrayList<>(); private ArrayList sellInventory = new ArrayList<>(); - private EnumSet allowedBuildings; + public EnumSet allowedBuildings; private ArrayList buyItemType = new ArrayList<>(); private ArrayList buySkillToken = new ArrayList<>(); private ArrayList buyUnknownToken = new ArrayList<>(); @@ -89,6 +89,8 @@ public class Contract extends AbstractGameObject { this.equipmentSet = rs.getInt("equipSetID"); this.inventorySet = rs.getInt("inventorySet"); + DbManager.ContractQueries.updateAllowedBuildings(this); + try { String menuoptions = rs.getString("menuoptions"); @@ -220,10 +222,6 @@ public class Contract extends AbstractGameObject { DbManager.ContractQueries.updateDatabase(this); } - public EnumSet getAllowedBuildings() { - return allowedBuildings; - } - public ArrayList getBuyItemType() { return this.buyItemType; } @@ -254,7 +252,4 @@ public class Contract extends AbstractGameObject { return (this.allowedBuildings.contains(building.getBlueprint().getBuildingGroup())); } - public int getEquipmentSet() { - return equipmentSet; - } } diff --git a/src/engine/objects/Mob.java b/src/engine/objects/Mob.java index ca4bc7f4..3c68ddc9 100644 --- a/src/engine/objects/Mob.java +++ b/src/engine/objects/Mob.java @@ -1160,7 +1160,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { // Setup equipset for contract if (this.contract != null) - this.equipmentSetID = this.contract.getEquipmentSet(); + this.equipmentSetID = this.contract.equipmentSet; // Mobiles default to the building guild. diff --git a/src/engine/objects/NPC.java b/src/engine/objects/NPC.java index c02536f9..38dee29c 100644 --- a/src/engine/objects/NPC.java +++ b/src/engine/objects/NPC.java @@ -162,8 +162,9 @@ public class NPC extends AbstractCharacter { //838, 950, 1051, 1181, 1251, 1351, 1451, 1501, 1526, 1551, 980101, - return contract.getAllowedBuildings().contains(BuildingGroup.WALLCORNER) || - contract.getAllowedBuildings().contains(BuildingGroup.WALLSTRAIGHTTOWER); + if (contract.allowedBuildings.contains(BuildingGroup.WALLCORNER)) + return true; + return contract.allowedBuildings.contains(BuildingGroup.WALLSTRAIGHTTOWER); } //This method restarts an upgrade timer when a building is loaded from the database.