Browse Source

refactored out dependency

combat-2
MagicBot 7 months ago
parent
commit
43b212ed42
  1. 2
      src/engine/db/handlers/dbContractHandler.java
  2. 7
      src/engine/devcmd/cmds/SlotNpcCmd.java
  3. 12
      src/engine/mbEnums.java
  4. 10
      src/engine/objects/Contract.java

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

@ -135,7 +135,7 @@ public class dbContractHandler extends dbHandlerBase {
preparedStatement.setInt(5, (con.getVendorDialog() != null) ? con.getVendorDialog().getObjectUUID() : 0); preparedStatement.setInt(5, (con.getVendorDialog() != null) ? con.getVendorDialog().getObjectUUID() : 0);
preparedStatement.setInt(6, con.getIconID()); preparedStatement.setInt(6, con.getIconID());
preparedStatement.setInt(8, con.getObjectUUID()); preparedStatement.setInt(8, con.getObjectUUID());
preparedStatement.setLong(7, con.getAllowedBuildings().toLong()); preparedStatement.setLong(7, mbEnums.toLong(con.getAllowedBuildings()));
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);

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

@ -9,10 +9,11 @@
package engine.devcmd.cmds; package engine.devcmd.cmds;
import engine.mbEnums.BuildingGroup;
import engine.devcmd.AbstractDevCmd; import engine.devcmd.AbstractDevCmd;
import engine.gameManager.ChatManager; import engine.gameManager.ChatManager;
import engine.gameManager.DbManager; import engine.gameManager.DbManager;
import engine.mbEnums;
import engine.mbEnums.BuildingGroup;
import engine.objects.*; import engine.objects.*;
import engine.util.StringUtils; import engine.util.StringUtils;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
@ -112,7 +113,7 @@ public class SlotNpcCmd extends AbstractDevCmd {
case "ON": case "ON":
contract.getAllowedBuildings().add(buildingGroup); contract.getAllowedBuildings().add(buildingGroup);
if (!DbManager.ContractQueries.updateAllowedBuildings(contract, contract.getAllowedBuildings().toLong())) { if (!DbManager.ContractQueries.updateAllowedBuildings(contract, mbEnums.toLong(contract.getAllowedBuildings()))) {
Logger.error("Failed to update Database for Contract Allowed buildings"); Logger.error("Failed to update Database for Contract Allowed buildings");
ChatManager.chatSystemError(pc, "Failed to update Database for Contract Allowed buildings. "); ChatManager.chatSystemError(pc, "Failed to update Database for Contract Allowed buildings. ");
return; return;
@ -122,7 +123,7 @@ public class SlotNpcCmd extends AbstractDevCmd {
break; break;
case "OFF": case "OFF":
contract.getAllowedBuildings().remove(buildingGroup); contract.getAllowedBuildings().remove(buildingGroup);
if (!DbManager.ContractQueries.updateAllowedBuildings(contract, contract.getAllowedBuildings().toLong())) { if (!DbManager.ContractQueries.updateAllowedBuildings(contract, mbEnums.toLong(contract.getAllowedBuildings()))) {
Logger.error("Failed to update Database for Contract Allowed buildings"); Logger.error("Failed to update Database for Contract Allowed buildings");
ChatManager.chatSystemError(pc, "Failed to update Database for Contract Allowed buildings. "); ChatManager.chatSystemError(pc, "Failed to update Database for Contract Allowed buildings. ");
return; return;

12
src/engine/mbEnums.java

@ -24,8 +24,6 @@ import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
;
/* /*
* MagicBane engine enumeration class. * MagicBane engine enumeration class.
* *
@ -36,6 +34,14 @@ import java.util.concurrent.ThreadLocalRandom;
public class mbEnums { public class mbEnums {
public static <T extends Enum<T>> long toLong(EnumSet<T> enumSet) {
long r = 0;
for (T value : enumSet) {
r |= 1L << value.ordinal();
}
return r;
}
public static <E extends java.lang.Enum<E>> EnumSet<E> fromLong(long bitVector, Class<E> enumClass) { public static <E extends java.lang.Enum<E>> EnumSet<E> fromLong(long bitVector, Class<E> enumClass) {
// Bitvector -> EnumSet without the EnumBitvector dependency // Bitvector -> EnumSet without the EnumBitvector dependency
@ -1582,7 +1588,7 @@ public class mbEnums {
// It is also used as a bitvector flag in the npc // It is also used as a bitvector flag in the npc
// building slot mechanics. // building slot mechanics.
public enum BuildingGroup implements EnumBitSetHelper<BuildingGroup> { public enum BuildingGroup {
NONE(0, 0), NONE(0, 0),
TOL(64f, 64f), TOL(64f, 64f),
BARRACK(32f, 64f), BARRACK(32f, 64f),

10
src/engine/objects/Contract.java

@ -9,7 +9,6 @@
package engine.objects; package engine.objects;
import ch.claude_martin.enumbitset.EnumBitSet;
import engine.gameManager.DbManager; import engine.gameManager.DbManager;
import engine.mbEnums; import engine.mbEnums;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
@ -17,6 +16,7 @@ import org.pmw.tinylog.Logger;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumSet;
public class Contract extends AbstractGameObject { public class Contract extends AbstractGameObject {
@ -36,7 +36,7 @@ public class Contract extends AbstractGameObject {
private ArrayList<Integer> npcModSuffixTable = new ArrayList<>(); private ArrayList<Integer> npcModSuffixTable = new ArrayList<>();
private ArrayList<Byte> itemModTable = new ArrayList<>(); private ArrayList<Byte> itemModTable = new ArrayList<>();
private ArrayList<Item> sellInventory = new ArrayList<>(); private ArrayList<Item> sellInventory = new ArrayList<>();
private EnumBitSet<mbEnums.BuildingGroup> allowedBuildings; private EnumSet<mbEnums.BuildingGroup> allowedBuildings;
private ArrayList<Integer> buyItemType = new ArrayList<>(); private ArrayList<Integer> buyItemType = new ArrayList<>();
private ArrayList<Integer> buySkillToken = new ArrayList<>(); private ArrayList<Integer> buySkillToken = new ArrayList<>();
private ArrayList<Integer> buyUnknownToken = new ArrayList<>(); private ArrayList<Integer> buyUnknownToken = new ArrayList<>();
@ -85,7 +85,7 @@ public class Contract extends AbstractGameObject {
this.vendorDialog = VendorDialog.getVendorDialog(rs.getInt("dialogID")); this.vendorDialog = VendorDialog.getVendorDialog(rs.getInt("dialogID"));
this.iconID = rs.getInt("iconID"); this.iconID = rs.getInt("iconID");
this.vendorID = rs.getInt("vendorID"); this.vendorID = rs.getInt("vendorID");
this.allowedBuildings = EnumBitSet.asEnumBitSet(rs.getLong("allowedBuildingTypeID"), mbEnums.BuildingGroup.class); this.allowedBuildings = mbEnums.fromLong(rs.getLong("allowedBuildingTypeID"), mbEnums.BuildingGroup.class);
this.equipmentSet = rs.getInt("equipSetID"); this.equipmentSet = rs.getInt("equipSetID");
this.inventorySet = rs.getInt("inventorySet"); this.inventorySet = rs.getInt("inventorySet");
@ -220,7 +220,7 @@ public class Contract extends AbstractGameObject {
DbManager.ContractQueries.updateDatabase(this); DbManager.ContractQueries.updateDatabase(this);
} }
public EnumBitSet<mbEnums.BuildingGroup> getAllowedBuildings() { public EnumSet<mbEnums.BuildingGroup> getAllowedBuildings() {
return allowedBuildings; return allowedBuildings;
} }
@ -251,7 +251,7 @@ public class Contract extends AbstractGameObject {
return false; return false;
// Binary match // Binary match
return (building.getBlueprint().getBuildingGroup().elementOf(this.allowedBuildings)); return (this.allowedBuildings.contains(building.getBlueprint().getBuildingGroup()));
} }
public int getEquipmentSet() { public int getEquipmentSet() {

Loading…
Cancel
Save