Browse Source

Writing string of bitset for contracts.

combat-2
MagicBot 9 months ago
parent
commit
f7c76937fb
  1. 10
      src/engine/db/handlers/dbContractHandler.java
  2. 6
      src/engine/devcmd/cmds/InfoCmd.java
  3. 12
      src/engine/devcmd/cmds/SlotNpcCmd.java
  4. 11
      src/engine/objects/Contract.java
  5. 2
      src/engine/objects/Mob.java
  6. 5
      src/engine/objects/NPC.java

10
src/engine/db/handlers/dbContractHandler.java

@ -106,12 +106,12 @@ public class dbContractHandler extends dbHandlerBase { @@ -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 { @@ -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 { @@ -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);

6
src/engine/devcmd/cmds/InfoCmd.java

@ -369,7 +369,8 @@ public class InfoCmd extends AbstractDevCmd { @@ -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 { @@ -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;

12
src/engine/devcmd/cmds/SlotNpcCmd.java

@ -12,7 +12,6 @@ package engine.devcmd.cmds; @@ -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 { @@ -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 { @@ -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 { @@ -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;

11
src/engine/objects/Contract.java

@ -36,7 +36,7 @@ public class Contract extends AbstractGameObject { @@ -36,7 +36,7 @@ public class Contract extends AbstractGameObject {
private ArrayList<Integer> npcModSuffixTable = new ArrayList<>();
private ArrayList<Byte> itemModTable = new ArrayList<>();
private ArrayList<Item> sellInventory = new ArrayList<>();
private EnumSet<mbEnums.BuildingGroup> allowedBuildings;
public EnumSet<mbEnums.BuildingGroup> allowedBuildings;
private ArrayList<Integer> buyItemType = new ArrayList<>();
private ArrayList<Integer> buySkillToken = new ArrayList<>();
private ArrayList<Integer> buyUnknownToken = new ArrayList<>();
@ -89,6 +89,8 @@ public class Contract extends AbstractGameObject { @@ -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 { @@ -220,10 +222,6 @@ public class Contract extends AbstractGameObject {
DbManager.ContractQueries.updateDatabase(this);
}
public EnumSet<mbEnums.BuildingGroup> getAllowedBuildings() {
return allowedBuildings;
}
public ArrayList<Integer> getBuyItemType() {
return this.buyItemType;
}
@ -254,7 +252,4 @@ public class Contract extends AbstractGameObject { @@ -254,7 +252,4 @@ public class Contract extends AbstractGameObject {
return (this.allowedBuildings.contains(building.getBlueprint().getBuildingGroup()));
}
public int getEquipmentSet() {
return equipmentSet;
}
}

2
src/engine/objects/Mob.java

@ -1160,7 +1160,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { @@ -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.

5
src/engine/objects/NPC.java

@ -162,8 +162,9 @@ public class NPC extends AbstractCharacter { @@ -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.

Loading…
Cancel
Save