Browse Source

Realms refactored to pull map color from database not hardcoded enum.

master
MagicBot 2 years ago
parent
commit
5cfb451041
  1. 71
      src/engine/Enum.java
  2. 45
      src/engine/InterestManagement/RealmMap.java
  3. 16
      src/engine/net/client/handlers/PlaceAssetMsgHandler.java
  4. 18
      src/engine/net/client/msg/WorldRealmMsg.java
  5. 22
      src/engine/objects/Realm.java
  6. 10
      src/engine/util/MapLoader.java

71
src/engine/Enum.java

@ -441,77 +441,6 @@ public class Enum {
CAPTURE; 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<Integer, Integer> _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 { public enum TaxType {
PROFIT, PROFIT,
WEEKLY, WEEKLY,

45
src/engine/InterestManagement/RealmMap.java

@ -9,8 +9,8 @@
package engine.InterestManagement; package engine.InterestManagement;
/* This class is the main interface for Magicbane's /* This class is the main interface for Magicbane's
* Interest management facilities. * Interest management facilities.
*/ */
import engine.Enum; import engine.Enum;
import engine.math.Vector3fImmutable; import engine.math.Vector3fImmutable;
@ -24,15 +24,26 @@ import engine.server.MBServerStatics;
import engine.util.MapLoader; import engine.util.MapLoader;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.awt.*;
import java.util.HashMap;
import static engine.objects.Realm.getRealm; import static engine.objects.Realm.getRealm;
public class RealmMap { public enum RealmMap {
REALM_MAP;
// Spatial hashmap. Used for detecting which Realm // Spatial hashmap. Used for determining which Realm
// a player is currently in.. // a player is currently located within.
public static int[][] _realmImageMap; public static int[][] _realmImageMap;
private static final HashMap<Integer, Integer> _rgbToIDMap = new HashMap<>();
public static int getRealmIDByRGB(int realmRGB) {
return _rgbToIDMap.get(realmRGB);
}
public static int getRealmIDAtLocation(Vector3fImmutable pos) { public static int getRealmIDAtLocation(Vector3fImmutable pos) {
@ -49,6 +60,10 @@ public class RealmMap {
return RealmMap._realmImageMap[xBuckets][yBuckets]; return RealmMap._realmImageMap[xBuckets][yBuckets];
} }
public static void addToColorMap(Color color, int realmID) {
_rgbToIDMap.put(color.getRGB(), realmID);
}
public static Realm getRealmForCity(City city) { public static Realm getRealmForCity(City city) {
Realm outRealm = null; Realm outRealm = null;
outRealm = city.getRealm(); 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()); int realmID = RealmMap.getRealmIDAtLocation(player.getLoc());
if (realmID != player.getLastRealmID()){ if (realmID != player.getLastRealmID()) {
player.setLastRealmID(realmID); player.setLastRealmID(realmID);
Realm realm = Realm.getRealm(realmID); Realm realm = Realm.getRealm(realmID);
if (realm != null){ if (realm != null) {
if (realm.isRuled()){ if (realm.isRuled()) {
City city = realm.getRulingCity(); City city = realm.getRulingCity();
if (city != null){ if (city != null) {
TerritoryChangeMessage tcm = new TerritoryChangeMessage((PlayerCharacter)realm.getRulingCity().getOwner(),realm); TerritoryChangeMessage tcm = new TerritoryChangeMessage((PlayerCharacter) realm.getRulingCity().getOwner(), realm);
Dispatch dispatch = Dispatch.borrow(player, tcm); Dispatch dispatch = Dispatch.borrow(player, tcm);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY);
}else{ } else {
TerritoryChangeMessage tcm = new TerritoryChangeMessage(null,realm); TerritoryChangeMessage tcm = new TerritoryChangeMessage(null, realm);
Dispatch dispatch = Dispatch.borrow(player, tcm); Dispatch dispatch = Dispatch.borrow(player, tcm);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY);
} }
}else{ } else {
TerritoryChangeMessage tcm = new TerritoryChangeMessage(null,realm); TerritoryChangeMessage tcm = new TerritoryChangeMessage(null, realm);
Dispatch dispatch = Dispatch.borrow(player, tcm); Dispatch dispatch = Dispatch.borrow(player, tcm);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY);
} }

16
src/engine/net/client/handlers/PlaceAssetMsgHandler.java

@ -984,11 +984,7 @@ public class PlaceAssetMsgHandler extends AbstractClientMsgHandler {
return false; return false;
} }
RealmType realmType = RealmType.getRealmTypeByUUID(serverRealm.getRealmID()); if (serverRealm == null || serverRealm.getCanPlaceCities() == false) {
if (
(realmType.equals(RealmType.MAELSTROM)) ||
(realmType.equals(RealmType.OBLIVION))) {
PlaceAssetMsg.sendPlaceAssetError(origin, 57, playerCharacter.getName()); // No building may be placed within this territory PlaceAssetMsg.sendPlaceAssetError(origin, 57, playerCharacter.getName()); // No building may be placed within this territory
return false; 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) { private static boolean validateBuildingPlacement(Zone serverZone, PlaceAssetMsg msg, ClientConnection origin, PlayerCharacter player, PlacementInfo placementInfo) {
RealmType currentRealm;
if (serverZone.isPlayerCity() == false) { if (serverZone.isPlayerCity() == false) {
PlaceAssetMsg.sendPlaceAssetError(origin, 52, player.getName()); PlaceAssetMsg.sendPlaceAssetError(origin, 52, player.getName());
return false; return false;
@ -1295,11 +1289,11 @@ public class PlaceAssetMsgHandler extends AbstractClientMsgHandler {
return false; 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 ( if (serverRealm == null || serverRealm.getCanPlaceCities() == false) {
(currentRealm.equals(RealmType.MAELSTROM)) ||
(currentRealm.equals(RealmType.OBLIVION))) {
PlaceAssetMsg.sendPlaceAssetError(origin, 57, player.getName()); // No building may be placed within this territory PlaceAssetMsg.sendPlaceAssetError(origin, 57, player.getName()); // No building may be placed within this territory
return false; return false;
} }

18
src/engine/net/client/msg/WorldRealmMsg.java

@ -21,7 +21,6 @@
package engine.net.client.msg; package engine.net.client.msg;
import engine.Enum.RealmType;
import engine.net.AbstractConnection; import engine.net.AbstractConnection;
import engine.net.ByteBufferReader; import engine.net.ByteBufferReader;
import engine.net.ByteBufferWriter; import engine.net.ByteBufferWriter;
@ -67,23 +66,12 @@ public class WorldRealmMsg extends ClientNetMsg {
Realm serverRealm; Realm serverRealm;
realmCount = RealmType.values().length - 1; realmCount = Realm._realms.size();
// Realm count without seafloor
writer.putInt(realmCount); writer.putInt(realmCount);
for (RealmType realmType : RealmType.values()) { for (Realm realm : Realm._realms.values())
realm.serializeForClientMsg(writer);
realmID = realmType.getRealmID();
// Don't serialize seafloor
if (realmID == 0)
continue;
serverRealm = Realm.getRealm(realmID);
serverRealm.serializeForClientMsg(writer);
}
writer.putInt(0x0); writer.putInt(0x0);
writer.putInt(3000000); writer.putInt(3000000);

22
src/engine/objects/Realm.java

@ -21,6 +21,7 @@ import engine.powers.PowersBase;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.awt.*;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
@ -36,8 +37,9 @@ public class Realm {
// Internal class cache // Internal class cache
private static ConcurrentHashMap<Integer, Realm> _realms = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); public static ConcurrentHashMap<Integer, Realm> _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 mapR; //Red color
private final float mapG; //Green color private final float mapG; //Green color
private final float mapB; //Blue color private final float mapB; //Blue color
@ -72,6 +74,7 @@ public class Realm {
*/ */
public Realm(ResultSet rs) throws SQLException, UnknownHostException { public Realm(ResultSet rs) throws SQLException, UnknownHostException {
this.mapColor = new Color(rs.getInt("mapColor"));
this.mapR = rs.getFloat("mapR"); this.mapR = rs.getFloat("mapR");
this.mapG = rs.getFloat("mapG"); this.mapG = rs.getFloat("mapG");
this.mapB = rs.getFloat("mapB"); this.mapB = rs.getFloat("mapB");
@ -200,20 +203,9 @@ public class Realm {
public static void configureAllRealms() { public static void configureAllRealms() {
Realm serverRealm; for (Realm realm : Realm._realms.values()) {
int realmID; RealmMap.addToColorMap(realm.mapColor, realm.realmID);
realm.configure();
for (Enum.RealmType realmType : Enum.RealmType.values()) {
realmID = realmType.getRealmID();
// Don't serialize seafloor
if (realmID == 0)
continue;
serverRealm = Realm.getRealm(realmID);
serverRealm.configure();
} }
} }

10
src/engine/util/MapLoader.java

@ -4,7 +4,7 @@
package engine.util; package engine.util;
import engine.Enum.RealmType; import engine.InterestManagement.RealmMap;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import engine.server.world.WorldServer; import engine.server.world.WorldServer;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
@ -47,19 +47,13 @@ public enum MapLoader {
image = flipImage(image); image = flipImage(image);
// Initialize color lookup table
for (RealmType realm : RealmType.values()) {
realm.addToColorMap();
}
// Load spatial imageMap with color data from file // Load spatial imageMap with color data from file
for (int i = 0; i < MBServerStatics.SPATIAL_HASH_BUCKETSY; i++) { for (int i = 0; i < MBServerStatics.SPATIAL_HASH_BUCKETSY; i++) {
for (int j = 0; j < MBServerStatics.SPATIAL_HASH_BUCKETSX; j++) { for (int j = 0; j < MBServerStatics.SPATIAL_HASH_BUCKETSX; j++) {
try { try {
int rgb = image.getRGB(j, i); int rgb = image.getRGB(j, i);
realmUUID = RealmType.getRealmIDByRGB(rgb); realmUUID = RealmMap.getRealmIDByRGB(rgb);
if (realmUUID == null) { if (realmUUID == null) {
Logger.error("Corrupted png: unknown color " + rgb); Logger.error("Corrupted png: unknown color " + rgb);

Loading…
Cancel
Save