SteamWar/FightSystem
Archiviert
13
1

Merge pull request 'Simplify percent system by adding entern percent and whitelist config toggles' (#406) from percentChange into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #406
Reviewed-by: D4rkr34lm <d4rkr34lm@steamwar.de>
Dieser Commit ist enthalten in:
Lixfel 2023-12-12 17:13:37 +01:00
Commit 5e8241605e
11 geänderte Dateien mit 29 neuen und 123 gelöschten Zeilen

Datei anzeigen

@ -114,8 +114,6 @@ WinConditions: # defaults to none if missing
# - CAPTAIN_DEAD
# - PERCENT_SYSTEM
# - WHITELIST_PERCENT
# - RELATIVE_PERCENT
# - POINTS
# - POINTS_AIRSHIP
@ -133,6 +131,10 @@ WinConditionParams:
TimeoutTime: 1200 # defaults to 1200 if missing
# The percentage when any of the percent win conditions limits or triggers a win
PercentWin: 7.0 # defaults to 7.0 if missing
# Does the percentage still change after the start of the enter phase
PercentEntern: true # defaults to true if missing
# Is Blocks a whitelist (true) or blacklist (false)
BlocksWhitelist: false # defaults to false if missing
# Special Blocks (Valid spigot material values) used by the percent win conditions
Blocks: [] # defaults to none if missing

Datei anzeigen

@ -107,6 +107,8 @@ public class Config {
//win condition parameters
public static final int TimeoutTime;
public static final double PercentWin;
public static final boolean PercentEntern;
public static final boolean PercentBlocksWhitelist;
public static final Set<Material> PercentBlocks;
//default kits
@ -197,6 +199,8 @@ public class Config {
TimeoutTime = config.getInt("WinConditionParams.TimeoutTime", 1200);
PercentWin = config.getDouble("WinConditionParams.PercentWin", 7.0);
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()));
EnterStages = Collections.unmodifiableList(config.getIntegerList("EnterStages"));

Datei anzeigen

@ -118,9 +118,7 @@ public class FightSystem extends JavaPlugin {
new WinconditionCaptainDead();
new WinconditionBlocks(Winconditions.WATER_TECH_KO, "WaterTechKO", "BAR_WATER", FlatteningWrapper.impl::isWater);
new WinconditionBlocks(Winconditions.PUMPKIN_TECH_KO, "PumpkinTechKO", "BAR_CANNONS", block -> block.getType() == WinconditionBlocks.PUMPKIN_LANTERN);
new WinconditionPercentSystem();
new WinconditionBlacklistPercent();
new WinconditionWhitelistPercent();
new WinconditionPercent(Winconditions.PERCENT_SYSTEM, "Percent");
new WinconditionPoints();
new WinconditionPointsAirShip();
new WinconditionTimeout();

Datei anzeigen

@ -34,7 +34,7 @@ import java.util.stream.Collectors;
public abstract class Wincondition {
protected static PercentWincondition percentWincondition = null;
protected static WinconditionPercent percentWincondition = null;
protected static StateDependentCountdown timeOverCountdown = null;
protected static final List<PrintableWincondition> printableWinconditions = new ArrayList<>();
@ -65,7 +65,7 @@ public abstract class Wincondition {
return printableWinconditions;
}
public static PercentWincondition getPercentWincondition() {
public static WinconditionPercent getPercentWincondition() {
return percentWincondition;
}

Datei anzeigen

@ -1,27 +0,0 @@
/*
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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.fightsystem.winconditions;
public class WinconditionBlacklistPercent extends PercentWincondition {
public WinconditionBlacklistPercent(){
super("RelativePercent", Winconditions.RELATIVE_PERCENT);
}
}

Datei anzeigen

@ -26,7 +26,6 @@ import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.OneShotStateDependent;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.utils.Message;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@ -34,27 +33,12 @@ import org.bukkit.event.entity.EntityExplodeEvent;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.ToIntFunction;
public class PercentWincondition extends Wincondition implements PrintableWincondition {
public class WinconditionPercent extends Wincondition implements PrintableWincondition {
private final Map<FightTeam, TeamPercent> teamMap = new HashMap<>();
protected BooleanSupplier explosionFilter = () -> !Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= Wincondition.getTimeOverCountdown().getTimeLeft();
protected Predicate<Material> testBlock = type -> !Config.PercentBlocks.contains(type);
protected ToIntFunction<FightTeam> totalBlockCalc = team -> {
AtomicInteger blocks = new AtomicInteger();
team.getSchemRegion().forEach((x, y, z) -> {
if (testBlock.test(Config.world.getBlockAt(x, y, z).getType())) {
blocks.getAndIncrement();
}
});
return blocks.get();
};
protected Consumer<FightTeam> checkWin = team -> {
if (getPercent(team) >= Config.PercentWin) {
win(Fight.getOpposite(team), "WIN_PERCENT", team.getColoredName());
@ -62,7 +46,7 @@ public class PercentWincondition extends Wincondition implements PrintableWincon
};
protected Consumer<FightTeam> postEnable = team -> {};
public PercentWincondition(String windescription, Winconditions wincondition) {
public WinconditionPercent(Winconditions wincondition, String windescription) {
super(windescription);
if (Config.ActiveWinconditions.contains(wincondition)) {
@ -74,7 +58,7 @@ public class PercentWincondition extends Wincondition implements PrintableWincon
}
public Message getDisplay(FightTeam team) {
return new Message("BAR_PERCENT", team.getPrefix() + (Math.round(100.0 * getPercent(team)) / 100.0));
return new Message("BAR_PERCENT", team.getPrefix() + (Math.round(100.0 * (100.0 - getPercent(team) / Config.PercentWin)) / 100.0));
}
public double getPercent(FightTeam team) {
@ -105,12 +89,16 @@ public class PercentWincondition extends Wincondition implements PrintableWincon
@EventHandler
public void onEntityExplode(EntityExplodeEvent event) {
if (event.getEntityType() == EntityType.FIREBALL || explosionFilter.getAsBoolean() || !team.getExtendRegion().inRegion(event.getEntity().getLocation())) {
if (
event.getEntityType() == EntityType.FIREBALL ||
!team.getExtendRegion().inRegion(event.getEntity().getLocation()) ||
(!Config.PercentEntern && !Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= Wincondition.getTimeOverCountdown().getTimeLeft())
) {
return;
}
event.blockList().forEach(block -> {
if (testBlock.test(block.getType())) {
if (Config.PercentBlocks.contains(block.getType()) == Config.PercentBlocksWhitelist) {
currentBlocks--;
}
});
@ -119,7 +107,11 @@ public class PercentWincondition extends Wincondition implements PrintableWincon
}
private void enable() {
totalBlocks = totalBlockCalc.applyAsInt(team);
totalBlocks = 0;
team.getSchemRegion().forEach((x, y, z) -> {
if (Config.PercentBlocks.contains(Config.world.getBlockAt(x, y, z).getType()) == Config.PercentBlocksWhitelist)
totalBlocks++;
});
currentBlocks = totalBlocks;
postEnable.accept(team);
}

Datei anzeigen

@ -1,30 +0,0 @@
/*
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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.fightsystem.winconditions;
public class WinconditionPercentSystem extends PercentWincondition {
public WinconditionPercentSystem() {
super("Percent", Winconditions.PERCENT_SYSTEM);
totalBlockCalc = team -> team.getSchemRegion().volume();
explosionFilter = () -> false;
}
}

Datei anzeigen

@ -36,12 +36,12 @@ import org.bukkit.event.player.PlayerQuitEvent;
import java.util.HashMap;
import java.util.Map;
public class WinconditionPoints extends PercentWincondition implements Listener {
public class WinconditionPoints extends WinconditionPercent implements Listener {
private final Map<FightTeam, TeamPoints> teamMap = new HashMap<>();
public WinconditionPoints(){
super("Points", Winconditions.POINTS);
super(Winconditions.POINTS, "Points");
checkWin = team -> {};
postEnable = this::pointInit;

Datei anzeigen

@ -35,7 +35,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
public class WinconditionPointsAirShip extends PercentWincondition implements Listener {
public class WinconditionPointsAirShip extends WinconditionPercent implements Listener {
private double[] as = new double[] {
0.5,
@ -56,7 +56,7 @@ public class WinconditionPointsAirShip extends PercentWincondition implements Li
private final Map<FightTeam, TeamPoints> teamMap = new HashMap<>();
public WinconditionPointsAirShip(){
super("Points", Winconditions.POINTS_AIRSHIP);
super(Winconditions.POINTS_AIRSHIP, "Points");
checkWin = team -> {
if (teamMap.get(team).getPoints() > TeamPoints.WIN_POINTS) {

Datei anzeigen

@ -1,31 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.Config;
public class WinconditionWhitelistPercent extends PercentWincondition {
public WinconditionWhitelistPercent() {
super("WhitelistPercent", Winconditions.WHITELIST_PERCENT);
testBlock = Config.PercentBlocks::contains;
}
}

Datei anzeigen

@ -28,8 +28,6 @@ public enum Winconditions {
CAPTAIN_DEAD,
PERCENT_SYSTEM,
WHITELIST_PERCENT,
RELATIVE_PERCENT,
POINTS,
POINTS_AIRSHIP,