diff --git a/src/engine/Enum.java b/src/engine/Enum.java index a702fe04..d9c2bc8d 100644 --- a/src/engine/Enum.java +++ b/src/engine/Enum.java @@ -441,77 +441,6 @@ public class Enum { CAPTURE; } - public enum RealmType { - - SEAFLOOR(0, 0x000000), - JOTUNHEIM(7, 0x006cff), - BOGLANDS(19, 0x00b4ff), - ESTRAGOTH(3, 0x00ff90), - RENNONVALE(14, 0X00ffea), - VOLGAARD(28, 0x1e00ff), - VOSTRAGOTH(29, 0x245fae), - NARROWS(21, 0x2f20a0), - FENMARCH(5, 0x3fb5ab), - MAELSTROM(11, 0x503e3e), - FARRICH(4, 0x52cd98), - TYRRANTHMINOR(25, 0x606060), - GREYSWATHE(6, 0x6c419d), - SUNSANVIL(17, 0x7800ff), - THERRONMARCH(24, 0x7bcdef), - DYVRENGISLE(1, 0x826b9c), - KINGSLUND(10, 0x871a94), - OUTERISLES(22, 0xa01313), - KAELENSFJORD(8, 0xa0c04a), - VARMADAI(26, 0xa16d1b), - WESTERMOORE(30, 0xaa3374), - OBLIVION(12, 0xababab), - SUDRAGOTH(16, 0xbaff00), - SKAARTHOL(15, 0xcfc57f), - KHALURAM(9, 0xe400ff), - VARSHADDUR(27, 0xf2845d), - FORBIDDENISLE(20, 0xff0000), - PIRATEISLES(23, 0xff008a), - SWATHMOORE(18, 0xff4200), - ESSENGLUND(2, 0xff9c00), - RELGOTH(13, 0xffde00); - - private final int realmID; - private final Color color; - private static final HashMap _rgbToIDMap = new HashMap<>(); - - RealmType(int realmID, int colorRGB) { - - this.realmID = realmID; - this.color = new Color(colorRGB); - - } - - public void addToColorMap() { - _rgbToIDMap.put(this.color.getRGB(), this.realmID); - } - - public static int getRealmIDByRGB(int realmRGB) { - - return _rgbToIDMap.get(realmRGB); - - } - - public int getRealmID() { - return realmID; - } - - public static RealmType getRealmTypeByUUID(int realmUUID) { - RealmType returnType = RealmType.SEAFLOOR; - - for (RealmType realmType : RealmType.values()) { - - if (realmType.realmID == realmUUID) - returnType = realmType; - } - return returnType; - } - } - public enum TaxType { PROFIT, WEEKLY, diff --git a/src/engine/InterestManagement/RealmMap.java b/src/engine/InterestManagement/RealmMap.java index b5604526..d9ef12e5 100644 --- a/src/engine/InterestManagement/RealmMap.java +++ b/src/engine/InterestManagement/RealmMap.java @@ -9,8 +9,8 @@ package engine.InterestManagement; /* This class is the main interface for Magicbane's -* Interest management facilities. -*/ + * Interest management facilities. + */ import engine.Enum; import engine.math.Vector3fImmutable; @@ -24,15 +24,26 @@ import engine.server.MBServerStatics; import engine.util.MapLoader; import org.pmw.tinylog.Logger; +import java.awt.*; +import java.util.HashMap; + import static engine.objects.Realm.getRealm; -public class RealmMap { +public enum RealmMap { + + REALM_MAP; + + // Spatial hashmap. Used for determining which Realm + // a player is currently located within. - // Spatial hashmap. Used for detecting which Realm - // a player is currently in.. - public static int[][] _realmImageMap; + private static final HashMap _rgbToIDMap = new HashMap<>(); + + public static int getRealmIDByRGB(int realmRGB) { + return _rgbToIDMap.get(realmRGB); + + } public static int getRealmIDAtLocation(Vector3fImmutable pos) { @@ -49,6 +60,10 @@ public class RealmMap { return RealmMap._realmImageMap[xBuckets][yBuckets]; } + public static void addToColorMap(Color color, int realmID) { + _rgbToIDMap.put(color.getRGB(), realmID); + } + public static Realm getRealmForCity(City city) { Realm outRealm = null; outRealm = city.getRealm(); @@ -61,28 +76,28 @@ public class RealmMap { } - public static void updateRealm(PlayerCharacter player){ + public static void updateRealm(PlayerCharacter player) { int realmID = RealmMap.getRealmIDAtLocation(player.getLoc()); - if (realmID != player.getLastRealmID()){ + if (realmID != player.getLastRealmID()) { player.setLastRealmID(realmID); Realm realm = Realm.getRealm(realmID); - if (realm != null){ - if (realm.isRuled()){ + if (realm != null) { + if (realm.isRuled()) { City city = realm.getRulingCity(); - if (city != null){ - TerritoryChangeMessage tcm = new TerritoryChangeMessage((PlayerCharacter)realm.getRulingCity().getOwner(),realm); + if (city != null) { + TerritoryChangeMessage tcm = new TerritoryChangeMessage((PlayerCharacter) realm.getRulingCity().getOwner(), realm); Dispatch dispatch = Dispatch.borrow(player, tcm); DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); - }else{ - TerritoryChangeMessage tcm = new TerritoryChangeMessage(null,realm); + } else { + TerritoryChangeMessage tcm = new TerritoryChangeMessage(null, realm); Dispatch dispatch = Dispatch.borrow(player, tcm); DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); } - }else{ - TerritoryChangeMessage tcm = new TerritoryChangeMessage(null,realm); + } else { + TerritoryChangeMessage tcm = new TerritoryChangeMessage(null, realm); Dispatch dispatch = Dispatch.borrow(player, tcm); DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); } diff --git a/src/engine/net/client/handlers/PlaceAssetMsgHandler.java b/src/engine/net/client/handlers/PlaceAssetMsgHandler.java index b7889309..9ea4bf12 100644 --- a/src/engine/net/client/handlers/PlaceAssetMsgHandler.java +++ b/src/engine/net/client/handlers/PlaceAssetMsgHandler.java @@ -984,11 +984,7 @@ public class PlaceAssetMsgHandler extends AbstractClientMsgHandler { return false; } - RealmType realmType = RealmType.getRealmTypeByUUID(serverRealm.getRealmID()); - - if ( - (realmType.equals(RealmType.MAELSTROM)) || - (realmType.equals(RealmType.OBLIVION))) { + if (serverRealm == null || serverRealm.getCanPlaceCities() == false) { PlaceAssetMsg.sendPlaceAssetError(origin, 57, playerCharacter.getName()); // No building may be placed within this territory return false; } @@ -1240,8 +1236,6 @@ public class PlaceAssetMsgHandler extends AbstractClientMsgHandler { private static boolean validateBuildingPlacement(Zone serverZone, PlaceAssetMsg msg, ClientConnection origin, PlayerCharacter player, PlacementInfo placementInfo) { - RealmType currentRealm; - if (serverZone.isPlayerCity() == false) { PlaceAssetMsg.sendPlaceAssetError(origin, 52, player.getName()); return false; @@ -1295,11 +1289,11 @@ public class PlaceAssetMsgHandler extends AbstractClientMsgHandler { return false; } - currentRealm = RealmType.getRealmTypeByUUID(RealmMap.getRealmIDAtLocation(player.getLoc())); + Realm serverRealm = RealmMap.getRealmAtLocation(player.getLoc()); + + // Cannot place buildings on seafloor or other restricted realms - if ( - (currentRealm.equals(RealmType.MAELSTROM)) || - (currentRealm.equals(RealmType.OBLIVION))) { + if (serverRealm == null || serverRealm.getCanPlaceCities() == false) { PlaceAssetMsg.sendPlaceAssetError(origin, 57, player.getName()); // No building may be placed within this territory return false; } diff --git a/src/engine/net/client/msg/WorldRealmMsg.java b/src/engine/net/client/msg/WorldRealmMsg.java index f2f05b0a..57abbb36 100644 --- a/src/engine/net/client/msg/WorldRealmMsg.java +++ b/src/engine/net/client/msg/WorldRealmMsg.java @@ -21,7 +21,6 @@ package engine.net.client.msg; -import engine.Enum.RealmType; import engine.net.AbstractConnection; import engine.net.ByteBufferReader; import engine.net.ByteBufferWriter; @@ -67,23 +66,12 @@ public class WorldRealmMsg extends ClientNetMsg { Realm serverRealm; - realmCount = RealmType.values().length - 1; - // Realm count without seafloor + realmCount = Realm._realms.size(); writer.putInt(realmCount); - for (RealmType realmType : RealmType.values()) { - - realmID = realmType.getRealmID(); - // Don't serialize seafloor - - if (realmID == 0) - continue; - - serverRealm = Realm.getRealm(realmID); - serverRealm.serializeForClientMsg(writer); - - } + for (Realm realm : Realm._realms.values()) + realm.serializeForClientMsg(writer); writer.putInt(0x0); writer.putInt(3000000); diff --git a/src/engine/objects/Realm.java b/src/engine/objects/Realm.java index 3936d85a..55133a12 100644 --- a/src/engine/objects/Realm.java +++ b/src/engine/objects/Realm.java @@ -21,6 +21,7 @@ import engine.powers.PowersBase; import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; +import java.awt.*; import java.net.UnknownHostException; import java.sql.ResultSet; import java.sql.SQLException; @@ -36,8 +37,9 @@ public class Realm { // Internal class cache - private static ConcurrentHashMap _realms = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + public static ConcurrentHashMap _realms = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + public Color mapColor; private final float mapR; //Red color private final float mapG; //Green color private final float mapB; //Blue color @@ -72,6 +74,7 @@ public class Realm { */ public Realm(ResultSet rs) throws SQLException, UnknownHostException { + this.mapColor = new Color(rs.getInt("mapColor")); this.mapR = rs.getFloat("mapR"); this.mapG = rs.getFloat("mapG"); this.mapB = rs.getFloat("mapB"); @@ -200,20 +203,9 @@ public class Realm { public static void configureAllRealms() { - Realm serverRealm; - int realmID; - - for (Enum.RealmType realmType : Enum.RealmType.values()) { - - realmID = realmType.getRealmID(); - // Don't serialize seafloor - - if (realmID == 0) - continue; - - serverRealm = Realm.getRealm(realmID); - serverRealm.configure(); - + for (Realm realm : Realm._realms.values()) { + RealmMap.addToColorMap(realm.mapColor, realm.realmID); + realm.configure(); } } diff --git a/src/engine/util/MapLoader.java b/src/engine/util/MapLoader.java index b2ac6849..aec069b8 100644 --- a/src/engine/util/MapLoader.java +++ b/src/engine/util/MapLoader.java @@ -4,7 +4,7 @@ package engine.util; -import engine.Enum.RealmType; +import engine.InterestManagement.RealmMap; import engine.server.MBServerStatics; import engine.server.world.WorldServer; import org.pmw.tinylog.Logger; @@ -46,12 +46,6 @@ public enum MapLoader { // Flip image on the y axis image = flipImage(image); - - // Initialize color lookup table - - for (RealmType realm : RealmType.values()) { - realm.addToColorMap(); - } // Load spatial imageMap with color data from file @@ -59,7 +53,7 @@ public enum MapLoader { for (int j = 0; j < MBServerStatics.SPATIAL_HASH_BUCKETSX; j++) { try { int rgb = image.getRGB(j, i); - realmUUID = RealmType.getRealmIDByRGB(rgb); + realmUUID = RealmMap.getRealmIDByRGB(rgb); if (realmUUID == null) { Logger.error("Corrupted png: unknown color " + rgb);