From 7817b4cd49d03086f47780e86fd48f528f002024 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sat, 4 Feb 2023 21:43:53 -0600 Subject: [PATCH 01/50] destroyed BoW no longer count towards total available assets --- src/engine/net/client/handlers/PlaceAssetMsgHandler.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/engine/net/client/handlers/PlaceAssetMsgHandler.java b/src/engine/net/client/handlers/PlaceAssetMsgHandler.java index 98e225d1..b7889309 100644 --- a/src/engine/net/client/handlers/PlaceAssetMsgHandler.java +++ b/src/engine/net/client/handlers/PlaceAssetMsgHandler.java @@ -436,7 +436,9 @@ public class PlaceAssetMsgHandler extends AbstractClientMsgHandler { if (!building.getGuild().equals(serverCity.getGuild()) && !building.getGuild().equals(serverCity.getBane().getOwner().getGuild())) continue; - + if (building.getRank() < 0) { + continue; + } if (building.getGuild().equals(serverCity.getGuild())) defenderBuildings.add(building); From 77b3213e79a6b4c3b0937d05dc8d56d0b79a6013 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sat, 4 Feb 2023 21:44:16 -0600 Subject: [PATCH 02/50] spire effects extend to siege bounds --- src/engine/objects/City.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/objects/City.java b/src/engine/objects/City.java index 8dbe69aa..6919b137 100644 --- a/src/engine/objects/City.java +++ b/src/engine/objects/City.java @@ -872,7 +872,7 @@ public class City extends AbstractWorldObject { if (playerObject == null) continue; - if (!this.isLocationOnCityZone(playerObject.getLoc())) + if (!this.isLocationWithinSiegeBounds(playerObject.getLoc())) continue; player = (PlayerCharacter) playerObject; From abd8697d56424ad607094874812a646e94501025 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Tue, 7 Feb 2023 11:13:55 -0500 Subject: [PATCH 03/50] Testing realm renumbering --- src/engine/Enum.java | 60 ++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/engine/Enum.java b/src/engine/Enum.java index 7bfa1d5f..a702fe04 100644 --- a/src/engine/Enum.java +++ b/src/engine/Enum.java @@ -444,36 +444,36 @@ public class Enum { public enum RealmType { SEAFLOOR(0, 0x000000), - JOTUNHEIM(131, 0x006cff), - BOGLANDS(184, 0x00b4ff), - ESTRAGOTH(213, 0x00ff90), - RENNONVALE(232, 0X00ffea), - VOLGAARD(56, 0x1e00ff), - VOSTRAGOTH(108, 0x245fae), - NARROWS(61, 0x2f20a0), - FENMARCH(170, 0x3fb5ab), - MAELSTROM(63, 0x503e3e), - FARRICH(185, 0x52cd98), - TYRRANTHMINOR(96, 0x606060), - GREYSWATHE(88, 0x6c419d), - SUNSANVIL(64, 0x7800ff), - THERRONMARCH(206, 0x7bcdef), - DYVRENGISLE(119, 0x826b9c), - KINGSLUND(60, 0x871a94), - OUTERISLES(29, 0xa01313), - KAELENSFJORD(165, 0xa0c04a), - VARMADAI(95, 0xa16d1b), - WESTERMOORE(73, 0xaa3374), - OBLIVION(171, 0xababab), - SUDRAGOTH(196, 0xbaff00), - SKAARTHOL(183, 0xcfc57f), - KHALURAM(71, 0xe400ff), - VARSHADDUR(132, 0xf2845d), - FORBIDDENISLE(18, 0xff0000), - PIRATEISLES(48, 0xff008a), - SWATHMOORE(66, 0xff4200), - ESSENGLUND(130, 0xff9c00), - RELGOTH(177, 0xffde00); + 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; From 5cfb45104138764cc8bae1e1fb144f3c9ec39567 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Wed, 8 Feb 2023 09:09:54 -0500 Subject: [PATCH 04/50] Realms refactored to pull map color from database not hardcoded enum. --- src/engine/Enum.java | 71 ------------------- src/engine/InterestManagement/RealmMap.java | 47 +++++++----- .../client/handlers/PlaceAssetMsgHandler.java | 16 ++--- src/engine/net/client/msg/WorldRealmMsg.java | 18 +---- src/engine/objects/Realm.java | 22 ++---- src/engine/util/MapLoader.java | 10 +-- 6 files changed, 48 insertions(+), 136 deletions(-) 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); From f64c059f265435fd0c1df99c19ba3f9f0f650023 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Wed, 8 Feb 2023 09:27:46 -0500 Subject: [PATCH 05/50] Color map built after realms loaded. --- src/engine/InterestManagement/RealmMap.java | 9 +++++++-- src/engine/objects/Realm.java | 3 +-- src/engine/server/world/WorldServer.java | 7 +++---- src/engine/util/MapLoader.java | 17 ++++------------- 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/engine/InterestManagement/RealmMap.java b/src/engine/InterestManagement/RealmMap.java index d9ef12e5..eda74ef8 100644 --- a/src/engine/InterestManagement/RealmMap.java +++ b/src/engine/InterestManagement/RealmMap.java @@ -52,8 +52,7 @@ public enum RealmMap { if (yBuckets < 0 || yBuckets >= MBServerStatics.SPATIAL_HASH_BUCKETSY || xBuckets < 0 || xBuckets >= MBServerStatics.SPATIAL_HASH_BUCKETSX) { - Logger.error("WorldServerRealm.getRealmFromPosition", - "Invalid range; Z: " + yBuckets + ", X: " + xBuckets); + Logger.error("Invalid range; Z: " + yBuckets + ", X: " + xBuckets); return 255; } @@ -110,6 +109,12 @@ public enum RealmMap { public static void loadRealmImageMap() { + // Build color lookup map for realms from database + + for (Realm realm : Realm._realms.values()) { + RealmMap.addToColorMap(realm.mapColor, realm.realmID); + } + RealmMap._realmImageMap = MapLoader.loadMap(); } diff --git a/src/engine/objects/Realm.java b/src/engine/objects/Realm.java index 55133a12..b2f7e22b 100644 --- a/src/engine/objects/Realm.java +++ b/src/engine/objects/Realm.java @@ -65,7 +65,7 @@ public class Realm { private final int stretchY; private final int locX; private final int locY; - private final int realmID; + public final int realmID; private final HashSet cities = new HashSet<>(); private String hash; @@ -204,7 +204,6 @@ public class Realm { public static void configureAllRealms() { for (Realm realm : Realm._realms.values()) { - RealmMap.addToColorMap(realm.mapColor, realm.realmID); realm.configure(); } } diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index 8e287c10..0e663827 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -326,6 +326,9 @@ public class WorldServer { Logger.info("Loading Realms"); Realm.loadAllRealms(); + Logger.info("Loading RealmMap"); + RealmMap.loadRealmImageMap(); + Logger.info("Loading Kits"); DbManager.KitQueries.GET_ALL_KITS(); @@ -334,10 +337,6 @@ public class WorldServer { Logger.info("Starting InterestManager."); WorldGrid.startLoadJob(); - - - Logger.info("Loading Spaital Hash"); - RealmMap.loadRealmImageMap(); DbManager.MobBaseQueries.SET_AI_DEFAULTS(); diff --git a/src/engine/util/MapLoader.java b/src/engine/util/MapLoader.java index aec069b8..cdc1b503 100644 --- a/src/engine/util/MapLoader.java +++ b/src/engine/util/MapLoader.java @@ -26,8 +26,7 @@ public enum MapLoader { long timeToLoad = System.currentTimeMillis(); long bytesRead = 0; long realmsWritten = 0; - - Integer realmUUID = null; + int realmUUID; // Load image from disk @@ -54,20 +53,14 @@ public enum MapLoader { try { int rgb = image.getRGB(j, i); realmUUID = RealmMap.getRealmIDByRGB(rgb); - - if (realmUUID == null) { - Logger.error("Corrupted png: unknown color " + rgb); - WorldServer.shutdown(); - } - realmMap[j][i] = realmUUID.intValue(); + realmMap[j][i] = realmUUID; bytesRead++; - if (realmUUID.intValue() != 0) + if (realmUUID != 0) realmsWritten++; }catch (Exception e){ - // Logger.error("REALMEDIT ERROR", e.getMessage()); continue; } @@ -76,9 +69,7 @@ public enum MapLoader { } timeToLoad = System.currentTimeMillis() - timeToLoad; - Logger.info( bytesRead + " pixels processed in " + timeToLoad / 1000 + " seconds"); - Logger.info("Realm pixels written : " + realmsWritten); - image = null; + Logger.info( bytesRead + "Realm imageMNap pixels processed in " + timeToLoad / 1000 + " seconds"); return realmMap; } From 6c138a15158a39b8150a289f7006f02810c7ba50 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 10 Feb 2023 08:49:24 -0500 Subject: [PATCH 06/50] Bugfix: effects without associated powers on login. --- src/engine/objects/PlayerCharacter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/objects/PlayerCharacter.java b/src/engine/objects/PlayerCharacter.java index 1fcbd66c..a7ceb19e 100644 --- a/src/engine/objects/PlayerCharacter.java +++ b/src/engine/objects/PlayerCharacter.java @@ -2213,7 +2213,7 @@ public void dismissNecroPets() { for (Effect eff : playerCharacter.getEffects().values()) { if (eff.getPower() == null && otherPlayer) continue; - if (eff.getPower().token == 429506619) // Oblivion's Caress + if (eff.getPower() != null && eff.getPower().token == 429506619) // Oblivion's Caress continue; if ( !eff.serializeForLoad(writer)) continue; From cbe82bb95a622eceac416c396f1f88279d98a475 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sat, 11 Feb 2023 07:11:00 -0500 Subject: [PATCH 07/50] Output cleanup in ./realminfo. --- src/engine/devcmd/cmds/RealmInfoCmd.java | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/engine/devcmd/cmds/RealmInfoCmd.java b/src/engine/devcmd/cmds/RealmInfoCmd.java index 9ee6b695..5c22d4a2 100644 --- a/src/engine/devcmd/cmds/RealmInfoCmd.java +++ b/src/engine/devcmd/cmds/RealmInfoCmd.java @@ -26,43 +26,39 @@ public class RealmInfoCmd extends AbstractDevCmd { } @Override - protected void _doCmd(PlayerCharacter pc, String[] words, + protected void _doCmd(PlayerCharacter playerCharacter, String[] words, AbstractGameObject target) { Zone serverZone; - Zone parentZone; Realm serverRealm; int realmID; String outString = ""; - if (pc == null) { - throwbackError(pc, "Unable to find the pc making the request."); + if (playerCharacter == null) return; - } - serverZone = ZoneManager.findSmallestZone(pc.getLoc()); + serverZone = ZoneManager.findSmallestZone(playerCharacter.getLoc()); if (serverZone == null) { - throwbackError(pc, "Zone not found"); + throwbackError(playerCharacter, "Zone not found"); return; } - parentZone = serverZone.getParent(); - - realmID = RealmMap.getRealmIDAtLocation(pc.getLoc()); + realmID = RealmMap.getRealmIDAtLocation(playerCharacter.getLoc()); String newline = "\r\n "; outString = newline; - outString += "RealmID: " + realmID; + outString += "Realm: " + realmID + "("; serverRealm = Realm.getRealm(realmID); if (serverRealm == null) - outString += " Name: SeaFloor"; + outString += "SeaFloor"; else outString += serverRealm.getRealmName(); + outString += ")"; outString += newline; outString += " Zone: " + serverZone.getName(); @@ -76,7 +72,7 @@ public class RealmInfoCmd extends AbstractDevCmd { outString += newline; - throwbackInfo(pc, outString); + throwbackInfo(playerCharacter, outString); } @Override From 9ff4d7c6dc55f0b8594f84b55688de705b6dd904 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sat, 11 Feb 2023 13:29:12 -0500 Subject: [PATCH 08/50] bugfix: Prior claims are no longer released when claiming a new mine. --- src/engine/powers/poweractions/ClaimMinePowerAction.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/engine/powers/poweractions/ClaimMinePowerAction.java b/src/engine/powers/poweractions/ClaimMinePowerAction.java index 20929f6e..c43b5d00 100644 --- a/src/engine/powers/poweractions/ClaimMinePowerAction.java +++ b/src/engine/powers/poweractions/ClaimMinePowerAction.java @@ -50,10 +50,6 @@ public class ClaimMinePowerAction extends AbstractPowerAction { if (mine == null) return; - // Release prior claims - - Mine.releaseMineClaims(playerCharacter); - if (mine.claimMine(playerCharacter) == true) ChatManager.sendSystemMessage( (PlayerCharacter) source, "You successfully claimed this mine.."); } From 9fa83fc3592ff114404b854df082343b306c39ff Mon Sep 17 00:00:00 2001 From: MagicBot Date: Wed, 15 Feb 2023 09:18:02 -0500 Subject: [PATCH 09/50] PortalType defined to supply offset and effect bitflag for Runegates. --- src/engine/Enum.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/engine/Enum.java b/src/engine/Enum.java index d9c2bc8d..45aedb58 100644 --- a/src/engine/Enum.java +++ b/src/engine/Enum.java @@ -548,6 +548,29 @@ public class Enum { } } + public enum PortalType { + + EARTH(6f, 19.5f, 128), + AIR(-6f, 19.5f, 256), + FIRE(15f, 7.5f, 512), + WATER(-15f, 8.5f, 1024), + SPIRIT(0, 10.5f, 2048), + CHAOS(22f, 3.5f, 8192), + OBLIV(0f, 42f, 16384), + MERCHANT(-22f, 4.5f, 4096), + FORBID(0.0f, 0.0f, 0); + + public final Vector2f offset; + public final int bitFlag; + + PortalType(float offsetX, float offsetY, int bitFlag) { + + this.offset = new Vector2f(offsetX, offsetY); + this.bitFlag = bitFlag; + + } + + } public enum RunegateType { EARTH(6f, 19.5f, 128, 33213), From 2c0a46e6520a4b303eb7d59789dfaa0ce56c141b Mon Sep 17 00:00:00 2001 From: MagicBot Date: Wed, 15 Feb 2023 12:12:30 -0500 Subject: [PATCH 10/50] Runegates and portals now loaded from database. --- src/engine/Enum.java | 66 +------ src/engine/db/handlers/dbRunegateHandler.java | 73 ++++++++ src/engine/devcmd/cmds/GateInfoCmd.java | 12 +- src/engine/gameManager/DbManager.java | 2 + src/engine/gameManager/SimulationManager.java | 2 +- src/engine/jobs/CloseGateJob.java | 10 +- src/engine/net/client/ClientMessagePump.java | 14 +- src/engine/net/client/msg/WorldObjectMsg.java | 15 +- src/engine/objects/Portal.java | 92 ++-------- src/engine/objects/Runegate.java | 173 +++--------------- .../poweractions/OpenGatePowerAction.java | 30 ++- .../RunegateTeleportPowerAction.java | 15 +- 12 files changed, 163 insertions(+), 341 deletions(-) create mode 100644 src/engine/db/handlers/dbRunegateHandler.java diff --git a/src/engine/Enum.java b/src/engine/Enum.java index 45aedb58..087110d4 100644 --- a/src/engine/Enum.java +++ b/src/engine/Enum.java @@ -9,7 +9,6 @@ package engine; import ch.claude_martin.enumbitset.EnumBitSetHelper; -import engine.gameManager.BuildingManager; import engine.gameManager.PowersManager; import engine.gameManager.ZoneManager; import engine.math.Vector2f; @@ -18,7 +17,6 @@ import engine.objects.*; import engine.powers.EffectsBase; import org.pmw.tinylog.Logger; -import java.awt.*; import java.util.ArrayList; import java.util.Collections; import java.util.EnumSet; @@ -561,74 +559,16 @@ public class Enum { FORBID(0.0f, 0.0f, 0); public final Vector2f offset; - public final int bitFlag; + public final int effectFlag; - PortalType(float offsetX, float offsetY, int bitFlag) { + PortalType(float offsetX, float offsetY, int effectFlag) { this.offset = new Vector2f(offsetX, offsetY); - this.bitFlag = bitFlag; + this.effectFlag = effectFlag; } - } - public enum RunegateType { - - EARTH(6f, 19.5f, 128, 33213), - AIR(-6f, 19.5f, 256, 33170), - FIRE(15f, 7.5f, 512, 49612), - WATER(-15f, 8.5f, 1024, 53073), - SPIRIT(0, 10.5f, 2048, 33127), - CHAOS(22f, 3.5f, 8192, 58093), - OBLIV(0f, 42f, 16384, 60198), - MERCHANT(-22f, 4.5f, 4096, 60245), - FORBID(0.0f, 0.0f, 0, 54617); - - private final Vector2f offset; - private final int bitFlag; - private final int buildingUUID; - - RunegateType(float offsetX, float offsetY, int bitFlag, - int buildingUUID) { - - this.offset = new Vector2f(offsetX, offsetY); - this.bitFlag = bitFlag; - this.buildingUUID = buildingUUID; - } - - public Vector2f getOffset() { - return this.offset; - } - - public int getEffectFlag() { - return this.bitFlag; - } - - public int getGateUUID() { - return this.buildingUUID; - } - - public Building getGateBuilding() { - return BuildingManager.getBuilding(this.buildingUUID); - } - - public static RunegateType getGateTypeFromUUID(int uuid) { - - RunegateType outType = RunegateType.AIR; - - for (RunegateType gateType : RunegateType.values()) { - - if (gateType.buildingUUID == uuid) { - outType = gateType; - return outType; - } - - } - - return outType; - } - - } // Enum for ItemBase flags diff --git a/src/engine/db/handlers/dbRunegateHandler.java b/src/engine/db/handlers/dbRunegateHandler.java new file mode 100644 index 00000000..01a41a82 --- /dev/null +++ b/src/engine/db/handlers/dbRunegateHandler.java @@ -0,0 +1,73 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + + +package engine.db.handlers; + +import engine.Enum; +import engine.gameManager.DbManager; +import engine.objects.Building; +import engine.objects.Portal; +import engine.objects.Resists; + +import java.sql.Array; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +public class dbRunegateHandler extends dbHandlerBase { + + public dbRunegateHandler() { + + } + + public ArrayList GET_RUNEGATE_LIST() { + + ArrayList gateList = new ArrayList<>(); + + prepareCallable("SELECT DISTINCT `source_Building` FROM `static_runegate_portals`;"); + + try { + ResultSet rs = executeQuery(); + if (rs.next()) { + gateList.add(rs.getInt("sourceBuilding")); + } + } catch (SQLException e) { + } finally { + closeCallable(); + } + return gateList; + } + + public ArrayList GET_PORTAL_LIST(int gateUID) { + + ArrayList portalList = new ArrayList<>(); + Building sourceBuilding = (Building) DbManager.getObject(Enum.GameObjectType.Building, gateUID); + + prepareCallable("SELECT * FROM `static_runegate_portals` WHERE `sourceBuilding` = ?;"); + setInt(1, gateUID); + + try { + ResultSet rs = executeQuery(); + + if (rs.next()) { + int targetBuildingID = rs.getInt("sourceBuilding"); + Building targetBuilding = (Building) DbManager.getObject(Enum.GameObjectType.Building, targetBuildingID); + Enum.PortalType portalType = Enum.PortalType.valueOf(rs.getString("portalType")); + Portal portal = new Portal(sourceBuilding, portalType, targetBuilding); + portalList.add(portal); + } + + } catch (SQLException e) { + } finally { + closeCallable(); + } + return portalList; + } +} diff --git a/src/engine/devcmd/cmds/GateInfoCmd.java b/src/engine/devcmd/cmds/GateInfoCmd.java index 44bfcf76..bba5164d 100644 --- a/src/engine/devcmd/cmds/GateInfoCmd.java +++ b/src/engine/devcmd/cmds/GateInfoCmd.java @@ -2,7 +2,6 @@ package engine.devcmd.cmds; import engine.Enum.BuildingGroup; import engine.Enum.GameObjectType; -import engine.Enum.RunegateType; import engine.devcmd.AbstractDevCmd; import engine.math.Vector3fImmutable; import engine.objects.*; @@ -21,7 +20,6 @@ public class GateInfoCmd extends AbstractDevCmd { Building targetBuilding; String outString; - RunegateType runegateType; Runegate runeGate; Blueprint blueprint; String newline = "\r\n "; @@ -41,10 +39,10 @@ public class GateInfoCmd extends AbstractDevCmd { return; } - runegateType = RunegateType.getGateTypeFromUUID(targetBuilding.getObjectUUID()); - runeGate = Runegate.getRunegates()[runegateType.ordinal()]; + + runeGate = Runegate._runegates.get(targetBuilding.getObjectUUID()); - outString = "RungateType: " + runegateType.name(); + outString = "RungateType: " + runeGate.gateBuilding.getName(); outString += newline; outString += "Portal State:"; @@ -52,9 +50,9 @@ public class GateInfoCmd extends AbstractDevCmd { for (Portal portal : runeGate.getPortals()) { - outString += "Portal: " + portal.getPortalType().name(); + outString += "Portal: " + portal.portalType.name(); outString += " Active: " + portal.isActive(); - outString += " Dest: " + portal.getDestinationGateType().name(); + outString += " Dest: " + portal.targetGate.getName(); outString += newline; outString += " Origin: " + portal.getPortalLocation().x + 'x'; outString += " " + portal.getPortalLocation().y + 'y'; diff --git a/src/engine/gameManager/DbManager.java b/src/engine/gameManager/DbManager.java index d99bbbc9..e172f333 100644 --- a/src/engine/gameManager/DbManager.java +++ b/src/engine/gameManager/DbManager.java @@ -311,4 +311,6 @@ public enum DbManager { public static final dbBoonHandler BoonQueries = new dbBoonHandler(); public static final dbShrineHandler ShrineQueries = new dbShrineHandler(); public static final dbHeightMapHandler HeightMapQueries = new dbHeightMapHandler(); + + public static final dbRunegateHandler RunegateQueries = new dbRunegateHandler(); } diff --git a/src/engine/gameManager/SimulationManager.java b/src/engine/gameManager/SimulationManager.java index 6905c099..088e4cba 100644 --- a/src/engine/gameManager/SimulationManager.java +++ b/src/engine/gameManager/SimulationManager.java @@ -206,7 +206,7 @@ public enum SimulationManager { */ private void pulseRunegates() { - for (Runegate runegate : Runegate.getRunegates()) { + for (Runegate runegate : Runegate._runegates.values()) { runegate.collidePortals(); } diff --git a/src/engine/jobs/CloseGateJob.java b/src/engine/jobs/CloseGateJob.java index 591a4d0a..2418835e 100644 --- a/src/engine/jobs/CloseGateJob.java +++ b/src/engine/jobs/CloseGateJob.java @@ -9,7 +9,8 @@ package engine.jobs; -import engine.Enum.RunegateType; +import engine.Enum; +import engine.Enum.PortalType; import engine.job.AbstractScheduleJob; import engine.objects.Building; import engine.objects.Runegate; @@ -18,9 +19,10 @@ import org.pmw.tinylog.Logger; public class CloseGateJob extends AbstractScheduleJob { private final Building building; - private final RunegateType portalType; + private final Enum.PortalType portalType; + + public CloseGateJob(Building building, PortalType portalType) { - public CloseGateJob(Building building, RunegateType portalType) { super(); this.building = building; this.portalType = portalType; @@ -34,7 +36,7 @@ public class CloseGateJob extends AbstractScheduleJob { return; } - Runegate.getRunegates()[RunegateType.getGateTypeFromUUID(building.getObjectUUID()).ordinal()].deactivatePortal(portalType); + Runegate._runegates.get(building.getObjectUUID()).deactivatePortal(portalType); } @Override diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 70177a74..5e438484 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -2183,23 +2183,17 @@ boolean updateCity = false; Building rg = null; Vector3fImmutable rgLoc; - for (Runegate runegate : Runegate.getRunegates()) { + for (Runegate runegate : Runegate._runegates.values()) { - if ((runegate.getGateType() == RunegateType.OBLIV) || - (runegate.getGateType() == RunegateType.CHAOS)) - continue; - - for (Runegate thisGate : Runegate.getRunegates()) { - - rgLoc = thisGate.getGateType().getGateBuilding().getLoc(); + rgLoc = runegate.gateBuilding.getLoc(); float distanceSquaredToRunegate = player.getLoc().distanceSquared2D(rgLoc); if (distanceSquaredToRunegate < sqr(dist)) - rg = thisGate.getGateType().getGateBuilding(); + rg = runegate.gateBuilding; } - } + //nearest runegate found. teleport characterTarget if (rg != null) { diff --git a/src/engine/net/client/msg/WorldObjectMsg.java b/src/engine/net/client/msg/WorldObjectMsg.java index 403563e5..e77f2767 100644 --- a/src/engine/net/client/msg/WorldObjectMsg.java +++ b/src/engine/net/client/msg/WorldObjectMsg.java @@ -10,7 +10,6 @@ package engine.net.client.msg; import engine.Enum; -import engine.Enum.RunegateType; import engine.gameManager.DbManager; import engine.net.AbstractConnection; import engine.net.ByteBufferReader; @@ -128,11 +127,10 @@ public class WorldObjectMsg extends ClientNetMsg { if (this.updateRunegates) { writer.put((byte) 0); - writer.putInt(RunegateType.values().length); + writer.putInt(Runegate._runegates.values().size()); - for(RunegateType gateType : engine.Enum.RunegateType.values()) { - - Runegate.getRunegates()[gateType.ordinal()]._serializeForEnterWorld(writer); + for(Runegate runegate : Runegate._runegates.values()) { + runegate._serializeForEnterWorld(writer); } } else writer.put((byte) 1); @@ -210,11 +208,10 @@ public class WorldObjectMsg extends ClientNetMsg { // Serialize runegates - temp.putInt(RunegateType.values().length); - - for(RunegateType gateType : engine.Enum.RunegateType.values()) { + temp.putInt(Runegate._runegates.values().size()); - Runegate.getRunegates()[gateType.ordinal()]._serializeForEnterWorld(temp); + for(Runegate runegate : Runegate._runegates.values()) { + runegate._serializeForEnterWorld(temp); } ArrayList mineList = new ArrayList<>(); diff --git a/src/engine/objects/Portal.java b/src/engine/objects/Portal.java index 498e0921..666d0d2d 100644 --- a/src/engine/objects/Portal.java +++ b/src/engine/objects/Portal.java @@ -1,13 +1,13 @@ package engine.objects; -import engine.Enum.RunegateType; +import engine.Enum; +import engine.Enum.PortalType; import engine.InterestManagement.WorldGrid; import engine.gameManager.ConfigManager; import engine.job.JobScheduler; import engine.jobs.CloseGateJob; import engine.math.Vector3fImmutable; import engine.server.MBServerStatics; -import org.pmw.tinylog.Logger; import java.util.HashSet; @@ -19,28 +19,20 @@ import java.util.HashSet; public class Portal { private boolean active; - private RunegateType sourceGateType; - private RunegateType portalType; - private RunegateType destinationGateType; - private final Vector3fImmutable portalLocation; + public Enum.PortalType portalType; + public Building sourceGate; + public Building targetGate; + public final Vector3fImmutable portalLocation; private long lastActive = 0; - public Portal(RunegateType gateType, RunegateType portalType, RunegateType destinationGate) { - - Building gateBuilding; + public Portal(Building sourceGate, PortalType portalType, Building targetGate) { this.active = false; - this.sourceGateType = gateType; - this.destinationGateType = destinationGate; + this.sourceGate = sourceGate; + this.targetGate = targetGate; this.portalType = portalType; - gateBuilding = this.sourceGateType.getGateBuilding(); - - if (gateBuilding == null) { - Logger.error("Gate building " + this.sourceGateType.getGateUUID() + " for " + this.sourceGateType.name() + " missing"); - } - - this.portalLocation = gateBuilding.getLoc().add(new Vector3fImmutable(portalType.getOffset().x, 6, portalType.getOffset().y)); + this.portalLocation = sourceGate.getLoc().add(new Vector3fImmutable(portalType.offset.x, 6, portalType.offset.y)); } public boolean isActive() { @@ -51,15 +43,12 @@ public class Portal { public void deactivate() { - Building sourceBuilding; - // Remove effect bit from the runegate building, which turns off this // portal type's particle effect - sourceBuilding = this.sourceGateType.getGateBuilding(); - sourceBuilding.removeEffectBit(portalType.getEffectFlag()); + sourceGate.removeEffectBit(portalType.effectFlag); this.active = false; - sourceBuilding.updateEffects(); + sourceGate.updateEffects(); } public void activate(boolean autoClose) { @@ -70,8 +59,8 @@ public class Portal { // Apply effect bit to the runegate building, which turns on this // portal type's particle effect - sourceBuilding = this.sourceGateType.getGateBuilding(); - sourceBuilding.addEffectBit(portalType.getEffectFlag()); + + sourceGate.addEffectBit(portalType.effectFlag); this.lastActive = System.currentTimeMillis(); this.active = true; @@ -79,10 +68,10 @@ public class Portal { // tries to send a dispatch. if (ConfigManager.worldServer.isRunning == true) - sourceBuilding.updateEffects(); + sourceGate.updateEffects(); if (autoClose == true) { - CloseGateJob cgj = new CloseGateJob(sourceBuilding, portalType); + CloseGateJob cgj = new CloseGateJob(sourceGate, portalType); JobScheduler.getInstance().scheduleJob(cgj, MBServerStatics.RUNEGATE_CLOSE_TIME); } } @@ -107,59 +96,12 @@ public class Portal { if (player.getTimeStamp("lastMoveGate") < this.lastActive) return; - Building gateBuilding; - gateBuilding = destinationGateType.getGateBuilding(); - - if (gateBuilding != null){ - player.teleport(gateBuilding.getLoc()); + player.teleport(targetGate.getLoc()); player.setSafeMode(); - } } - /** - * @return the sourceGateType - */ - public RunegateType getSourceGateType() { - return sourceGateType; - } - - /** - * @param sourceGateType the sourceGateType to set - */ - public void setSourceGateType(RunegateType sourceGateType) { - this.sourceGateType = sourceGateType; - } - - /** - * @return the portalType - */ - public RunegateType getPortalType() { - return portalType; - } - - /** - * @param portalType the portalType to set - */ - public void setPortalType(RunegateType portalType) { - this.portalType = portalType; - } - - /** - * @return the destinationGateType - */ - public RunegateType getDestinationGateType() { - return destinationGateType; - } - - /** - * @param destinationGateType the destinationGateType to set - */ - public void setDestinationGateType(RunegateType destinationGateType) { - this.destinationGateType = destinationGateType; - } - /** * @return the portalLocation */ diff --git a/src/engine/objects/Runegate.java b/src/engine/objects/Runegate.java index ad67bbaf..4d38f4ec 100644 --- a/src/engine/objects/Runegate.java +++ b/src/engine/objects/Runegate.java @@ -1,61 +1,52 @@ package engine.objects; -import engine.Enum.RunegateType; -import engine.gameManager.BuildingManager; +import engine.Enum; +import engine.Enum.PortalType; +import engine.gameManager.DbManager; import engine.net.ByteBufferWriter; import java.util.ArrayList; +import java.util.HashMap; /* Runegates are tied to particular buildings at - * bootstrap. They aren't tighly coupled, with - * the Runegate merely toggling effect bits on it's - * parent building. + * bootstrap derived from the Portal creation. + * This is only to enable the toggling of effect + * bits when traveler is used. */ public class Runegate { // Runegate class Instance variables - private static final Runegate[] _runegates = new Runegate[9]; + public static HashMap _runegates = new HashMap<>(); - private final Portal[] _portals; - private final RunegateType gateType; + public Portal[] _portals; + public Building gateBuilding; - private Runegate(RunegateType gateType) { + private Runegate(Building gateBuilding) { this._portals = new Portal[8]; - this.gateType = gateType; - - // Each Runegate has a different destination - // for each portal opened. - configureGatePortals(); + this.gateBuilding = gateBuilding; // Chaos, Khar and Oblivion are on by default - _portals[RunegateType.CHAOS.ordinal()].activate(false); - _portals[RunegateType.OBLIV.ordinal()].activate(false); - _portals[RunegateType.MERCHANT.ordinal()].activate(false); + _portals[Enum.PortalType.CHAOS.ordinal()].activate(false); + _portals[Enum.PortalType.OBLIV.ordinal()].activate(false); + _portals[Enum.PortalType.MERCHANT.ordinal()].activate(false); } - public void activatePortal(RunegateType gateType) { + public void activatePortal(Enum.PortalType portalType) { - this._portals[gateType.ordinal()].activate(true); + this._portals[portalType.ordinal()].activate(true); } - public void deactivatePortal(RunegateType gateType) { - - this._portals[gateType.ordinal()].deactivate(); + public void deactivatePortal(Enum.PortalType portalType) { - } + this._portals[portalType.ordinal()].deactivate(); - public RunegateType getGateType() { - return this.gateType; } - public static Runegate[] getRunegates() { - return Runegate._runegates; - } public Portal[] getPortals() { @@ -74,17 +65,21 @@ public class Runegate { public static void loadAllRunegates() { - for (RunegateType runegateType : RunegateType.values()) { - _runegates[runegateType.ordinal()] = new Runegate(runegateType); - } + ArrayList gateList; - } + gateList = DbManager.RunegateQueries.GET_RUNEGATE_LIST(); - public void _serializeForEnterWorld(ByteBufferWriter writer) { + for (int gateID : gateList) { + + Building gateBuilding = (Building) DbManager.getObject(Enum.GameObjectType.Building, gateID); - Building gateBuilding; + Runegate runegate = new Runegate(gateBuilding); + _runegates.put(gateID, runegate); + } + + } - gateBuilding = BuildingManager.getBuilding(this.gateType.getGateUUID()); + public void _serializeForEnterWorld(ByteBufferWriter writer) { writer.putInt(gateBuilding.getObjectType().ordinal()); writer.putInt(gateBuilding.getObjectUUID()); @@ -94,114 +89,6 @@ public class Runegate { writer.putFloat(gateBuilding.getLoc().getLong()); } - private void configureGatePortals() { - - // Source gate type, portal type and destination gate type; - switch (this.gateType) { - - case EARTH: - _portals[RunegateType.EARTH.ordinal()] = new Portal(RunegateType.EARTH, RunegateType.EARTH, RunegateType.EARTH); - _portals[RunegateType.AIR.ordinal()] = new Portal(RunegateType.EARTH, RunegateType.AIR, RunegateType.AIR); - _portals[RunegateType.FIRE.ordinal()] = new Portal(RunegateType.EARTH, RunegateType.FIRE, RunegateType.FORBID); - _portals[RunegateType.WATER.ordinal()] = new Portal(RunegateType.EARTH, RunegateType.WATER, RunegateType.WATER); - _portals[RunegateType.SPIRIT.ordinal()] = new Portal(RunegateType.EARTH, RunegateType.SPIRIT, RunegateType.SPIRIT); - _portals[RunegateType.CHAOS.ordinal()] = new Portal(RunegateType.EARTH, RunegateType.CHAOS, RunegateType.CHAOS); - _portals[RunegateType.OBLIV.ordinal()] = new Portal(RunegateType.EARTH, RunegateType.OBLIV, RunegateType.OBLIV); - _portals[RunegateType.MERCHANT.ordinal()] = new Portal(RunegateType.EARTH, RunegateType.MERCHANT, RunegateType.MERCHANT); - break; - - case AIR: - _portals[RunegateType.EARTH.ordinal()] = new Portal(RunegateType.AIR, RunegateType.EARTH, RunegateType.EARTH); - _portals[RunegateType.AIR.ordinal()] = new Portal(RunegateType.AIR, RunegateType.AIR, RunegateType.FORBID); - _portals[RunegateType.FIRE.ordinal()] = new Portal(RunegateType.AIR, RunegateType.FIRE, RunegateType.FIRE); - _portals[RunegateType.WATER.ordinal()] = new Portal(RunegateType.AIR, RunegateType.WATER, RunegateType.WATER); - _portals[RunegateType.SPIRIT.ordinal()] = new Portal(RunegateType.AIR, RunegateType.SPIRIT, RunegateType.SPIRIT); - _portals[RunegateType.CHAOS.ordinal()] = new Portal(RunegateType.AIR, RunegateType.CHAOS, RunegateType.CHAOS); - _portals[RunegateType.OBLIV.ordinal()] = new Portal(RunegateType.AIR, RunegateType.OBLIV, RunegateType.OBLIV); - _portals[RunegateType.MERCHANT.ordinal()] = new Portal(RunegateType.AIR, RunegateType.MERCHANT, RunegateType.MERCHANT); - - break; - - case FIRE: - _portals[RunegateType.EARTH.ordinal()] = new Portal(RunegateType.FIRE, RunegateType.EARTH, RunegateType.EARTH); - _portals[RunegateType.AIR.ordinal()] = new Portal(RunegateType.FIRE, RunegateType.AIR, RunegateType.AIR); - _portals[RunegateType.FIRE.ordinal()] = new Portal(RunegateType.FIRE, RunegateType.FIRE, RunegateType.FORBID); - _portals[RunegateType.WATER.ordinal()] = new Portal(RunegateType.FIRE, RunegateType.WATER, RunegateType.WATER); - _portals[RunegateType.SPIRIT.ordinal()] = new Portal(RunegateType.FIRE, RunegateType.SPIRIT, RunegateType.SPIRIT); - _portals[RunegateType.CHAOS.ordinal()] = new Portal(RunegateType.FIRE, RunegateType.CHAOS, RunegateType.CHAOS); - _portals[RunegateType.OBLIV.ordinal()] = new Portal(RunegateType.FIRE, RunegateType.OBLIV, RunegateType.OBLIV); - _portals[RunegateType.MERCHANT.ordinal()] = new Portal(RunegateType.FIRE, RunegateType.MERCHANT, RunegateType.MERCHANT); - break; - - case WATER: - _portals[RunegateType.EARTH.ordinal()] = new Portal(RunegateType.WATER, RunegateType.EARTH, RunegateType.EARTH); - _portals[RunegateType.AIR.ordinal()] = new Portal(RunegateType.WATER, RunegateType.AIR, RunegateType.AIR); - _portals[RunegateType.FIRE.ordinal()] = new Portal(RunegateType.WATER, RunegateType.FIRE, RunegateType.FIRE); - _portals[RunegateType.WATER.ordinal()] = new Portal(RunegateType.WATER, RunegateType.WATER, RunegateType.FORBID); - _portals[RunegateType.SPIRIT.ordinal()] = new Portal(RunegateType.WATER, RunegateType.SPIRIT, RunegateType.SPIRIT); - _portals[RunegateType.CHAOS.ordinal()] = new Portal(RunegateType.WATER, RunegateType.CHAOS, RunegateType.CHAOS); - _portals[RunegateType.OBLIV.ordinal()] = new Portal(RunegateType.WATER, RunegateType.OBLIV, RunegateType.OBLIV); - _portals[RunegateType.MERCHANT.ordinal()] = new Portal(RunegateType.WATER, RunegateType.MERCHANT, RunegateType.MERCHANT); - break; - - case SPIRIT: - _portals[RunegateType.EARTH.ordinal()] = new Portal(RunegateType.SPIRIT, RunegateType.EARTH, RunegateType.EARTH); - _portals[RunegateType.AIR.ordinal()] = new Portal(RunegateType.SPIRIT, RunegateType.AIR, RunegateType.AIR); - _portals[RunegateType.FIRE.ordinal()] = new Portal(RunegateType.SPIRIT, RunegateType.FIRE, RunegateType.FIRE); - _portals[RunegateType.WATER.ordinal()] = new Portal(RunegateType.SPIRIT, RunegateType.WATER, RunegateType.WATER); - _portals[RunegateType.SPIRIT.ordinal()] = new Portal(RunegateType.SPIRIT, RunegateType.SPIRIT, RunegateType.FORBID); - _portals[RunegateType.CHAOS.ordinal()] = new Portal(RunegateType.SPIRIT, RunegateType.CHAOS, RunegateType.CHAOS); - _portals[RunegateType.OBLIV.ordinal()] = new Portal(RunegateType.SPIRIT, RunegateType.OBLIV, RunegateType.OBLIV); - _portals[RunegateType.MERCHANT.ordinal()] = new Portal(RunegateType.SPIRIT, RunegateType.MERCHANT, RunegateType.MERCHANT); - break; - - case CHAOS: - _portals[RunegateType.EARTH.ordinal()] = new Portal(RunegateType.CHAOS, RunegateType.EARTH, RunegateType.EARTH); - _portals[RunegateType.AIR.ordinal()] = new Portal(RunegateType.CHAOS, RunegateType.AIR, RunegateType.AIR); - _portals[RunegateType.FIRE.ordinal()] = new Portal(RunegateType.CHAOS, RunegateType.FIRE, RunegateType.FIRE); - _portals[RunegateType.WATER.ordinal()] = new Portal(RunegateType.CHAOS, RunegateType.WATER, RunegateType.WATER); - _portals[RunegateType.SPIRIT.ordinal()] = new Portal(RunegateType.CHAOS, RunegateType.SPIRIT, RunegateType.SPIRIT); - _portals[RunegateType.CHAOS.ordinal()] = new Portal(RunegateType.CHAOS, RunegateType.CHAOS, RunegateType.MERCHANT); - _portals[RunegateType.OBLIV.ordinal()] = new Portal(RunegateType.CHAOS, RunegateType.OBLIV, RunegateType.OBLIV); - _portals[RunegateType.MERCHANT.ordinal()] = new Portal(RunegateType.CHAOS, RunegateType.MERCHANT, RunegateType.MERCHANT); - break; - - case OBLIV: - _portals[RunegateType.EARTH.ordinal()] = new Portal(RunegateType.OBLIV, RunegateType.EARTH, RunegateType.EARTH); - _portals[RunegateType.AIR.ordinal()] = new Portal(RunegateType.OBLIV, RunegateType.AIR, RunegateType.AIR); - _portals[RunegateType.FIRE.ordinal()] = new Portal(RunegateType.OBLIV, RunegateType.FIRE, RunegateType.FIRE); - _portals[RunegateType.WATER.ordinal()] = new Portal(RunegateType.OBLIV, RunegateType.WATER, RunegateType.WATER); - _portals[RunegateType.SPIRIT.ordinal()] = new Portal(RunegateType.OBLIV, RunegateType.SPIRIT, RunegateType.SPIRIT); - _portals[RunegateType.CHAOS.ordinal()] = new Portal(RunegateType.OBLIV, RunegateType.CHAOS, RunegateType.CHAOS); - _portals[RunegateType.OBLIV.ordinal()] = new Portal(RunegateType.OBLIV, RunegateType.OBLIV, RunegateType.MERCHANT); - _portals[RunegateType.MERCHANT.ordinal()] = new Portal(RunegateType.OBLIV, RunegateType.MERCHANT, RunegateType.MERCHANT); - break; - - case MERCHANT: - _portals[RunegateType.EARTH.ordinal()] = new Portal(RunegateType.MERCHANT, RunegateType.EARTH, RunegateType.EARTH); - _portals[RunegateType.AIR.ordinal()] = new Portal(RunegateType.MERCHANT, RunegateType.AIR, RunegateType.AIR); - _portals[RunegateType.FIRE.ordinal()] = new Portal(RunegateType.MERCHANT, RunegateType.FIRE, RunegateType.FIRE); - _portals[RunegateType.WATER.ordinal()] = new Portal(RunegateType.MERCHANT, RunegateType.WATER, RunegateType.WATER); - _portals[RunegateType.SPIRIT.ordinal()] = new Portal(RunegateType.MERCHANT, RunegateType.SPIRIT, RunegateType.SPIRIT); - _portals[RunegateType.CHAOS.ordinal()] = new Portal(RunegateType.MERCHANT, RunegateType.CHAOS, RunegateType.CHAOS); - _portals[RunegateType.OBLIV.ordinal()] = new Portal(RunegateType.MERCHANT, RunegateType.OBLIV, RunegateType.OBLIV); - _portals[RunegateType.MERCHANT.ordinal()] = new Portal(RunegateType.MERCHANT, RunegateType.MERCHANT, RunegateType.FORBID); - break; - - case FORBID: - _portals[RunegateType.EARTH.ordinal()] = new Portal(RunegateType.FORBID, RunegateType.EARTH, RunegateType.EARTH); - _portals[RunegateType.AIR.ordinal()] = new Portal(RunegateType.FORBID, RunegateType.AIR, RunegateType.AIR); - _portals[RunegateType.FIRE.ordinal()] = new Portal(RunegateType.FORBID, RunegateType.FIRE, RunegateType.FIRE); - _portals[RunegateType.WATER.ordinal()] = new Portal(RunegateType.FORBID, RunegateType.WATER, RunegateType.WATER); - _portals[RunegateType.SPIRIT.ordinal()] = new Portal(RunegateType.FORBID, RunegateType.SPIRIT, RunegateType.SPIRIT); - _portals[RunegateType.CHAOS.ordinal()] = new Portal(RunegateType.FORBID, RunegateType.CHAOS, RunegateType.CHAOS); - _portals[RunegateType.OBLIV.ordinal()] = new Portal(RunegateType.FORBID, RunegateType.OBLIV, RunegateType.OBLIV); - _portals[RunegateType.MERCHANT.ordinal()] = new Portal(RunegateType.FORBID, RunegateType.MERCHANT, RunegateType.MERCHANT); - break; - - } - - } public static ArrayList GetAllOpenGateIDStrings(){ ArrayList openGateIDStrings = new ArrayList<>(); diff --git a/src/engine/powers/poweractions/OpenGatePowerAction.java b/src/engine/powers/poweractions/OpenGatePowerAction.java index 84032829..809bed5a 100644 --- a/src/engine/powers/poweractions/OpenGatePowerAction.java +++ b/src/engine/powers/poweractions/OpenGatePowerAction.java @@ -12,7 +12,7 @@ package engine.powers.poweractions; import engine.Enum; import engine.Enum.BuildingGroup; import engine.Enum.GameObjectType; -import engine.Enum.RunegateType; +import engine.Enum.PortalType; import engine.math.Vector3fImmutable; import engine.objects.AbstractCharacter; import engine.objects.AbstractWorldObject; @@ -44,11 +44,8 @@ public class OpenGatePowerAction extends AbstractPowerAction { if (awo.getObjectType().equals(GameObjectType.Building) == false) return; - + Building targetBuilding = (Building) awo; - Runegate runeGate; - RunegateType runegateType; - RunegateType portalType; int token; // Sanity check. @@ -69,39 +66,39 @@ public class OpenGatePowerAction extends AbstractPowerAction { // Which portal was opened? token = pb.getToken(); - portalType = RunegateType.AIR; + PortalType portalType = PortalType.AIR; switch (token) { case 428937084: //Death Gate - portalType = RunegateType.OBLIV; + portalType = PortalType.OBLIV; break; case 429756284: //Chaos Gate - portalType = RunegateType.CHAOS; + portalType = PortalType.CHAOS; break; case 429723516: //Khar Gate - portalType = RunegateType.MERCHANT; + portalType = PortalType.MERCHANT; break; case 429559676: //Spirit Gate - portalType = RunegateType.SPIRIT; + portalType = PortalType.SPIRIT; break; case 429592444: //Water Gate - portalType = RunegateType.WATER; + portalType = PortalType.WATER; break; case 429428604: //Fire Gate - portalType = RunegateType.FIRE; + portalType = PortalType.FIRE; break; case 429526908: //Air Gate - portalType = RunegateType.AIR; + portalType = PortalType.AIR; break; case 429625212: //Earth Gate - portalType = RunegateType.EARTH; + portalType = PortalType.EARTH; break; default: @@ -109,12 +106,9 @@ public class OpenGatePowerAction extends AbstractPowerAction { // Which runegate was clicked on? - runegateType = RunegateType.getGateTypeFromUUID(targetBuilding.getObjectUUID()); - runeGate = Runegate.getRunegates()[runegateType.ordinal()]; - + Runegate runeGate = Runegate._runegates.get(targetBuilding.getObjectUUID()); runeGate.activatePortal(portalType); - } @Override diff --git a/src/engine/powers/poweractions/RunegateTeleportPowerAction.java b/src/engine/powers/poweractions/RunegateTeleportPowerAction.java index 559df3f9..c41db745 100644 --- a/src/engine/powers/poweractions/RunegateTeleportPowerAction.java +++ b/src/engine/powers/poweractions/RunegateTeleportPowerAction.java @@ -10,7 +10,7 @@ package engine.powers.poweractions; import engine.Enum; -import engine.Enum.RunegateType; +import engine.Enum.PortalType; import engine.math.Vector3fImmutable; import engine.net.Dispatch; import engine.net.DispatchMessage; @@ -45,24 +45,17 @@ public class RunegateTeleportPowerAction extends AbstractPowerAction { Building rg = null; Vector3fImmutable rgLoc; - for (Runegate runegate: Runegate.getRunegates()) { + for (Runegate runegate: Runegate._runegates.values()) { - if ((runegate.getGateType() == RunegateType.OBLIV) || - (runegate.getGateType() == RunegateType.CHAOS)) - continue; - - for (Runegate thisGate : Runegate.getRunegates()) { - - rgLoc = thisGate.getGateType().getGateBuilding().getLoc(); + rgLoc = runegate.gateBuilding.getLoc(); float distanceToRunegateSquared = source.getLoc().distanceSquared2D(rgLoc); if (distanceToRunegateSquared < sqr(dist)) { dist = sqrt(distanceToRunegateSquared); - rg = thisGate.getGateType().getGateBuilding(); + rg = runegate.gateBuilding; } } - } if(source.getObjectUUID() != pc.getObjectUUID()) { pc.setTimeStampNow("PromptRecall"); From eac2e3f42b5372873487367ffb05529b91dd79b1 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Wed, 15 Feb 2023 12:29:38 -0500 Subject: [PATCH 11/50] Portal array list now filled at bootstrap. --- src/engine/db/handlers/dbRunegateHandler.java | 2 +- src/engine/objects/Runegate.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/engine/db/handlers/dbRunegateHandler.java b/src/engine/db/handlers/dbRunegateHandler.java index 01a41a82..be9bf624 100644 --- a/src/engine/db/handlers/dbRunegateHandler.java +++ b/src/engine/db/handlers/dbRunegateHandler.java @@ -31,7 +31,7 @@ public class dbRunegateHandler extends dbHandlerBase { ArrayList gateList = new ArrayList<>(); - prepareCallable("SELECT DISTINCT `source_Building` FROM `static_runegate_portals`;"); + prepareCallable("SELECT DISTINCT `sourceBuilding` FROM `static_runegate_portals`;"); try { ResultSet rs = executeQuery(); diff --git a/src/engine/objects/Runegate.java b/src/engine/objects/Runegate.java index 4d38f4ec..f55b48de 100644 --- a/src/engine/objects/Runegate.java +++ b/src/engine/objects/Runegate.java @@ -74,11 +74,21 @@ public class Runegate { Building gateBuilding = (Building) DbManager.getObject(Enum.GameObjectType.Building, gateID); Runegate runegate = new Runegate(gateBuilding); + runegate.configurePortals(); _runegates.put(gateID, runegate); } } + public void configurePortals() { + + ArrayList portalList = DbManager.RunegateQueries.GET_PORTAL_LIST(this.gateBuilding.getObjectUUID()); + + for (Portal portal : portalList) { + this._portals[portal.portalType.ordinal()] = portal; + } + } + public void _serializeForEnterWorld(ByteBufferWriter writer) { writer.putInt(gateBuilding.getObjectType().ordinal()); From 1e0738594a4bec8cc69ff0f837f9ddb82d5eae14 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Wed, 15 Feb 2023 13:10:08 -0500 Subject: [PATCH 12/50] More than one row in result set is needed. --- src/engine/db/handlers/dbRunegateHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/engine/db/handlers/dbRunegateHandler.java b/src/engine/db/handlers/dbRunegateHandler.java index be9bf624..67151bbd 100644 --- a/src/engine/db/handlers/dbRunegateHandler.java +++ b/src/engine/db/handlers/dbRunegateHandler.java @@ -35,7 +35,7 @@ public class dbRunegateHandler extends dbHandlerBase { try { ResultSet rs = executeQuery(); - if (rs.next()) { + while (rs.next()) { gateList.add(rs.getInt("sourceBuilding")); } } catch (SQLException e) { @@ -56,7 +56,7 @@ public class dbRunegateHandler extends dbHandlerBase { try { ResultSet rs = executeQuery(); - if (rs.next()) { + while (rs.next()) { int targetBuildingID = rs.getInt("sourceBuilding"); Building targetBuilding = (Building) DbManager.getObject(Enum.GameObjectType.Building, targetBuildingID); Enum.PortalType portalType = Enum.PortalType.valueOf(rs.getString("portalType")); From f1a652122cf206330ed687766195273ab93e652c Mon Sep 17 00:00:00 2001 From: MagicBot Date: Wed, 15 Feb 2023 13:38:13 -0500 Subject: [PATCH 13/50] Portals configured in the runegate constructor. --- src/engine/objects/Runegate.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/engine/objects/Runegate.java b/src/engine/objects/Runegate.java index f55b48de..59da6d10 100644 --- a/src/engine/objects/Runegate.java +++ b/src/engine/objects/Runegate.java @@ -27,6 +27,10 @@ public class Runegate { this._portals = new Portal[8]; this.gateBuilding = gateBuilding; + // Load portals for this runegate portals from the database + + configurePortals(); + // Chaos, Khar and Oblivion are on by default _portals[Enum.PortalType.CHAOS.ordinal()].activate(false); @@ -74,7 +78,6 @@ public class Runegate { Building gateBuilding = (Building) DbManager.getObject(Enum.GameObjectType.Building, gateID); Runegate runegate = new Runegate(gateBuilding); - runegate.configurePortals(); _runegates.put(gateID, runegate); } From 7b16c55dc61e98a92e0b45829f8606504e44028e Mon Sep 17 00:00:00 2001 From: MagicBot Date: Wed, 15 Feb 2023 13:49:34 -0500 Subject: [PATCH 14/50] Teleport to the target gate. --- src/engine/db/handlers/dbRunegateHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/db/handlers/dbRunegateHandler.java b/src/engine/db/handlers/dbRunegateHandler.java index 67151bbd..32ec6324 100644 --- a/src/engine/db/handlers/dbRunegateHandler.java +++ b/src/engine/db/handlers/dbRunegateHandler.java @@ -57,7 +57,7 @@ public class dbRunegateHandler extends dbHandlerBase { ResultSet rs = executeQuery(); while (rs.next()) { - int targetBuildingID = rs.getInt("sourceBuilding"); + int targetBuildingID = rs.getInt("targetBuilding"); Building targetBuilding = (Building) DbManager.getObject(Enum.GameObjectType.Building, targetBuildingID); Enum.PortalType portalType = Enum.PortalType.valueOf(rs.getString("portalType")); Portal portal = new Portal(sourceBuilding, portalType, targetBuilding); From 8dc647fb4f50637917afb8f432b212afd4555d34 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sat, 18 Feb 2023 09:30:39 -0500 Subject: [PATCH 15/50] Bugfix: empty guild not errant --- .../GuildCreationFinalizeHandler.java | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/engine/net/client/handlers/GuildCreationFinalizeHandler.java b/src/engine/net/client/handlers/GuildCreationFinalizeHandler.java index 57295aa1..29b4e055 100644 --- a/src/engine/net/client/handlers/GuildCreationFinalizeHandler.java +++ b/src/engine/net/client/handlers/GuildCreationFinalizeHandler.java @@ -54,6 +54,7 @@ public class GuildCreationFinalizeHandler extends AbstractClientMsgHandler { GuildCreationFinalizeMsg msg; Enum.GuildType charterType; Guild newGuild; + Guild playerGuild; ItemBase itemBase; Item charter; Dispatch dispatch; @@ -61,9 +62,9 @@ public class GuildCreationFinalizeHandler extends AbstractClientMsgHandler { msg = (GuildCreationFinalizeMsg) baseMsg; player = SessionManager.getPlayerCharacter(origin); + playerGuild = player.getGuild(); - boolean isGuildLeader = GuildStatusController.isGuildLeader(player.getGuildStatus()); - if (GuildStatusController.isGuildLeader(player.getGuildStatus()) || player.getGuild() != null && player.getGuild().getGuildLeaderUUID() == player.getObjectUUID()) { + if (playerGuild.isEmptyGuild() == false && player.getGuild().getGuildLeaderUUID() == player.getObjectUUID()) { ErrorPopupMsg.sendErrorPopup(player, GuildManager.MUST_LEAVE_GUILD); return true; } @@ -77,30 +78,22 @@ public class GuildCreationFinalizeHandler extends AbstractClientMsgHandler { return true; } - - itemBase = charter.getItemBase(); - // Item must be a valid charterType (type 10 in db) if (itemBase == null || (itemBase.getType().equals(ItemType.GUILDCHARTER) == false)) { ErrorPopupMsg.sendErrorPopup(player, GuildManager.NO_CHARTER_FOUND); return true; } - charterType = Enum.GuildType.getGuildTypeFromCharter(itemBase); - + charterType = Enum.GuildType.getGuildTypeFromCharter(itemBase); if (charterType == null){ ErrorPopupMsg.sendErrorPopup(player, GuildManager.NO_CHARTER_FOUND); return true; } - - - - //Validate Guild Tags if (!msg.getGuildTag().isValid()) { @@ -110,11 +103,9 @@ public class GuildCreationFinalizeHandler extends AbstractClientMsgHandler { // Validation passes. Leave current guild and create new one. - if (player.getGuild() != null && player.getGuild().getObjectUUID() != 0) + if (player.getGuild() != null && player.getGuild().isEmptyGuild() == false) player.getGuild().removePlayer(player,GuildHistoryType.LEAVE); - - int leadershipType = ((msg.getICVoteFlag() << 1) | msg.getMemberVoteFlag()); newGuild = new Guild( msg.getName(),null, charterType.ordinal(), From ecaf56f647c1ad04f0d502b091f1bbe3f006252f Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sat, 18 Feb 2023 10:54:11 -0600 Subject: [PATCH 16/50] maintenance to run on specific day of week only --- src/engine/gameManager/MaintenanceManager.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/engine/gameManager/MaintenanceManager.java b/src/engine/gameManager/MaintenanceManager.java index cecc5035..f54a904b 100644 --- a/src/engine/gameManager/MaintenanceManager.java +++ b/src/engine/gameManager/MaintenanceManager.java @@ -13,9 +13,12 @@ package engine.gameManager; import engine.Enum; import engine.objects.*; +import org.joda.time.DateTime; import org.pmw.tinylog.Logger; +import java.time.DayOfWeek; import java.time.LocalDateTime; +import java.time.temporal.TemporalAdjusters; import java.util.ArrayList; public enum MaintenanceManager { @@ -50,12 +53,12 @@ public enum MaintenanceManager { if (chargeUpkeep(building) == false) derankList.add(building); } - // Reset maintenance dates for these buildings - for (Building building : maintList) - setMaintDateTime(building, building.maintDateTime.plusDays(7)); + for (Building building : maintList) { + setMaintDateTime(building, LocalDateTime.now().plusDays(7)); + } // Derak or destroy buildings that did not // have funds available. @@ -120,6 +123,11 @@ public enum MaintenanceManager { if (building.maintDateTime.isAfter(LocalDateTime.now())) continue; + + //no maintenance if day of week doesnt match + if(LocalDateTime.now().getDayOfWeek().ordinal() != building.maintDateTime.getDayOfWeek().ordinal()){ + continue; + } // Add building to maintenance queue maintList.add(building); From 82249a6d6dd55411c5182febe7f820f667982f92 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sat, 18 Feb 2023 13:53:27 -0600 Subject: [PATCH 17/50] drop rates calculated via magicbane.conf on server boot --- src/engine/gameManager/ConfigManager.java | 13 ++++++++++--- src/engine/server/world/WorldServer.java | 9 +++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/engine/gameManager/ConfigManager.java b/src/engine/gameManager/ConfigManager.java index ec745dd7..833fdeec 100644 --- a/src/engine/gameManager/ConfigManager.java +++ b/src/engine/gameManager/ConfigManager.java @@ -14,6 +14,7 @@ package engine.gameManager; import engine.Enum; import engine.net.NetMsgHandler; +import engine.server.MBServerStatics; import engine.server.login.LoginServer; import engine.server.world.WorldServer; import org.pmw.tinylog.Logger; @@ -80,8 +81,10 @@ public enum ConfigManager { MB_MAGICBOT_RECRUIT, MB_MAGICBOT_ADMINLOG, MB_MAGICBOT_BOTVERSION, - MB_MAGICBOT_GAMEVERSION; - + MB_MAGICBOT_GAMEVERSION, + //drop rates + MB_STUFF_ACQUIRED_NORMALLY, + MB_STUFF_ACQUIRED_FROM_HOTZONE; // Map to hold our config pulled in from the environment // We also use the config to point to the current message pump // and determine the server type at runtime. @@ -93,8 +96,13 @@ public enum ConfigManager { public static LoginServer loginServer; public static Map regex = new HashMap<>(); + //drop rates pulled form config file + + public float amountOfStuffYouGetInHotzones; + // Called at bootstrap: ensures that all config values are loaded. + public static boolean init() { Logger.info("ConfigManager: init()"); @@ -112,7 +120,6 @@ public enum ConfigManager { // compile regex here regex.put(MB_LOGIN_FNAME_REGEX, Pattern.compile(MB_LOGIN_FNAME_REGEX.getValue())); - return true; } diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index 0e663827..1eaa33e8 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -482,6 +482,15 @@ public class WorldServer { Logger.info("Running garbage collection..."); System.gc(); + + //set rates from config file + Logger.info("Setting rates based on conf file..."); + MBServerStatics.EXP_RATE_MOD = Float.parseFloat(ConfigManager.MB_STUFF_ACQUIRED_NORMALLY.getValue()); + MBServerStatics.GOLD_RATE_MOD = Float.parseFloat(ConfigManager.MB_STUFF_ACQUIRED_NORMALLY.getValue()); + MBServerStatics.DROP_RATE_MOD = Float.parseFloat(ConfigManager.MB_STUFF_ACQUIRED_NORMALLY.getValue()); + MBServerStatics.HOT_EXP_RATE_MOD = Float.parseFloat(ConfigManager.MB_STUFF_ACQUIRED_FROM_HOTZONE.getValue()); + MBServerStatics.HOT_GOLD_RATE_MOD = Float.parseFloat(ConfigManager.MB_STUFF_ACQUIRED_FROM_HOTZONE.getValue()); + MBServerStatics.HOT_DROP_RATE_MOD = Float.parseFloat(ConfigManager.MB_STUFF_ACQUIRED_FROM_HOTZONE.getValue()); return true; } From 61df76c80afaabc4b4b6259e7cbfefc620af6d43 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sat, 18 Feb 2023 13:58:49 -0600 Subject: [PATCH 18/50] mines default to not be claimed at hour 1400 --- src/engine/workthreads/HourlyJobThread.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/engine/workthreads/HourlyJobThread.java b/src/engine/workthreads/HourlyJobThread.java index 059072e0..54605c20 100644 --- a/src/engine/workthreads/HourlyJobThread.java +++ b/src/engine/workthreads/HourlyJobThread.java @@ -181,7 +181,9 @@ public class HourlyJobThread implements Runnable { ArrayList mines = Mine.getMines(); for (Mine mine : mines) { - + if(LocalDateTime.now().getHour() == 1400){ + mine.wasClaimed = false; + } try { // Open Errant Mines From ffe0ecd488a9d5ce1c0836d591dcbfd790e419f6 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sat, 18 Feb 2023 14:02:35 -0600 Subject: [PATCH 19/50] name change --- src/engine/gameManager/ConfigManager.java | 4 ++-- src/engine/server/world/WorldServer.java | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/engine/gameManager/ConfigManager.java b/src/engine/gameManager/ConfigManager.java index 833fdeec..722d0731 100644 --- a/src/engine/gameManager/ConfigManager.java +++ b/src/engine/gameManager/ConfigManager.java @@ -83,8 +83,8 @@ public enum ConfigManager { MB_MAGICBOT_BOTVERSION, MB_MAGICBOT_GAMEVERSION, //drop rates - MB_STUFF_ACQUIRED_NORMALLY, - MB_STUFF_ACQUIRED_FROM_HOTZONE; + MB_NORMAL_RATE, + MB_HOTZONE_RATE; // Map to hold our config pulled in from the environment // We also use the config to point to the current message pump // and determine the server type at runtime. diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index 1eaa33e8..d261cb25 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -485,12 +485,12 @@ public class WorldServer { //set rates from config file Logger.info("Setting rates based on conf file..."); - MBServerStatics.EXP_RATE_MOD = Float.parseFloat(ConfigManager.MB_STUFF_ACQUIRED_NORMALLY.getValue()); - MBServerStatics.GOLD_RATE_MOD = Float.parseFloat(ConfigManager.MB_STUFF_ACQUIRED_NORMALLY.getValue()); - MBServerStatics.DROP_RATE_MOD = Float.parseFloat(ConfigManager.MB_STUFF_ACQUIRED_NORMALLY.getValue()); - MBServerStatics.HOT_EXP_RATE_MOD = Float.parseFloat(ConfigManager.MB_STUFF_ACQUIRED_FROM_HOTZONE.getValue()); - MBServerStatics.HOT_GOLD_RATE_MOD = Float.parseFloat(ConfigManager.MB_STUFF_ACQUIRED_FROM_HOTZONE.getValue()); - MBServerStatics.HOT_DROP_RATE_MOD = Float.parseFloat(ConfigManager.MB_STUFF_ACQUIRED_FROM_HOTZONE.getValue()); + MBServerStatics.EXP_RATE_MOD = Float.parseFloat(ConfigManager.MB_NORMAL_RATE.getValue()); + MBServerStatics.GOLD_RATE_MOD = Float.parseFloat(ConfigManager.MB_NORMAL_RATE.getValue()); + MBServerStatics.DROP_RATE_MOD = Float.parseFloat(ConfigManager.MB_NORMAL_RATE.getValue()); + MBServerStatics.HOT_EXP_RATE_MOD = Float.parseFloat(ConfigManager.MB_HOTZONE_RATE.getValue()); + MBServerStatics.HOT_GOLD_RATE_MOD = Float.parseFloat(ConfigManager.MB_HOTZONE_RATE.getValue()); + MBServerStatics.HOT_DROP_RATE_MOD = Float.parseFloat(ConfigManager.MB_HOTZONE_RATE.getValue()); return true; } From 38e25bf132b4534d2c72eaeeee072e3e2864a8c9 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sat, 18 Feb 2023 14:30:15 -0600 Subject: [PATCH 20/50] hotzone duration config, non repeating hotzones --- src/engine/gameManager/ConfigManager.java | 3 ++- src/engine/gameManager/ZoneManager.java | 7 +++++-- src/engine/objects/Zone.java | 3 ++- src/engine/workthreads/HourlyJobThread.java | 8 +++++--- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/engine/gameManager/ConfigManager.java b/src/engine/gameManager/ConfigManager.java index 722d0731..83c5d57c 100644 --- a/src/engine/gameManager/ConfigManager.java +++ b/src/engine/gameManager/ConfigManager.java @@ -84,7 +84,8 @@ public enum ConfigManager { MB_MAGICBOT_GAMEVERSION, //drop rates MB_NORMAL_RATE, - MB_HOTZONE_RATE; + MB_HOTZONE_RATE, + MB_HOTZONE_DURATION; // Map to hold our config pulled in from the environment // We also use the config to point to the current message pump // and determine the server type at runtime. diff --git a/src/engine/gameManager/ZoneManager.java b/src/engine/gameManager/ZoneManager.java index ef8c1c61..80adcd74 100644 --- a/src/engine/gameManager/ZoneManager.java +++ b/src/engine/gameManager/ZoneManager.java @@ -44,7 +44,6 @@ public enum ZoneManager { private static Set macroZones = Collections.newSetFromMap(new ConcurrentHashMap<>()); private static Set npcCityZones = Collections.newSetFromMap(new ConcurrentHashMap<>()); private static Set playerCityZones = Collections.newSetFromMap(new ConcurrentHashMap<>()); - // Find all zones coordinates fit into, starting with Sea Floor public static ArrayList getAllZonesIn(final Vector3fImmutable loc) { @@ -127,6 +126,7 @@ public enum ZoneManager { if (!zone.isMacroZone()) return; ZoneManager.hotzone = zone; + zone.hasBeenHotzone = true; } public static boolean inHotZone(final Vector3fImmutable loc) { @@ -224,7 +224,10 @@ public enum ZoneManager { if (zone.equals(ZoneManager.seaFloor)) return false; - + //no duplicate hotzones + if(zone.hasBeenHotzone == true){ + return false; + } // return false; //first time setting, accept it // if (this.hotzone.getUUID() == zone.getUUID()) // return true; //no same hotzone diff --git a/src/engine/objects/Zone.java b/src/engine/objects/Zone.java index 18cccae9..0a9c23be 100644 --- a/src/engine/objects/Zone.java +++ b/src/engine/objects/Zone.java @@ -59,7 +59,8 @@ public class Zone extends AbstractGameObject { public final Set zoneBuildingSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); public final Set zoneNPCSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); public final Set zoneMobSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); - + public boolean hasBeenHotzone = false; + public int hoursAsHotzone = 0; /** * ResultSet Constructor */ diff --git a/src/engine/workthreads/HourlyJobThread.java b/src/engine/workthreads/HourlyJobThread.java index 059072e0..0983499d 100644 --- a/src/engine/workthreads/HourlyJobThread.java +++ b/src/engine/workthreads/HourlyJobThread.java @@ -45,12 +45,14 @@ public class HourlyJobThread implements Runnable { ZoneManager.generateAndSetRandomHotzone(); Zone hotzone = ZoneManager.getHotZone(); - if (hotzone == null) { Logger.error("Null hotzone returned from mapmanager"); } else { - Logger.info("new hotzone: " + hotzone.getName()); - WorldServer.setLastHZChange(System.currentTimeMillis()); + hotzone.hoursAsHotzone += 1; + if(hotzone.hoursAsHotzone >= Integer.valueOf(ConfigManager.MB_HOTZONE_DURATION.getValue())) { + Logger.info("new hotzone: " + hotzone.getName()); + WorldServer.setLastHZChange(System.currentTimeMillis()); + } } } catch (Exception e) { From 10cd3636f722619c233f506970fea47dd0afaa06 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sat, 18 Feb 2023 15:04:34 -0600 Subject: [PATCH 21/50] hotzone cleanup --- src/engine/gameManager/ZoneManager.java | 2 ++ src/engine/objects/Zone.java | 3 ++- src/engine/workthreads/HourlyJobThread.java | 14 +++++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/engine/gameManager/ZoneManager.java b/src/engine/gameManager/ZoneManager.java index 80adcd74..41cc0cf0 100644 --- a/src/engine/gameManager/ZoneManager.java +++ b/src/engine/gameManager/ZoneManager.java @@ -20,6 +20,7 @@ import engine.server.MBServerStatics; import engine.server.world.WorldServer; import org.pmw.tinylog.Logger; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -127,6 +128,7 @@ public enum ZoneManager { return; ZoneManager.hotzone = zone; zone.hasBeenHotzone = true; + zone.becameHotzone = LocalDateTime.now(); } public static boolean inHotZone(final Vector3fImmutable loc) { diff --git a/src/engine/objects/Zone.java b/src/engine/objects/Zone.java index 0a9c23be..a758279d 100644 --- a/src/engine/objects/Zone.java +++ b/src/engine/objects/Zone.java @@ -23,6 +23,7 @@ import org.pmw.tinylog.Logger; import java.sql.ResultSet; import java.sql.SQLException; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Collections; import java.util.Set; @@ -60,7 +61,7 @@ public class Zone extends AbstractGameObject { public final Set zoneNPCSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); public final Set zoneMobSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); public boolean hasBeenHotzone = false; - public int hoursAsHotzone = 0; + public LocalDateTime becameHotzone = null; /** * ResultSet Constructor */ diff --git a/src/engine/workthreads/HourlyJobThread.java b/src/engine/workthreads/HourlyJobThread.java index 0983499d..77c86626 100644 --- a/src/engine/workthreads/HourlyJobThread.java +++ b/src/engine/workthreads/HourlyJobThread.java @@ -42,17 +42,21 @@ public class HourlyJobThread implements Runnable { Logger.info("Hourly job is now running."); try { - - ZoneManager.generateAndSetRandomHotzone(); Zone hotzone = ZoneManager.getHotZone(); + if(hotzone == null){ + //no hotzone? set one. + ZoneManager.generateAndSetRandomHotzone(); + } + int hotzoneDuration = Integer.valueOf(ConfigManager.MB_HOTZONE_DURATION.getValue()); + if(((LocalDateTime.now().getHour()) - hotzone.becameHotzone.getHour()) >= hotzoneDuration) { + ZoneManager.generateAndSetRandomHotzone(); + hotzone = ZoneManager.getHotZone(); + } if (hotzone == null) { Logger.error("Null hotzone returned from mapmanager"); } else { - hotzone.hoursAsHotzone += 1; - if(hotzone.hoursAsHotzone >= Integer.valueOf(ConfigManager.MB_HOTZONE_DURATION.getValue())) { Logger.info("new hotzone: " + hotzone.getName()); WorldServer.setLastHZChange(System.currentTimeMillis()); - } } } catch (Exception e) { From 5af1687f190be588203ce62a73cdea2a1b47c391 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 19 Feb 2023 07:48:50 -0500 Subject: [PATCH 22/50] Maintenance hour and bot/game version config entries removed. --- src/discord/handlers/StatusRequestHandler.java | 6 +----- src/engine/gameManager/ConfigManager.java | 15 +++++++-------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/discord/handlers/StatusRequestHandler.java b/src/discord/handlers/StatusRequestHandler.java index 7f173d9d..473ca172 100644 --- a/src/discord/handlers/StatusRequestHandler.java +++ b/src/discord/handlers/StatusRequestHandler.java @@ -20,12 +20,8 @@ public class StatusRequestHandler { String outString; - // Add version information - outString = "MagicBot: " + ConfigManager.MB_MAGICBOT_BOTVERSION.getValue() + "\n" + - "MagicBane: " + ConfigManager.MB_MAGICBOT_GAMEVERSION.getValue() + "\n"; - // Add server status info - outString += "\nServer Status: "; + outString = "Server Status: "; if (LoginServer.isPortInUse(Integer.parseInt(ConfigManager.MB_WORLD_PORT.getValue()))) outString += "ONLINE\n"; diff --git a/src/engine/gameManager/ConfigManager.java b/src/engine/gameManager/ConfigManager.java index 83c5d57c..adcb601c 100644 --- a/src/engine/gameManager/ConfigManager.java +++ b/src/engine/gameManager/ConfigManager.java @@ -63,10 +63,14 @@ public enum ConfigManager { MB_WORLD_UUID, MB_WORLD_WAREHOUSE_PUSH, MB_WORLD_MAINTENANCE, - MB_WORLD_MAINTENANCE_HOUR, MB_WORLD_GREETING, MB_WORLD_KEYCLONE_MAX, + //drop rates + MB_NORMAL_RATE, + MB_HOTZONE_RATE, + MB_HOTZONE_DURATION, + // MagicBot configuration. MB_MAGICBOT_SERVERID, @@ -79,13 +83,8 @@ public enum ConfigManager { MB_MAGICBOT_GENERAL, MB_MAGICBOT_FORTOFIX, MB_MAGICBOT_RECRUIT, - MB_MAGICBOT_ADMINLOG, - MB_MAGICBOT_BOTVERSION, - MB_MAGICBOT_GAMEVERSION, - //drop rates - MB_NORMAL_RATE, - MB_HOTZONE_RATE, - MB_HOTZONE_DURATION; + MB_MAGICBOT_ADMINLOG; + // Map to hold our config pulled in from the environment // We also use the config to point to the current message pump // and determine the server type at runtime. From 70ca0a1df39c7e706064b6a640c8f5c5e3c119d5 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 19 Feb 2023 08:25:58 -0500 Subject: [PATCH 23/50] Refactored caching of drop rates. Whittling away at MBServerStatics. --- src/engine/Enum.java | 33 +++++++++++++++++++++++- src/engine/devcmd/cmds/SetRateCmd.java | 15 ++++++----- src/engine/objects/Experience.java | 8 +++--- src/engine/objects/LootTable.java | 4 ++- src/engine/objects/Mob.java | 6 ++--- src/engine/server/MBServerStatics.java | 20 -------------- src/engine/server/world/WorldServer.java | 12 +++------ 7 files changed, 55 insertions(+), 43 deletions(-) diff --git a/src/engine/Enum.java b/src/engine/Enum.java index 087110d4..6c82024c 100644 --- a/src/engine/Enum.java +++ b/src/engine/Enum.java @@ -9,6 +9,7 @@ package engine; import ch.claude_martin.enumbitset.EnumBitSetHelper; +import engine.gameManager.ConfigManager; import engine.gameManager.PowersManager; import engine.gameManager.ZoneManager; import engine.math.Vector2f; @@ -2641,7 +2642,37 @@ public class Enum { ARCHER, MAGE; } - + + public enum DropRateType { + EXP_RATE_MOD, + GOLD_RATE_MOD, + DROP_RATE_MOD, + HOT_EXP_RATE_MOD, + HOT_GOLD_RATE_MOD, + HOT_DROP_RATE_MOD; + + public float rate; + + public static void init() { + + for (DropRateType rateType : DropRateType.values()) { + + switch (rateType) { + case EXP_RATE_MOD: + case GOLD_RATE_MOD: + case DROP_RATE_MOD: + rateType.rate = Float.parseFloat(ConfigManager.MB_NORMAL_RATE.getValue()); + break; + case HOT_EXP_RATE_MOD: + case HOT_GOLD_RATE_MOD: + case HOT_DROP_RATE_MOD: + rateType.rate = Float.parseFloat(ConfigManager.MB_HOTZONE_RATE.getValue()); + break; + } + } + } + } + public enum MinionType { AELFBORNGUARD(951,1637, MinionClass.MELEE, "Guard","Aelfborn"), AELFBORNMAGE(952, 1635, MinionClass.MAGE,"Adept","Aelfborn"), diff --git a/src/engine/devcmd/cmds/SetRateCmd.java b/src/engine/devcmd/cmds/SetRateCmd.java index b73c0d92..f40c627b 100644 --- a/src/engine/devcmd/cmds/SetRateCmd.java +++ b/src/engine/devcmd/cmds/SetRateCmd.java @@ -9,11 +9,12 @@ package engine.devcmd.cmds; +import engine.Enum.DropRateType; import engine.devcmd.AbstractDevCmd; import engine.objects.AbstractGameObject; import engine.objects.PlayerCharacter; import engine.server.MBServerStatics; - +import engine.server.world.WorldServer; /** * @@ -46,32 +47,32 @@ public class SetRateCmd extends AbstractDevCmd { if (args[0].equals("exp")){ - MBServerStatics.EXP_RATE_MOD = mod; + DropRateType.EXP_RATE_MOD.rate = mod; throwbackInfo(pc, "Experience Rate set to: " + mod); } else if (args[0].equals("gold")){ - MBServerStatics.GOLD_RATE_MOD = mod; + DropRateType.GOLD_RATE_MOD.rate = mod; throwbackInfo(pc, "Gold Rate set to: " + mod); } else if (args[0].equals("drop")){ - MBServerStatics.DROP_RATE_MOD = mod; + DropRateType.DROP_RATE_MOD.rate = mod; throwbackInfo(pc, "Drop Multiplier Rate set to: " + mod); } else if (args[0].equals("hotexp")){ - MBServerStatics.HOT_EXP_RATE_MOD = mod; + DropRateType.HOT_EXP_RATE_MOD.rate = mod; throwbackInfo(pc, "HOTZONE Experience Rate set to: " + mod); } else if (args[0].equals("hotgold")){ - MBServerStatics.HOT_GOLD_RATE_MOD = mod; + DropRateType.HOT_GOLD_RATE_MOD.rate = mod; throwbackInfo(pc, "HOTZONE Gold Rate set to: " + mod); } else if (args[0].equals("hotdrop")){ - MBServerStatics.HOT_DROP_RATE_MOD = mod; + DropRateType.HOT_DROP_RATE_MOD.rate = mod; throwbackInfo(pc, "HOTZONE Drop Multiplier Rate set to: " + mod); } else if (args[0].equals("production")){ diff --git a/src/engine/objects/Experience.java b/src/engine/objects/Experience.java index ab5c2789..d828c24b 100644 --- a/src/engine/objects/Experience.java +++ b/src/engine/objects/Experience.java @@ -9,10 +9,12 @@ package engine.objects; +import engine.Enum; import engine.Enum.TargetColor; import engine.gameManager.ZoneManager; import engine.math.Vector3fImmutable; import engine.server.MBServerStatics; +import engine.server.world.WorldServer; import java.util.ArrayList; import java.util.TreeMap; @@ -333,7 +335,7 @@ public class Experience { double xp = 0.0; //Get the xp modifier for the world - float xpMod = MBServerStatics.EXP_RATE_MOD; + float xpMod = Enum.DropRateType.EXP_RATE_MOD.rate; @@ -393,7 +395,7 @@ public class Experience { // Modify for hotzone if (xp != 0) if (ZoneManager.inHotZone(mob.getLoc())) - xp *= MBServerStatics.HOT_EXP_RATE_MOD; + xp *= Enum.DropRateType.HOT_EXP_RATE_MOD.rate; // Check for 0 XP due to white mob, otherwise subtract penalty // xp @@ -427,7 +429,7 @@ public class Experience { // Modify for hotzone if (ZoneManager.inHotZone(mob.getLoc())) - xp *= MBServerStatics.HOT_EXP_RATE_MOD; + xp *= Enum.DropRateType.HOT_EXP_RATE_MOD.rate; // Errant penalty if (xp != 1) diff --git a/src/engine/objects/LootTable.java b/src/engine/objects/LootTable.java index 16a9523a..acdc033d 100644 --- a/src/engine/objects/LootTable.java +++ b/src/engine/objects/LootTable.java @@ -9,12 +9,14 @@ package engine.objects; +import engine.Enum; import engine.Enum.ItemContainerType; import engine.Enum.ItemType; import engine.Enum.OwnerType; import engine.gameManager.DbManager; import engine.gameManager.ZoneManager; import engine.server.MBServerStatics; +import engine.server.world.WorldServer; import org.pmw.tinylog.Logger; import java.util.ArrayList; @@ -208,7 +210,7 @@ public class LootTable { float chance = mlb.getChance() *.01f; - chance *= MBServerStatics.DROP_RATE_MOD; + chance *= Enum.DropRateType.DROP_RATE_MOD.rate; calculatedLootTable = mlb.getLootTableID(); diff --git a/src/engine/objects/Mob.java b/src/engine/objects/Mob.java index 4f0979bd..9c28ec9f 100644 --- a/src/engine/objects/Mob.java +++ b/src/engine/objects/Mob.java @@ -1508,15 +1508,15 @@ public class Mob extends AbstractIntelligenceAgent { //server specific gold multiplier - double goldMod = MBServerStatics.GOLD_RATE_MOD; + double goldMod = DropRateType.GOLD_RATE_MOD.rate; gold *= goldMod; //modify for hotzone if (ZoneManager.inHotZone(mob.getLoc())) - gold *= MBServerStatics.HOT_GOLD_RATE_MOD; + gold *= DropRateType.HOT_GOLD_RATE_MOD.rate; - gold *= MBServerStatics.GOLD_RATE_MOD; + gold *= DropRateType.GOLD_RATE_MOD.rate; return (int) gold; } diff --git a/src/engine/server/MBServerStatics.java b/src/engine/server/MBServerStatics.java index 03f83b2a..a986901b 100644 --- a/src/engine/server/MBServerStatics.java +++ b/src/engine/server/MBServerStatics.java @@ -406,26 +406,6 @@ public class MBServerStatics { public static int SPATIAL_HASH_BUCKETSY = 12288; public static float MAX_PLAYER_X_LOC = 129999; public static float MAX_PLAYER_Y_LOC = -97000; - public static String NO_DELETE_COMBAT = "Can't delete items when in Combat with another player."; - - /* - * Rates - */ - - public static float EXP_RATE_MOD = 2f; // Probably don't want to declare - // as final. - public static float GOLD_RATE_MOD = 1.0f; // Probably don't want to declare - // as final. - public static float DROP_RATE_MOD = 1.0f; // Probably don't want to declare - // as final. - - // Hotzones - public static float HOT_EXP_RATE_MOD = 2.0f; // Probably don't want to - // declare as final. - public static float HOT_GOLD_RATE_MOD = 1.5f; // Probably don't want to - // declare as final. - public static float HOT_DROP_RATE_MOD = 1.8f; // Probably don't want to - // declare as final. /* * Ranges diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index d261cb25..dc675f45 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -483,14 +483,10 @@ public class WorldServer { Logger.info("Running garbage collection..."); System.gc(); - //set rates from config file - Logger.info("Setting rates based on conf file..."); - MBServerStatics.EXP_RATE_MOD = Float.parseFloat(ConfigManager.MB_NORMAL_RATE.getValue()); - MBServerStatics.GOLD_RATE_MOD = Float.parseFloat(ConfigManager.MB_NORMAL_RATE.getValue()); - MBServerStatics.DROP_RATE_MOD = Float.parseFloat(ConfigManager.MB_NORMAL_RATE.getValue()); - MBServerStatics.HOT_EXP_RATE_MOD = Float.parseFloat(ConfigManager.MB_HOTZONE_RATE.getValue()); - MBServerStatics.HOT_GOLD_RATE_MOD = Float.parseFloat(ConfigManager.MB_HOTZONE_RATE.getValue()); - MBServerStatics.HOT_DROP_RATE_MOD = Float.parseFloat(ConfigManager.MB_HOTZONE_RATE.getValue()); + //set drop rates from config file + + Logger.info("Setting drop rates..."); + Enum.DropRateType.init(); return true; } From d9125566f7ed87a67abc9ea577c92f70a19a729b Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 19 Feb 2023 08:39:28 -0500 Subject: [PATCH 24/50] Drop rates are set by ConfigManager --- src/engine/gameManager/ConfigManager.java | 19 +++++++++++-------- src/engine/server/world/WorldServer.java | 4 ---- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/engine/gameManager/ConfigManager.java b/src/engine/gameManager/ConfigManager.java index adcb601c..4cf9da5c 100644 --- a/src/engine/gameManager/ConfigManager.java +++ b/src/engine/gameManager/ConfigManager.java @@ -96,16 +96,12 @@ public enum ConfigManager { public static LoginServer loginServer; public static Map regex = new HashMap<>(); - //drop rates pulled form config file - - public float amountOfStuffYouGetInHotzones; - // Called at bootstrap: ensures that all config values are loaded. public static boolean init() { - Logger.info("ConfigManager: init()"); + Logger.info("Loading config from environment..."); for (ConfigManager configSetting : ConfigManager.values()) if (configMap.containsKey(configSetting.name())) @@ -117,10 +113,17 @@ public enum ConfigManager { return false; } - // compile regex here + // Setting drop rates + + Logger.info("Setting drop rates..."); + Enum.DropRateType.init(); + + // compile regex here + + Logger.info("Compiling regex"); - regex.put(MB_LOGIN_FNAME_REGEX, Pattern.compile(MB_LOGIN_FNAME_REGEX.getValue())); - return true; + regex.put(MB_LOGIN_FNAME_REGEX, Pattern.compile(MB_LOGIN_FNAME_REGEX.getValue())); + return true; } // Get the value associated with this enumeration diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index dc675f45..70a5f3fa 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -483,10 +483,6 @@ public class WorldServer { Logger.info("Running garbage collection..."); System.gc(); - //set drop rates from config file - - Logger.info("Setting drop rates..."); - Enum.DropRateType.init(); return true; } From 4db45a9cbf6ece87d8c587d379c9a0584a69c6de Mon Sep 17 00:00:00 2001 From: MagicBot Date: Wed, 22 Feb 2023 08:23:13 -0500 Subject: [PATCH 25/50] Handler created for cityDataMsg.java --- src/engine/net/client/ClientMessagePump.java | 59 ------------ src/engine/net/client/Protocol.java | 2 +- .../net/client/handlers/CityDataHandler.java | 95 +++++++++++++++++++ .../handlers/RequestEnterWorldHandler.java | 2 +- .../{WorldObjectMsg.java => cityDataMsg.java} | 10 +- 5 files changed, 102 insertions(+), 66 deletions(-) create mode 100644 src/engine/net/client/handlers/CityDataHandler.java rename src/engine/net/client/msg/{WorldObjectMsg.java => cityDataMsg.java} (95%) diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 5e438484..adbe76ee 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -97,9 +97,6 @@ public class ClientMessagePump implements NetMsgHandler { case SETSELECTEDOBECT: ClientMessagePump.targetObject((TargetObjectMsg) msg, origin); break; - case CITYDATA: - ClientMessagePump.MapData(s, origin); - break; /* * Chat @@ -351,62 +348,6 @@ public class ClientMessagePump implements NetMsgHandler { } - private static void MapData(Session s, ClientConnection origin) { - - Dispatch dispatch; -try{ - - - if (s == null || origin == null) - return; - - PlayerCharacter pc = s.getPlayerCharacter(); - - if (pc == null) - return; -boolean updateMine = false; -boolean updateCity = false; - -//do not update Cities and mines everytime you open map. only update them to client when something's changed. - long lastRefresh = pc.getTimeStamp("mineupdate"); - if (lastRefresh <= Mine.getLastChange()){ - pc.setTimeStamp("mineupdate", System.currentTimeMillis()); - updateMine = true; - } - long lastCityRefresh = pc.getTimeStamp("cityUpdate"); - if (lastCityRefresh <= City.lastCityUpdate){ - pc.setTimeStamp("cityUpdate", System.currentTimeMillis()); - updateCity = true; - } - - - - WorldObjectMsg wom = new WorldObjectMsg(s, false); - wom.updateMines(true); - wom.updateCities(updateCity); - dispatch = Dispatch.borrow(pc, wom); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - // } - - lastRefresh = pc.getTimeStamp("hotzoneupdate"); - if (lastRefresh <= WorldServer.getLastHZChange()) { - Zone hotzone = ZoneManager.getHotZone(); - if (hotzone != null) { - HotzoneChangeMsg hcm = new HotzoneChangeMsg(hotzone.getObjectType().ordinal(), hotzone.getObjectUUID()); - dispatch = Dispatch.borrow(pc, hcm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - pc.setTimeStamp("hotzoneupdate", System.currentTimeMillis() - 100); - } - } - - WorldRealmMsg wrm = new WorldRealmMsg(); - dispatch = Dispatch.borrow(pc, wrm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); -}catch(Exception e){ - e.printStackTrace(); -} - } - private static void WhoRequest(WhoRequestMsg msg, ClientConnection origin) { // Handle /who request diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 6eee1d13..70f3cf52 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -74,7 +74,7 @@ public enum Protocol { CHECKUNIQUEGUILD(0x689097D7, GuildCreationOptionsMsg.class, GuildCreationOptionsHandler.class), // Set Guild Name/Motto in Use Guild Charter CITYASSET(0x7cae1678, CityAssetMsg.class, null), CITYCHOICE(0x406610BB, CityChoiceMsg.class, CityChoiceMsgHandler.class), - CITYDATA(0xB8A947D4, WorldObjectMsg.class, null), //Realm Data - Optional(?) + CITYDATA(0xB8A947D4, cityDataMsg.class, CityDataHandler.class), CITYZONE(0x254947F2, CityZoneMsg.class, null), //For Creating City Object Clientside(Terraform)/Rename City. CLAIMASSET(0x948C62CC, ClaimAssetMsg.class, ClaimAssetMsgHandler.class), // ClaimAsset CLAIMGUILDTREE(0xFD1C6442, ClaimGuildTreeMsg.class, ClaimGuildTreeMsgHandler.class), diff --git a/src/engine/net/client/handlers/CityDataHandler.java b/src/engine/net/client/handlers/CityDataHandler.java new file mode 100644 index 00000000..cc9423c2 --- /dev/null +++ b/src/engine/net/client/handlers/CityDataHandler.java @@ -0,0 +1,95 @@ +package engine.net.client.handlers; + +import engine.Enum; +import engine.Enum.DispatchChannel; +import engine.exception.MsgSendException; +import engine.gameManager.SessionManager; +import engine.gameManager.ZoneManager; +import engine.net.Dispatch; +import engine.net.DispatchMessage; +import engine.net.client.ClientConnection; +import engine.net.client.msg.*; +import engine.objects.City; +import engine.objects.Mine; +import engine.objects.PlayerCharacter; +import engine.objects.Zone; +import engine.server.world.WorldServer; +import engine.session.Session; + +/* + * @Author: + * @Summary: Processes application protocol message which displays + * the map interface. (Zones, Cities, Realms, Hotzones) + */ + +public class CityDataHandler extends AbstractClientMsgHandler { + + public CityDataHandler() { + super(KeepAliveServerClientMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + boolean updateMine = false; + boolean updateCity = false; + Session playerSession; + PlayerCharacter playerCharacter; + Zone hotZone; + + playerCharacter = origin.getPlayerCharacter(); + + if (playerCharacter == null) + return true; + + // Session is needed as param for worldObjectMsg. + + playerSession = SessionManager.getSession(playerCharacter); + + if (playerSession == null) + return true; + + // Cache current hotZone + + hotZone = ZoneManager.getHotZone(); + + // No reason to serialize cities and mines everytime map is + // opened. Wait until something has changed. + + if (playerCharacter.getTimeStamp("mineupdate") <= Mine.getLastChange()){ + playerCharacter.setTimeStamp("mineupdate", System.currentTimeMillis()); + updateMine = true; + } + + if (playerCharacter.getTimeStamp("cityUpdate") <= City.lastCityUpdate){ + playerCharacter.setTimeStamp("cityUpdate", System.currentTimeMillis()); + updateCity = true; + } + + cityDataMsg cityDataMsg = new cityDataMsg(SessionManager.getSession(playerCharacter), false); + cityDataMsg.updateMines(updateMine); + cityDataMsg.updateCities(updateCity); + + Dispatch dispatch = Dispatch.borrow(playerCharacter, cityDataMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + if (playerCharacter.getTimeStamp("hotzoneupdate") <= WorldServer.getLastHZChange()) { + + if (hotZone != null) { + HotzoneChangeMsg hotzoneChangeMsg = new HotzoneChangeMsg(Enum.GameObjectType.Zone.ordinal(), hotZone.getObjectUUID()); + dispatch = Dispatch.borrow(playerCharacter, hotzoneChangeMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + playerCharacter.setTimeStamp("hotzoneupdate", System.currentTimeMillis() - 100); + } + } + + // Serialize the realms for this map + + WorldRealmMsg worldRealmMsg = new WorldRealmMsg(); + dispatch = Dispatch.borrow(playerCharacter, worldRealmMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + return true; + } + +} \ No newline at end of file diff --git a/src/engine/net/client/handlers/RequestEnterWorldHandler.java b/src/engine/net/client/handlers/RequestEnterWorldHandler.java index 4724439f..e40ad17a 100644 --- a/src/engine/net/client/handlers/RequestEnterWorldHandler.java +++ b/src/engine/net/client/handlers/RequestEnterWorldHandler.java @@ -99,7 +99,7 @@ public class RequestEnterWorldHandler extends AbstractClientMsgHandler { } // Object Data - WorldObjectMsg wom = new WorldObjectMsg(session, true); + cityDataMsg wom = new cityDataMsg(session, true); dispatch = Dispatch.borrow(player, wom); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); diff --git a/src/engine/net/client/msg/WorldObjectMsg.java b/src/engine/net/client/msg/cityDataMsg.java similarity index 95% rename from src/engine/net/client/msg/WorldObjectMsg.java rename to src/engine/net/client/msg/cityDataMsg.java index e77f2767..b1334ab4 100644 --- a/src/engine/net/client/msg/WorldObjectMsg.java +++ b/src/engine/net/client/msg/cityDataMsg.java @@ -27,7 +27,7 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.concurrent.ConcurrentHashMap; -public class WorldObjectMsg extends ClientNetMsg { +public class cityDataMsg extends ClientNetMsg { private Session s; private boolean forEnterWorld; @@ -49,13 +49,13 @@ public class WorldObjectMsg extends ClientNetMsg { * @param forEnterWorld * boolean flag */ - public WorldObjectMsg(Session s, boolean forEnterWorld) { + public cityDataMsg(Session s, boolean forEnterWorld) { super(Protocol.CITYDATA); this.s = s; this.forEnterWorld = forEnterWorld; } - public WorldObjectMsg(boolean updateCities, boolean updateRunegates, boolean updateMines) { + public cityDataMsg(boolean updateCities, boolean updateRunegates, boolean updateMines) { super(Protocol.CITYDATA); this.s = null; this.forEnterWorld = false; @@ -70,7 +70,7 @@ public class WorldObjectMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public WorldObjectMsg(AbstractConnection origin, ByteBufferReader reader) + public cityDataMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.CITYDATA, origin, reader); this.forEnterWorld = false; @@ -178,7 +178,7 @@ public class WorldObjectMsg extends ClientNetMsg { //Check to see if its time to renew cache. if (cachedExpireTime < System.currentTimeMillis()) { synchronized (cachedEnterWorld) { - WorldObjectMsg.attemptSerializeForEnterWorld(cachedEnterWorld); + cityDataMsg.attemptSerializeForEnterWorld(cachedEnterWorld); } cachedExpireTime = startT + 60000; } From f723e35785e0ec0269297ee64cf5e45aa002473d Mon Sep 17 00:00:00 2001 From: MagicBot Date: Wed, 22 Feb 2023 08:34:10 -0500 Subject: [PATCH 26/50] Reformatted file. --- src/engine/gameManager/ZoneManager.java | 564 +++++++++--------- src/engine/net/client/Protocol.java | 96 +-- .../net/client/handlers/CityDataHandler.java | 98 +-- src/engine/net/client/msg/cityDataMsg.java | 485 ++++++++------- src/engine/workthreads/HourlyJobThread.java | 10 +- 5 files changed, 622 insertions(+), 631 deletions(-) diff --git a/src/engine/gameManager/ZoneManager.java b/src/engine/gameManager/ZoneManager.java index 41cc0cf0..cd3ce6b4 100644 --- a/src/engine/gameManager/ZoneManager.java +++ b/src/engine/gameManager/ZoneManager.java @@ -34,409 +34,405 @@ import java.util.concurrent.ThreadLocalRandom; */ public enum ZoneManager { - ZONEMANAGER; + ZONEMANAGER; + + /* Instance variables */ + private static Zone seaFloor = null; + private static Zone hotzone = null; + private static final ConcurrentHashMap zonesByID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD); + private static final ConcurrentHashMap zonesByUUID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD); + private static final ConcurrentHashMap zonesByName = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD); + private static final Set macroZones = Collections.newSetFromMap(new ConcurrentHashMap<>()); + private static final Set npcCityZones = Collections.newSetFromMap(new ConcurrentHashMap<>()); + private static final Set playerCityZones = Collections.newSetFromMap(new ConcurrentHashMap<>()); + // Find all zones coordinates fit into, starting with Sea Floor + + public static ArrayList getAllZonesIn(final Vector3fImmutable loc) { + + ArrayList allIn = new ArrayList<>(); + Zone zone; + + zone = ZoneManager.findSmallestZone(loc); + + if (zone != null) { + allIn.add(zone); + while (zone.getParent() != null) { + zone = zone.getParent(); + allIn.add(zone); + } + } + return allIn; + } - /* Instance variables */ - private static Zone seaFloor = null; - private static Zone hotzone = null; - private static ConcurrentHashMap zonesByID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD); - private static ConcurrentHashMap zonesByUUID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD); - private static ConcurrentHashMap zonesByName = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD); - private static Set macroZones = Collections.newSetFromMap(new ConcurrentHashMap<>()); - private static Set npcCityZones = Collections.newSetFromMap(new ConcurrentHashMap<>()); - private static Set playerCityZones = Collections.newSetFromMap(new ConcurrentHashMap<>()); - // Find all zones coordinates fit into, starting with Sea Floor + // Find smallest zone coordinates fit into. - public static ArrayList getAllZonesIn(final Vector3fImmutable loc) { + public static final Zone findSmallestZone(final Vector3fImmutable loc) { - ArrayList allIn = new ArrayList<>(); - Zone zone; + Zone zone = ZoneManager.seaFloor; - zone = ZoneManager.findSmallestZone(loc); + if (zone == null) + return null; - if (zone != null) { - allIn.add(zone); - while (zone.getParent() != null) { - zone = zone.getParent(); - allIn.add(zone); - } - } - return allIn; - } + boolean childFound = true; - // Find smallest zone coordinates fit into. + while (childFound) { - public static final Zone findSmallestZone(final Vector3fImmutable loc) { + childFound = false; - Zone zone = ZoneManager.seaFloor; + ArrayList nodes = zone.getNodes(); - if (zone == null) - return null; + // Logger.info("soze", "" + nodes.size()); + if (nodes != null) + for (Zone child : nodes) { - boolean childFound = true; + if (Bounds.collide(loc, child.getBounds()) == true) { + zone = child; + childFound = true; + break; + } + } + } + return zone; + } - while (childFound) { + public static void addZone(final int zoneID, final Zone zone) { - childFound = false; + ZoneManager.zonesByID.put(zoneID, zone); - ArrayList nodes = zone.getNodes(); + if (zone != null) + ZoneManager.zonesByUUID.put(zone.getObjectUUID(), zone); - // Logger.info("soze", "" + nodes.size()); - if (nodes != null) - for (Zone child : nodes) { + ZoneManager.zonesByName.put(zone.getName().toLowerCase(), zone); - if (Bounds.collide(loc, child.getBounds()) == true) { - zone = child; - childFound = true; - break; - } - } - } - return zone; - } + } - public static void addZone(final int zoneID, final Zone zone) { + public static Zone getZoneByUUID(final int zoneUUID) { + return ZoneManager.zonesByUUID.get(zoneUUID); + } - ZoneManager.zonesByID.put(zoneID, zone); + public static Zone getZoneByZoneID(final int zoneID) { - if (zone != null) - ZoneManager.zonesByUUID.put(zone.getObjectUUID(), zone); + return ZoneManager.zonesByID.get(zoneID); + } - ZoneManager.zonesByName.put(zone.getName().toLowerCase(), zone); + public static final Collection getAllZones() { + return ZoneManager.zonesByUUID.values(); + } - } + public static final Zone getHotZone() { + return ZoneManager.hotzone; + } - public static Zone getZoneByUUID(final int zoneUUID) { - return ZoneManager.zonesByUUID.get(zoneUUID); - } + public static final void setHotZone(final Zone zone) { + if (!zone.isMacroZone()) + return; + ZoneManager.hotzone = zone; + zone.hasBeenHotzone = true; + zone.becameHotzone = LocalDateTime.now(); + } - public static Zone getZoneByZoneID(final int zoneID) { + public static boolean inHotZone(final Vector3fImmutable loc) { - return ZoneManager.zonesByID.get(zoneID); - } + if (ZoneManager.hotzone == null) + return false; - public static final Collection getAllZones() { - return ZoneManager.zonesByUUID.values(); - } + return (Bounds.collide(loc, ZoneManager.hotzone.getBounds()) == true); + } - public static final Zone getHotZone() { - return ZoneManager.hotzone; - } + public static void setSeaFloor(final Zone value) { + ZoneManager.seaFloor = value; + } - public static final void setHotZone(final Zone zone) { - if (!zone.isMacroZone()) - return; - ZoneManager.hotzone = zone; - zone.hasBeenHotzone = true; - zone.becameHotzone = LocalDateTime.now(); - } + public static Zone getSeaFloor() { + return ZoneManager.seaFloor; + } - public static boolean inHotZone(final Vector3fImmutable loc) { + public static final void populateWorldZones(final Zone zone) { - if (ZoneManager.hotzone == null) - return false; + int loadNum = zone.getLoadNum(); - return (Bounds.collide(loc, ZoneManager.hotzone.getBounds()) == true); - } + // Zones are added to separate + // collections for quick access + // based upon their type. - public static void setSeaFloor(final Zone value) { - ZoneManager.seaFloor = value; - } + if (zone.isMacroZone()) { + addMacroZone(zone); + return; + } - public static Zone getSeaFloor() { - return ZoneManager.seaFloor; - } - public static final void populateWorldZones(final Zone zone) { + if (zone.isPlayerCity()) { + addPlayerCityZone(zone); + return; + } - int loadNum = zone.getLoadNum(); + if (zone.isNPCCity()) + addNPCCityZone(zone); - // Zones are added to separate - // collections for quick access - // based upon their type. + } - if (zone.isMacroZone()) { - addMacroZone(zone); - return; - } + private static void addMacroZone(final Zone zone) { + ZoneManager.macroZones.add(zone); + } + private static void addNPCCityZone(final Zone zone) { + zone.setNPCCity(true); + ZoneManager.npcCityZones.add(zone); + } - if (zone.isPlayerCity()) { - addPlayerCityZone(zone); - return; - } + public static final void addPlayerCityZone(final Zone zone) { + zone.setPlayerCity(true); + ZoneManager.playerCityZones.add(zone); + } - if (zone.isNPCCity()) - addNPCCityZone(zone); + public static final void generateAndSetRandomHotzone() { - } + Zone hotzone; + ArrayList zoneArray = new ArrayList<>(); - private static void addMacroZone(final Zone zone) { - ZoneManager.macroZones.add(zone); - } + if (ZoneManager.macroZones.isEmpty()) + return; - private static void addNPCCityZone(final Zone zone) { - zone.setNPCCity(true); - ZoneManager.npcCityZones.add(zone); - } + for (Zone zone : ZoneManager.macroZones) { - public static final void addPlayerCityZone(final Zone zone) { - zone.setPlayerCity(true); - ZoneManager.playerCityZones.add(zone); - } + if (validHotZone(zone)) + zoneArray.add(zone.getObjectUUID()); - public static final void generateAndSetRandomHotzone() { + } - Zone hotzone; - ArrayList zoneArray = new ArrayList<>(); + int entryIndex = ThreadLocalRandom.current().nextInt(zoneArray.size()); - if (ZoneManager.macroZones.isEmpty()) - return; + hotzone = ZoneManager.getZoneByUUID(zoneArray.get(entryIndex)); - for (Zone zone : ZoneManager.macroZones) { - if (validHotZone(zone)) - zoneArray.add(zone.getObjectUUID()); + if (hotzone == null) { + Logger.error("Hotzone is null"); + return; + } - } - int entryIndex = ThreadLocalRandom.current().nextInt(zoneArray.size()); + ZoneManager.setHotZone(hotzone); + WorldServer.setLastHZChange(System.currentTimeMillis()); - hotzone = ZoneManager.getZoneByUUID(zoneArray.get(entryIndex)); + } + public static final boolean validHotZone(Zone zone) { - if (hotzone == null){ - Logger.error( "Hotzone is null"); - return; - } + if (zone.getSafeZone() == (byte) 1) + return false; // no safe zone hotzones// if (this.hotzone == null) + if (zone.getNodes().isEmpty()) + return false; - ZoneManager.setHotZone(hotzone); - WorldServer.setLastHZChange(System.currentTimeMillis()); + if (zone.equals(ZoneManager.seaFloor)) + return false; + //no duplicate hotzones + if (zone.hasBeenHotzone == true) { + return false; + } + // return false; //first time setting, accept it + // if (this.hotzone.getUUID() == zone.getUUID()) + // return true; //no same hotzone - } + if (ZoneManager.hotzone != null) + return ZoneManager.hotzone.getObjectUUID() != zone.getObjectUUID(); - public static final boolean validHotZone(Zone zone) { + return true; + } - if (zone.getSafeZone() == (byte) 1) - return false; // no safe zone hotzones// if (this.hotzone == null) + /** + * Gets a MacroZone by name. + * + * @param inputName MacroZone name to search for + * @return Zone of the MacroZone, or Null + */ + + public static Zone findMacroZoneByName(String inputName) { + synchronized (ZoneManager.macroZones) { + for (Zone zone : ZoneManager.macroZones) { + String zoneName = zone.getName(); + if (zoneName.equalsIgnoreCase(inputName)) + return zone; + } + } + return null; + } - if (zone.getNodes().isEmpty()) - return false; + // Converts world coordinates to coordinates local to a given zone. - if (zone.equals(ZoneManager.seaFloor)) - return false; - //no duplicate hotzones - if(zone.hasBeenHotzone == true){ - return false; - } - // return false; //first time setting, accept it - // if (this.hotzone.getUUID() == zone.getUUID()) - // return true; //no same hotzone + public static Vector3fImmutable worldToLocal(Vector3fImmutable worldVector, + Zone serverZone) { - if (ZoneManager.hotzone != null) - return ZoneManager.hotzone.getObjectUUID() != zone.getObjectUUID(); + Vector3fImmutable localCoords; - return true; - } + localCoords = new Vector3fImmutable(worldVector.x - serverZone.absX, + worldVector.y - serverZone.absY, worldVector.z + - serverZone.absZ); - /** - * Gets a MacroZone by name. - * - * @param inputName - * MacroZone name to search for - * @return Zone of the MacroZone, or Null - */ + return localCoords; + } - public static Zone findMacroZoneByName(String inputName) { - synchronized (ZoneManager.macroZones) { - for (Zone zone : ZoneManager.macroZones) { - String zoneName = zone.getName(); - if (zoneName.equalsIgnoreCase(inputName)) - return zone; - } - } - return null; - } + public static Vector2f worldToZoneSpace(Vector3fImmutable worldVector, + Zone serverZone) { - // Converts world coordinates to coordinates local to a given zone. + Vector2f localCoords; + Vector2f zoneOrigin; - public static Vector3fImmutable worldToLocal(Vector3fImmutable worldVector, - Zone serverZone) { + // Top left corner of zone is calculated in world space by the center and it's extents. - Vector3fImmutable localCoords; + zoneOrigin = new Vector2f(serverZone.getLoc().x, serverZone.getLoc().z); + zoneOrigin = zoneOrigin.subtract(new Vector2f(serverZone.getBounds().getHalfExtents().x, serverZone.getBounds().getHalfExtents().y)); - localCoords = new Vector3fImmutable(worldVector.x - serverZone.absX, - worldVector.y - serverZone.absY, worldVector.z - - serverZone.absZ); + // Local coordinate in world space translated to an offset from the calculated zone origin. - return localCoords; - } + localCoords = new Vector2f(worldVector.x, worldVector.z); + localCoords = localCoords.subtract(zoneOrigin); - public static Vector2f worldToZoneSpace(Vector3fImmutable worldVector, - Zone serverZone) { + localCoords.setY((serverZone.getBounds().getHalfExtents().y * 2) - localCoords.y); - Vector2f localCoords; - Vector2f zoneOrigin; - // Top left corner of zone is calculated in world space by the center and it's extents. + // TODO : Make sure this value does not go outside the zone's bounds. - zoneOrigin = new Vector2f(serverZone.getLoc().x, serverZone.getLoc().z); - zoneOrigin = zoneOrigin.subtract(new Vector2f(serverZone.getBounds().getHalfExtents().x, serverZone.getBounds().getHalfExtents().y)); + return localCoords; + } - // Local coordinate in world space translated to an offset from the calculated zone origin. + // Converts local zone coordinates to world coordinates - localCoords = new Vector2f(worldVector.x, worldVector.z); - localCoords = localCoords.subtract(zoneOrigin); + public static Vector3fImmutable localToWorld(Vector3fImmutable worldVector, + Zone serverZone) { - localCoords.setY((serverZone.getBounds().getHalfExtents().y * 2) - localCoords.y); + Vector3fImmutable worldCoords; + worldCoords = new Vector3fImmutable(worldVector.x + serverZone.absX, + worldVector.y + serverZone.absY, worldVector.z + + serverZone.absZ); + return worldCoords; + } - // TODO : Make sure this value does not go outside the zone's bounds. + /** + * Converts from local (relative to this building) to world. + * + * @param localPos position in local reference (relative to this building) + * @return position relative to world + */ - return localCoords; - } + public static Vector3fImmutable convertLocalToWorld(Building building, Vector3fImmutable localPos) { - // Converts local zone coordinates to world coordinates + // convert from SB rotation value to radians - public static Vector3fImmutable localToWorld(Vector3fImmutable worldVector, - Zone serverZone) { - Vector3fImmutable worldCoords; + if (building.getBounds().getQuaternion() == null) + return building.getLoc(); + Vector3fImmutable rotatedLocal = Vector3fImmutable.rotateAroundPoint(Vector3fImmutable.ZERO, localPos, building.getBounds().getQuaternion()); + // handle building rotation + // handle building translation - worldCoords = new Vector3fImmutable(worldVector.x + serverZone.absX, - worldVector.y + serverZone.absY, worldVector.z - + serverZone.absZ); + return building.getLoc().add(rotatedLocal.x, rotatedLocal.y, rotatedLocal.z); + } - return worldCoords; - } + //used for regions, Building bounds not set yet. + public static Vector3f convertLocalToWorld(Building building, Vector3f localPos, Bounds bounds) { - /** - * Converts from local (relative to this building) to world. - * - * @param localPos position in local reference (relative to this building) - * @return position relative to world - */ + // convert from SB rotation value to radians - public static Vector3fImmutable convertLocalToWorld(Building building, Vector3fImmutable localPos) { - // convert from SB rotation value to radians - - - if (building.getBounds().getQuaternion() == null) - return building.getLoc(); - Vector3fImmutable rotatedLocal = Vector3fImmutable.rotateAroundPoint(Vector3fImmutable.ZERO, localPos, building.getBounds().getQuaternion()); - // handle building rotation - // handle building translation + Vector3f rotatedLocal = Vector3f.rotateAroundPoint(Vector3f.ZERO, localPos, bounds.getQuaternion()); + // handle building rotation + // handle building translation - return building.getLoc().add(rotatedLocal.x, rotatedLocal.y,rotatedLocal.z); - } - - - //used for regions, Building bounds not set yet. - public static Vector3f convertLocalToWorld(Building building, Vector3f localPos, Bounds bounds) { + return new Vector3f(building.getLoc().add(rotatedLocal.x, rotatedLocal.y, rotatedLocal.z)); + } - // convert from SB rotation value to radians - - - Vector3f rotatedLocal = Vector3f.rotateAroundPoint(Vector3f.ZERO, localPos, bounds.getQuaternion()); - // handle building rotation - // handle building translation + public static Vector3fImmutable convertWorldToLocal(Building building, Vector3fImmutable WorldPos) { + Vector3fImmutable convertLoc = Vector3fImmutable.rotateAroundPoint(building.getLoc(), WorldPos, -building.getBounds().getQuaternion().angleY); - return new Vector3f(building.getLoc().add(rotatedLocal.x, rotatedLocal.y,rotatedLocal.z)); - } - public static Vector3fImmutable convertWorldToLocal(Building building, Vector3fImmutable WorldPos) { - Vector3fImmutable convertLoc = Vector3fImmutable.rotateAroundPoint(building.getLoc(),WorldPos,-building.getBounds().getQuaternion().angleY); - - - convertLoc = convertLoc.subtract(building.getLoc()); + convertLoc = convertLoc.subtract(building.getLoc()); - // convert from SB rotation value to radians - - return convertLoc; + // convert from SB rotation value to radians - } + return convertLoc; - public static Vector3fImmutable convertNPCLoc(Building building, Vector3fImmutable npcLoc) { + } - return Vector3fImmutable.rotateAroundPoint(Vector3fImmutable.ZERO, npcLoc, -building.getBounds().getQuaternion().angleY); + public static Vector3fImmutable convertNPCLoc(Building building, Vector3fImmutable npcLoc) { - } + return Vector3fImmutable.rotateAroundPoint(Vector3fImmutable.ZERO, npcLoc, -building.getBounds().getQuaternion().angleY); - // Method returns a city if the given location is within - // a city siege radius. + } + + // Method returns a city if the given location is within + // a city siege radius. + + public static City getCityAtLocation(Vector3fImmutable worldLoc) { + + Zone currentZone; + ArrayList zoneList; + City city; - public static City getCityAtLocation(Vector3fImmutable worldLoc) { + currentZone = ZoneManager.findSmallestZone(worldLoc); - Zone currentZone; - ArrayList zoneList; - City city; + if (currentZone.isPlayerCity()) + return City.getCity(currentZone.getPlayerCityUUID()); - currentZone = ZoneManager.findSmallestZone(worldLoc); + // Not currently on a city grid. Test nearby cities + // to see if we are on one of their seige bounds. - if (currentZone.isPlayerCity()) - return City.getCity(currentZone.getPlayerCityUUID()); + zoneList = currentZone.getNodes(); - // Not currently on a city grid. Test nearby cities - // to see if we are on one of their seige bounds. + for (Zone zone : zoneList) { - zoneList = currentZone.getNodes(); + if (zone == currentZone) + continue; - for (Zone zone : zoneList) { + if (zone.isPlayerCity() == false) + continue; - if (zone == currentZone) - continue; + city = City.getCity(zone.getPlayerCityUUID()); + + if (worldLoc.isInsideCircle(city.getLoc(), Enum.CityBoundsType.SIEGE.extents)) + return city; + } + + return null; + } - if (zone.isPlayerCity() == false) - continue; + /* Method is called when creating a new player city to + * validate that the new zone does not overlap any other + * zone that might currently exist + */ - city = City.getCity(zone.getPlayerCityUUID()); + public static boolean validTreePlacementLoc(Zone currentZone, float positionX, float positionZ) { - if (worldLoc.isInsideCircle(city.getLoc(), Enum.CityBoundsType.SIEGE.extents)) - return city; - } + // Member Variable declaration - return null; - } + ArrayList zoneList; + boolean validLocation = true; + Bounds treeBounds; - /* Method is called when creating a new player city to - * validate that the new zone does not overlap any other - * zone that might currently exist - */ + if (currentZone.isContininent() == false) + return false; - public static boolean validTreePlacementLoc(Zone currentZone, float positionX, float positionZ) { - // Member Variable declaration + treeBounds = Bounds.borrow(); + treeBounds.setBounds(new Vector2f(positionX, positionZ), new Vector2f(Enum.CityBoundsType.SIEGE.extents, Enum.CityBoundsType.SIEGE.extents), 0.0f); - ArrayList zoneList; - boolean validLocation = true; - Bounds treeBounds; - - if (currentZone.isContininent() == false) - return false; - - - treeBounds = Bounds.borrow(); - treeBounds.setBounds(new Vector2f(positionX, positionZ), new Vector2f(Enum.CityBoundsType.SIEGE.extents, Enum.CityBoundsType.SIEGE.extents), 0.0f); + zoneList = currentZone.getNodes(); - zoneList = currentZone.getNodes(); - - - for (Zone zone : zoneList) { + for (Zone zone : zoneList) { - if (zone.isContininent()) - continue; + if (zone.isContininent()) + continue; - if (Bounds.collide(treeBounds, zone.getBounds(), 0.0f)) - validLocation = false; - } + if (Bounds.collide(treeBounds, zone.getBounds(), 0.0f)) + validLocation = false; + } - treeBounds.release(); - return validLocation; + treeBounds.release(); + return validLocation; } } diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 70f3cf52..c26d31f8 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -26,14 +26,14 @@ public enum Protocol { ACTIVATECHARTER(0x296C0B22, UseCharterMsg.class, null),// Use Guild Charter ACTIVATENPC(0xC9AAE81E, ActivateNPCMessage.class, ActivateNPCMsgHandler.class), ACTIVATEPLEDGE(0x5A694DC0, SwearInMsg.class, SwearInHandler.class), // Swear In - ADDFRIEND(0xCFA1C787,AddFriendMessage.class,null), - ALLIANCECHANGE(0x0E7D0B57, AllianceChangeMsg.class, AllianceChangeMsgHandler.class), // Remove From Allies/Enemies List + ADDFRIEND(0xCFA1C787, AddFriendMessage.class, null), + ALLIANCECHANGE(0x0E7D0B57, AllianceChangeMsg.class, AllianceChangeMsgHandler.class), // Remove From Allies/Enemies List ALLYENEMYLIST(0xAEA443FD, AllyEnemyListMsg.class, AllyEnemyListMsgHandler.class), - ARCCOMBATMODEATTACKING(0xD8B10579, SetCombatModeMsg.class, null), // Attack From Outside Combat Mode + ARCCOMBATMODEATTACKING(0xD8B10579, SetCombatModeMsg.class, null), // Attack From Outside Combat Mode ARCHOTZONECHANGE(0xDCFF196F, null, null), //change hotzone ARCIGNORELISTUPDATE(0x4B1B17C2, IgnoreListMsg.class, null), //req/show ignore list ARCLOGINNOTIFY(0x010FED87, ArcLoginNotifyMsg.class, ArcLoginNotifyMsgHandler.class), //Client Confirms entering world - ARCMINECHANGEPRODUCTION(0x1EAA993F, ArcMineChangeProductionMsg.class, ArcMineChangeProductionMsgHandler.class), + ARCMINECHANGEPRODUCTION(0x1EAA993F, ArcMineChangeProductionMsg.class, ArcMineChangeProductionMsgHandler.class), ARCMINETOWERCRESTUPDATE(0x34164D0D, null, null), ARCMINEWINDOWAVAILABLETIME(0x6C909DE7, ArcMineWindowAvailableTimeMsg.class, ArcMineWindowAvailableTimeHandler.class), ARCMINEWINDOWCHANGE(0x92B2148A, ArcMineWindowChangeMsg.class, MineWindowChangeHandler.class), @@ -62,7 +62,7 @@ public enum Protocol { CHANNELMUTE(0xC1BDC53A, ChatFilterMsg.class, ChannelMuteMsgHandler.class), //Chat Channels that are turned on CHARSELECTSCREEN(0x682C935D, null, null), // Character Selection Screen CHATCITY(0x9D402901, ChatCityMsg.class, null), // Chat Channel: /City - CHATCSR(0x14EBA1C3, ChatCSRMsg.class, null), //Chat Channel: CSR + CHATCSR(0x14EBA1C3, ChatCSRMsg.class, null), //Chat Channel: CSR CHATGROUP(0xA895B634, ChatGroupMsg.class, null), // Chat Channel: /group CHATGUILD(0xA9D92ED4, ChatGuildMsg.class, null), // Chat Channel: /guild CHATIC(0x00A75F35, ChatICMsg.class, null), // Chat Channel: /IC @@ -78,13 +78,13 @@ public enum Protocol { CITYZONE(0x254947F2, CityZoneMsg.class, null), //For Creating City Object Clientside(Terraform)/Rename City. CLAIMASSET(0x948C62CC, ClaimAssetMsg.class, ClaimAssetMsgHandler.class), // ClaimAsset CLAIMGUILDTREE(0xFD1C6442, ClaimGuildTreeMsg.class, ClaimGuildTreeMsgHandler.class), - CLIENTADMINCOMMAND(0x624EAB5F, ClientAdminCommandMsg.class, null), //Admin Command - CLIENTUPDATEVAULT( 0x66EDBECD, UpdateVaultMsg.class, null), + CLIENTADMINCOMMAND(0x624EAB5F, ClientAdminCommandMsg.class, null), //Admin Command + CLIENTUPDATEVAULT(0x66EDBECD, UpdateVaultMsg.class, null), COMBATMODE(0xFE4BF353, ToggleCombatMsg.class, null), //Toggle Combat mode CONFIRMPROMOTE(0x153BB5F9, ConfirmPromoteMsg.class, null), COSTTOOPENBANK(0x135BE5E8, AckBankWindowOpenedMsg.class, null), // ACK Bank Window Opened CREATECHAR(0x5D18B5C8, CommitNewCharacterMsg.class, null), // Commit New Character, - CREATEPETITION(0xD489CFED, GuildCreationFinalizeMsg.class, GuildCreationFinalizeHandler.class), //Confirm guild creation + CREATEPETITION(0xD489CFED, GuildCreationFinalizeMsg.class, GuildCreationFinalizeHandler.class), //Confirm guild creation CUSTOMERPETITION(0x7F9D7D6D, PetitionReceivedMsg.class, null), DELETEOBJECT(0x57F069D8, DeleteItemMsg.class, null), //Delete Item from Inventory DESTROYBUILDING(0x3CB6FAD3, DestroyBuildingMsg.class, DestroyBuildingHandler.class), // Destroy Building @@ -95,8 +95,8 @@ public enum Protocol { EQUIP(0x3CB1AF8C, TransferItemFromInventoryToEquipMsg.class, null), // Transfer Item from Inventory to Equip EXPERIENCE(0xC57802A7, GrantExperienceMsg.class, null), //TODO rename once identified FORGETOBJECTS(0xE307A0E1, UnloadObjectsMsg.class, null), // Unload Objects - FRIENDACCEPT(0xCA297870,AcceptFriendMsg.class,FriendAcceptHandler.class), - FRIENDDECLINE(0xF08FC279,DeclineFriendMsg.class,FriendDeclineHandler.class), + FRIENDACCEPT(0xCA297870, AcceptFriendMsg.class, FriendAcceptHandler.class), + FRIENDDECLINE(0xF08FC279, DeclineFriendMsg.class, FriendDeclineHandler.class), FURNITURE(0xCE7FA503, FurnitureMsg.class, FurnitureHandler.class), GAMESERVERIPRESPONSE(0x6C95CF87, GameServerIPResponseMsg.class, null), // Game Server IP Response GLOBALCHANNELMESSAGE(0x2bf03fd2, null, null), @@ -109,7 +109,7 @@ public enum Protocol { GUILDMEMBERONLINE(0x7B79EB3A, GuildEnterWorldMsg.class, null), // Send Enter World Message to Guild GUILDRANKCHANGE(0x0DEFB21F, ChangeRankMsg.class, ChangeRankHandler.class), // Change Rank GUILDTREESTATUS(0x4B95FB85, GuildTreeStatusMsg.class, null), - HIRELINGSERVICE(0xD3D93322,HirelingServiceMsg.class,HirelingServiceMsgHandler.class), + HIRELINGSERVICE(0xD3D93322, HirelingServiceMsg.class, HirelingServiceMsgHandler.class), IGNORE(0xBD8881EE, IgnoreMsg.class, null), //client sent /ignore command INITIATETRADEHUDS(0x667D29D8, OpenTradeWindowMsg.class, null), // Open Trade Window INVITEGROUP(0x004A2012, GroupInviteMsg.class, GroupInviteHandler.class), // Send/Receive/Deny Group Invite @@ -164,11 +164,11 @@ public enum Protocol { RAISEATTR(0x5EEB65E0, ModifyStatMsg.class, null), // Modify Stat RANDOM(0xAC5D0135, RandomMsg.class, null), //RequestSend random roll READYTOENTER(0x490E4FE0, EnterWorldReceivedMsg.class, null), //Client Ack Receive Enter World - REALMDATA(0x2399B775, null, null), //Realm Data - Optional(?) + REALMDATA(0x2399B775, null, null), //Realm Data - Optional(?) RECOMMENDNATION(0x6D4579E9, RecommendNationMsg.class, RecommendNationMsgHandler.class), // Recommend as Ally/Enemy, error RECYCLEPOWER(0x24033B67, RecyclePowerMsg.class, null), //Unlock power for reUse REMOVECHAR(0x5D3F9739, DeleteCharacterMsg.class, null), // Delete Character - REMOVEFRIEND(0xE0D5DB42,RemoveFriendMessage.class,RemoveFriendHandler.class), + REMOVEFRIEND(0xE0D5DB42, RemoveFriendMessage.class, RemoveFriendHandler.class), REPAIRBUILDING(0xAF8C2560, RepairBuildingMsg.class, RepairBuildingMsgHandler.class), REPAIROBJECT(0x782219CE, RepairMsg.class, null), //Repair Window Req/Ack, RepairObject item Req/Ack REQUESTCONTENTS(0xA786B0A2, LootWindowRequestMsg.class, null), // MoveObjectToContainer Window Request @@ -179,7 +179,7 @@ public enum Protocol { REQUESTTOTRADE(0x4D84259B, TradeRequestMsg.class, null), // Trade Request REQUESTTRADECANCEL(0xCB0C5735, RejectTradeRequestMsg.class, null), // Reject RequestToTrade REQUESTTRADEOK(0xFFD29841, AcceptTradeRequestMsg.class, null), // Accept Trade Request - RESETAFTERDEATH(0xFDCBB98F,RespawnMsg.class, null), //Respawn Request/Response + RESETAFTERDEATH(0xFDCBB98F, RespawnMsg.class, null), //Respawn Request/Response ROTATEMSG(0x57F2088E, RotateObjectMsg.class, null), SAFEMODE(0x9CF3922A, SafeModeMsg.class, null), //Tell client they're in safe mode SCALEOBJECT(0xE2B392D9, null, null), // Adjust scale of object @@ -210,7 +210,7 @@ public enum Protocol { TAXCITY(0xCD41EAA6, TaxCityMsg.class, TaxCityMsgHandler.class), TAXRESOURCES(0x4AD458AF, TaxResourcesMsg.class, TaxResourcesMsgHandler.class), TELEPORT(0x23E726EA, TeleportToPointMsg.class, null), // Teleport to point - TERRITORYCHANGE(0x6B388C8C,TerritoryChangeMessage.class, null), //Hey rich, look what I found? :) + TERRITORYCHANGE(0x6B388C8C, TerritoryChangeMessage.class, null), //Hey rich, look what I found? :) TOGGLESITSTAND(0x624F3C0F, ToggleSitStandMsg.class, null), //Toggle Sit/Stand TRADEADDGOLD(0x654ACB45, AddGoldToTradeWindowMsg.class, null), // Add Gold to Trade Window TRADEADDOBJECT(0x55D363E9, AddItemToTradeWindowMsg.class, null), // Add an Item to the Trade Window @@ -227,7 +227,7 @@ public enum Protocol { TRANSFERITEMFROMVAULTTOINVENTORY(0x0119A64D, TransferItemFromVaultToInventoryMsg.class, null), // Transfer Item from Vault to Inventory TRANSFERITEMTOBANK(0xD48C46FA, TransferItemFromInventoryToBankMsg.class, null), // Transfer Item from Inventory to Bank UNEQUIP(0xC6BFB907, TransferItemFromEquipToInventoryMsg.class, null), // Transfer Item from Equip to Inventory - UNKNOWN(0x238C9259, UnknownMsg.class,null), + UNKNOWN(0x238C9259, UnknownMsg.class, null), UPDATECHARORMOB(0xB6D78961, null, null), UPDATECLIENTALLIANCES(0xF3FEB5D4, null, GuildUnknownHandler.class), //AlliancesMsg UPDATECLIENTINVENTORIES(0xE66F533D, UpdateInventoryMsg.class, null), //Update player inventory @@ -247,14 +247,14 @@ public enum Protocol { WEIGHTINVENTORY(0xF1B6A85C, LootWindowResponseMsg.class, null), // MoveObjectToContainer Window Response WHOREQUEST(0xF431CCE9, WhoRequestMsg.class, null), // Request /who WHORESPONSE(0xD7C36568, WhoResponseMsg.class, null), // Response /who - REQUESTBALLLIST(0xE366FF64,RequestBallListMessage.class,RequestBallListHandler.class), - SENDBALLENTRY(0xAC2B5EDC,SendBallEntryMessage.class,SendBallEntryHandler.class), - UNKNOWN1(-263523523, Unknown1Msg.class,null), - DROPGOLD(1461654160,DropGoldMsg.class,null); + REQUESTBALLLIST(0xE366FF64, RequestBallListMessage.class, RequestBallListHandler.class), + SENDBALLENTRY(0xAC2B5EDC, SendBallEntryMessage.class, SendBallEntryHandler.class), + UNKNOWN1(-263523523, Unknown1Msg.class, null), + DROPGOLD(1461654160, DropGoldMsg.class, null); public int opcode; - private Class message; - private Class handlerClass; + private final Class message; + private final Class handlerClass; public Constructor constructor; public AbstractClientMsgHandler handler; @@ -275,7 +275,7 @@ public enum Protocol { } } - // Create instance of message handler for incoming protocol messages + // Create instance of message handler for incoming protocol messages if (this.handlerClass != null) { try { @@ -286,7 +286,7 @@ public enum Protocol { } } - private static HashMap _protocolMsgByOpcode = new HashMap<>(); + private static final HashMap _protocolMsgByOpcode = new HashMap<>(); public static Protocol getByOpcode(int opcode) { @@ -302,37 +302,37 @@ public enum Protocol { for (Protocol protocol : Protocol.values()) { - if (_protocolMsgByOpcode.containsKey(protocol.opcode)){ - Logger.error("Duplicate opcodes for " + protocol.name() + " and " + _protocolMsgByOpcode.get(protocol.opcode).name()); - } + if (_protocolMsgByOpcode.containsKey(protocol.opcode)) { + Logger.error("Duplicate opcodes for " + protocol.name() + " and " + _protocolMsgByOpcode.get(protocol.opcode).name()); + } _protocolMsgByOpcode.put(protocol.opcode, protocol); } } -public static int FindNextValidOpcode(ByteBufferReader reader){ - int startPos = reader.position(); - int bytesLeft = reader.remaining(); + public static int FindNextValidOpcode(ByteBufferReader reader) { + int startPos = reader.position(); + int bytesLeft = reader.remaining(); - if (bytesLeft < 4) - return startPos; - int nextPos = startPos; - for (int i = 1; i< bytesLeft; i++ ){ - reader.position(nextPos); - if (reader.remaining() < 4) - return reader.position(); - int newOpcode = reader.getInt(); + if (bytesLeft < 4) + return startPos; + int nextPos = startPos; + for (int i = 1; i < bytesLeft; i++) { + reader.position(nextPos); + if (reader.remaining() < 4) + return reader.position(); + int newOpcode = reader.getInt(); - Protocol foundProtocol = Protocol.getByOpcode(newOpcode); - if (foundProtocol.equals(Protocol.NONE)){ - nextPos += 1; - continue; - } + Protocol foundProtocol = Protocol.getByOpcode(newOpcode); + if (foundProtocol.equals(Protocol.NONE)) { + nextPos += 1; + continue; + } - //found opcode. return position - 4 to rewind back to start of opcode, so we can handle it. - return reader.position() - 4; - } + //found opcode. return position - 4 to rewind back to start of opcode, so we can handle it. + return reader.position() - 4; + } - return startPos; -} + return startPos; + } } diff --git a/src/engine/net/client/handlers/CityDataHandler.java b/src/engine/net/client/handlers/CityDataHandler.java index cc9423c2..3706d798 100644 --- a/src/engine/net/client/handlers/CityDataHandler.java +++ b/src/engine/net/client/handlers/CityDataHandler.java @@ -19,77 +19,77 @@ import engine.session.Session; /* * @Author: * @Summary: Processes application protocol message which displays - * the map interface. (Zones, Cities, Realms, Hotzones) + * the map interface. (Zones, Cities, Realms, Hot-zones) */ public class CityDataHandler extends AbstractClientMsgHandler { - public CityDataHandler() { - super(KeepAliveServerClientMsg.class); - } + public CityDataHandler() { + super(KeepAliveServerClientMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - boolean updateMine = false; - boolean updateCity = false; - Session playerSession; - PlayerCharacter playerCharacter; - Zone hotZone; + boolean updateMine = false; + boolean updateCity = false; + Session playerSession; + PlayerCharacter playerCharacter; + Zone hotZone; - playerCharacter = origin.getPlayerCharacter(); + playerCharacter = origin.getPlayerCharacter(); - if (playerCharacter == null) - return true; + if (playerCharacter == null) + return true; - // Session is needed as param for worldObjectMsg. + // Session is needed as param for worldObjectMsg. - playerSession = SessionManager.getSession(playerCharacter); + playerSession = SessionManager.getSession(playerCharacter); - if (playerSession == null) - return true; + if (playerSession == null) + return true; - // Cache current hotZone + // Cache current hotZone - hotZone = ZoneManager.getHotZone(); + hotZone = ZoneManager.getHotZone(); - // No reason to serialize cities and mines everytime map is - // opened. Wait until something has changed. + // No reason to serialize cities and mines everytime map is + // opened. Wait until something has changed. - if (playerCharacter.getTimeStamp("mineupdate") <= Mine.getLastChange()){ - playerCharacter.setTimeStamp("mineupdate", System.currentTimeMillis()); - updateMine = true; - } + if (playerCharacter.getTimeStamp("mineupdate") <= Mine.getLastChange()) { + playerCharacter.setTimeStamp("mineupdate", System.currentTimeMillis()); + updateMine = true; + } - if (playerCharacter.getTimeStamp("cityUpdate") <= City.lastCityUpdate){ - playerCharacter.setTimeStamp("cityUpdate", System.currentTimeMillis()); - updateCity = true; - } + if (playerCharacter.getTimeStamp("cityUpdate") <= City.lastCityUpdate) { + playerCharacter.setTimeStamp("cityUpdate", System.currentTimeMillis()); + updateCity = true; + } - cityDataMsg cityDataMsg = new cityDataMsg(SessionManager.getSession(playerCharacter), false); - cityDataMsg.updateMines(updateMine); - cityDataMsg.updateCities(updateCity); + cityDataMsg cityDataMsg = new cityDataMsg(SessionManager.getSession(playerCharacter), false); + cityDataMsg.updateMines(updateMine); + cityDataMsg.updateCities(updateCity); - Dispatch dispatch = Dispatch.borrow(playerCharacter, cityDataMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + Dispatch dispatch = Dispatch.borrow(playerCharacter, cityDataMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - if (playerCharacter.getTimeStamp("hotzoneupdate") <= WorldServer.getLastHZChange()) { + if (playerCharacter.getTimeStamp("hotzoneupdate") <= WorldServer.getLastHZChange()) { - if (hotZone != null) { - HotzoneChangeMsg hotzoneChangeMsg = new HotzoneChangeMsg(Enum.GameObjectType.Zone.ordinal(), hotZone.getObjectUUID()); - dispatch = Dispatch.borrow(playerCharacter, hotzoneChangeMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - playerCharacter.setTimeStamp("hotzoneupdate", System.currentTimeMillis() - 100); - } - } + if (hotZone != null) { + HotzoneChangeMsg hotzoneChangeMsg = new HotzoneChangeMsg(Enum.GameObjectType.Zone.ordinal(), hotZone.getObjectUUID()); + dispatch = Dispatch.borrow(playerCharacter, hotzoneChangeMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + playerCharacter.setTimeStamp("hotzoneupdate", System.currentTimeMillis() - 100); + } + } - // Serialize the realms for this map + // Serialize the realms for this map - WorldRealmMsg worldRealmMsg = new WorldRealmMsg(); - dispatch = Dispatch.borrow(playerCharacter, worldRealmMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + WorldRealmMsg worldRealmMsg = new WorldRealmMsg(); + dispatch = Dispatch.borrow(playerCharacter, worldRealmMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - } + return true; + } } \ No newline at end of file diff --git a/src/engine/net/client/msg/cityDataMsg.java b/src/engine/net/client/msg/cityDataMsg.java index b1334ab4..f8ca702c 100644 --- a/src/engine/net/client/msg/cityDataMsg.java +++ b/src/engine/net/client/msg/cityDataMsg.java @@ -29,251 +29,246 @@ import java.util.concurrent.ConcurrentHashMap; public class cityDataMsg extends ClientNetMsg { - private Session s; - private boolean forEnterWorld; - private static ByteBuffer cachedEnterWorld; - private static long cachedExpireTime; - - public static final long wdComp = 0xFF00FF0000000003L; - private static byte ver = 1; - - private boolean updateCities = false; - private boolean updateRunegates = false; - private boolean updateMines = false; - - /** - * This is the general purpose constructor. - * - * @param s - * Session - * @param forEnterWorld - * boolean flag - */ - public cityDataMsg(Session s, boolean forEnterWorld) { - super(Protocol.CITYDATA); - this.s = s; - this.forEnterWorld = forEnterWorld; - } - - public cityDataMsg(boolean updateCities, boolean updateRunegates, boolean updateMines) { - super(Protocol.CITYDATA); - this.s = null; - this.forEnterWorld = false; - this.updateCities = updateCities; - this.updateRunegates = updateRunegates; - this.updateMines = updateMines; - } - - /** - * This constructor is used by NetMsgFactory. It attempts to deserialize the - * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading - * past the limit) then this constructor Throws that Exception to the - * caller. - */ - public cityDataMsg(AbstractConnection origin, ByteBufferReader reader) - { - super(Protocol.CITYDATA, origin, reader); - this.forEnterWorld = false; - } - - @Override - protected int getPowerOfTwoBufferSize() { - return (18); // 2^14 == 16384 - } - - /** - * Serializes the subclass specific items to the supplied NetMsgWriter. - */ - @Override - protected void _serialize(ByteBufferWriter writer) { - if (this.forEnterWorld) - serializeForEnterWorld(writer); - else - serializeForMapUpdate(writer); - } - - /** - * Specific use serializer - * - * @param writer - */ - private void serializeForMapUpdate(ByteBufferWriter writer) { - - //Handle City updates - - if (this.updateCities) { - writer.put((byte) 0); - ArrayList cityList = new ArrayList<>(); - ConcurrentHashMap map = DbManager.getMap(Enum.GameObjectType.City); - if (map != null) { - for (AbstractGameObject ago : map.values()) - if (ago.getObjectType().equals(Enum.GameObjectType.City)) - cityList.add((City)ago); - - writer.putInt(cityList.size()); - for (City city: cityList){ - City.serializeForClientMsg(city, writer); - } - - } else { - Logger.error("missing city map"); - writer.putInt(0); - } - } else - writer.put((byte) 1); - - - //Handle Runegate updates - if (this.updateRunegates) { - - writer.put((byte) 0); - writer.putInt(Runegate._runegates.values().size()); - - for(Runegate runegate : Runegate._runegates.values()) { - runegate._serializeForEnterWorld(writer); - } - } else - writer.put((byte) 1); - - - //Handle Mine updates - try{ - if (this.updateMines) { - ArrayList mineList = new ArrayList<>(); - for (Mine toAdd: Mine.mineMap.keySet()){ - mineList.add(toAdd); - } - - writer.putInt(mineList.size()); - for (Mine mine: mineList) - Mine.serializeForClientMsg(mine, writer); - } else - writer.putInt(0); - }catch(Exception e){ - Logger.error(e); - } - - - - writer.put((byte) 0); // PAD - } - - /** - * Specific use serializer - * - * @param writer - */ - private void serializeForEnterWorld(ByteBufferWriter writer) { - if (s == null || s.getPlayerCharacter() == null) - return; - - long startT = System.currentTimeMillis(); - - if (cachedEnterWorld == null) { - // Never before been cached, so init stuff - cachedEnterWorld = Network.byteBufferPool.getBuffer(19); - cachedExpireTime = 0L; - } - - //Check to see if its time to renew cache. - if (cachedExpireTime < System.currentTimeMillis()) { - synchronized (cachedEnterWorld) { - cityDataMsg.attemptSerializeForEnterWorld(cachedEnterWorld); - } - cachedExpireTime = startT + 60000; - } - - writer.putBB(cachedEnterWorld); - - } - - private static void attemptSerializeForEnterWorld(ByteBuffer bb) { - bb.clear(); - ByteBufferWriter temp = new ByteBufferWriter(bb); - temp.put((byte) 0); // PAD - - - ArrayList cityList = new ArrayList<>(); - ConcurrentHashMap map = DbManager.getMap(Enum.GameObjectType.City); - for (AbstractGameObject ago : map.values()) - - if (ago.getObjectType().equals(Enum.GameObjectType.City)) - cityList.add((City)ago); - - temp.putInt(cityList.size()); - - for (City city: cityList) - City.serializeForClientMsg(city, temp); - temp.put((byte) 0); // PAD - - // Serialize runegates - - temp.putInt(Runegate._runegates.values().size()); - - for(Runegate runegate : Runegate._runegates.values()) { - runegate._serializeForEnterWorld(temp); - } - - ArrayList mineList = new ArrayList<>(); - for (Mine toAdd : Mine.mineMap.keySet()){ - mineList.add(toAdd); - } - - temp.putInt(mineList.size()); - for (Mine mine: mineList) - Mine.serializeForClientMsg(mine, temp); - temp.put((byte) 0); // PAD - } - - /** - * Deserializes the subclass specific items from the supplied NetMsgReader. - */ - @Override - protected void _deserialize(ByteBufferReader reader) - { - // Client only sends 11 bytes. - - byte type = reader.get(); - - if (type == 1){ - reader.get(); - reader.get(); - reader.getInt(); - - }else{ - reader.get(); - reader.getInt(); - reader.get(); - reader.getInt(); - } - - } - - /** - * @return the s - */ - public Session getS() { - return s; - } - - /** - * @return the forEnterWorld - */ - public boolean isForEnterWorld() { - return forEnterWorld; - } - - public void updateCities(boolean value) { - this.updateCities = value; - } - - public void updateRunegates(boolean value) { - this.updateRunegates = value; - } - - public void updateMines(boolean value) { - this.updateMines = value; - } + private Session s; + private final boolean forEnterWorld; + private static ByteBuffer cachedEnterWorld; + private static long cachedExpireTime; + + public static final long wdComp = 0xFF00FF0000000003L; + private static final byte ver = 1; + + private boolean updateCities = false; + private boolean updateRunegates = false; + private boolean updateMines = false; + + /** + * This is the general purpose constructor. + * + * @param s Session + * @param forEnterWorld boolean flag + */ + public cityDataMsg(Session s, boolean forEnterWorld) { + super(Protocol.CITYDATA); + this.s = s; + this.forEnterWorld = forEnterWorld; + } + + public cityDataMsg(boolean updateCities, boolean updateRunegates, boolean updateMines) { + super(Protocol.CITYDATA); + this.s = null; + this.forEnterWorld = false; + this.updateCities = updateCities; + this.updateRunegates = updateRunegates; + this.updateMines = updateMines; + } + + /** + * This constructor is used by NetMsgFactory. It attempts to deserialize the + * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading + * past the limit) then this constructor Throws that Exception to the + * caller. + */ + public cityDataMsg(AbstractConnection origin, ByteBufferReader reader) { + super(Protocol.CITYDATA, origin, reader); + this.forEnterWorld = false; + } + + @Override + protected int getPowerOfTwoBufferSize() { + return (18); // 2^14 == 16384 + } + + /** + * Serializes the subclass specific items to the supplied NetMsgWriter. + */ + @Override + protected void _serialize(ByteBufferWriter writer) { + if (this.forEnterWorld) + serializeForEnterWorld(writer); + else + serializeForMapUpdate(writer); + } + + /** + * Specific use serializer + * + * @param writer + */ + private void serializeForMapUpdate(ByteBufferWriter writer) { + + //Handle City updates + + if (this.updateCities) { + writer.put((byte) 0); + ArrayList cityList = new ArrayList<>(); + ConcurrentHashMap map = DbManager.getMap(Enum.GameObjectType.City); + if (map != null) { + for (AbstractGameObject ago : map.values()) + if (ago.getObjectType().equals(Enum.GameObjectType.City)) + cityList.add((City) ago); + + writer.putInt(cityList.size()); + for (City city : cityList) { + City.serializeForClientMsg(city, writer); + } + + } else { + Logger.error("missing city map"); + writer.putInt(0); + } + } else + writer.put((byte) 1); + + + //Handle Runegate updates + if (this.updateRunegates) { + + writer.put((byte) 0); + writer.putInt(Runegate._runegates.values().size()); + + for (Runegate runegate : Runegate._runegates.values()) { + runegate._serializeForEnterWorld(writer); + } + } else + writer.put((byte) 1); + + + //Handle Mine updates + try { + if (this.updateMines) { + ArrayList mineList = new ArrayList<>(); + for (Mine toAdd : Mine.mineMap.keySet()) { + mineList.add(toAdd); + } + + writer.putInt(mineList.size()); + for (Mine mine : mineList) + Mine.serializeForClientMsg(mine, writer); + } else + writer.putInt(0); + } catch (Exception e) { + Logger.error(e); + } + + + writer.put((byte) 0); // PAD + } + + /** + * Specific use serializer + * + * @param writer + */ + private void serializeForEnterWorld(ByteBufferWriter writer) { + if (s == null || s.getPlayerCharacter() == null) + return; + + long startT = System.currentTimeMillis(); + + if (cachedEnterWorld == null) { + // Never before been cached, so init stuff + cachedEnterWorld = Network.byteBufferPool.getBuffer(19); + cachedExpireTime = 0L; + } + + //Check to see if its time to renew cache. + if (cachedExpireTime < System.currentTimeMillis()) { + synchronized (cachedEnterWorld) { + cityDataMsg.attemptSerializeForEnterWorld(cachedEnterWorld); + } + cachedExpireTime = startT + 60000; + } + + writer.putBB(cachedEnterWorld); + + } + + private static void attemptSerializeForEnterWorld(ByteBuffer bb) { + bb.clear(); + ByteBufferWriter temp = new ByteBufferWriter(bb); + temp.put((byte) 0); // PAD + + + ArrayList cityList = new ArrayList<>(); + ConcurrentHashMap map = DbManager.getMap(Enum.GameObjectType.City); + for (AbstractGameObject ago : map.values()) + + if (ago.getObjectType().equals(Enum.GameObjectType.City)) + cityList.add((City) ago); + + temp.putInt(cityList.size()); + + for (City city : cityList) + City.serializeForClientMsg(city, temp); + temp.put((byte) 0); // PAD + + // Serialize runegates + + temp.putInt(Runegate._runegates.values().size()); + + for (Runegate runegate : Runegate._runegates.values()) { + runegate._serializeForEnterWorld(temp); + } + + ArrayList mineList = new ArrayList<>(); + for (Mine toAdd : Mine.mineMap.keySet()) { + mineList.add(toAdd); + } + + temp.putInt(mineList.size()); + for (Mine mine : mineList) + Mine.serializeForClientMsg(mine, temp); + temp.put((byte) 0); // PAD + } + + /** + * Deserializes the subclass specific items from the supplied NetMsgReader. + */ + @Override + protected void _deserialize(ByteBufferReader reader) { + // Client only sends 11 bytes. + + byte type = reader.get(); + + if (type == 1) { + reader.get(); + reader.get(); + reader.getInt(); + + } else { + reader.get(); + reader.getInt(); + reader.get(); + reader.getInt(); + } + + } + + /** + * @return the s + */ + public Session getS() { + return s; + } + + /** + * @return the forEnterWorld + */ + public boolean isForEnterWorld() { + return forEnterWorld; + } + + public void updateCities(boolean value) { + this.updateCities = value; + } + + public void updateRunegates(boolean value) { + this.updateRunegates = value; + } + + public void updateMines(boolean value) { + this.updateMines = value; + } } diff --git a/src/engine/workthreads/HourlyJobThread.java b/src/engine/workthreads/HourlyJobThread.java index b46e93d7..c7387576 100644 --- a/src/engine/workthreads/HourlyJobThread.java +++ b/src/engine/workthreads/HourlyJobThread.java @@ -43,20 +43,20 @@ public class HourlyJobThread implements Runnable { try { Zone hotzone = ZoneManager.getHotZone(); - if(hotzone == null){ + if (hotzone == null) { //no hotzone? set one. ZoneManager.generateAndSetRandomHotzone(); } int hotzoneDuration = Integer.valueOf(ConfigManager.MB_HOTZONE_DURATION.getValue()); - if(((LocalDateTime.now().getHour()) - hotzone.becameHotzone.getHour()) >= hotzoneDuration) { + if (((LocalDateTime.now().getHour()) - hotzone.becameHotzone.getHour()) >= hotzoneDuration) { ZoneManager.generateAndSetRandomHotzone(); hotzone = ZoneManager.getHotZone(); } if (hotzone == null) { Logger.error("Null hotzone returned from mapmanager"); } else { - Logger.info("new hotzone: " + hotzone.getName()); - WorldServer.setLastHZChange(System.currentTimeMillis()); + Logger.info("new hotzone: " + hotzone.getName()); + WorldServer.setLastHZChange(System.currentTimeMillis()); } } catch (Exception e) { @@ -187,7 +187,7 @@ public class HourlyJobThread implements Runnable { ArrayList mines = Mine.getMines(); for (Mine mine : mines) { - if(LocalDateTime.now().getHour() == 1400){ + if (LocalDateTime.now().getHour() == 1400) { mine.wasClaimed = false; } try { From 6ac1911770d34f3c32b201f34c23595406645fc6 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Wed, 22 Feb 2023 08:38:18 -0500 Subject: [PATCH 27/50] Code cleanup; reworked conditional. --- src/engine/net/client/handlers/CityDataHandler.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/engine/net/client/handlers/CityDataHandler.java b/src/engine/net/client/handlers/CityDataHandler.java index 3706d798..1b304b30 100644 --- a/src/engine/net/client/handlers/CityDataHandler.java +++ b/src/engine/net/client/handlers/CityDataHandler.java @@ -36,6 +36,7 @@ public class CityDataHandler extends AbstractClientMsgHandler { Session playerSession; PlayerCharacter playerCharacter; Zone hotZone; + Dispatch dispatch; playerCharacter = origin.getPlayerCharacter(); @@ -70,17 +71,16 @@ public class CityDataHandler extends AbstractClientMsgHandler { cityDataMsg.updateMines(updateMine); cityDataMsg.updateCities(updateCity); - Dispatch dispatch = Dispatch.borrow(playerCharacter, cityDataMsg); + dispatch = Dispatch.borrow(playerCharacter, cityDataMsg); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - if (playerCharacter.getTimeStamp("hotzoneupdate") <= WorldServer.getLastHZChange()) { + // If the hotZone has changed then update the client's map accordingly. - if (hotZone != null) { + if (playerCharacter.getTimeStamp("hotzoneupdate") <= WorldServer.getLastHZChange() && hotZone != null) { HotzoneChangeMsg hotzoneChangeMsg = new HotzoneChangeMsg(Enum.GameObjectType.Zone.ordinal(), hotZone.getObjectUUID()); dispatch = Dispatch.borrow(playerCharacter, hotzoneChangeMsg); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); playerCharacter.setTimeStamp("hotzoneupdate", System.currentTimeMillis() - 100); - } } // Serialize the realms for this map From 8ae973f5f402afb1d6f3000583d7555eb51e7ad9 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Wed, 22 Feb 2023 16:40:11 -0500 Subject: [PATCH 28/50] Refactored usage of HotZone; added cycle counter. --- src/engine/devcmd/cmds/HotzoneCmd.java | 6 ++--- src/engine/gameManager/ZoneManager.java | 25 +++++++++-------- .../handlers/ArcLoginNotifyMsgHandler.java | 6 ++--- .../net/client/handlers/CityDataHandler.java | 8 ++---- src/engine/net/client/msg/WorldDataMsg.java | 2 +- src/engine/server/world/WorldServer.java | 2 +- src/engine/workthreads/HourlyJobThread.java | 27 +++++++++---------- 7 files changed, 35 insertions(+), 41 deletions(-) diff --git a/src/engine/devcmd/cmds/HotzoneCmd.java b/src/engine/devcmd/cmds/HotzoneCmd.java index ff206fe0..2b6d64ef 100644 --- a/src/engine/devcmd/cmds/HotzoneCmd.java +++ b/src/engine/devcmd/cmds/HotzoneCmd.java @@ -52,7 +52,7 @@ public class HotzoneCmd extends AbstractDevCmd { if (input.equalsIgnoreCase("random")) { throwbackInfo(pc, "Previous hotzone: " + hotzoneInfo()); ZoneManager.generateAndSetRandomHotzone(); - zone = ZoneManager.getHotZone(); + zone = ZoneManager.hotZone; } else { zone = ZoneManager.findMacroZoneByName(input); @@ -61,7 +61,7 @@ public class HotzoneCmd extends AbstractDevCmd { return; } - if (zone == ZoneManager.getHotZone()) { + if (zone == ZoneManager.hotZone) { throwbackInfo(pc, "That macrozone is already the Hotzone."); return; } @@ -92,7 +92,7 @@ public class HotzoneCmd extends AbstractDevCmd { private static String hotzoneInfo() { final int hotzoneTimeLeft = FastMath.secondsUntilNextHour(); - final Zone hotzone = ZoneManager.getHotZone(); + final Zone hotzone = ZoneManager.hotZone; String hotzoneInfo; if (hotzone == null) { diff --git a/src/engine/gameManager/ZoneManager.java b/src/engine/gameManager/ZoneManager.java index cd3ce6b4..df3e370c 100644 --- a/src/engine/gameManager/ZoneManager.java +++ b/src/engine/gameManager/ZoneManager.java @@ -38,7 +38,8 @@ public enum ZoneManager { /* Instance variables */ private static Zone seaFloor = null; - private static Zone hotzone = null; + public static Zone hotZone = null; + public static int hotZoneCycle = 0; // Used with HOTZONE_DURATION from config. private static final ConcurrentHashMap zonesByID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD); private static final ConcurrentHashMap zonesByUUID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD); private static final ConcurrentHashMap zonesByName = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD); @@ -119,24 +120,25 @@ public enum ZoneManager { return ZoneManager.zonesByUUID.values(); } - public static final Zone getHotZone() { - return ZoneManager.hotzone; - } - public static final void setHotZone(final Zone zone) { + if (!zone.isMacroZone()) return; - ZoneManager.hotzone = zone; + + ZoneManager.hotZone = zone; + ZoneManager.hotZoneCycle = 1; // Used with HOTZONE_DURATION from config. zone.hasBeenHotzone = true; zone.becameHotzone = LocalDateTime.now(); + WorldServer.setLastHZChange(System.currentTimeMillis()); + } public static boolean inHotZone(final Vector3fImmutable loc) { - if (ZoneManager.hotzone == null) + if (ZoneManager.hotZone == null) return false; - return (Bounds.collide(loc, ZoneManager.hotzone.getBounds()) == true); + return (Bounds.collide(loc, ZoneManager.hotZone.getBounds()) == true); } public static void setSeaFloor(final Zone value) { @@ -204,15 +206,12 @@ public enum ZoneManager { hotzone = ZoneManager.getZoneByUUID(zoneArray.get(entryIndex)); - if (hotzone == null) { Logger.error("Hotzone is null"); return; } - ZoneManager.setHotZone(hotzone); - WorldServer.setLastHZChange(System.currentTimeMillis()); } @@ -234,8 +233,8 @@ public enum ZoneManager { // if (this.hotzone.getUUID() == zone.getUUID()) // return true; //no same hotzone - if (ZoneManager.hotzone != null) - return ZoneManager.hotzone.getObjectUUID() != zone.getObjectUUID(); + if (ZoneManager.hotZone != null) + return ZoneManager.hotZone.getObjectUUID() != zone.getObjectUUID(); return true; } diff --git a/src/engine/net/client/handlers/ArcLoginNotifyMsgHandler.java b/src/engine/net/client/handlers/ArcLoginNotifyMsgHandler.java index 63d4ac49..c72b5cb8 100644 --- a/src/engine/net/client/handlers/ArcLoginNotifyMsgHandler.java +++ b/src/engine/net/client/handlers/ArcLoginNotifyMsgHandler.java @@ -1,5 +1,6 @@ package engine.net.client.handlers; +import engine.Enum; import engine.Enum.DispatchChannel; import engine.exception.MsgSendException; import engine.gameManager.*; @@ -125,10 +126,9 @@ public class ArcLoginNotifyMsgHandler extends AbstractClientMsgHandler { } //Send current hotzone - Zone hotzone = ZoneManager.getHotZone(); - if (hotzone != null) { - HotzoneChangeMsg hcm = new HotzoneChangeMsg(hotzone.getObjectType().ordinal(), hotzone.getObjectUUID()); + if (ZoneManager.hotZone != null) { + HotzoneChangeMsg hcm = new HotzoneChangeMsg(Enum.GameObjectType.Zone.ordinal(), ZoneManager.hotZone.getObjectUUID()); Dispatch dispatch = Dispatch.borrow(player, hcm); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); } diff --git a/src/engine/net/client/handlers/CityDataHandler.java b/src/engine/net/client/handlers/CityDataHandler.java index 1b304b30..4e9f7640 100644 --- a/src/engine/net/client/handlers/CityDataHandler.java +++ b/src/engine/net/client/handlers/CityDataHandler.java @@ -50,10 +50,6 @@ public class CityDataHandler extends AbstractClientMsgHandler { if (playerSession == null) return true; - // Cache current hotZone - - hotZone = ZoneManager.getHotZone(); - // No reason to serialize cities and mines everytime map is // opened. Wait until something has changed. @@ -76,8 +72,8 @@ public class CityDataHandler extends AbstractClientMsgHandler { // If the hotZone has changed then update the client's map accordingly. - if (playerCharacter.getTimeStamp("hotzoneupdate") <= WorldServer.getLastHZChange() && hotZone != null) { - HotzoneChangeMsg hotzoneChangeMsg = new HotzoneChangeMsg(Enum.GameObjectType.Zone.ordinal(), hotZone.getObjectUUID()); + if (playerCharacter.getTimeStamp("hotzoneupdate") <= WorldServer.getLastHZChange() && ZoneManager.hotZone != null) { + HotzoneChangeMsg hotzoneChangeMsg = new HotzoneChangeMsg(Enum.GameObjectType.Zone.ordinal(), ZoneManager.hotZone.getObjectUUID()); dispatch = Dispatch.borrow(playerCharacter, hotzoneChangeMsg); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); playerCharacter.setTimeStamp("hotzoneupdate", System.currentTimeMillis() - 100); diff --git a/src/engine/net/client/msg/WorldDataMsg.java b/src/engine/net/client/msg/WorldDataMsg.java index 119163c5..c9391d84 100644 --- a/src/engine/net/client/msg/WorldDataMsg.java +++ b/src/engine/net/client/msg/WorldDataMsg.java @@ -80,7 +80,7 @@ public class WorldDataMsg extends ClientNetMsg { writer.putInt(getTotalMapSize(root) + 1); Zone.serializeForClientMsg(root,writer); - Zone hotzone = ZoneManager.getHotZone(); + Zone hotzone = ZoneManager.hotZone;; if (hotzone == null) writer.putLong(0L); diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index 70a5f3fa..2e1a1361 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -430,7 +430,7 @@ public class WorldServer { Logger.info("Running Heraldry Audit for Deleted Players"); Heraldry.AuditHeraldry(); - if (ZoneManager.getHotZone() != null) + if (ZoneManager.hotZone != null) WorldServer.setLastHZChange(System.currentTimeMillis()); Logger.info("Starting Mobile AI FSM"); diff --git a/src/engine/workthreads/HourlyJobThread.java b/src/engine/workthreads/HourlyJobThread.java index c7387576..25173743 100644 --- a/src/engine/workthreads/HourlyJobThread.java +++ b/src/engine/workthreads/HourlyJobThread.java @@ -29,8 +29,6 @@ import static engine.server.MBServerStatics.MINE_LATE_WINDOW; public class HourlyJobThread implements Runnable { - private static final int hotzoneCount = 0; - public HourlyJobThread() { } @@ -42,21 +40,22 @@ public class HourlyJobThread implements Runnable { Logger.info("Hourly job is now running."); try { - Zone hotzone = ZoneManager.getHotZone(); - if (hotzone == null) { - //no hotzone? set one. + + //no hotzone? set one. + + if (ZoneManager.hotZone == null) ZoneManager.generateAndSetRandomHotzone(); - } - int hotzoneDuration = Integer.valueOf(ConfigManager.MB_HOTZONE_DURATION.getValue()); - if (((LocalDateTime.now().getHour()) - hotzone.becameHotzone.getHour()) >= hotzoneDuration) { + + ZoneManager.hotZoneCycle = ZoneManager.hotZoneCycle + 1; + + if (ZoneManager.hotZoneCycle > Integer.valueOf(ConfigManager.MB_HOTZONE_DURATION.getValue())) ZoneManager.generateAndSetRandomHotzone(); - hotzone = ZoneManager.getHotZone(); - } - if (hotzone == null) { - Logger.error("Null hotzone returned from mapmanager"); + + + if (ZoneManager.hotZone == null) { + Logger.error("Null HotZone returned from ZoneManager"); } else { - Logger.info("new hotzone: " + hotzone.getName()); - WorldServer.setLastHZChange(System.currentTimeMillis()); + Logger.info("HotZone switched to: " + ZoneManager.hotZone.getName()); } } catch (Exception e) { From dc23755081585f9b66137d584fc7b7871127d03e Mon Sep 17 00:00:00 2001 From: MagicBot Date: Wed, 22 Feb 2023 17:25:48 -0500 Subject: [PATCH 29/50] Use of Instant to track hotzone refresh times. --- src/engine/devcmd/cmds/HotzoneCmd.java | 1 - src/engine/gameManager/ZoneManager.java | 3 ++- .../net/client/handlers/CityDataHandler.java | 6 +++--- src/engine/net/client/msg/HotzoneChangeMsg.java | 13 ++++++++++++- src/engine/server/world/WorldServer.java | 16 +++------------- src/engine/workthreads/HourlyJobThread.java | 9 ++++----- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/engine/devcmd/cmds/HotzoneCmd.java b/src/engine/devcmd/cmds/HotzoneCmd.java index 2b6d64ef..dd2e8225 100644 --- a/src/engine/devcmd/cmds/HotzoneCmd.java +++ b/src/engine/devcmd/cmds/HotzoneCmd.java @@ -77,7 +77,6 @@ public class HotzoneCmd extends AbstractDevCmd { throwbackInfo(pc, "New hotzone: " + hotzoneInfo()); HotzoneChangeMsg hcm = new HotzoneChangeMsg(zone.getObjectType().ordinal(), zone.getObjectUUID()); - WorldServer.setLastHZChange(System.currentTimeMillis()); } @Override diff --git a/src/engine/gameManager/ZoneManager.java b/src/engine/gameManager/ZoneManager.java index df3e370c..d801bdda 100644 --- a/src/engine/gameManager/ZoneManager.java +++ b/src/engine/gameManager/ZoneManager.java @@ -21,6 +21,7 @@ import engine.server.world.WorldServer; import org.pmw.tinylog.Logger; import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -129,7 +130,7 @@ public enum ZoneManager { ZoneManager.hotZoneCycle = 1; // Used with HOTZONE_DURATION from config. zone.hasBeenHotzone = true; zone.becameHotzone = LocalDateTime.now(); - WorldServer.setLastHZChange(System.currentTimeMillis()); + WorldServer.hotZoneLastUpdate = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant(); } diff --git a/src/engine/net/client/handlers/CityDataHandler.java b/src/engine/net/client/handlers/CityDataHandler.java index 4e9f7640..d12ecf91 100644 --- a/src/engine/net/client/handlers/CityDataHandler.java +++ b/src/engine/net/client/handlers/CityDataHandler.java @@ -12,10 +12,11 @@ import engine.net.client.msg.*; import engine.objects.City; import engine.objects.Mine; import engine.objects.PlayerCharacter; -import engine.objects.Zone; import engine.server.world.WorldServer; import engine.session.Session; +import java.time.ZoneId; + /* * @Author: * @Summary: Processes application protocol message which displays @@ -35,7 +36,6 @@ public class CityDataHandler extends AbstractClientMsgHandler { boolean updateCity = false; Session playerSession; PlayerCharacter playerCharacter; - Zone hotZone; Dispatch dispatch; playerCharacter = origin.getPlayerCharacter(); @@ -72,7 +72,7 @@ public class CityDataHandler extends AbstractClientMsgHandler { // If the hotZone has changed then update the client's map accordingly. - if (playerCharacter.getTimeStamp("hotzoneupdate") <= WorldServer.getLastHZChange() && ZoneManager.hotZone != null) { + if (playerCharacter.getTimeStamp("hotzoneupdate") <= WorldServer.hotZoneLastUpdate.toEpochMilli() && ZoneManager.hotZone != null) { HotzoneChangeMsg hotzoneChangeMsg = new HotzoneChangeMsg(Enum.GameObjectType.Zone.ordinal(), ZoneManager.hotZone.getObjectUUID()); dispatch = Dispatch.borrow(playerCharacter, hotzoneChangeMsg); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); diff --git a/src/engine/net/client/msg/HotzoneChangeMsg.java b/src/engine/net/client/msg/HotzoneChangeMsg.java index c39f218d..d5874c41 100644 --- a/src/engine/net/client/msg/HotzoneChangeMsg.java +++ b/src/engine/net/client/msg/HotzoneChangeMsg.java @@ -10,17 +10,23 @@ package engine.net.client.msg; +import engine.gameManager.ConfigManager; import engine.math.FastMath; import engine.net.AbstractConnection; import engine.net.ByteBufferReader; import engine.net.ByteBufferWriter; import engine.net.client.Protocol; +import engine.server.world.WorldServer; + +import java.time.Duration; +import java.time.LocalDateTime; public class HotzoneChangeMsg extends ClientNetMsg { private int zoneType; private int zoneID; + private Duration endOfCycle; /** * This is the general purpose constructor. @@ -29,6 +35,11 @@ public class HotzoneChangeMsg extends ClientNetMsg { super(Protocol.ARCHOTZONECHANGE); this.zoneType = zoneType; this.zoneID = zoneID; + + int hotZoneDuration = Integer.parseInt(ConfigManager.MB_HOTZONE_DURATION.getValue()); + + endOfCycle = Duration.between(WorldServer.hotZoneLastUpdate, WorldServer.hotZoneLastUpdate.plusSeconds(hotZoneDuration * 3600)); + } /** @@ -49,7 +60,7 @@ public class HotzoneChangeMsg extends ClientNetMsg { protected void _serialize(ByteBufferWriter writer) { writer.putInt(this.zoneType); writer.putInt(this.zoneID); - writer.putInt(FastMath.secondsUntilNextHour()); + writer.putInt((int) endOfCycle.getSeconds()); } /** diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index 2e1a1361..d239a41b 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -58,7 +58,9 @@ import java.io.IOException; import java.net.InetAddress; import java.nio.file.Files; import java.nio.file.Paths; +import java.time.Instant; import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -70,7 +72,7 @@ import static java.lang.System.exit; public class WorldServer { private static LocalDateTime bootTime = LocalDateTime.now(); - private static long lastHZChange = System.currentTimeMillis(); + public static Instant hotZoneLastUpdate; public boolean isRunning = false; // Member variable declaration @@ -121,14 +123,6 @@ public class WorldServer { } } - public static long getLastHZChange() { - return lastHZChange; - } - - public static void setLastHZChange(long lastChange) { - lastHZChange = lastChange; - } - public static void trainerInfo(TrainerInfoMsg msg, ClientConnection origin) { NPC npc = NPC.getFromCache(msg.getObjectID()); @@ -430,13 +424,9 @@ public class WorldServer { Logger.info("Running Heraldry Audit for Deleted Players"); Heraldry.AuditHeraldry(); - if (ZoneManager.hotZone != null) - WorldServer.setLastHZChange(System.currentTimeMillis()); - Logger.info("Starting Mobile AI FSM"); MobileFSMManager.getInstance(); - for (Zone zone : ZoneManager.getAllZones()) { if (zone.getHeightMap() != null) { if (zone.getHeightMap().getBucketWidthX() == 0) { diff --git a/src/engine/workthreads/HourlyJobThread.java b/src/engine/workthreads/HourlyJobThread.java index 25173743..031cebd8 100644 --- a/src/engine/workthreads/HourlyJobThread.java +++ b/src/engine/workthreads/HourlyJobThread.java @@ -41,17 +41,17 @@ public class HourlyJobThread implements Runnable { try { - //no hotzone? set one. - if (ZoneManager.hotZone == null) ZoneManager.generateAndSetRandomHotzone(); + // Use the same hotZone this hour up and until + // the HotZone_Duration from the ConfigManager + ZoneManager.hotZoneCycle = ZoneManager.hotZoneCycle + 1; - if (ZoneManager.hotZoneCycle > Integer.valueOf(ConfigManager.MB_HOTZONE_DURATION.getValue())) + if (ZoneManager.hotZoneCycle > Integer.parseInt(ConfigManager.MB_HOTZONE_DURATION.getValue())) ZoneManager.generateAndSetRandomHotzone(); - if (ZoneManager.hotZone == null) { Logger.error("Null HotZone returned from ZoneManager"); } else { @@ -91,7 +91,6 @@ public class HourlyJobThread implements Runnable { } } - // Mines can only be claimed once per cycle. // This will reset at 1am after the last mine // window closes. From 2e576b3065f36be1931a158939c3899b4a417cc7 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Wed, 22 Feb 2023 17:35:30 -0500 Subject: [PATCH 30/50] Increment only when a hotZone is set. --- src/engine/workthreads/HourlyJobThread.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/engine/workthreads/HourlyJobThread.java b/src/engine/workthreads/HourlyJobThread.java index 031cebd8..04538d29 100644 --- a/src/engine/workthreads/HourlyJobThread.java +++ b/src/engine/workthreads/HourlyJobThread.java @@ -41,13 +41,13 @@ public class HourlyJobThread implements Runnable { try { - if (ZoneManager.hotZone == null) - ZoneManager.generateAndSetRandomHotzone(); - // Use the same hotZone this hour up and until // the HotZone_Duration from the ConfigManager - ZoneManager.hotZoneCycle = ZoneManager.hotZoneCycle + 1; + if (ZoneManager.hotZone == null) + ZoneManager.generateAndSetRandomHotzone(); + else + ZoneManager.hotZoneCycle = ZoneManager.hotZoneCycle + 1; if (ZoneManager.hotZoneCycle > Integer.parseInt(ConfigManager.MB_HOTZONE_DURATION.getValue())) ZoneManager.generateAndSetRandomHotzone(); From 6912a063513f6ecc5e881f6823320a73b47d98c7 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Thu, 23 Feb 2023 16:38:23 -0500 Subject: [PATCH 31/50] MB_HOTZONE_MIN_LEVEL added to ConfigManager --- src/engine/gameManager/ConfigManager.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/engine/gameManager/ConfigManager.java b/src/engine/gameManager/ConfigManager.java index 4cf9da5c..8278bbf5 100644 --- a/src/engine/gameManager/ConfigManager.java +++ b/src/engine/gameManager/ConfigManager.java @@ -71,6 +71,8 @@ public enum ConfigManager { MB_HOTZONE_RATE, MB_HOTZONE_DURATION, + MB_HOTZONE_MIN_LEVEL, + // MagicBot configuration. MB_MAGICBOT_SERVERID, From 4c625cdfbf1072dea2fb106115cda34d50ac1dab Mon Sep 17 00:00:00 2001 From: MagicBot Date: Thu, 23 Feb 2023 16:46:55 -0500 Subject: [PATCH 32/50] HotZone minLevel enforced. --- src/engine/gameManager/ZoneManager.java | 15 +++++++++------ src/engine/objects/Zone.java | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/engine/gameManager/ZoneManager.java b/src/engine/gameManager/ZoneManager.java index d801bdda..147affe2 100644 --- a/src/engine/gameManager/ZoneManager.java +++ b/src/engine/gameManager/ZoneManager.java @@ -226,13 +226,16 @@ public enum ZoneManager { if (zone.equals(ZoneManager.seaFloor)) return false; - //no duplicate hotzones - if (zone.hasBeenHotzone == true) { + + //no duplicate hotZones + + if (zone.hasBeenHotzone == true) + return false; + + // Enforce min level + + if (zone.minLvl < Integer.parseInt(ConfigManager.MB_HOTZONE_MIN_LEVEL.getValue())) return false; - } - // return false; //first time setting, accept it - // if (this.hotzone.getUUID() == zone.getUUID()) - // return true; //no same hotzone if (ZoneManager.hotZone != null) return ZoneManager.hotZone.getObjectUUID() != zone.getObjectUUID(); diff --git a/src/engine/objects/Zone.java b/src/engine/objects/Zone.java index a758279d..c1b9389e 100644 --- a/src/engine/objects/Zone.java +++ b/src/engine/objects/Zone.java @@ -51,8 +51,8 @@ public class Zone extends AbstractGameObject { private boolean isNPCCity = false; private boolean isPlayerCity = false; private String hash; - private int minLvl; - private int maxLvl; + public int minLvl; + public int maxLvl; private float worldAltitude = 0; From 0dad677bc0066975c29aa8fd61260867ce83216b Mon Sep 17 00:00:00 2001 From: MagicBot Date: Thu, 23 Feb 2023 17:14:34 -0500 Subject: [PATCH 33/50] hotzone dev command updated. --- src/engine/devcmd/cmds/HotzoneCmd.java | 61 ++++---------------------- 1 file changed, 9 insertions(+), 52 deletions(-) diff --git a/src/engine/devcmd/cmds/HotzoneCmd.java b/src/engine/devcmd/cmds/HotzoneCmd.java index dd2e8225..d1427800 100644 --- a/src/engine/devcmd/cmds/HotzoneCmd.java +++ b/src/engine/devcmd/cmds/HotzoneCmd.java @@ -22,9 +22,8 @@ import engine.server.world.WorldServer; /** * ./hotzone <- display the current hotzone & time remaining * ./hotzone random <- change hotzone to random new zone - * ./hotzone name of a macrozone <- change hotzone to the zone name provided - * */ + public class HotzoneCmd extends AbstractDevCmd { public HotzoneCmd() { @@ -36,78 +35,36 @@ public class HotzoneCmd extends AbstractDevCmd { AbstractGameObject target) { StringBuilder data = new StringBuilder(); + for (String s : words) { data.append(s); data.append(' '); } + String input = data.toString().trim(); if (input.length() == 0) { - throwbackInfo(pc, "Current hotzone: " + hotzoneInfo()); + throwbackInfo(pc, "Current hotZone: " + ZoneManager.hotZone.getName()); return; } - Zone zone; - if (input.equalsIgnoreCase("random")) { - throwbackInfo(pc, "Previous hotzone: " + hotzoneInfo()); + throwbackInfo(pc, "Previous hotZone: " + ZoneManager.hotZone.getName()); ZoneManager.generateAndSetRandomHotzone(); - zone = ZoneManager.hotZone; - } else { - zone = ZoneManager.findMacroZoneByName(input); - - if (zone == null) { - throwbackError(pc, "Cannot find a macrozone with that name."); - return; - } - - if (zone == ZoneManager.hotZone) { - throwbackInfo(pc, "That macrozone is already the Hotzone."); - return; - } - - if (ZoneManager.validHotZone(zone) == false) { - throwbackError(pc, "That macrozone cannot be set as the Hotzone."); - return; - } - - throwbackInfo(pc, "Previous hotzone: " + hotzoneInfo()); - ZoneManager.setHotZone(zone); + throwbackInfo(pc, "New hotZone: " + ZoneManager.hotZone.getName()); } - throwbackInfo(pc, "New hotzone: " + hotzoneInfo()); - HotzoneChangeMsg hcm = new HotzoneChangeMsg(zone.getObjectType().ordinal(), zone.getObjectUUID()); + return; } - @Override protected String _getHelpString() { - return "Use no arguments to see the current hotzone. Specify a macrozone name to change the hotzone, or \"random\" to change it randomly."; + return "Use no arguments to see the current hotzone or \"random\" to change it randomly."; } @Override protected String _getUsageString() { - return "'./hotzone [random | ]"; + return "'./hotzone [random]"; } - private static String hotzoneInfo() { - final int hotzoneTimeLeft = FastMath.secondsUntilNextHour(); - final Zone hotzone = ZoneManager.hotZone; - String hotzoneInfo; - - if (hotzone == null) { - hotzoneInfo = "none"; - } else { - int hr = hotzoneTimeLeft/3600; - int rem = hotzoneTimeLeft%3600; - int mn = rem/60; - int sec = rem%60; - hotzoneInfo = hotzone.getName() + - " (" + (hr<10 ? "0" : "") + hr + ':' + - (mn<10 ? "0" : "") + mn + ':' + - (sec<10 ? "0" : "") + sec + - " remaining)"; - } - return hotzoneInfo; - } } From 85798822cc6f138723860432a571619def784c09 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Thu, 23 Feb 2023 17:37:14 -0500 Subject: [PATCH 34/50] Force serialize mines. --- src/engine/net/client/handlers/CityDataHandler.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/engine/net/client/handlers/CityDataHandler.java b/src/engine/net/client/handlers/CityDataHandler.java index d12ecf91..f1033a22 100644 --- a/src/engine/net/client/handlers/CityDataHandler.java +++ b/src/engine/net/client/handlers/CityDataHandler.java @@ -50,13 +50,9 @@ public class CityDataHandler extends AbstractClientMsgHandler { if (playerSession == null) return true; - // No reason to serialize cities and mines everytime map is + // No reason to serialize cities everytime map is // opened. Wait until something has changed. - - if (playerCharacter.getTimeStamp("mineupdate") <= Mine.getLastChange()) { - playerCharacter.setTimeStamp("mineupdate", System.currentTimeMillis()); - updateMine = true; - } + // This does not work for mines. if (playerCharacter.getTimeStamp("cityUpdate") <= City.lastCityUpdate) { playerCharacter.setTimeStamp("cityUpdate", System.currentTimeMillis()); @@ -64,7 +60,7 @@ public class CityDataHandler extends AbstractClientMsgHandler { } cityDataMsg cityDataMsg = new cityDataMsg(SessionManager.getSession(playerCharacter), false); - cityDataMsg.updateMines(updateMine); + cityDataMsg.updateMines(true); cityDataMsg.updateCities(updateCity); dispatch = Dispatch.borrow(playerCharacter, cityDataMsg); From 2ef60933b26feac45e005d24cd0c0db3d3fc10e5 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Thu, 23 Feb 2023 17:47:22 -0500 Subject: [PATCH 35/50] reset added to ./hotzone --- src/engine/devcmd/cmds/HotzoneCmd.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/engine/devcmd/cmds/HotzoneCmd.java b/src/engine/devcmd/cmds/HotzoneCmd.java index d1427800..dc9fce73 100644 --- a/src/engine/devcmd/cmds/HotzoneCmd.java +++ b/src/engine/devcmd/cmds/HotzoneCmd.java @@ -49,11 +49,14 @@ public class HotzoneCmd extends AbstractDevCmd { } if (input.equalsIgnoreCase("random")) { - throwbackInfo(pc, "Previous hotZone: " + ZoneManager.hotZone.getName()); ZoneManager.generateAndSetRandomHotzone(); throwbackInfo(pc, "New hotZone: " + ZoneManager.hotZone.getName()); } + if (input.equalsIgnoreCase("reset")) + for (Zone zone: ZoneManager.getAllZones()) + zone.hasBeenHotzone = false; + return; } @Override From 6a948fbe2e0068b1f314206b438c3e031e20cac3 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 24 Feb 2023 00:09:57 -0500 Subject: [PATCH 36/50] lastChanged is unused as cannot omit mines from map. --- src/engine/devcmd/cmds/MineActiveCmd.java | 60 ++-- src/engine/devcmd/cmds/SetMineExpansion.java | 95 +++--- src/engine/devcmd/cmds/SetMineTypeCmd.java | 59 ++-- .../ArcMineChangeProductionMsgHandler.java | 62 ++-- src/engine/objects/Mine.java | 278 +++++++++--------- src/engine/workthreads/HourlyJobThread.java | 218 +++++++------- 6 files changed, 371 insertions(+), 401 deletions(-) diff --git a/src/engine/devcmd/cmds/MineActiveCmd.java b/src/engine/devcmd/cmds/MineActiveCmd.java index 2263128c..6f36030a 100644 --- a/src/engine/devcmd/cmds/MineActiveCmd.java +++ b/src/engine/devcmd/cmds/MineActiveCmd.java @@ -23,46 +23,44 @@ import engine.workthreads.HourlyJobThread; */ public class MineActiveCmd extends AbstractDevCmd { - public MineActiveCmd() { + public MineActiveCmd() { super("mineactive"); } - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] args, - AbstractGameObject target) { - Building mineBuilding = BuildingManager.getBuilding(target.getObjectUUID()); - if (mineBuilding == null) - return; + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] args, + AbstractGameObject target) { + Building mineBuilding = BuildingManager.getBuilding(target.getObjectUUID()); + if (mineBuilding == null) + return; - Mine mine = Mine.getMineFromTower(mineBuilding.getObjectUUID()); - if (mine == null) - return; + Mine mine = Mine.getMineFromTower(mineBuilding.getObjectUUID()); + if (mine == null) + return; - String trigger = args[0]; - switch (trigger){ - case "true": - HourlyJobThread.mineWindowOpen(mine); - Mine.setLastChange(System.currentTimeMillis()); - break; - case "false": - HourlyJobThread.mineWindowClose(mine); - Mine.setLastChange(System.currentTimeMillis()); - break; - default: - this.sendUsage(pcSender); - break; + String trigger = args[0]; + switch (trigger) { + case "true": + HourlyJobThread.mineWindowOpen(mine); + break; + case "false": + HourlyJobThread.mineWindowClose(mine); + break; + default: + this.sendUsage(pcSender); + break; - } - } + } + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "' /mineactive true|false"; - } + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "Temporarily add visual effects to Character"; - } + } } diff --git a/src/engine/devcmd/cmds/SetMineExpansion.java b/src/engine/devcmd/cmds/SetMineExpansion.java index 0bffe902..192329d5 100644 --- a/src/engine/devcmd/cmds/SetMineExpansion.java +++ b/src/engine/devcmd/cmds/SetMineExpansion.java @@ -21,67 +21,60 @@ import engine.objects.Mine; import engine.objects.PlayerCharacter; /** - * * @author Eighty - * */ public class SetMineExpansion extends AbstractDevCmd { - public SetMineExpansion() { + public SetMineExpansion() { super("setexpansion"); this.addCmdString("setexpansion"); } - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] args, - AbstractGameObject target) { - - - if (target.getObjectType() != GameObjectType.Building) - return; - Building mineBuilding = BuildingManager.getBuilding(target.getObjectUUID()); - if (mineBuilding == null) - return; - Mine mine = Mine.getMineFromTower(mineBuilding.getObjectUUID()); - if (mine == null) - return; - int bit = 2; - switch (args[0].toUpperCase()) { - case "ON": - - bit |= mine.getFlags(); - if (!DbManager.MineQueries.SET_FLAGS(mine, bit)) - return; - mine.setFlags(bit); - ChatManager.chatSystemInfo(pcSender, mine.getZoneName() + "'s " + mine.getMineType().name + " is now an expansion mine."); - Mine.setLastChange(System.currentTimeMillis()); - break; - - case "OFF": - bit &= ~mine.getFlags(); - if (!DbManager.MineQueries.SET_FLAGS(mine, bit)) - return; - mine.setFlags(bit); - ChatManager.chatSystemInfo(pcSender, mine.getZoneName() + "'s " + mine.getMineType().name + " is no longer an expansion mine."); - Mine.setLastChange(System.currentTimeMillis()); - break; - - } - - - - - - } - - @Override - protected String _getUsageString() { + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] args, + AbstractGameObject target) { + + + if (target.getObjectType() != GameObjectType.Building) + return; + Building mineBuilding = BuildingManager.getBuilding(target.getObjectUUID()); + if (mineBuilding == null) + return; + Mine mine = Mine.getMineFromTower(mineBuilding.getObjectUUID()); + if (mine == null) + return; + int bit = 2; + switch (args[0].toUpperCase()) { + case "ON": + + bit |= mine.getFlags(); + if (!DbManager.MineQueries.SET_FLAGS(mine, bit)) + return; + mine.setFlags(bit); + ChatManager.chatSystemInfo(pcSender, mine.getZoneName() + "'s " + mine.getMineType().name + " is now an expansion mine."); + break; + + case "OFF": + bit &= ~mine.getFlags(); + if (!DbManager.MineQueries.SET_FLAGS(mine, bit)) + return; + mine.setFlags(bit); + ChatManager.chatSystemInfo(pcSender, mine.getZoneName() + "'s " + mine.getMineType().name + " is no longer an expansion mine."); + break; + + } + + + } + + @Override + protected String _getUsageString() { return "' /setmineexpansion on|off"; - } + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "enables or disables an expansion type for a mine."; - } + } } diff --git a/src/engine/devcmd/cmds/SetMineTypeCmd.java b/src/engine/devcmd/cmds/SetMineTypeCmd.java index c932923e..a469fe07 100644 --- a/src/engine/devcmd/cmds/SetMineTypeCmd.java +++ b/src/engine/devcmd/cmds/SetMineTypeCmd.java @@ -18,48 +18,45 @@ import engine.gameManager.DbManager; import engine.objects.*; /** - * * @author Eighty - * */ public class SetMineTypeCmd extends AbstractDevCmd { - public SetMineTypeCmd() { + public SetMineTypeCmd() { super("setminetype"); this.addCmdString("setminetype"); } - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] args, - AbstractGameObject target) { - - MineProduction mineType = MineProduction.valueOf(args[0].toUpperCase()); - if (mineType == null) - return; - - if (target.getObjectType() != GameObjectType.Building) - return; - Building mineBuilding = BuildingManager.getBuilding(target.getObjectUUID()); - if (mineBuilding == null) - return; - Mine mine = Mine.getMineFromTower(mineBuilding.getObjectUUID()); - if (mine == null) - return; - if (!DbManager.MineQueries.CHANGE_TYPE(mine, mineType)) - return; - mine.setMineType(mineType.name()); - ChatManager.chatSystemInfo(pcSender, "The mine in " + mine.getZoneName() + " is now a(n) " + mine.getMineType().name); - Mine.setLastChange(System.currentTimeMillis()); - } + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] args, + AbstractGameObject target) { + + MineProduction mineType = MineProduction.valueOf(args[0].toUpperCase()); + if (mineType == null) + return; + + if (target.getObjectType() != GameObjectType.Building) + return; + Building mineBuilding = BuildingManager.getBuilding(target.getObjectUUID()); + if (mineBuilding == null) + return; + Mine mine = Mine.getMineFromTower(mineBuilding.getObjectUUID()); + if (mine == null) + return; + if (!DbManager.MineQueries.CHANGE_TYPE(mine, mineType)) + return; + mine.setMineType(mineType.name()); + ChatManager.chatSystemInfo(pcSender, "The mine in " + mine.getZoneName() + " is now a(n) " + mine.getMineType().name); + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "' /setminetype gold|ore|magic|lumber"; - } + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "Changes the mine type of the current mine."; - } + } } diff --git a/src/engine/net/client/handlers/ArcMineChangeProductionMsgHandler.java b/src/engine/net/client/handlers/ArcMineChangeProductionMsgHandler.java index c2198b7e..67e42527 100644 --- a/src/engine/net/client/handlers/ArcMineChangeProductionMsgHandler.java +++ b/src/engine/net/client/handlers/ArcMineChangeProductionMsgHandler.java @@ -7,7 +7,6 @@ import engine.net.DispatchMessage; import engine.net.client.ClientConnection; import engine.net.client.msg.ArcMineChangeProductionMsg; import engine.net.client.msg.ClientNetMsg; -import engine.net.client.msg.KeepAliveServerClientMsg; import engine.objects.GuildStatusController; import engine.objects.Mine; import engine.objects.PlayerCharacter; @@ -21,49 +20,48 @@ import engine.objects.Resource; public class ArcMineChangeProductionMsgHandler extends AbstractClientMsgHandler { - public ArcMineChangeProductionMsgHandler() { - super(ArcMineChangeProductionMsg.class); - } + public ArcMineChangeProductionMsgHandler() { + super(ArcMineChangeProductionMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - - PlayerCharacter playerCharacter = origin.getPlayerCharacter(); - ArcMineChangeProductionMsg changeProductionMsg = (ArcMineChangeProductionMsg) baseMsg; + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - if (playerCharacter == null) - return true; + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + ArcMineChangeProductionMsg changeProductionMsg = (ArcMineChangeProductionMsg) baseMsg; - //TODO verify this against the warehouse? + if (playerCharacter == null) + return true; - if (GuildStatusController.isInnerCouncil(playerCharacter.getGuildStatus()) == false) // is this only GL? - return true; + //TODO verify this against the warehouse? - Mine mine = Mine.getMine(changeProductionMsg.getMineID()); + if (GuildStatusController.isInnerCouncil(playerCharacter.getGuildStatus()) == false) // is this only GL? + return true; - if (mine == null) - return true; + Mine mine = Mine.getMine(changeProductionMsg.getMineID()); - //make sure mine belongs to guild + if (mine == null) + return true; - if (mine.getOwningGuild().isEmptyGuild() || - mine.getOwningGuild().getObjectUUID() != playerCharacter.getGuild().getObjectUUID()) - return true; + //make sure mine belongs to guild - //make sure valid resource + if (mine.getOwningGuild().isEmptyGuild() || + mine.getOwningGuild().getObjectUUID() != playerCharacter.getGuild().getObjectUUID()) + return true; - Resource resource = Resource.resourceByHash.get(changeProductionMsg.getResourceHash()); + //make sure valid resource - if (resource == null) - return true; + Resource resource = Resource.resourceByHash.get(changeProductionMsg.getResourceHash()); - //update resource + if (resource == null) + return true; - mine.changeProductionType(resource); - Mine.setLastChange(System.currentTimeMillis()); - Dispatch dispatch = Dispatch.borrow(playerCharacter, changeProductionMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - } + //update resource + + mine.changeProductionType(resource); + Dispatch dispatch = Dispatch.borrow(playerCharacter, changeProductionMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + } } \ No newline at end of file diff --git a/src/engine/objects/Mine.java b/src/engine/objects/Mine.java index b43bf21e..d58b46ad 100644 --- a/src/engine/objects/Mine.java +++ b/src/engine/objects/Mine.java @@ -20,7 +20,10 @@ package engine.objects; import engine.Enum; import engine.InterestManagement.WorldGrid; -import engine.gameManager.*; +import engine.gameManager.BuildingManager; +import engine.gameManager.ChatManager; +import engine.gameManager.DbManager; +import engine.gameManager.ZoneManager; import engine.net.ByteBufferWriter; import engine.net.client.msg.ErrorPopupMsg; import engine.server.MBServerStatics; @@ -33,38 +36,34 @@ import java.time.LocalDateTime; import java.util.ArrayList; import java.util.concurrent.ConcurrentHashMap; -import static engine.gameManager.DbManager.*; +import static engine.gameManager.DbManager.MineQueries; +import static engine.gameManager.DbManager.getObject; import static engine.math.FastMath.sqr; public class Mine extends AbstractGameObject { - private String zoneName; - private Resource production; + public static ConcurrentHashMap mineMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + public static ConcurrentHashMap towerMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); public boolean isActive = false; - - private float latitude; - private float longitude; - private float altitude; - private Guild owningGuild; public PlayerCharacter lastClaimer; public boolean wasClaimed = false; - private int flags; - private int buildingID; - private Zone parentZone; - private MineProduction mineType; - - //flags 1: never been claimed (make active). - - // Not persisted to DB public String guildName; public GuildTag guildTag; public String nationName; public GuildTag nationTag; - public static ConcurrentHashMap mineMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - public static ConcurrentHashMap towerMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + private final String zoneName; + private Resource production; + private final float latitude; + private final float longitude; - private static long lastChange = System.currentTimeMillis(); + //flags 1: never been claimed (make active). + private final float altitude; + private Guild owningGuild; + private int flags; + private int buildingID; + private final Zone parentZone; + private MineProduction mineType; /** * ResultSet Constructor @@ -139,6 +138,7 @@ public class Mine extends AbstractGameObject { } } + public static void SendMineAttackMessage(Building mine) { if (mine.getBlueprint() == null) @@ -186,90 +186,10 @@ public class Mine extends AbstractGameObject { * Getters */ - public boolean changeProductionType(Resource resource) { - if (!this.validForMine(resource)) - return false; - //update resource in database; - if (!MineQueries.CHANGE_RESOURCE(this, resource)) - return false; - - this.production = resource; - return true; - } - - public MineProduction getMineType() { - return this.mineType; - } - - public String getZoneName() { - return this.zoneName; - } - - public Resource getProduction() { - return this.production; - } - - public boolean getIsActive() { - return this.isActive; - } - - public float getAltitude() { - return this.altitude; - } - - public Guild getOwningGuild() { - if (this.owningGuild == null) - return Guild.getErrantGuild(); - else - return this.owningGuild; - } - - public int getFlags() { - return flags; - } - - public void setFlags(int flags) { - this.flags = flags; - } - - public Zone getParentZone() { - return parentZone; - } - - public GuildTag getGuildTag() { - return guildTag; - } - - public void setMineType(String type) { - this.mineType = MineProduction.getByName(type); - } - - public void setActive(boolean isAc) { - - this.isActive = isAc; - Building building = BuildingManager.getBuildingFromCache(this.buildingID); - if (building != null && !this.isActive) - building.isDeranking.compareAndSet(true, false); - } - - public void setOwningGuild(Guild owningGuild) { - this.owningGuild = owningGuild; - } - public static Mine getMineFromTower(int towerID) { return Mine.towerMap.get(towerID); } - public boolean validForMine(Resource r) { - if (this.mineType == null) - return false; - return this.mineType.validForMine(r, this.isExpansion()); - } - - /* - * Serialization - */ - public static void serializeForClientMsg(Mine mine, ByteBufferWriter writer) { writer.putInt(mine.getObjectType().ordinal()); writer.putInt(mine.getObjectUUID()); @@ -284,15 +204,15 @@ public class Mine extends AbstractGameObject { // Errant mines are currently open. Set time to now. LocalDateTime mineOpenTime = LocalDateTime.now().withMinute(0).withSecond(0).withNano(0); - + // Mine times are those of the nation not individual guild. - + Guild mineNatonGuild = mine.getOwningGuild().getNation(); // Adjust the serialized mine time based upon whether // the Guild's mine window has passed or not and if it was claimed. - // If a mine is active serialize current datetime irrespective - // of any claim. + // If a mine is active serialize current datetime irrespective + // of any claim. if (mineNatonGuild.isEmptyGuild() == false && mine.isActive == false) { @@ -321,20 +241,6 @@ public class Mine extends AbstractGameObject { GuildTag._serializeForDisplay(mine.nationTag, writer); } - public void serializeForMineProduction(ByteBufferWriter writer) { - writer.putInt(this.getObjectType().ordinal()); - writer.putInt(this.getObjectUUID()); - writer.putInt(this.getObjectUUID()); //actually a hash of mine - // writer.putInt(0x215C92BB); //this.unknown1); - writer.putString(this.mineType.name); - writer.putString(this.zoneName); - writer.putInt(this.production.hash); - writer.putInt(this.production.baseProduction); - writer.putInt(this.getModifiedProductionAmount()); //TODO calculate range penalty here - writer.putInt(3600); //window in seconds - writer.putInt(this.isExpansion() ? this.mineType.xpacHash : this.mineType.hash); - } - public static ArrayList getMinesForGuild(int guildID) { ArrayList mineList = new ArrayList<>(); @@ -343,20 +249,12 @@ public class Mine extends AbstractGameObject { for (Mine mine : Mine.mineMap.keySet()) { if (mine.owningGuild.getObjectUUID() == guildID && - mine.isActive == false) + mine.isActive == false) mineList.add(mine); } return mineList; } - public static long getLastChange() { - return lastChange; - } - - public static void setLastChange(long lastChange) { - Mine.lastChange = lastChange; - } - /* * Database */ @@ -369,19 +267,6 @@ public class Mine extends AbstractGameObject { return new ArrayList<>(mineMap.keySet()); } - @Override - public void updateDatabase() { - // TODO Create update logic. - } - - public int getBuildingID() { - return buildingID; - } - - public void setBuildingID(int buildingID) { - this.buildingID = buildingID; - } - public static boolean validateClaimer(PlayerCharacter playerCharacter) { // Method validates that the claimer meets @@ -407,7 +292,7 @@ public class Mine extends AbstractGameObject { if (playerGuild.getNation().isEmptyGuild()) return false; - // Guild must own a city to hold a mine. + // Guild must own a city to hold a mine. City guildCity = playerGuild.getOwnedCity(); @@ -433,7 +318,7 @@ public class Mine extends AbstractGameObject { if (treeRank < 1) return false; - if (guildUnderMineLimit(playerGuild.getNation(), treeRank) == false){ + if (guildUnderMineLimit(playerGuild.getNation(), treeRank) == false) { ErrorPopupMsg.sendErrorMsg(playerCharacter, "Your nation cannot support another mine."); return false; } @@ -450,11 +335,116 @@ public class Mine extends AbstractGameObject { for (Guild guild : playerGuild.getSubGuildList()) mineCnt += Mine.getMinesForGuild(guild.getObjectUUID()).size(); - if (mineCnt > tolRank) + return mineCnt <= tolRank; + } + + public boolean changeProductionType(Resource resource) { + if (!this.validForMine(resource)) + return false; + //update resource in database; + if (!MineQueries.CHANGE_RESOURCE(this, resource)) return false; + this.production = resource; return true; } + + public MineProduction getMineType() { + return this.mineType; + } + + public void setMineType(String type) { + this.mineType = MineProduction.getByName(type); + } + + public String getZoneName() { + return this.zoneName; + } + + public Resource getProduction() { + return this.production; + } + + public boolean getIsActive() { + return this.isActive; + } + + public float getAltitude() { + return this.altitude; + } + + public Guild getOwningGuild() { + if (this.owningGuild == null) + return Guild.getErrantGuild(); + else + return this.owningGuild; + } + + public void setOwningGuild(Guild owningGuild) { + this.owningGuild = owningGuild; + } + + /* + * Serialization + */ + + public int getFlags() { + return flags; + } + + public void setFlags(int flags) { + this.flags = flags; + } + + public Zone getParentZone() { + return parentZone; + } + + public GuildTag getGuildTag() { + return guildTag; + } + + public void setActive(boolean isAc) { + + this.isActive = isAc; + Building building = BuildingManager.getBuildingFromCache(this.buildingID); + if (building != null && !this.isActive) + building.isDeranking.compareAndSet(true, false); + } + + public boolean validForMine(Resource r) { + if (this.mineType == null) + return false; + return this.mineType.validForMine(r, this.isExpansion()); + } + + public void serializeForMineProduction(ByteBufferWriter writer) { + writer.putInt(this.getObjectType().ordinal()); + writer.putInt(this.getObjectUUID()); + writer.putInt(this.getObjectUUID()); //actually a hash of mine + // writer.putInt(0x215C92BB); //this.unknown1); + writer.putString(this.mineType.name); + writer.putString(this.zoneName); + writer.putInt(this.production.hash); + writer.putInt(this.production.baseProduction); + writer.putInt(this.getModifiedProductionAmount()); //TODO calculate range penalty here + writer.putInt(3600); //window in seconds + writer.putInt(this.isExpansion() ? this.mineType.xpacHash : this.mineType.hash); + } + + @Override + public void updateDatabase() { + // TODO Create update logic. + } + + public int getBuildingID() { + return buildingID; + } + + public void setBuildingID(int buildingID) { + this.buildingID = buildingID; + } + public void handleDestroyMine() { if (!this.isActive) @@ -465,7 +455,6 @@ public class Mine extends AbstractGameObject { this.guildName = ""; this.nationName = ""; this.owningGuild = Guild.getErrantGuild(); - Mine.setLastChange(System.currentTimeMillis()); this.lastClaimer = null; this.wasClaimed = false; @@ -513,6 +502,7 @@ public class Mine extends AbstractGameObject { return true; } + public boolean depositMineResources() { if (this.owningGuild.isEmptyGuild()) diff --git a/src/engine/workthreads/HourlyJobThread.java b/src/engine/workthreads/HourlyJobThread.java index 04538d29..dbf17e0c 100644 --- a/src/engine/workthreads/HourlyJobThread.java +++ b/src/engine/workthreads/HourlyJobThread.java @@ -33,111 +33,6 @@ public class HourlyJobThread implements Runnable { } - public void run() { - - // *** REFACTOR: TRY TRY TRY TRY {{{{{{{{{{{ OMG - - Logger.info("Hourly job is now running."); - - try { - - // Use the same hotZone this hour up and until - // the HotZone_Duration from the ConfigManager - - if (ZoneManager.hotZone == null) - ZoneManager.generateAndSetRandomHotzone(); - else - ZoneManager.hotZoneCycle = ZoneManager.hotZoneCycle + 1; - - if (ZoneManager.hotZoneCycle > Integer.parseInt(ConfigManager.MB_HOTZONE_DURATION.getValue())) - ZoneManager.generateAndSetRandomHotzone(); - - if (ZoneManager.hotZone == null) { - Logger.error("Null HotZone returned from ZoneManager"); - } else { - Logger.info("HotZone switched to: " + ZoneManager.hotZone.getName()); - } - - } catch (Exception e) { - Logger.error(e.toString()); - } - - // Open or Close mines for the current mine window. - - processMineWindow(); - - // Deposit mine resources to Guilds - - for (Mine mine : Mine.getMines()) { - - try { - mine.depositMineResources(); - } catch (Exception e) { - Logger.info(e.getMessage() + " for Mine " + mine.getObjectUUID()); - } - } - - // Reset time-gated access to WOO slider. - // *** Do this after the mines open/close! - - if (LocalDateTime.now().getHour() == MINE_LATE_WINDOW) { - Guild guild; - - for (AbstractGameObject dbObject : DbManager.getList(Enum.GameObjectType.Guild)) { - guild = (Guild) dbObject; - - if (guild != null) - guild.wooWasModified = false; - } - } - - // Mines can only be claimed once per cycle. - // This will reset at 1am after the last mine - // window closes. - - if (LocalDateTime.now().getHour() == MINE_LATE_WINDOW + 1) { - - for (Mine mine : Mine.getMines()) { - - if (mine.wasClaimed == true) - mine.wasClaimed = false; - } - } - - // Decay Shrines at midnight every day - - if (LocalDateTime.now().getHour() == MINE_LATE_WINDOW) - decayShrines(); - - // Update city population values - - ConcurrentHashMap map = DbManager.getMap(Enum.GameObjectType.City); - - if (map != null) { - - for (AbstractGameObject ago : map.values()) { - - City city = (City) ago; - - if (city != null) - if (city.getGuild() != null) { - ArrayList guildList = Guild.GuildRoster(city.getGuild()); - city.setPopulation(guildList.size()); - } - } - City.lastCityUpdate = System.currentTimeMillis(); - } else { - Logger.error("missing city map"); - } - - // Log metrics to console - Logger.info(WorldServer.getUptimeString()); - Logger.info(SimulationManager.getPopulationString()); - Logger.info(MessageDispatcher.getNetstatString()); - Logger.info(PurgeOprhans.recordsDeleted.toString() + "orphaned items deleted"); - } - - public static void decayShrines() { ArrayList shrineList = new ArrayList<>(); @@ -194,7 +89,6 @@ public class HourlyJobThread implements Runnable { if (mine.getOwningGuild().isEmptyGuild()) { HourlyJobThread.mineWindowOpen(mine); - Mine.setLastChange(System.currentTimeMillis()); continue; } @@ -204,14 +98,12 @@ public class HourlyJobThread implements Runnable { if (mine.getOwningGuild().getNation().getMineTime() == LocalDateTime.now().getHour() && mine.wasClaimed == false) { HourlyJobThread.mineWindowOpen(mine); - Mine.setLastChange(System.currentTimeMillis()); continue; } - // Close all the remaining mines + // Close the mine if it reaches this far - if (mineWindowClose(mine)) - Mine.setLastChange(System.currentTimeMillis()); + mineWindowClose(mine); } catch (Exception e) { Logger.error("mineID: " + mine.getObjectUUID(), e.toString()); @@ -271,8 +163,6 @@ public class HourlyJobThread implements Runnable { mine.nationName = nation.getName(); mine.nationTag = nation.getGuildTag(); - Mine.setLastChange(System.currentTimeMillis()); - mineBuilding.rebuildMine(); WorldGrid.updateObject(mineBuilding); @@ -292,4 +182,108 @@ public class HourlyJobThread implements Runnable { mine.wasClaimed = true; return true; } + + public void run() { + + // *** REFACTOR: TRY TRY TRY TRY {{{{{{{{{{{ OMG + + Logger.info("Hourly job is now running."); + + try { + + // Use the same hotZone this hour up and until + // the HotZone_Duration from the ConfigManager + + if (ZoneManager.hotZone == null) + ZoneManager.generateAndSetRandomHotzone(); + else + ZoneManager.hotZoneCycle = ZoneManager.hotZoneCycle + 1; + + if (ZoneManager.hotZoneCycle > Integer.parseInt(ConfigManager.MB_HOTZONE_DURATION.getValue())) + ZoneManager.generateAndSetRandomHotzone(); + + if (ZoneManager.hotZone == null) { + Logger.error("Null HotZone returned from ZoneManager"); + } else { + Logger.info("HotZone switched to: " + ZoneManager.hotZone.getName()); + } + + } catch (Exception e) { + Logger.error(e.toString()); + } + + // Open or Close mines for the current mine window. + + processMineWindow(); + + // Deposit mine resources to Guilds + + for (Mine mine : Mine.getMines()) { + + try { + mine.depositMineResources(); + } catch (Exception e) { + Logger.info(e.getMessage() + " for Mine " + mine.getObjectUUID()); + } + } + + // Reset time-gated access to WOO slider. + // *** Do this after the mines open/close! + + if (LocalDateTime.now().getHour() == MINE_LATE_WINDOW) { + Guild guild; + + for (AbstractGameObject dbObject : DbManager.getList(Enum.GameObjectType.Guild)) { + guild = (Guild) dbObject; + + if (guild != null) + guild.wooWasModified = false; + } + } + + // Mines can only be claimed once per cycle. + // This will reset at 1am after the last mine + // window closes. + + if (LocalDateTime.now().getHour() == MINE_LATE_WINDOW + 1) { + + for (Mine mine : Mine.getMines()) { + + if (mine.wasClaimed == true) + mine.wasClaimed = false; + } + } + + // Decay Shrines at midnight every day + + if (LocalDateTime.now().getHour() == MINE_LATE_WINDOW) + decayShrines(); + + // Update city population values + + ConcurrentHashMap map = DbManager.getMap(Enum.GameObjectType.City); + + if (map != null) { + + for (AbstractGameObject ago : map.values()) { + + City city = (City) ago; + + if (city != null) + if (city.getGuild() != null) { + ArrayList guildList = Guild.GuildRoster(city.getGuild()); + city.setPopulation(guildList.size()); + } + } + City.lastCityUpdate = System.currentTimeMillis(); + } else { + Logger.error("missing city map"); + } + + // Log metrics to console + Logger.info(WorldServer.getUptimeString()); + Logger.info(SimulationManager.getPopulationString()); + Logger.info(MessageDispatcher.getNetstatString()); + Logger.info(PurgeOprhans.recordsDeleted.toString() + "orphaned items deleted"); + } } From 176fdb51daf93a6bb9b05be7c0e3435ffca9d72a Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 24 Feb 2023 00:32:18 -0500 Subject: [PATCH 37/50] HotZone availability reset at 01am. --- src/engine/devcmd/cmds/HotzoneCmd.java | 3 +-- src/engine/gameManager/ZoneManager.java | 28 +++++++++++++++++++-- src/engine/objects/Zone.java | 1 - src/engine/workthreads/HourlyJobThread.java | 7 ++++++ 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/engine/devcmd/cmds/HotzoneCmd.java b/src/engine/devcmd/cmds/HotzoneCmd.java index dc9fce73..8dc61b5a 100644 --- a/src/engine/devcmd/cmds/HotzoneCmd.java +++ b/src/engine/devcmd/cmds/HotzoneCmd.java @@ -54,8 +54,7 @@ public class HotzoneCmd extends AbstractDevCmd { } if (input.equalsIgnoreCase("reset")) - for (Zone zone: ZoneManager.getAllZones()) - zone.hasBeenHotzone = false; + ZoneManager.resetHotZones(); return; } diff --git a/src/engine/gameManager/ZoneManager.java b/src/engine/gameManager/ZoneManager.java index 147affe2..8f8a7072 100644 --- a/src/engine/gameManager/ZoneManager.java +++ b/src/engine/gameManager/ZoneManager.java @@ -44,9 +44,10 @@ public enum ZoneManager { private static final ConcurrentHashMap zonesByID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD); private static final ConcurrentHashMap zonesByUUID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD); private static final ConcurrentHashMap zonesByName = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD); - private static final Set macroZones = Collections.newSetFromMap(new ConcurrentHashMap<>()); + public static final Set macroZones = Collections.newSetFromMap(new ConcurrentHashMap<>()); private static final Set npcCityZones = Collections.newSetFromMap(new ConcurrentHashMap<>()); private static final Set playerCityZones = Collections.newSetFromMap(new ConcurrentHashMap<>()); + // Find all zones coordinates fit into, starting with Sea Floor public static ArrayList getAllZonesIn(final Vector3fImmutable loc) { @@ -108,6 +109,30 @@ public enum ZoneManager { } + // Returns the number of available hotZones + // remaining in this cycle (1am) + public static int availableHotZones() { + + int count = 0; + + for (Zone zone : ZoneManager.macroZones) + if (zone.hasBeenHotzone) + count = count + 1; + + return count; + } + + // Resets the availability of hotZones + // for this cycle + + public static void resetHotZones() { + + for (Zone zone : ZoneManager.macroZones) + if (zone.hasBeenHotzone) + zone.hasBeenHotzone = false; + + } + public static Zone getZoneByUUID(final int zoneUUID) { return ZoneManager.zonesByUUID.get(zoneUUID); } @@ -129,7 +154,6 @@ public enum ZoneManager { ZoneManager.hotZone = zone; ZoneManager.hotZoneCycle = 1; // Used with HOTZONE_DURATION from config. zone.hasBeenHotzone = true; - zone.becameHotzone = LocalDateTime.now(); WorldServer.hotZoneLastUpdate = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant(); } diff --git a/src/engine/objects/Zone.java b/src/engine/objects/Zone.java index c1b9389e..10ca5136 100644 --- a/src/engine/objects/Zone.java +++ b/src/engine/objects/Zone.java @@ -61,7 +61,6 @@ public class Zone extends AbstractGameObject { public final Set zoneNPCSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); public final Set zoneMobSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); public boolean hasBeenHotzone = false; - public LocalDateTime becameHotzone = null; /** * ResultSet Constructor */ diff --git a/src/engine/workthreads/HourlyJobThread.java b/src/engine/workthreads/HourlyJobThread.java index dbf17e0c..5500a715 100644 --- a/src/engine/workthreads/HourlyJobThread.java +++ b/src/engine/workthreads/HourlyJobThread.java @@ -191,6 +191,13 @@ public class HourlyJobThread implements Runnable { try { + // Reset zone availability at 1am + // or if we run out of hotZones + + if (LocalDateTime.now().getHour() == 01 || + ZoneManager.availableHotZones() == 0) + ZoneManager.resetHotZones(); + // Use the same hotZone this hour up and until // the HotZone_Duration from the ConfigManager From a572a5fbf945bfde542cdf24ca5b704c13b4f20d Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 24 Feb 2023 00:42:34 -0500 Subject: [PATCH 38/50] Available hotZones added to devcmd. --- src/engine/devcmd/cmds/HotzoneCmd.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/engine/devcmd/cmds/HotzoneCmd.java b/src/engine/devcmd/cmds/HotzoneCmd.java index 8dc61b5a..d3389750 100644 --- a/src/engine/devcmd/cmds/HotzoneCmd.java +++ b/src/engine/devcmd/cmds/HotzoneCmd.java @@ -31,10 +31,11 @@ public class HotzoneCmd extends AbstractDevCmd { } @Override - protected void _doCmd(PlayerCharacter pc, String[] words, + protected void _doCmd(PlayerCharacter playerCharacter, String[] words, AbstractGameObject target) { StringBuilder data = new StringBuilder(); + String outString; for (String s : words) { data.append(s); @@ -44,17 +45,25 @@ public class HotzoneCmd extends AbstractDevCmd { String input = data.toString().trim(); if (input.length() == 0) { - throwbackInfo(pc, "Current hotZone: " + ZoneManager.hotZone.getName()); + outString = "Current hotZone: " + ZoneManager.hotZone.getName() + "\r\n"; + outString += "Available hotZones: " + ZoneManager.availableHotZones(); + throwbackInfo(playerCharacter, outString); return; } if (input.equalsIgnoreCase("random")) { ZoneManager.generateAndSetRandomHotzone(); - throwbackInfo(pc, "New hotZone: " + ZoneManager.hotZone.getName()); + outString = "New hotZone: " + ZoneManager.hotZone.getName() + "\r\n"; + outString += "Available hotZones: " + ZoneManager.availableHotZones(); + throwbackInfo(playerCharacter, outString); + return; } - if (input.equalsIgnoreCase("reset")) + if (input.equalsIgnoreCase("reset")) { ZoneManager.resetHotZones(); + throwbackInfo(playerCharacter, "Available hotZones: " + ZoneManager.availableHotZones()); + return; + } return; } From 52e46380a96553904b86b6cff0016c8b3cf00b45 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 24 Feb 2023 00:49:03 -0500 Subject: [PATCH 39/50] Available hotZones added to devcmd. --- src/engine/gameManager/ZoneManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/gameManager/ZoneManager.java b/src/engine/gameManager/ZoneManager.java index 8f8a7072..3fac70f9 100644 --- a/src/engine/gameManager/ZoneManager.java +++ b/src/engine/gameManager/ZoneManager.java @@ -116,7 +116,7 @@ public enum ZoneManager { int count = 0; for (Zone zone : ZoneManager.macroZones) - if (zone.hasBeenHotzone) + if (zone.hasBeenHotzone == false) count = count + 1; return count; From 3260582e3749af15d5022d6c62c896fc7ccd033b Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 24 Feb 2023 01:04:29 -0500 Subject: [PATCH 40/50] validHotZone filters hotZone count. --- src/engine/gameManager/ZoneManager.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/engine/gameManager/ZoneManager.java b/src/engine/gameManager/ZoneManager.java index 3fac70f9..463568f5 100644 --- a/src/engine/gameManager/ZoneManager.java +++ b/src/engine/gameManager/ZoneManager.java @@ -111,12 +111,13 @@ public enum ZoneManager { // Returns the number of available hotZones // remaining in this cycle (1am) + public static int availableHotZones() { int count = 0; for (Zone zone : ZoneManager.macroZones) - if (zone.hasBeenHotzone == false) + if (ZoneManager.validHotZone(zone)) count = count + 1; return count; From 8fde121570fe21b3008a224919104c692290f264 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 24 Feb 2023 01:22:00 -0500 Subject: [PATCH 41/50] lastHotZoneUpdate instant moved to ZoneManager. --- src/engine/gameManager/ZoneManager.java | 5 +++-- src/engine/net/client/handlers/CityDataHandler.java | 6 +----- src/engine/net/client/msg/HotzoneChangeMsg.java | 6 ++---- src/engine/server/world/WorldServer.java | 3 --- 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/engine/gameManager/ZoneManager.java b/src/engine/gameManager/ZoneManager.java index 463568f5..f73fbadb 100644 --- a/src/engine/gameManager/ZoneManager.java +++ b/src/engine/gameManager/ZoneManager.java @@ -17,9 +17,9 @@ import engine.objects.Building; import engine.objects.City; import engine.objects.Zone; import engine.server.MBServerStatics; -import engine.server.world.WorldServer; import org.pmw.tinylog.Logger; +import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; import java.util.ArrayList; @@ -37,6 +37,7 @@ public enum ZoneManager { ZONEMANAGER; + public static Instant hotZoneLastUpdate; /* Instance variables */ private static Zone seaFloor = null; public static Zone hotZone = null; @@ -155,7 +156,7 @@ public enum ZoneManager { ZoneManager.hotZone = zone; ZoneManager.hotZoneCycle = 1; // Used with HOTZONE_DURATION from config. zone.hasBeenHotzone = true; - WorldServer.hotZoneLastUpdate = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant(); + hotZoneLastUpdate = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant(); } diff --git a/src/engine/net/client/handlers/CityDataHandler.java b/src/engine/net/client/handlers/CityDataHandler.java index f1033a22..cad913b3 100644 --- a/src/engine/net/client/handlers/CityDataHandler.java +++ b/src/engine/net/client/handlers/CityDataHandler.java @@ -10,13 +10,9 @@ import engine.net.DispatchMessage; import engine.net.client.ClientConnection; import engine.net.client.msg.*; import engine.objects.City; -import engine.objects.Mine; import engine.objects.PlayerCharacter; -import engine.server.world.WorldServer; import engine.session.Session; -import java.time.ZoneId; - /* * @Author: * @Summary: Processes application protocol message which displays @@ -68,7 +64,7 @@ public class CityDataHandler extends AbstractClientMsgHandler { // If the hotZone has changed then update the client's map accordingly. - if (playerCharacter.getTimeStamp("hotzoneupdate") <= WorldServer.hotZoneLastUpdate.toEpochMilli() && ZoneManager.hotZone != null) { + if (playerCharacter.getTimeStamp("hotzoneupdate") <= ZoneManager.hotZoneLastUpdate.toEpochMilli() && ZoneManager.hotZone != null) { HotzoneChangeMsg hotzoneChangeMsg = new HotzoneChangeMsg(Enum.GameObjectType.Zone.ordinal(), ZoneManager.hotZone.getObjectUUID()); dispatch = Dispatch.borrow(playerCharacter, hotzoneChangeMsg); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); diff --git a/src/engine/net/client/msg/HotzoneChangeMsg.java b/src/engine/net/client/msg/HotzoneChangeMsg.java index d5874c41..2072976c 100644 --- a/src/engine/net/client/msg/HotzoneChangeMsg.java +++ b/src/engine/net/client/msg/HotzoneChangeMsg.java @@ -11,15 +11,13 @@ package engine.net.client.msg; import engine.gameManager.ConfigManager; -import engine.math.FastMath; +import engine.gameManager.ZoneManager; import engine.net.AbstractConnection; import engine.net.ByteBufferReader; import engine.net.ByteBufferWriter; import engine.net.client.Protocol; -import engine.server.world.WorldServer; import java.time.Duration; -import java.time.LocalDateTime; public class HotzoneChangeMsg extends ClientNetMsg { @@ -38,7 +36,7 @@ public class HotzoneChangeMsg extends ClientNetMsg { int hotZoneDuration = Integer.parseInt(ConfigManager.MB_HOTZONE_DURATION.getValue()); - endOfCycle = Duration.between(WorldServer.hotZoneLastUpdate, WorldServer.hotZoneLastUpdate.plusSeconds(hotZoneDuration * 3600)); + endOfCycle = Duration.between(ZoneManager.hotZoneLastUpdate, ZoneManager.hotZoneLastUpdate.plusSeconds(hotZoneDuration * 3600)); } diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index d239a41b..20bb7f1d 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -58,9 +58,7 @@ import java.io.IOException; import java.net.InetAddress; import java.nio.file.Files; import java.nio.file.Paths; -import java.time.Instant; import java.time.LocalDateTime; -import java.time.ZoneId; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -72,7 +70,6 @@ import static java.lang.System.exit; public class WorldServer { private static LocalDateTime bootTime = LocalDateTime.now(); - public static Instant hotZoneLastUpdate; public boolean isRunning = false; // Member variable declaration From 7a2c0d34569b9336bc19f84abf5ddfef97ed8061 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 24 Feb 2023 01:26:39 -0500 Subject: [PATCH 42/50] Work variable cleanup. --- src/engine/net/client/handlers/CityDataHandler.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/engine/net/client/handlers/CityDataHandler.java b/src/engine/net/client/handlers/CityDataHandler.java index cad913b3..17071b8d 100644 --- a/src/engine/net/client/handlers/CityDataHandler.java +++ b/src/engine/net/client/handlers/CityDataHandler.java @@ -28,8 +28,7 @@ public class CityDataHandler extends AbstractClientMsgHandler { @Override protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - boolean updateMine = false; - boolean updateCity = false; + boolean updateCities = false; Session playerSession; PlayerCharacter playerCharacter; Dispatch dispatch; @@ -52,12 +51,12 @@ public class CityDataHandler extends AbstractClientMsgHandler { if (playerCharacter.getTimeStamp("cityUpdate") <= City.lastCityUpdate) { playerCharacter.setTimeStamp("cityUpdate", System.currentTimeMillis()); - updateCity = true; + updateCities = true; } cityDataMsg cityDataMsg = new cityDataMsg(SessionManager.getSession(playerCharacter), false); cityDataMsg.updateMines(true); - cityDataMsg.updateCities(updateCity); + cityDataMsg.updateCities(updateCities); dispatch = Dispatch.borrow(playerCharacter, cityDataMsg); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); From 4422182eaeb8bdc5631cbabe175a87fbd9f56054 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 24 Feb 2023 08:34:25 -0500 Subject: [PATCH 43/50] Reset logic moved to within method. --- src/engine/gameManager/ZoneManager.java | 8 +++++--- src/engine/workthreads/HourlyJobThread.java | 4 +--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/engine/gameManager/ZoneManager.java b/src/engine/gameManager/ZoneManager.java index f73fbadb..53885f1c 100644 --- a/src/engine/gameManager/ZoneManager.java +++ b/src/engine/gameManager/ZoneManager.java @@ -222,13 +222,15 @@ public enum ZoneManager { if (ZoneManager.macroZones.isEmpty()) return; - for (Zone zone : ZoneManager.macroZones) { + // Reset hotZone availability if none are left. + if (ZoneManager.availableHotZones() == 0) + ZoneManager.resetHotZones(); + + for (Zone zone : ZoneManager.macroZones) if (validHotZone(zone)) zoneArray.add(zone.getObjectUUID()); - } - int entryIndex = ThreadLocalRandom.current().nextInt(zoneArray.size()); hotzone = ZoneManager.getZoneByUUID(zoneArray.get(entryIndex)); diff --git a/src/engine/workthreads/HourlyJobThread.java b/src/engine/workthreads/HourlyJobThread.java index 5500a715..f84e6346 100644 --- a/src/engine/workthreads/HourlyJobThread.java +++ b/src/engine/workthreads/HourlyJobThread.java @@ -192,10 +192,8 @@ public class HourlyJobThread implements Runnable { try { // Reset zone availability at 1am - // or if we run out of hotZones - if (LocalDateTime.now().getHour() == 01 || - ZoneManager.availableHotZones() == 0) + if (LocalDateTime.now().getHour() == 01) ZoneManager.resetHotZones(); // Use the same hotZone this hour up and until From 994db1e13170094df706367139f620abd6757d48 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 24 Feb 2023 08:45:03 -0500 Subject: [PATCH 44/50] Class renamed to fix case. --- src/engine/net/client/Protocol.java | 2 +- src/engine/net/client/handlers/CityDataHandler.java | 2 +- .../net/client/handlers/RequestEnterWorldHandler.java | 2 +- .../client/msg/{cityDataMsg.java => CityDataMsg.java} | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) rename src/engine/net/client/msg/{cityDataMsg.java => CityDataMsg.java} (96%) diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index c26d31f8..19cc0e4e 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -74,7 +74,7 @@ public enum Protocol { CHECKUNIQUEGUILD(0x689097D7, GuildCreationOptionsMsg.class, GuildCreationOptionsHandler.class), // Set Guild Name/Motto in Use Guild Charter CITYASSET(0x7cae1678, CityAssetMsg.class, null), CITYCHOICE(0x406610BB, CityChoiceMsg.class, CityChoiceMsgHandler.class), - CITYDATA(0xB8A947D4, cityDataMsg.class, CityDataHandler.class), + CITYDATA(0xB8A947D4, CityDataMsg.class, CityDataHandler.class), CITYZONE(0x254947F2, CityZoneMsg.class, null), //For Creating City Object Clientside(Terraform)/Rename City. CLAIMASSET(0x948C62CC, ClaimAssetMsg.class, ClaimAssetMsgHandler.class), // ClaimAsset CLAIMGUILDTREE(0xFD1C6442, ClaimGuildTreeMsg.class, ClaimGuildTreeMsgHandler.class), diff --git a/src/engine/net/client/handlers/CityDataHandler.java b/src/engine/net/client/handlers/CityDataHandler.java index 17071b8d..928a6964 100644 --- a/src/engine/net/client/handlers/CityDataHandler.java +++ b/src/engine/net/client/handlers/CityDataHandler.java @@ -54,7 +54,7 @@ public class CityDataHandler extends AbstractClientMsgHandler { updateCities = true; } - cityDataMsg cityDataMsg = new cityDataMsg(SessionManager.getSession(playerCharacter), false); + CityDataMsg cityDataMsg = new CityDataMsg(SessionManager.getSession(playerCharacter), false); cityDataMsg.updateMines(true); cityDataMsg.updateCities(updateCities); diff --git a/src/engine/net/client/handlers/RequestEnterWorldHandler.java b/src/engine/net/client/handlers/RequestEnterWorldHandler.java index e40ad17a..ddd017c5 100644 --- a/src/engine/net/client/handlers/RequestEnterWorldHandler.java +++ b/src/engine/net/client/handlers/RequestEnterWorldHandler.java @@ -99,7 +99,7 @@ public class RequestEnterWorldHandler extends AbstractClientMsgHandler { } // Object Data - cityDataMsg wom = new cityDataMsg(session, true); + CityDataMsg wom = new CityDataMsg(session, true); dispatch = Dispatch.borrow(player, wom); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); diff --git a/src/engine/net/client/msg/cityDataMsg.java b/src/engine/net/client/msg/CityDataMsg.java similarity index 96% rename from src/engine/net/client/msg/cityDataMsg.java rename to src/engine/net/client/msg/CityDataMsg.java index f8ca702c..c70ca624 100644 --- a/src/engine/net/client/msg/cityDataMsg.java +++ b/src/engine/net/client/msg/CityDataMsg.java @@ -27,7 +27,7 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.concurrent.ConcurrentHashMap; -public class cityDataMsg extends ClientNetMsg { +public class CityDataMsg extends ClientNetMsg { private Session s; private final boolean forEnterWorld; @@ -47,13 +47,13 @@ public class cityDataMsg extends ClientNetMsg { * @param s Session * @param forEnterWorld boolean flag */ - public cityDataMsg(Session s, boolean forEnterWorld) { + public CityDataMsg(Session s, boolean forEnterWorld) { super(Protocol.CITYDATA); this.s = s; this.forEnterWorld = forEnterWorld; } - public cityDataMsg(boolean updateCities, boolean updateRunegates, boolean updateMines) { + public CityDataMsg(boolean updateCities, boolean updateRunegates, boolean updateMines) { super(Protocol.CITYDATA); this.s = null; this.forEnterWorld = false; @@ -68,7 +68,7 @@ public class cityDataMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public cityDataMsg(AbstractConnection origin, ByteBufferReader reader) { + public CityDataMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.CITYDATA, origin, reader); this.forEnterWorld = false; } @@ -174,7 +174,7 @@ public class cityDataMsg extends ClientNetMsg { //Check to see if its time to renew cache. if (cachedExpireTime < System.currentTimeMillis()) { synchronized (cachedEnterWorld) { - cityDataMsg.attemptSerializeForEnterWorld(cachedEnterWorld); + CityDataMsg.attemptSerializeForEnterWorld(cachedEnterWorld); } cachedExpireTime = startT + 60000; } From bbbd5f89964a81c6f477cbcd82a4078924a7d67b Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 24 Feb 2023 08:48:36 -0500 Subject: [PATCH 45/50] Time remaining is from now(). --- src/engine/net/client/msg/HotzoneChangeMsg.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/engine/net/client/msg/HotzoneChangeMsg.java b/src/engine/net/client/msg/HotzoneChangeMsg.java index 2072976c..aa570a33 100644 --- a/src/engine/net/client/msg/HotzoneChangeMsg.java +++ b/src/engine/net/client/msg/HotzoneChangeMsg.java @@ -18,6 +18,7 @@ import engine.net.ByteBufferWriter; import engine.net.client.Protocol; import java.time.Duration; +import java.time.Instant; public class HotzoneChangeMsg extends ClientNetMsg { @@ -36,7 +37,7 @@ public class HotzoneChangeMsg extends ClientNetMsg { int hotZoneDuration = Integer.parseInt(ConfigManager.MB_HOTZONE_DURATION.getValue()); - endOfCycle = Duration.between(ZoneManager.hotZoneLastUpdate, ZoneManager.hotZoneLastUpdate.plusSeconds(hotZoneDuration * 3600)); + endOfCycle = Duration.between(Instant.now(), ZoneManager.hotZoneLastUpdate.plusSeconds(hotZoneDuration * 3600)); } From 72a610fd0ceb81aca561049b1bb14d8289983dd6 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 24 Feb 2023 09:05:47 -0500 Subject: [PATCH 46/50] Seconds remaining calculated only once. --- src/engine/gameManager/ZoneManager.java | 2 +- src/engine/net/client/msg/HotzoneChangeMsg.java | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/engine/gameManager/ZoneManager.java b/src/engine/gameManager/ZoneManager.java index 53885f1c..66211db9 100644 --- a/src/engine/gameManager/ZoneManager.java +++ b/src/engine/gameManager/ZoneManager.java @@ -156,7 +156,7 @@ public enum ZoneManager { ZoneManager.hotZone = zone; ZoneManager.hotZoneCycle = 1; // Used with HOTZONE_DURATION from config. zone.hasBeenHotzone = true; - hotZoneLastUpdate = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant(); + ZoneManager.hotZoneLastUpdate = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant(); } diff --git a/src/engine/net/client/msg/HotzoneChangeMsg.java b/src/engine/net/client/msg/HotzoneChangeMsg.java index aa570a33..9fc1a665 100644 --- a/src/engine/net/client/msg/HotzoneChangeMsg.java +++ b/src/engine/net/client/msg/HotzoneChangeMsg.java @@ -19,13 +19,15 @@ import engine.net.client.Protocol; import java.time.Duration; import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; public class HotzoneChangeMsg extends ClientNetMsg { private int zoneType; private int zoneID; - private Duration endOfCycle; + private int secondsRemaining; /** * This is the general purpose constructor. @@ -36,8 +38,8 @@ public class HotzoneChangeMsg extends ClientNetMsg { this.zoneID = zoneID; int hotZoneDuration = Integer.parseInt(ConfigManager.MB_HOTZONE_DURATION.getValue()); - - endOfCycle = Duration.between(Instant.now(), ZoneManager.hotZoneLastUpdate.plusSeconds(hotZoneDuration * 3600)); + Instant currentInstant = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant(); + secondsRemaining = (int) Duration.between(currentInstant, ZoneManager.hotZoneLastUpdate.plusSeconds(hotZoneDuration * 3600)).getSeconds(); } @@ -59,7 +61,7 @@ public class HotzoneChangeMsg extends ClientNetMsg { protected void _serialize(ByteBufferWriter writer) { writer.putInt(this.zoneType); writer.putInt(this.zoneID); - writer.putInt((int) endOfCycle.getSeconds()); + writer.putInt(secondsRemaining); } /** From cacf67a81c6714605ab1e43ff1845c0f3cce1e1a Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 24 Feb 2023 09:08:45 -0500 Subject: [PATCH 47/50] lastUpdate always from top of the hour. --- src/engine/gameManager/ZoneManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/gameManager/ZoneManager.java b/src/engine/gameManager/ZoneManager.java index 66211db9..1be004cb 100644 --- a/src/engine/gameManager/ZoneManager.java +++ b/src/engine/gameManager/ZoneManager.java @@ -156,7 +156,7 @@ public enum ZoneManager { ZoneManager.hotZone = zone; ZoneManager.hotZoneCycle = 1; // Used with HOTZONE_DURATION from config. zone.hasBeenHotzone = true; - ZoneManager.hotZoneLastUpdate = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant(); + ZoneManager.hotZoneLastUpdate = LocalDateTime.now().withMinute(0).withSecond(0).atZone(ZoneId.systemDefault()).toInstant(); } From c51f6b73affeee74b77301543d4f5b3fdc3bad58 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 24 Feb 2023 09:48:15 -0500 Subject: [PATCH 48/50] ProductionRate added to ConfigManager. --- src/engine/devcmd/cmds/SetRateCmd.java | 99 ----------------------- src/engine/gameManager/ConfigManager.java | 2 + src/engine/gameManager/DevCmdManager.java | 1 - src/engine/objects/ItemFactory.java | 17 ++-- src/engine/server/MBServerStatics.java | 1 - 5 files changed, 9 insertions(+), 111 deletions(-) delete mode 100644 src/engine/devcmd/cmds/SetRateCmd.java diff --git a/src/engine/devcmd/cmds/SetRateCmd.java b/src/engine/devcmd/cmds/SetRateCmd.java deleted file mode 100644 index f40c627b..00000000 --- a/src/engine/devcmd/cmds/SetRateCmd.java +++ /dev/null @@ -1,99 +0,0 @@ -// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . -// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· -// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ -// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ -// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ -// Magicbane Emulator Project © 2013 - 2022 -// www.magicbane.com - - -package engine.devcmd.cmds; - -import engine.Enum.DropRateType; -import engine.devcmd.AbstractDevCmd; -import engine.objects.AbstractGameObject; -import engine.objects.PlayerCharacter; -import engine.server.MBServerStatics; -import engine.server.world.WorldServer; - -/** - * - * @author Murray - * - */ -public class SetRateCmd extends AbstractDevCmd { - - public SetRateCmd() { - super("setrate"); - } - - @Override - protected void _doCmd(PlayerCharacter pc, String[] args, AbstractGameObject target) { - - if (args.length != 2) { - this.sendUsage(pc); - return; - } - - float mod = 0f; - - try { - mod = Float.parseFloat(args[1]); - } catch (NumberFormatException e) { - throwbackError(pc, "Supplied data failed to parse to Float."); - return; - } - - - if (args[0].equals("exp")){ - - DropRateType.EXP_RATE_MOD.rate = mod; - throwbackInfo(pc, "Experience Rate set to: " + mod); - - } else if (args[0].equals("gold")){ - - DropRateType.GOLD_RATE_MOD.rate = mod; - throwbackInfo(pc, "Gold Rate set to: " + mod); - - } else if (args[0].equals("drop")){ - - DropRateType.DROP_RATE_MOD.rate = mod; - throwbackInfo(pc, "Drop Multiplier Rate set to: " + mod); - - } else if (args[0].equals("hotexp")){ - - DropRateType.HOT_EXP_RATE_MOD.rate = mod; - throwbackInfo(pc, "HOTZONE Experience Rate set to: " + mod); - - } else if (args[0].equals("hotgold")){ - - DropRateType.HOT_GOLD_RATE_MOD.rate = mod; - throwbackInfo(pc, "HOTZONE Gold Rate set to: " + mod); - - } else if (args[0].equals("hotdrop")){ - - DropRateType.HOT_DROP_RATE_MOD.rate = mod; - throwbackInfo(pc, "HOTZONE Drop Multiplier Rate set to: " + mod); - - } else if (args[0].equals("production")){ - - MBServerStatics.PRODUCTION_TIME_MULTIPLIER = mod; - throwbackInfo(pc, "Production Time Multiplier Rate set to: " + mod); - - } else { - this.sendUsage(pc); - } - - } - - @Override - protected String _getUsageString() { - return "' /setrate {exp|gold|drop|hotexp|hotgold|hotdrop} rate'"; - } - - @Override - protected String _getHelpString() { - return "Sets the rates for exp, gold or drops. Accepts a float, defaults to 1.0"; - } - -} \ No newline at end of file diff --git a/src/engine/gameManager/ConfigManager.java b/src/engine/gameManager/ConfigManager.java index 8278bbf5..f3de52ec 100644 --- a/src/engine/gameManager/ConfigManager.java +++ b/src/engine/gameManager/ConfigManager.java @@ -73,6 +73,8 @@ public enum ConfigManager { MB_HOTZONE_MIN_LEVEL, + MB_PRODUCTION_RATE, + // MagicBot configuration. MB_MAGICBOT_SERVERID, diff --git a/src/engine/gameManager/DevCmdManager.java b/src/engine/gameManager/DevCmdManager.java index 8f6d8ea8..f51157d2 100644 --- a/src/engine/gameManager/DevCmdManager.java +++ b/src/engine/gameManager/DevCmdManager.java @@ -109,7 +109,6 @@ public enum DevCmdManager { DevCmdManager.registerDevCmd(new GetCacheCountCmd()); DevCmdManager.registerDevCmd(new GetRuneDropRateCmd()); DevCmdManager.registerDevCmd(new DecachePlayerCmd()); - DevCmdManager.registerDevCmd(new SetRateCmd()); DevCmdManager.registerDevCmd(new AuditMobsCmd()); DevCmdManager.registerDevCmd(new ChangeNameCmd()); DevCmdManager.registerDevCmd(new GuildListCmd()); diff --git a/src/engine/objects/ItemFactory.java b/src/engine/objects/ItemFactory.java index 92491684..33d93d8c 100644 --- a/src/engine/objects/ItemFactory.java +++ b/src/engine/objects/ItemFactory.java @@ -13,10 +13,7 @@ import engine.Enum; import engine.Enum.ItemContainerType; import engine.Enum.ItemType; import engine.Enum.OwnerType; -import engine.gameManager.BuildingManager; -import engine.gameManager.ChatManager; -import engine.gameManager.DbManager; -import engine.gameManager.PowersManager; +import engine.gameManager.*; import engine.net.ItemProductionManager; import engine.net.ItemQueue; import engine.net.client.ClientConnection; @@ -202,7 +199,7 @@ public class ItemFactory { // is used to determin whether or not an object has // compelted rolling. The game object exists previously // to this, not when 'compelte' is pressed. - long upgradeTime = System.currentTimeMillis() + (long)(time * MBServerStatics.PRODUCTION_TIME_MULTIPLIER) ; + long upgradeTime = System.currentTimeMillis() + (long)(time * Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue())); DateTime dateTime = new DateTime(); dateTime = dateTime.withMillis(upgradeTime); @@ -220,7 +217,7 @@ public class ItemFactory { pi.setAmount(itemsToRoll); pi.setRandom(false); - ItemQueue produced = ItemQueue.borrow(pi, (long) (time * MBServerStatics.PRODUCTION_TIME_MULTIPLIER)); + ItemQueue produced = ItemQueue.borrow(pi, (long) (time * Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue()))); ItemProductionManager.send(produced); return ml; @@ -620,7 +617,7 @@ public class ItemFactory { // is used to determin whether or not an object has // compelted rolling. The game object exists previously // to this, not when 'compelte' is pressed. - long upgradeTime = System.currentTimeMillis() + (long)(time * MBServerStatics.PRODUCTION_TIME_MULTIPLIER) ; + long upgradeTime = System.currentTimeMillis() + (long)(time * Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue())) ; DateTime dateTime = new DateTime(); dateTime = dateTime.withMillis(upgradeTime); @@ -637,7 +634,7 @@ public class ItemFactory { pi.setProducedItemID(ml.getObjectUUID()); pi.setAmount(itemsToRoll); - ItemQueue produced = ItemQueue.borrow(pi, (long) (time * MBServerStatics.PRODUCTION_TIME_MULTIPLIER)); + ItemQueue produced = ItemQueue.borrow(pi, (long) (time * Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue()))); ItemProductionManager.send(produced); }catch(Exception e){ Logger.error(e); @@ -906,7 +903,7 @@ public class ItemFactory { // is used to determin whether or not an object has // compelted rolling. The game object exists previously // to this, not when 'compelte' is pressed. - long upgradeTime = System.currentTimeMillis() + (long)(time * MBServerStatics.PRODUCTION_TIME_MULTIPLIER) ; + long upgradeTime = System.currentTimeMillis() + (long)(time * Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue())) ; DateTime dateTime = new DateTime(); dateTime = dateTime.withMillis(upgradeTime); @@ -920,7 +917,7 @@ public class ItemFactory { ProducedItem pi = new ProducedItem(toRoll.getObjectUUID(),vendor.getObjectUUID(),toRoll.getItemBaseID(),dateTime,true,prefix, suffix, toRoll.getCustomName(),playerID); pi.setProducedItemID(toRoll.getObjectUUID()); pi.setAmount(itemsToRoll); - ItemQueue produced = ItemQueue.borrow(pi, (long) (time * MBServerStatics.PRODUCTION_TIME_MULTIPLIER)); + ItemQueue produced = ItemQueue.borrow(pi, (long) (time * Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue()))); ItemProductionManager.send(produced); return toRoll; } diff --git a/src/engine/server/MBServerStatics.java b/src/engine/server/MBServerStatics.java index a986901b..0e1ccc12 100644 --- a/src/engine/server/MBServerStatics.java +++ b/src/engine/server/MBServerStatics.java @@ -683,7 +683,6 @@ public class MBServerStatics { public static final int DESPAWN_TIMER_ONCE_LOOTED = 5 * 1000; public static final int MAX_COMBAT_HITBOX_RADIUS = 80; public static final int PROC_CHANCE = 5; // %chance to proc - public static float PRODUCTION_TIME_MULTIPLIER = .5f; /* * Mob loot -- gold calculations From d5c219897d6ffc2c8e1b321998c5ef74b62722c6 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 24 Feb 2023 10:45:46 -0500 Subject: [PATCH 49/50] Experience Modifiers added to ConfigManager --- src/engine/Enum.java | 30 -------------- src/engine/gameManager/ConfigManager.java | 12 ++---- src/engine/objects/Experience.java | 50 +++++++++++------------ src/engine/objects/LootTable.java | 3 +- src/engine/objects/Mob.java | 9 ++-- 5 files changed, 32 insertions(+), 72 deletions(-) diff --git a/src/engine/Enum.java b/src/engine/Enum.java index 6c82024c..d2718ab9 100644 --- a/src/engine/Enum.java +++ b/src/engine/Enum.java @@ -2643,36 +2643,6 @@ public class Enum { MAGE; } - public enum DropRateType { - EXP_RATE_MOD, - GOLD_RATE_MOD, - DROP_RATE_MOD, - HOT_EXP_RATE_MOD, - HOT_GOLD_RATE_MOD, - HOT_DROP_RATE_MOD; - - public float rate; - - public static void init() { - - for (DropRateType rateType : DropRateType.values()) { - - switch (rateType) { - case EXP_RATE_MOD: - case GOLD_RATE_MOD: - case DROP_RATE_MOD: - rateType.rate = Float.parseFloat(ConfigManager.MB_NORMAL_RATE.getValue()); - break; - case HOT_EXP_RATE_MOD: - case HOT_GOLD_RATE_MOD: - case HOT_DROP_RATE_MOD: - rateType.rate = Float.parseFloat(ConfigManager.MB_HOTZONE_RATE.getValue()); - break; - } - } - } - } - public enum MinionType { AELFBORNGUARD(951,1637, MinionClass.MELEE, "Guard","Aelfborn"), AELFBORNMAGE(952, 1635, MinionClass.MAGE,"Adept","Aelfborn"), diff --git a/src/engine/gameManager/ConfigManager.java b/src/engine/gameManager/ConfigManager.java index f3de52ec..b23ca660 100644 --- a/src/engine/gameManager/ConfigManager.java +++ b/src/engine/gameManager/ConfigManager.java @@ -14,7 +14,6 @@ package engine.gameManager; import engine.Enum; import engine.net.NetMsgHandler; -import engine.server.MBServerStatics; import engine.server.login.LoginServer; import engine.server.world.WorldServer; import org.pmw.tinylog.Logger; @@ -67,8 +66,10 @@ public enum ConfigManager { MB_WORLD_KEYCLONE_MAX, //drop rates - MB_NORMAL_RATE, - MB_HOTZONE_RATE, + MB_NORMAL_EXP_RATE, + MB_NORMAL_DROP_RATE, + MB_HOTZONE_EXP_RATE, + MB_HOTZONE_DROP_RATE, MB_HOTZONE_DURATION, MB_HOTZONE_MIN_LEVEL, @@ -117,11 +118,6 @@ public enum ConfigManager { return false; } - // Setting drop rates - - Logger.info("Setting drop rates..."); - Enum.DropRateType.init(); - // compile regex here Logger.info("Compiling regex"); diff --git a/src/engine/objects/Experience.java b/src/engine/objects/Experience.java index d828c24b..32653186 100644 --- a/src/engine/objects/Experience.java +++ b/src/engine/objects/Experience.java @@ -11,6 +11,7 @@ package engine.objects; import engine.Enum; import engine.Enum.TargetColor; +import engine.gameManager.ConfigManager; import engine.gameManager.ZoneManager; import engine.math.Vector3fImmutable; import engine.server.MBServerStatics; @@ -332,12 +333,7 @@ public class Experience { if (killer == null || mob == null) return; - double xp = 0.0; - - //Get the xp modifier for the world - float xpMod = Enum.DropRateType.EXP_RATE_MOD.rate; - - + double grantedExperience = 0.0; if (g != null) { // Do group EXP stuff @@ -374,18 +370,18 @@ public class Experience { } // Process every player in the group getting XP - for (PlayerCharacter pc : giveEXPTo) { - if (pc.getLevel() >= MBServerStatics.LEVELCAP) + for (PlayerCharacter playerCharacter : giveEXPTo) { + if (playerCharacter.getLevel() >= MBServerStatics.LEVELCAP) continue; // Sets Max XP with server exp mod taken into account. - xp = (double) xpMod * maxXPPerKill(pc.getLevel()); + grantedExperience = (double) Float.parseFloat(ConfigManager.MB_NORMAL_EXP_RATE.getValue()) * maxXPPerKill(playerCharacter.getLevel()); // Adjust XP for Mob Level - xp *= getConMod(pc, mob); + grantedExperience *= getConMod(playerCharacter, mob); // Process XP for this member - penalty = getGroupMemberPenalty(leadership, pc, giveEXPTo, + penalty = getGroupMemberPenalty(leadership, playerCharacter, giveEXPTo, highestLevel); // Leadership Penalty Reduction @@ -393,27 +389,27 @@ public class Experience { penalty -= ((leadership) * 0.01) * penalty; // Modify for hotzone - if (xp != 0) + if (grantedExperience != 0) if (ZoneManager.inHotZone(mob.getLoc())) - xp *= Enum.DropRateType.HOT_EXP_RATE_MOD.rate; + grantedExperience *= Float.parseFloat(ConfigManager.MB_HOTZONE_EXP_RATE.getValue()); // Check for 0 XP due to white mob, otherwise subtract penalty // xp - if (xp == 0) { - xp = 1; + if (grantedExperience == 0) { + grantedExperience = 1; } else { - xp -= (penalty * 0.01) * xp; + grantedExperience -= (penalty * 0.01) * grantedExperience; // Errant Penalty Calculation - if (pc.getGuild().isEmptyGuild()) - xp *= 0.6; + if (playerCharacter.getGuild().isEmptyGuild()) + grantedExperience *= 0.6; } - if (xp == 0) - xp = 1; + if (grantedExperience == 0) + grantedExperience = 1; // Grant the player the EXP - pc.grantXP((int) Math.floor(xp)); + playerCharacter.grantXP((int) Math.floor(grantedExperience)); } } else { // Give EXP to a single character @@ -424,20 +420,20 @@ public class Experience { return; // Get XP and adjust for Mob Level with world xp modifier taken into account - xp = (double) xpMod * maxXPPerKill(killer.getLevel()); - xp *= getConMod(killer, mob); + grantedExperience = (double) Float.parseFloat(ConfigManager.MB_NORMAL_EXP_RATE.getValue()) * maxXPPerKill(killer.getLevel()); + grantedExperience *= getConMod(killer, mob); // Modify for hotzone if (ZoneManager.inHotZone(mob.getLoc())) - xp *= Enum.DropRateType.HOT_EXP_RATE_MOD.rate; + grantedExperience *= Float.parseFloat(ConfigManager.MB_HOTZONE_EXP_RATE.getValue()); // Errant penalty - if (xp != 1) + if (grantedExperience != 1) if (killer.getGuild().isEmptyGuild()) - xp *= .6; + grantedExperience *= .6; // Grant XP - killer.grantXP((int) Math.floor(xp)); + killer.grantXP((int) Math.floor(grantedExperience)); } } } diff --git a/src/engine/objects/LootTable.java b/src/engine/objects/LootTable.java index acdc033d..c9c5fb9d 100644 --- a/src/engine/objects/LootTable.java +++ b/src/engine/objects/LootTable.java @@ -13,6 +13,7 @@ import engine.Enum; import engine.Enum.ItemContainerType; import engine.Enum.ItemType; import engine.Enum.OwnerType; +import engine.gameManager.ConfigManager; import engine.gameManager.DbManager; import engine.gameManager.ZoneManager; import engine.server.MBServerStatics; @@ -210,7 +211,7 @@ public class LootTable { float chance = mlb.getChance() *.01f; - chance *= Enum.DropRateType.DROP_RATE_MOD.rate; + chance *= Float.parseFloat(ConfigManager.MB_NORMAL_DROP_RATE.getValue()); calculatedLootTable = mlb.getLootTableID(); diff --git a/src/engine/objects/Mob.java b/src/engine/objects/Mob.java index 9c28ec9f..1bd41d53 100644 --- a/src/engine/objects/Mob.java +++ b/src/engine/objects/Mob.java @@ -1506,17 +1506,14 @@ public class Mob extends AbstractIntelligenceAgent { double gold = (ThreadLocalRandom.current().nextDouble() * (maxGold - minGold) + minGold); - //server specific gold multiplier - double goldMod = DropRateType.GOLD_RATE_MOD.rate; - gold *= goldMod; + + gold *= Float.parseFloat(ConfigManager.MB_NORMAL_DROP_RATE.getValue()); //modify for hotzone if (ZoneManager.inHotZone(mob.getLoc())) - gold *= DropRateType.HOT_GOLD_RATE_MOD.rate; - - gold *= DropRateType.GOLD_RATE_MOD.rate; + gold *= Float.parseFloat(ConfigManager.MB_HOTZONE_DROP_RATE.getValue()); return (int) gold; } From f0f91325ba547055591ee8f9420600703fe0d8c3 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 26 Feb 2023 07:31:26 -0500 Subject: [PATCH 50/50] Reset is handled when picking new hotZone. --- src/engine/gameManager/ZoneManager.java | 8 ++++---- src/engine/workthreads/HourlyJobThread.java | 5 ----- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/engine/gameManager/ZoneManager.java b/src/engine/gameManager/ZoneManager.java index 1be004cb..5ac8a055 100644 --- a/src/engine/gameManager/ZoneManager.java +++ b/src/engine/gameManager/ZoneManager.java @@ -216,7 +216,7 @@ public enum ZoneManager { public static final void generateAndSetRandomHotzone() { - Zone hotzone; + Zone hotZone; ArrayList zoneArray = new ArrayList<>(); if (ZoneManager.macroZones.isEmpty()) @@ -233,14 +233,14 @@ public enum ZoneManager { int entryIndex = ThreadLocalRandom.current().nextInt(zoneArray.size()); - hotzone = ZoneManager.getZoneByUUID(zoneArray.get(entryIndex)); + hotZone = ZoneManager.getZoneByUUID(zoneArray.get(entryIndex)); - if (hotzone == null) { + if (hotZone == null) { Logger.error("Hotzone is null"); return; } - ZoneManager.setHotZone(hotzone); + ZoneManager.setHotZone(hotZone); } diff --git a/src/engine/workthreads/HourlyJobThread.java b/src/engine/workthreads/HourlyJobThread.java index f84e6346..dbf17e0c 100644 --- a/src/engine/workthreads/HourlyJobThread.java +++ b/src/engine/workthreads/HourlyJobThread.java @@ -191,11 +191,6 @@ public class HourlyJobThread implements Runnable { try { - // Reset zone availability at 1am - - if (LocalDateTime.now().getHour() == 01) - ZoneManager.resetHotZones(); - // Use the same hotZone this hour up and until // the HotZone_Duration from the ConfigManager