From d4ea31b91f45e68b4b9daee3ac7f08ca2b15f94b Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Wed, 11 Sep 2024 19:51:48 -0500 Subject: [PATCH] teleport to mines --- .../client/msg/TeleportRepledgeListMsg.java | 14 +- src/engine/objects/Mine.java | 141 ++++++++++++++++++ 2 files changed, 152 insertions(+), 3 deletions(-) diff --git a/src/engine/net/client/msg/TeleportRepledgeListMsg.java b/src/engine/net/client/msg/TeleportRepledgeListMsg.java index a76f2abf..efccf8e4 100644 --- a/src/engine/net/client/msg/TeleportRepledgeListMsg.java +++ b/src/engine/net/client/msg/TeleportRepledgeListMsg.java @@ -16,6 +16,7 @@ import engine.net.ByteBufferReader; import engine.net.ByteBufferWriter; import engine.net.client.Protocol; import engine.objects.City; +import engine.objects.Mine; import engine.objects.PlayerCharacter; import java.util.ArrayList; @@ -24,6 +25,7 @@ import java.util.ArrayList; public class TeleportRepledgeListMsg extends ClientNetMsg { ArrayList cities; + ArrayList mines; private PlayerCharacter player; private boolean isTeleport; @@ -77,10 +79,12 @@ public class TeleportRepledgeListMsg extends ClientNetMsg { public void configure() { - if (isTeleport) + if (isTeleport) { cities = City.getCitiesToTeleportTo(player); - else + mines = Mine.getMinesToTeleportTo(player); + }else { cities = City.getCitiesToRepledgeTo(player); + } } /** @@ -96,10 +100,14 @@ public class TeleportRepledgeListMsg extends ClientNetMsg { for (int i = 0; i < 3; i++) writer.putInt(0); - writer.putInt(cities.size()); + writer.putInt(cities.size() + mines.size()); for (City city : cities) City.serializeForClientMsg(city, writer); + + for(Mine mine : mines) + Mine.serializeForClientMsgTeleport(mine, writer); + } public PlayerCharacter getPlayer() { diff --git a/src/engine/objects/Mine.java b/src/engine/objects/Mine.java index 882b6b20..af8ec310 100644 --- a/src/engine/objects/Mine.java +++ b/src/engine/objects/Mine.java @@ -319,6 +319,15 @@ public class Mine extends AbstractGameObject { return true; } + public static ArrayList getMinesToTeleportTo(PlayerCharacter player) { + ArrayList mines = new ArrayList<>(); + for(Mine mine : Mine.getMines()) + if(mine.getOwningGuild() != null && mine.getOwningGuild().getNation().equals(player.getGuild().getNation())) + mines.add(mine); + + return mines; + } + public boolean changeProductionType(Resource resource) { if (!this.validForMine(resource)) return false; @@ -661,4 +670,136 @@ public class Mine extends AbstractGameObject { _playerMemory.removeAll(toRemove); } + public static Building getTower(Mine mine){ + + return null; + } + public static void serializeForClientMsgTeleport(Mine mine, ByteBufferWriter writer) { + AbstractCharacter guildRuler; + Guild rulingGuild; + Guild rulingNation; + java.time.LocalDateTime dateTime1900; + + // Cities aren't a mine without a TOL. Time to early exit. + // No need to spam the log here as non-existant TOL's are indicated + // during bootstrap routines. + + if (Mine.getTower(mine) == null) { + + Logger.error("NULL TOL FOR " + mine.zoneName + " mine"); + } + + + // Assign mine owner + + if (Mine.getTower(mine) != null && Mine.getTower(mine).getOwner() != null) + guildRuler = Mine.getTower(mine).getOwner(); + else + guildRuler = null; + + // If is an errant tree, use errant guild for serialization. + // otherwise we serialize the soverign guild + + if (guildRuler == null) + rulingGuild = Guild.getErrantGuild(); + else + rulingGuild = guildRuler.getGuild(); + + rulingNation = rulingGuild.getNation(); + + // Begin Serialzing soverign guild data + writer.putInt(mine.getObjectType().ordinal()); + writer.putInt(mine.getObjectUUID()); + writer.putString(Mine.getTower(mine).getName()); + writer.putInt(rulingGuild.getObjectType().ordinal()); + writer.putInt(rulingGuild.getObjectUUID()); + + writer.putString(rulingGuild.getName()); + writer.putString(""); + writer.putString(rulingGuild.getLeadershipType()); + + // Serialize guild ruler's name + // If tree is abandoned blank out the name + // to allow them a rename. + + if (guildRuler == null) + writer.putString(""); + else + writer.putString(guildRuler.getFirstName() + ' ' + guildRuler.getLastName()); + + writer.putInt(rulingGuild.getCharter()); + writer.putInt(0); // always 00000000 + + writer.put((byte)0); + + writer.put((byte) 1); + writer.put((byte) 1); // *** Refactor: What are these flags? + writer.put((byte) 1); + writer.put((byte) 1); + writer.put((byte) 1); + + GuildTag._serializeForDisplay(rulingGuild.getGuildTag(), writer); + GuildTag._serializeForDisplay(rulingNation.getGuildTag(), writer); + + writer.putInt(0);// TODO Implement description text + + writer.put((byte) 1); + writer.put((byte) 0); + writer.put((byte) 1); + + // Begin serializing nation guild info + + if (rulingNation.isEmptyGuild()) { + writer.putInt(rulingGuild.getObjectType().ordinal()); + writer.putInt(rulingGuild.getObjectUUID()); + } else { + writer.putInt(rulingNation.getObjectType().ordinal()); + writer.putInt(rulingNation.getObjectUUID()); + } + + + // Serialize nation name + + if (rulingNation.isEmptyGuild()) + writer.putString("None"); + else + writer.putString(rulingNation.getName()); + + if(Mine.getTower(mine) != null) { + writer.putInt(Mine.getTower(mine).getRank()); + } else{ + writer.putInt(1); + } + writer.putInt(0xFFFFFFFF); + + writer.putInt(0); + + if (rulingNation.isEmptyGuild()) + writer.putString(" "); + else + writer.putString(Guild.GetGL(rulingNation).getFirstName() + ' ' + Guild.GetGL(rulingNation).getLastName()); + + + writer.putLocalDateTime(LocalDateTime.now()); + +// writer.put((byte) mine.established.getDayOfMonth()); +// writer.put((byte) mine.established.minusMonths(1).getMonth().getValue()); +// writer.putInt((int) years); +// writer.put((byte) hours); +// writer.put((byte) minutes); +// writer.put((byte) seconds); + + writer.putFloat(Mine.getTower(mine).loc.x); + writer.putFloat(Mine.getTower(mine).loc.y); + writer.putFloat(Mine.getTower(mine).loc.z); + + writer.putInt(0); + + writer.put((byte) 1); + writer.put((byte) 0); + writer.putInt(0x64); + writer.put((byte) 0); + writer.put((byte) 0); + writer.put((byte) 0); + } }