RedstoneWincondition #274
@ -19,7 +19,14 @@
|
||||
|
||||
package de.steamwar.fightsystem.winconditions;
|
||||
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
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 org.bukkit.Bukkit;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
public abstract class PercentWincondition extends Wincondition implements PrintableWincondition {
|
||||
|
||||
@ -32,4 +39,37 @@ public abstract class PercentWincondition extends Wincondition implements Printa
|
||||
}
|
||||
|
||||
abstract double getPercent(FightTeam team);
|
||||
|
||||
public class TeamPercent {
|
||||
public final FightTeam team;
|
||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
|
||||
|
||||
public int totalBlocks;
|
||||
public int currentBlocks;
|
||||
|
||||
protected TeamPercent(FightTeam team) {
|
||||
this.team = team;
|
||||
}
|
||||
|
||||
public void lose() {
|
||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + team.getColoredName() + " §chat zu viel Schaden erlitten!");
|
||||
win(Fight.getOpposite(team));
|
||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Ich glaube, hier können ein paar Fields final gesetzt werden. Ich glaube, hier können ein paar Fields final gesetzt werden.
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class StateDependentTeamPercent extends StateDependent {
|
||||
public final FightTeam team;
|
||||
|
||||
public int totalBlocks;
|
||||
public int currentBlocks;
|
||||
|
||||
protected StateDependentTeamPercent(FightTeam team, Winconditions winconditions) {
|
||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
OneShotStateDependents werden schon im Konstruktor registered, bitte nicht dopplet registern. OneShotStateDependents werden schon im Konstruktor registered, bitte nicht dopplet registern.
|
||||
super(winconditions, FightState.Running);
|
||||
this.team = team;
|
||||
}
|
||||
|
||||
public void lose() {
|
||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + team.getColoredName() + " §chat zu viel Schaden erlitten!");
|
||||
win(Fight.getOpposite(team));
|
||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Hier am Ende des Konstruktors würde ich gleich dieses TeamPercent in die teamMap einfügen, dann musst du das nicht an den ganzen anderen Stellen machen (und kannst es nicht vergessen) Hier am Ende des Konstruktors würde ich gleich dieses TeamPercent in die teamMap einfügen, dann musst du das nicht an den ganzen anderen Stellen machen (und kannst es nicht vergessen)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,12 +20,10 @@
|
||||
package de.steamwar.fightsystem.winconditions;
|
||||
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
@ -42,17 +40,17 @@ public class WinconditionPercentSystem extends PercentWincondition implements Li
|
||||
teamMap.put(Fight.getBlueTeam(), new TeamPercent(Fight.getBlueTeam()));
|
||||
teamMap.put(Fight.getRedTeam(), new TeamPercent(Fight.getRedTeam()));
|
||||
|
||||
new StateDependentListener(Winconditions.PERCENT_SYSTEM, FightState.Running, this){
|
||||
new StateDependentListener(Winconditions.PERCENT_SYSTEM, FightState.Running, this) {
|
||||
@Override
|
||||
public void enable() {
|
||||
super.enable();
|
||||
teamMap.forEach((team, percent) -> {
|
||||
percent.destroyedBlocks = 0;
|
||||
percent.currentBlocks = 0;
|
||||
percent.percent = 0;
|
||||
});
|
||||
}
|
||||
};
|
||||
if(Config.ActiveWinconditions.contains(Winconditions.PERCENT_SYSTEM)){
|
||||
if (Config.ActiveWinconditions.contains(Winconditions.PERCENT_SYSTEM)) {
|
||||
printableWinconditions.add(this);
|
||||
percentWincondition = this;
|
||||
}
|
||||
@ -63,38 +61,29 @@ public class WinconditionPercentSystem extends PercentWincondition implements Li
|
||||
teamMap.values().forEach(teamPercent -> teamPercent.check(event));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplay(FightTeam team) {
|
||||
return team.getPrefix() + "Schaden: " + (Math.round(100.0 * getPercent(team)) / 100.0) + "%";
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getPercent(FightTeam team) {
|
||||
return teamMap.get(team).percent;
|
||||
}
|
||||
|
||||
private class TeamPercent {
|
||||
private class TeamPercent extends PercentWincondition.TeamPercent {
|
||||
|
||||
private final FightTeam team;
|
||||
private final int volume;
|
||||
private double percent;
|
||||
private int destroyedBlocks;
|
||||
|
||||
private TeamPercent(FightTeam team) {
|
||||
this.team = team;
|
||||
this.volume = team.getSchemRegion().volume();
|
||||
super(team);
|
||||
totalBlocks = team.getSchemRegion().volume();
|
||||
}
|
||||
|
||||
private void check(EntityExplodeEvent event) {
|
||||
if(!team.getExtendRegion().inRegion(event.getEntity().getLocation())){
|
||||
if (!team.getExtendRegion().inRegion(event.getEntity().getLocation())) {
|
||||
return;
|
||||
}
|
||||
|
||||
destroyedBlocks += event.blockList().size();
|
||||
percent = (double)destroyedBlocks * 100 / volume;
|
||||
if(percent >= Config.PercentWin) {
|
||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + team.getColoredName() + " §chat zu viel Schaden erlitten!");
|
||||
win(Fight.getOpposite(team));
|
||||
currentBlocks += event.blockList().size();
|
||||
percent = (double) currentBlocks * 100 / totalBlocks;
|
||||
if (percent >= Config.PercentWin) {
|
||||
lose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,8 +23,6 @@ import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
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 org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
@ -38,12 +36,12 @@ public class WinconditionRelativePercent extends PercentWincondition {
|
||||
|
||||
private final Map<FightTeam, TeamPercent> teamMap = new HashMap<>();
|
||||
|
||||
public WinconditionRelativePercent(){
|
||||
public WinconditionRelativePercent() {
|
||||
super("RelativePercent");
|
||||
teamMap.put(Fight.getBlueTeam(), new TeamPercent(Fight.getBlueTeam()));
|
||||
teamMap.put(Fight.getRedTeam(), new TeamPercent(Fight.getRedTeam()));
|
||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
WÜrde empfehlen, in der COnfig diesen Codeblock zu verwenden, 4 Zeilen sind da etwas kürzer :) WÜrde empfehlen, in der COnfig diesen Codeblock zu verwenden, 4 Zeilen sind da etwas kürzer :)
|
||||
|
||||
if(Config.ActiveWinconditions.contains(Winconditions.RELATIVE_PERCENT)){
|
||||
if (Config.ActiveWinconditions.contains(Winconditions.RELATIVE_PERCENT)) {
|
||||
printableWinconditions.add(this);
|
||||
percentWincondition = this;
|
||||
}
|
||||
@ -54,67 +52,59 @@ public class WinconditionRelativePercent extends PercentWincondition {
|
||||
return teamMap.get(team).getPercent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplay(FightTeam team) {
|
||||
return team.getPrefix() + "Schaden: " + (Math.round(100.0 * getPercent(team)) / 100.0) + "%";
|
||||
}
|
||||
public class TeamPercent extends StateDependentTeamPercent {
|
||||
|
||||
public static class TeamPercent extends StateDependent {
|
||||
private final FightTeam team;
|
||||
|
||||
private int blockCount;
|
||||
private BukkitTask task;
|
||||
private int currentBlocks;
|
||||
|
||||
public TeamPercent(FightTeam team){
|
||||
super(Winconditions.RELATIVE_PERCENT, FightState.Running);
|
||||
this.team = team;
|
||||
this.currentBlocks = 1;
|
||||
public TeamPercent(FightTeam team) {
|
||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Muss kein AtomicInteger sein, wenn es sich um eine Objektvariable handelt Muss kein AtomicInteger sein, wenn es sich um eine Objektvariable handelt
|
||||
super(team, Winconditions.RELATIVE_PERCENT);
|
||||
currentBlocks = 1;
|
||||
register();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable(){
|
||||
blockCount = currentBlocks();
|
||||
public void enable() {
|
||||
totalBlocks = currentBlocks();
|
||||
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::check, 400, 400);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable(){
|
||||
public void disable() {
|
||||
task.cancel();
|
||||
}
|
||||
|
||||
private void check(){
|
||||
private void check() {
|
||||
currentBlocks();
|
||||
|
||||
if(!Config.ActiveWinconditions.contains(Winconditions.RELATIVE_PERCENT))
|
||||
if (!Config.ActiveWinconditions.contains(Winconditions.RELATIVE_PERCENT))
|
||||
return;
|
||||
|
||||
if(getPercent() >= Config.PercentWin){
|
||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + team.getColoredName() + " §chat zu viel Schaden erlitten!");
|
||||
FightSystem.setSpectateState(Fight.getOpposite(team), "RelativePercent");
|
||||
if (getPercent() >= Config.PercentWin) {
|
||||
lose();
|
||||
}
|
||||
}
|
||||
|
||||
public double getPercent(){
|
||||
if(currentBlocks > blockCount)
|
||||
public double getPercent() {
|
||||
if (currentBlocks > totalBlocks) {
|
||||
return 0;
|
||||
return (blockCount - currentBlocks) * 100 / (double) blockCount;
|
||||
}
|
||||
return (totalBlocks - currentBlocks) * 100 / (double) totalBlocks;
|
||||
}
|
||||
|
||||
public int getBlockCount(){
|
||||
return blockCount;
|
||||
public int getBlockCount() {
|
||||
return totalBlocks;
|
||||
}
|
||||
|
||||
private int currentBlocks(){
|
||||
private int currentBlocks() {
|
||||
// Entern active
|
||||
if(!Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= Wincondition.getTimeOverCountdown().getTimeLeft())
|
||||
if (!Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= Wincondition.getTimeOverCountdown().getTimeLeft())
|
||||
return currentBlocks;
|
||||
|
||||
currentBlocks = 0;
|
||||
team.getSchemRegion().forEach((x, y, z) -> {
|
||||
if(!Config.Blocks.contains(world.getBlockAt(x,y,z).getType()))
|
||||
if (!Config.Blocks.contains(world.getBlockAt(x, y, z).getType())) {
|
||||
currentBlocks++;
|
||||
}
|
||||
});
|
||||
return currentBlocks;
|
||||
}
|
||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Hier wird ein wichtiges Feature für die RelativePercentWincondition und die PointsWincondition enfernt: Wenn die Enterphase begonnen hat, dürfen bei diesen beiden Winconditions keine Prozente mehr gezählt werden. Hier wird ein wichtiges Feature für die RelativePercentWincondition und die PointsWincondition enfernt: Wenn die Enterphase begonnen hat, dürfen bei diesen beiden Winconditions keine Prozente mehr gezählt werden.
|
||||
|
@ -57,11 +57,6 @@ public class WinconditionRelativeRedstonePercent extends PercentWincondition imp
|
||||
return teamMap.get(team).getPercent();
|
||||
}
|
||||
|
||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Liest sich wie Code-Duplication, evtl PercentWincondition PrintableWincondition extenden lassen und dann eine default-Implementierung im Interface (Formatierung dürfte für alle 3 Prozentsysteme gleich sein) Liest sich wie Code-Duplication, evtl PercentWincondition PrintableWincondition extenden lassen und dann eine default-Implementierung im Interface (Formatierung dürfte für alle 3 Prozentsysteme gleich sein)
|
||||
@Override
|
||||
public String getDisplay(FightTeam team) {
|
||||
return team.getPrefix() + "Schaden: " + (Math.round(100.0 * getPercent(team)) / 100.0) + "%";
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
FightPlayer fightPlayer = Fight.getFightPlayer(event.getPlayer());
|
||||
|
Jeder Prozentmodus braucht irgendwo beide Teams, die Map FightTeam -> TeamPercent müsste daher hierher abstrahierbar sein.
Aka: Die Teammap schon hier in PercentWincondition zur Verfügung stellen und füllen (parameter im Konstruktor übergeben lassen), getPercent gleich hier implementieren.
In der PointWincondition hast du dann einfach noch eine zweite Map