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. 47
      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 { @@ -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<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 {
PROFIT,
WEEKLY,

47
src/engine/InterestManagement/RealmMap.java

@ -9,8 +9,8 @@ @@ -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; @@ -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<Integer, Integer> _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 { @@ -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 { @@ -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);
}

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

@ -984,11 +984,7 @@ public class PlaceAssetMsgHandler extends AbstractClientMsgHandler { @@ -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 { @@ -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 { @@ -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;
}

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

@ -21,7 +21,6 @@ @@ -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 { @@ -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);

22
src/engine/objects/Realm.java

@ -21,6 +21,7 @@ import engine.powers.PowersBase; @@ -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 { @@ -36,8 +37,9 @@ public class Realm {
// 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 mapG; //Green color
private final float mapB; //Blue color
@ -72,6 +74,7 @@ public class Realm { @@ -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 { @@ -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();
}
}

10
src/engine/util/MapLoader.java

@ -4,7 +4,7 @@ @@ -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 { @@ -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 { @@ -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);

Loading…
Cancel
Save