refactored out dependency
This commit is contained in:
@@ -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, con.getAllowedBuildings().toLong());
|
||||
preparedStatement.setLong(7, mbEnums.toLong(con.getAllowedBuildings()));
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
|
||||
@@ -9,10 +9,11 @@
|
||||
|
||||
package engine.devcmd.cmds;
|
||||
|
||||
import engine.mbEnums.BuildingGroup;
|
||||
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;
|
||||
import org.pmw.tinylog.Logger;
|
||||
@@ -112,7 +113,7 @@ public class SlotNpcCmd extends AbstractDevCmd {
|
||||
case "ON":
|
||||
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");
|
||||
ChatManager.chatSystemError(pc, "Failed to update Database for Contract Allowed buildings. ");
|
||||
return;
|
||||
@@ -122,7 +123,7 @@ public class SlotNpcCmd extends AbstractDevCmd {
|
||||
break;
|
||||
case "OFF":
|
||||
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");
|
||||
ChatManager.chatSystemError(pc, "Failed to update Database for Contract Allowed buildings. ");
|
||||
return;
|
||||
|
||||
@@ -24,8 +24,6 @@ import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
;
|
||||
|
||||
/*
|
||||
* MagicBane engine enumeration class.
|
||||
*
|
||||
@@ -36,6 +34,14 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
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) {
|
||||
|
||||
// Bitvector -> EnumSet without the EnumBitvector dependency
|
||||
@@ -1582,7 +1588,7 @@ public class mbEnums {
|
||||
// It is also used as a bitvector flag in the npc
|
||||
// building slot mechanics.
|
||||
|
||||
public enum BuildingGroup implements EnumBitSetHelper<BuildingGroup> {
|
||||
public enum BuildingGroup {
|
||||
NONE(0, 0),
|
||||
TOL(64f, 64f),
|
||||
BARRACK(32f, 64f),
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
package engine.objects;
|
||||
|
||||
import ch.claude_martin.enumbitset.EnumBitSet;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.mbEnums;
|
||||
import org.pmw.tinylog.Logger;
|
||||
@@ -17,6 +16,7 @@ import org.pmw.tinylog.Logger;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
|
||||
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 EnumBitSet<mbEnums.BuildingGroup> allowedBuildings;
|
||||
private EnumSet<mbEnums.BuildingGroup> allowedBuildings;
|
||||
private ArrayList<Integer> buyItemType = new ArrayList<>();
|
||||
private ArrayList<Integer> buySkillToken = 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.iconID = rs.getInt("iconID");
|
||||
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.inventorySet = rs.getInt("inventorySet");
|
||||
|
||||
@@ -220,7 +220,7 @@ public class Contract extends AbstractGameObject {
|
||||
DbManager.ContractQueries.updateDatabase(this);
|
||||
}
|
||||
|
||||
public EnumBitSet<mbEnums.BuildingGroup> getAllowedBuildings() {
|
||||
public EnumSet<mbEnums.BuildingGroup> getAllowedBuildings() {
|
||||
return allowedBuildings;
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ public class Contract extends AbstractGameObject {
|
||||
return false;
|
||||
|
||||
// Binary match
|
||||
return (building.getBlueprint().getBuildingGroup().elementOf(this.allowedBuildings));
|
||||
return (this.allowedBuildings.contains(building.getBlueprint().getBuildingGroup()));
|
||||
}
|
||||
|
||||
public int getEquipmentSet() {
|
||||
|
||||
Reference in New Issue
Block a user