diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java index 3ecfa070..d7ce5f9e 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java @@ -108,6 +108,7 @@ public class Config { public static final boolean PercentEntern; public static final boolean PercentBlocksWhitelist; public static final Set PercentBlocks; + public static final int TechKoTime; //default kits public static final String MemberDefault; @@ -209,6 +210,7 @@ public class Config { PercentEntern = config.getBoolean("WinConditionParams.PercentEntern", true); PercentBlocksWhitelist = config.getBoolean("WinConditionParams.BlocksWhitelist", false); PercentBlocks = Collections.unmodifiableSet(config.getStringList("WinConditionParams.Blocks").stream().map(Material::valueOf).collect(Collectors.toSet())); + TechKoTime = config.getInt("WinConditionParams.TechKoTime", 90); EnterStages = Collections.unmodifiableList(config.getIntegerList("EnterStages")); AllowMissiles = config.getBoolean("Arena.AllowMissiles", !EnterStages.isEmpty()); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 9ebc4f0c..d181ce02 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -126,6 +126,7 @@ public class FightSystem extends JavaPlugin { new WinconditionPointsAirShip(); new WinconditionTimeout(); new WinconditionTimeTechKO(); + new WinconditionTimedDamageTechKO(); new EventTeamOffWincondition(); new WinconditionComparisonTimeout(Winconditions.HEART_RATIO_TIMEOUT, "HeartTimeout", "WIN_MORE_HEALTH", FightTeam::getHeartRatio); new WinconditionComparisonTimeout(Winconditions.PERCENT_TIMEOUT, "PercentTimeout", "WIN_LESS_DAMAGE", team -> -Wincondition.getPercentWincondition().getPercent(team)); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties index 455e0444..22babff0 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties @@ -191,6 +191,7 @@ BAR_POINTS_OF={0}§8/§7{1} §8Points BAR_PERCENT={0}§8% BAR_CANNONS={0} §8Cannons BAR_WATER={0} §8Water +BAR_SECONDS={0}§8s # Winconditions diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java index 1f205122..61f6a162 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java @@ -19,20 +19,14 @@ package de.steamwar.fightsystem.fight; -import com.comphenix.tinyprotocol.TinyProtocol; -import com.mojang.authlib.GameProfile; import de.steamwar.core.Core; -import de.steamwar.core.ProtocolWrapper; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.record.GlobalRecorder; import lombok.Getter; import org.bukkit.Bukkit; -import org.bukkit.GameMode; import org.bukkit.Sound; import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; import java.util.Collection; import java.util.HashSet; diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index d566c022..63395d03 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -31,6 +31,7 @@ import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.utils.ColorConverter; import de.steamwar.fightsystem.utils.Region; import de.steamwar.fightsystem.utils.WorldeditWrapper; +import de.steamwar.fightsystem.winconditions.Winconditions; import de.steamwar.sql.SchematicData; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicType; @@ -51,20 +52,28 @@ public class FightSchematic extends StateDependent { private final FightTeam team; private final Region region; + private final boolean rotate; + @Getter + private boolean usedRotate; @Getter private Clipboard clipboard = null; private int schematic = 0; - public FightSchematic(FightTeam team, boolean rotate) { + public FightSchematic(FightTeam team, boolean usedRotate) { super(ArenaMode.All, FightState.PostSchemSetup); this.team = team; this.region = team.getSchemRegion(); - this.rotate = rotate; + this.rotate = usedRotate; + this.usedRotate = usedRotate; register(); } + public void setChangeRotate(boolean rotate) { + this.usedRotate = this.rotate ^ rotate; + } + public boolean hasSchematic() { return clipboard != null; } @@ -119,10 +128,15 @@ public class FightSchematic extends StateDependent { } if(ArenaMode.AntiReplay.contains(Config.mode)) { + boolean changeRotation = false; + if (Config.ActiveWinconditions.contains(Winconditions.RANDOM_ROTATE)) { + changeRotation = new Random().nextBoolean(); + usedRotate = rotate ^ changeRotation; + } if(team.isBlue()) - GlobalRecorder.getInstance().blueSchem(schematic); + GlobalRecorder.getInstance().blueSchem(schematic, changeRotation); else - GlobalRecorder.getInstance().redSchem(schematic); + GlobalRecorder.getInstance().redSchem(schematic, changeRotation); } Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::paste); @@ -140,7 +154,6 @@ public class FightSchematic extends StateDependent { FreezeWorld freezer = new FreezeWorld(); team.teleportToSpawn(); - Vector dims = WorldeditWrapper.impl.getDimensions(clipboard); WorldeditWrapper.impl.pasteClipboard( clipboard, @@ -149,8 +162,8 @@ public class FightSchematic extends StateDependent { Config.PasteAligned && Config.BlueToRedX != 0 ? region.getSizeX()/2.0 - dims.getBlockX() : -dims.getBlockX()/2.0, Config.WaterDepth != 0 ? Config.WaterDepth - WorldeditWrapper.impl.getWaterDepth(clipboard) : 0, Config.PasteAligned && Config.BlueToRedZ != 0 ? region.getSizeZ()/2.0 - dims.getBlockZ() : -dims.getBlockZ()/2.0 - ).add(new Vector(rotate ? 1 : 0, 0, rotate ? 1 : 0)), - new AffineTransform().rotateY(rotate ? 180 : 0) + ).add(new Vector(usedRotate ? 1 : 0, 0, usedRotate ? 1 : 0)), + new AffineTransform().rotateY(usedRotate ? 180 : 0) ); FightSystem.getHullHider().initialize(team); team.getPlayers().forEach(fightPlayer -> fightPlayer.ifAI(ai -> ai.schematic(clipboard))); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 0cb68f71..6c9c0345 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -458,6 +458,10 @@ public class FightTeam { return schematic.getId(); } + public void setSchematicChangeRotate(boolean rotate) { + schematic.setChangeRotate(rotate); + } + public Clipboard getClipboard() { return schematic.getClipboard(); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index 47efc09d..f4906f42 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -20,7 +20,6 @@ package de.steamwar.fightsystem.record; import com.sk89q.worldedit.extent.clipboard.Clipboard; -import de.steamwar.core.Core; import de.steamwar.core.TrickyTrialsWrapper; import de.steamwar.core.WorldEditWrapper; import de.steamwar.entity.REntity; @@ -144,6 +143,8 @@ public class PacketProcessor implements Listener { packetDecoder[0xb2] = this::teams; packetDecoder[0xb3] = () -> pasteEmbeddedSchem(Fight.getBlueTeam()); packetDecoder[0xb4] = () -> pasteEmbeddedSchem(Fight.getRedTeam()); + packetDecoder[0xb5] = () -> rotateSchem(Fight.getBlueTeam()); + packetDecoder[0xb6] = () -> rotateSchem(Fight.getRedTeam()); packetDecoder[0xc0] = this::scoreboardTitle; packetDecoder[0xc1] = this::scoreboardData; packetDecoder[0xc2] = this::bossBar; @@ -529,6 +530,14 @@ public class PacketProcessor implements Listener { execSync(() -> team.pasteSchem(schemId, clipboard)); } + private void rotateSchem(FightTeam team) throws IOException { + boolean changeRotate = source.readBoolean(); + + execSync(() -> { + team.setSchematicChangeRotate(changeRotate); + }); + } + private void teams() throws IOException { int blueId = source.readInt(); int redId = source.readInt(); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java index 73821e6f..8b159660 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java @@ -61,9 +61,9 @@ public interface Recorder { default void enableTeam(FightTeam team){ if(FightState.Schem.contains(FightState.getFightState())){ if(team.isBlue()) - blueSchem(team.getSchematic()); + blueSchem(team.getSchematic(), false); else - redSchem(team.getSchematic()); + redSchem(team.getSchematic(), false); } if(FightState.AntiSpectate.contains(FightState.getFightState())){ @@ -123,6 +123,8 @@ public interface Recorder { * TeamIDPacket (0xb2) + int blueTeamId, redTeamId * BlueEmbeddedSchemPacket (0xb3) + int blueSchemId + gzipt NBT blob * RedEmbeddedSchemPacket (0xb4) + int redSchemId + gzipt NBT blob + * BlueSchemRotatePacket (0xb5) + boolean changeRotate + * RedSchemRotatePacket (0xb6) + boolean changeRotate * * DEPRECATED ScoreboardTitlePacket (0xc0) + String scoreboardTitle * DEPRECATED ScoreboardDataPacket (0xc1) + String key + int value @@ -259,14 +261,20 @@ public interface Recorder { write(0xb2, blueTeamId, redTeamId); } - default void blueSchem(int schemId) { + default void blueSchem(int schemId, boolean changeRotate) { + rotate(0xb5, changeRotate); schem(0xb3, 0xb0, schemId); } - default void redSchem(int schemId) { + default void redSchem(int schemId, boolean changeRotate) { + rotate(0xb6, changeRotate); schem(0xb4, 0xb1, schemId); } + default void rotate(int packetId, boolean changeRotate) { + write(packetId, changeRotate); + } + default void schem(int embedId, int noEmbedId, int schemId){ if(schemId == 0) { write(noEmbedId, schemId); @@ -339,6 +347,8 @@ public interface Recorder { stream.writeShort((Short)o); else if(o instanceof Integer) stream.writeInt((Integer)o); + else if(o instanceof Long) + stream.writeLong((Long)o); else if(o instanceof Float) stream.writeFloat((Float)o); else if(o instanceof Double) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java index f1177afa..789b130f 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java @@ -20,6 +20,7 @@ package de.steamwar.fightsystem.winconditions; import de.steamwar.core.TrickyTrialsWrapper; +import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.countdown.Countdown; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; @@ -30,7 +31,6 @@ import de.steamwar.fightsystem.states.StateDependentTask; import de.steamwar.fightsystem.utils.Message; import de.steamwar.fightsystem.utils.SWSound; import org.bukkit.Location; -import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityExplodeEvent; @@ -41,8 +41,7 @@ import java.util.Map; public class WinconditionTimeTechKO extends Wincondition implements Listener { - private static final int TECH_KO_TIME_IN_S = 90; - private static final int TECH_KO_HALF_TIME = TECH_KO_TIME_IN_S/2; + private static final int TECH_KO_HALF_TIME = Config.TechKoTime/2; private final Map spawnLocations = new HashMap<>(); private final Map countdowns = new HashMap<>(); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimedDamageTechKO.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimedDamageTechKO.java new file mode 100644 index 00000000..c561400c --- /dev/null +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimedDamageTechKO.java @@ -0,0 +1,115 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.fightsystem.winconditions; + +import de.steamwar.core.TrickyTrialsWrapper; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.countdown.Countdown; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependent; +import de.steamwar.fightsystem.states.StateDependentListener; +import de.steamwar.fightsystem.utils.Message; +import de.steamwar.fightsystem.utils.SWSound; +import org.bukkit.Location; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityExplodeEvent; + +import java.util.HashMap; +import java.util.Map; + +public class WinconditionTimedDamageTechKO extends Wincondition implements PrintableWincondition, Listener { + + private final Map countdowns = new HashMap<>(); + + public WinconditionTimedDamageTechKO() { + super("TechKO"); + + new StateDependentListener(Winconditions.TIMED_DAMAGE_TECH_KO, FightState.Running, this); + new StateDependent(Winconditions.TIMED_DAMAGE_TECH_KO, FightState.Running) { + @Override + public void enable() { + Fight.teams().forEach(team -> { + TechKOCountdown countdown = new TechKOCountdown(team, Config.TechKoTime); + countdowns.put(team, countdown); + countdown.enable(); + }); + } + + @Override + public void disable() { + countdowns.values().forEach(Countdown::disable); + countdowns.clear(); + } + }.register(); + } + + @Override + public Message getDisplay(FightTeam team) { + return new Message("BAR_SECONDS", team.getPrefix() + countdowns.get(team).getTimeLeft()); + } + + @EventHandler + public void onExplode(EntityExplodeEvent e) { + if (e.getEntityType() != TrickyTrialsWrapper.impl.getTntEntityType()) + return; + + Location location = e.getLocation(); + TechKOCountdown countdown = null; + FightTeam fightTeam = null; + for (FightTeam team : Fight.teams()) { + FightTeam current = Fight.getOpposite(team); + if (current.getExtendRegion().inRegion(location)) { + fightTeam = current; + countdown = countdowns.get(team); + break; + } + } + if (fightTeam == null) { + return; + } + + FightTeam finalFightTeam = fightTeam; + TechKOCountdown finalCountdown = countdown; + e.blockList().forEach(block -> { + if (block.isEmpty()) return; + if (finalFightTeam.getExtendRegion().inRegion(block)) { + finalCountdown.disable(); + finalCountdown.enable(); + } + }); + } + + private class TechKOCountdown extends Countdown { + private final FightTeam team; + + public TechKOCountdown(FightTeam team, int countdownTime) { + super(countdownTime, new Message("TECHKO_COUNTDOWN", team.getColoredName()), SWSound.BLOCK_NOTE_PLING, false); + this.team = team; + } + + @Override + public void countdownFinished() { + win(Fight.getOpposite(team), "WIN_TECHKO", team.getColoredName()); + } + } +} diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java index 2aaecae6..4ba66cf3 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java @@ -31,6 +31,7 @@ public enum Winconditions { POINTS, POINTS_AIRSHIP, + TIMED_DAMAGE_TECH_KO, TIME_TECH_KO, WATER_TECH_KO, PUMPKIN_TECH_KO, @@ -41,4 +42,5 @@ public enum Winconditions { PERSISTENT_DAMAGE, TNT_DISTRIBUTION, NO_GRAVITY, + RANDOM_ROTATE, }