From 8ffcbc33d3673284a035d42b022614a41fe2d6b5 Mon Sep 17 00:00:00 2001 From: Aubri Seebauer Date: Tue, 11 Apr 2023 11:44:45 -0400 Subject: [PATCH] Combat phase tweaks --- .../me/ShermansWorld/AlathraWar/Raid.java | 70 +++++++++++++++---- .../AlathraWar/commands/RaidCommands.java | 29 +++++--- .../AlathraWar/data/RaidData.java | 22 ++++-- .../AlathraWar/listeners/KillsListener.java | 32 +++++++-- 4 files changed, 121 insertions(+), 32 deletions(-) diff --git a/src/main/java/me/ShermansWorld/AlathraWar/Raid.java b/src/main/java/me/ShermansWorld/AlathraWar/Raid.java index 72ae9da..da02cde 100644 --- a/src/main/java/me/ShermansWorld/AlathraWar/Raid.java +++ b/src/main/java/me/ShermansWorld/AlathraWar/Raid.java @@ -44,7 +44,7 @@ The raid is split into two phases: v/ Defenders are given time to get to the town. (travel is announced way in ahead) - COMBAT PHASE v/ Raiders go to town - - Combat occurs + v/ Combat occurs - Decides outcome of raid TODO LIST: @@ -89,7 +89,8 @@ public class Raid { public ArrayList defenderPlayers; public Map lootedChunks; - /** Constructs raid for staging phase + /** + * Constructs raid for staging phase * * @param war * @param raidedTown @@ -115,6 +116,7 @@ public class Raid { /** * IDK why this constructor exists but it does + * * @param war * @param raidedTown * @param gatherTown @@ -132,6 +134,7 @@ public class Raid { /** * Initial Constructor + * * @param war * @param raidedTown * @param gatherTown @@ -230,7 +233,7 @@ public class Raid { //Broadcast if (raidTicks % 6000 == 0) { Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The raid of " - + Raid.this.getRaidedTown().getName() + " will begin in " + (int) (RaidPhase.TRAVEL.startTick / 20 / 60) + " minutes!"); + + Raid.this.getRaidedTown().getName() + " will begin in " + (int) ((RaidPhase.TRAVEL.startTick - raidTicks) / 20 / 60) + " minutes!"); Bukkit.broadcastMessage( "The Raiders are gathering at " + getGatherTown().getName() + " before making the journey over!"); } @@ -381,12 +384,12 @@ public class Raid { raidTicks += incremental; //check and start travel phase - if (Raid.this.raidTicks >= RaidPhase.TRAVEL.startTick && Raid.this.phase != RaidPhase.TRAVEL) { + if (Raid.this.raidTicks >= RaidPhase.TRAVEL.startTick && Raid.this.phase == RaidPhase.GATHER) { startTravel(); } //check and start combat phase - if (Raid.this.raidTicks >= RaidPhase.COMBAT.startTick && Raid.this.phase != RaidPhase.COMBAT) { + if (Raid.this.raidTicks >= RaidPhase.COMBAT.startTick && Raid.this.phase == RaidPhase.TRAVEL) { startCombat(); } @@ -419,12 +422,12 @@ public class Raid { e.printStackTrace(); } } - } //Raid Travel phase behavior else if (Raid.this.phase == RaidPhase.TRAVEL) { + //Report if (raidTicks % 2400 == 0) { Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The Raiders of " + (side1AreRaiders ? Raid.this.war.getSide1() : Raid.this.war.getSide2()) @@ -432,15 +435,28 @@ public class Raid { + Raid.this.getRaidedTown().getName() + "!"); } - //Check if a player has arrived at the town (in it) and if so start combat + //Check if a player has arrived at the town (in it, or within 200 blocks) and if so start combat for (String player : activeRaiders) { - WorldCoord playercoord = WorldCoord.parseWorldCoord(Bukkit.getPlayer(player)); - if (Raid.this.getRaidedTown().hasTownBlock(playercoord)) { - startCombat(); + try { + boolean playerCloseToHomeBlockRaid = false; + final int homeBlockXCoordRaided = Raid.this.getRaidedTown().getHomeBlock().getCoord().getX() * 16; + final int homeBlockZCoordRaided = Raid.this.getRaidedTown().getHomeBlock().getCoord().getZ() * 16; + Player p = Bukkit.getPlayer(player); + //Carryover from sieges + if (Math.abs(p.getLocation().getBlockX() - homeBlockXCoordRaided) <= 200 && Math.abs(p.getLocation().getBlockZ() - homeBlockZCoordRaided) <= 200) { + playerCloseToHomeBlockRaid = true; + } + + WorldCoord playercoord = WorldCoord.parseWorldCoord(Bukkit.getPlayer(player)); + if (Raid.this.getRaidedTown().hasTownBlock(playercoord) || playerCloseToHomeBlockRaid) { + startCombat(); + } + } catch (TownyException e) { + e.printStackTrace(); } } - } + //Raid combat phase behavior else if (Raid.this.phase == RaidPhase.COMBAT) { @@ -663,6 +679,16 @@ public class Raid { throw new RuntimeException(e); } } + + //teleport the killer back to the raided towns spawn + if (this.getDefenders().contains(killed.getKiller().getName())) { + try { + killed.getKiller().teleport(this.getRaidedTown().getSpawn()); + killed.getKiller().sendMessage(String.valueOf(Helper.Chatlabel()) + "You killed a raider before the raid began and have been teleported back to the defending town."); + } catch (TownyException e) { + throw new RuntimeException(e); + } + } } /** @@ -684,14 +710,27 @@ public class Raid { //tp to raid town spawn final Player killed = event.getEntity(); - if (this.getActiveRaiders().contains(killed.getName())) { - // killed.teleport(this.getGatherTown().getSpawn()); - // killed.sendMessage(String.valueOf(Helper.Chatlabel()) + "You died before being raided and have been teleported back to your town's spawn."); + if (this.getDefenders().contains(killed.getName())) { +// killed.teleport(this.getGatherTown().getSpawn()); +// killed.sendMessage(String.valueOf(Helper.Chatlabel()) + "You died before being raided and have been teleported back to the defending town's spawn."); + } + + //teleport the killer back to the raided towns spawn + if (killed.getKiller() instanceof Player) { + if (this.getActiveRaiders().contains(killed.getKiller().getName())) { + try { + killed.getKiller().teleport(this.getGatherTown().getSpawn()); + killed.getKiller().sendMessage(String.valueOf(Helper.Chatlabel()) + "You killed a defender before the raid began and have been teleported back to the gather town."); + } catch (TownyException e) { + throw new RuntimeException(e); + } + } } } /** * Raiders win, give payout and finalize raid + * * @param owner * @param raidScore */ @@ -762,6 +801,7 @@ public class Raid { /** * Defenders win, payout, and finalize raid + * * @param raidScore */ public void defendersWin(int raidScore) { @@ -810,6 +850,7 @@ public class Raid { /** * Positively impact the raid score + * * @param points */ public void addPointsToRaidScore(final int points) { @@ -820,6 +861,7 @@ public class Raid { /** * Negatively impact the raid score + * * @param points */ public void subtractPointsFromRaidScore(final int points) { diff --git a/src/main/java/me/ShermansWorld/AlathraWar/commands/RaidCommands.java b/src/main/java/me/ShermansWorld/AlathraWar/commands/RaidCommands.java index 80fc3c4..5bd586a 100644 --- a/src/main/java/me/ShermansWorld/AlathraWar/commands/RaidCommands.java +++ b/src/main/java/me/ShermansWorld/AlathraWar/commands/RaidCommands.java @@ -104,18 +104,21 @@ public class RaidCommands implements CommandExecutor { if (war.getSide1Players().contains(p.getName())) { //Time and raid activity validity check int c = RaidData.isValidRaid(war, raidedTown); - if (c == 1) { + if (c == 2) { raid2 = new Raid(war, raidedTown, gatherTown, true); + } else if (c == 1) { + p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town is already being raided at this time!"); + return; } else if (c == 0) { p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Your side has raided too recently!"); return; } else if (c == -1) { p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town was raided too recently!"); return; - } else if (c == 2) { - p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town is already being raided at this time!"); + } else if (c == -2) { + p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town has no online players to defend it!"); return; - } else { + } else { throw new IllegalArgumentException(); } } else { @@ -126,18 +129,21 @@ public class RaidCommands implements CommandExecutor { } //Time and raid activity validity check int c = RaidData.isValidRaid(war, raidedTown); - if (c == 1) { + if (c == 2) { raid2 = new Raid(war, raidedTown, gatherTown, false); + } else if (c == 1) { + p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town is already being raided at this time!"); + return; } else if (c == 0) { p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Your side has raided too recently!"); return; } else if (c == -1) { p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town was raided too recently!"); return; - } else if (c == 2) { - p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town is already being raided at this time!"); + } else if (c == -2) { + p.sendMessage(String.valueOf(Helper.Chatlabel()) + "At least on member of the raided town must be online to defend it!"); return; - } else { + } else { throw new IllegalArgumentException(); } } @@ -181,8 +187,15 @@ public class RaidCommands implements CommandExecutor { //broadcast Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "As part of " + war.getName() + ", forces from " + raid2.getRaiders() + " are gathering to raid the town of " + raidedTown.getName() + "!"); + Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "All players from the defending side have been drafted for the town's defense."); + Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The raid of " + + raidedTown.getName() + " will begin in " + (int) (RaidPhase.TRAVEL.startTick / 20 / 60) + " minutes!"); + Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + + "The Raiders are gathering at " + gatherTown.getName() + " before making the journey over!"); + Main.warLogger.log(p.getName() + " started a raid."); Main.warLogger.log("As part of " + war.getName() + ", forces from " + raid2.getRaiders() + " are raiding the town of " + raidedTown.getName() + "!"); + Main.warLogger.log("The Raiders are gathering at " + gatherTown.getName() + " before making the journey over!"); } } } diff --git a/src/main/java/me/ShermansWorld/AlathraWar/data/RaidData.java b/src/main/java/me/ShermansWorld/AlathraWar/data/RaidData.java index 65f3eed..adb7099 100644 --- a/src/main/java/me/ShermansWorld/AlathraWar/data/RaidData.java +++ b/src/main/java/me/ShermansWorld/AlathraWar/data/RaidData.java @@ -1,6 +1,7 @@ package me.ShermansWorld.AlathraWar.data; import com.palmergames.bukkit.towny.TownyAPI; +import com.palmergames.bukkit.towny.object.Resident; import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.WorldCoord; import com.palmergames.bukkit.towny.object.metadata.CustomDataField; @@ -10,6 +11,7 @@ import me.ShermansWorld.AlathraWar.Main; import me.ShermansWorld.AlathraWar.Raid; import me.ShermansWorld.AlathraWar.War; +import javax.annotation.Nonnull; import java.io.File; import java.io.FilenameFilter; import java.util.ArrayList; @@ -215,10 +217,10 @@ public class RaidData { /** * @return - * @Isaac this is for getting if a town can be raided, return (-1, 0, 1, 2) based on status - * (24 hours town cooldown, 6 hour war cooldown, valid time to raid, town being raided already) + * @Isaac this is for getting if a town can be raided, return (-2, -1, 0, 1, 2) based on status + * (no players online, 24 hours town cooldown, 6 hour war cooldown, town being raided already, valid time to raid) */ - public static int isValidRaid(War war, Town town) { + public static int isValidRaid(War war, @Nonnull Town town) { long townTime = whenTownLastRaided(town); //24 hours town cooldown @@ -231,14 +233,24 @@ public class RaidData { return 0; } + //make sure a player is online in the raided town + boolean onlinePlayer = false; + for(Resident r : town.getResidents()) { + if(r.isOnline()) { + onlinePlayer = true; + } + } + if(!onlinePlayer) return -2; + //check if being raided for (Raid raid : war.getRaids()) { if (raid.getRaidedTown().getName().equals(town.getName())) { - return 2; + return 1; } + } - return 1; + return 2; } } diff --git a/src/main/java/me/ShermansWorld/AlathraWar/listeners/KillsListener.java b/src/main/java/me/ShermansWorld/AlathraWar/listeners/KillsListener.java index 86589ff..1cb0e64 100644 --- a/src/main/java/me/ShermansWorld/AlathraWar/listeners/KillsListener.java +++ b/src/main/java/me/ShermansWorld/AlathraWar/listeners/KillsListener.java @@ -100,31 +100,39 @@ public final class KillsListener implements Listener final int homeBlockZCoordRaided = raid.getRaidedTown().getHomeBlock().getCoord().getZ() * 16; // final int homeBlockXCoordGather = raid.getGatherTown().getHomeBlock().getCoord().getX() * 16; // final int homeBlockZCoordGather = raid.getGatherTown().getHomeBlock().getCoord().getZ() * 16; + //Carryover from sieges if (Math.abs(killed.getLocation().getBlockX() - homeBlockXCoordRaided) <= 300 && Math.abs(killed.getLocation().getBlockZ() - homeBlockZCoordRaided) <= 300) { playerCloseToHomeBlockRaid = true; } if (raid.getActiveRaiders().contains(killer.getName()) && ((town != null && town.equals(raid.getRaidedTown())) || playerCloseToHomeBlockRaid)) { - + //There is seperate behavior if combat hasnt started if(raid.getPhase() == RaidPhase.COMBAT) { + this.siegeKill(killed, event); if (raid.getDefenderPlayers().contains(killed.getName())) { raid.defenderKilledInCombat(event); } - this.siegeKill(killed, event); return; } else { + //teleport back to raided spawn, without damaged gear + this.oocKill(killed, event); raid.defenderKilledOutofCombat(event); + return; } } if (raid.getDefenderPlayers().contains(killer.getName()) && ((town != null && town.equals(raid.getRaidedTown())) || playerCloseToHomeBlockRaid)) { - + //There is seperate behavior if combat hasnt started if(raid.getPhase() == RaidPhase.COMBAT) { + this.siegeKill(killed, event); if (raid.getActiveRaiders().contains(killed.getName())) { raid.raiderKilledInCombat(event); } - this.siegeKill(killed, event); return; } else { + //teleport back to gather town spawn, without damaged gear + //this is to disincentive people prekilling + this.oocKill(killed, event); raid.raiderKilledOutofCombat(event); + return; } } @@ -154,5 +162,19 @@ public final class KillsListener implements Listener event.getDrops().clear(); event.setKeepLevel(true); } - + + /** + * Dont damage items held by the player + * They don't lose items from death. + * @param killed + * @param event + */ + private void oocKill(final Player killed, final PlayerDeathEvent event) { + //Siege specific + Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), "spawn " + killed.getName()); + event.setKeepInventory(true); + event.getDrops().clear(); + event.setKeepLevel(true); + } + }