The big refactoring #238
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem;
|
package de.steamwar.fightsystem;
|
||||||
|
|
||||||
|
import de.steamwar.fightsystem.winconditions.Winconditions;
|
||||||
import de.steamwar.sql.Event;
|
import de.steamwar.sql.Event;
|
||||||
import de.steamwar.sql.EventFight;
|
import de.steamwar.sql.EventFight;
|
||||||
import de.steamwar.sql.Team;
|
import de.steamwar.sql.Team;
|
||||||
@ -33,6 +34,7 @@ import org.bukkit.util.Vector;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Config {
|
public class Config {
|
||||||
|
|
||||||
@ -104,16 +106,7 @@ public class Config {
|
|||||||
public static final boolean Ranked;
|
public static final boolean Ranked;
|
||||||
|
|
||||||
//Active win conditions
|
//Active win conditions
|
||||||
public static final boolean Timeout;
|
public static final Set<Winconditions> ActiveWinconditions;
|
||||||
public static final boolean HeartRatioTimeout;
|
|
||||||
public static final boolean AllDead;
|
|
||||||
public static final boolean CaptainDead;
|
|
||||||
public static final boolean PercentSystem;
|
|
||||||
public static final boolean RelativePercent;
|
|
||||||
public static final boolean Points;
|
|
||||||
public static final boolean TechKO;
|
|
||||||
public static final boolean WaterTechKO;
|
|
||||||
public static final boolean PumpkinTechKO;
|
|
||||||
|
|
||||||
//win condition parameters
|
//win condition parameters
|
||||||
public static final int TimeoutTime;
|
public static final int TimeoutTime;
|
||||||
@ -202,16 +195,7 @@ public class Config {
|
|||||||
GameName = config.getString("Output.GameName");
|
GameName = config.getString("Output.GameName");
|
||||||
TeamChatDetection = config.getString("Output.TeamChatDetection");
|
TeamChatDetection = config.getString("Output.TeamChatDetection");
|
||||||
|
|
||||||
Timeout = config.getBoolean("WinConditions.Timeout");
|
ActiveWinconditions = config.getStringList("WinConditions").stream().map(Winconditions::valueOf).collect(Collectors.toSet());
|
||||||
HeartRatioTimeout = config.getBoolean("WinConditions.HeartRatioTimeout");
|
|
||||||
AllDead = config.getBoolean("WinConditions.AllDead");
|
|
||||||
CaptainDead = config.getBoolean("WinConditions.CaptainDead");
|
|
||||||
PercentSystem = config.getBoolean("WinConditions.PercentSystem");
|
|
||||||
RelativePercent = config.getBoolean("WinConditions.RelativePercent");
|
|
||||||
Points = config.getBoolean("WinConditions.Points");
|
|
||||||
TechKO = config.getBoolean("WinConditions.TechKO");
|
|
||||||
WaterTechKO = config.getBoolean("WinConditions.WaterTechKO");
|
|
||||||
PumpkinTechKO = config.getBoolean("WinConditions.PumpkinTechKO");
|
|
||||||
|
|
||||||
TimeoutTime = config.getInt("WinConditionParams.TimeoutTime");
|
TimeoutTime = config.getInt("WinConditionParams.TimeoutTime");
|
||||||
PercentWin = config.getDouble("WinConditionParams.PercentWin");
|
PercentWin = config.getDouble("WinConditionParams.PercentWin");
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
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 enum Winconditions {
|
||||||
|
TIMEOUT,
|
||||||
|
HEART_RATIO_TIMEOUT,
|
||||||
|
PERCENT_TIMEOUT,
|
||||||
|
ALL_DEAD,
|
||||||
|
CAPTAIN_DEAD,
|
||||||
|
PERCENT_SYSTEM,
|
||||||
|
RELATIVE_PERCENT,
|
||||||
|
POINTS,
|
||||||
|
TIME_TECH_KO,
|
||||||
|
WATER_TECH_KO,
|
||||||
|
PUMPKIN_TECH_KO
|
||||||
|
}
|
@ -96,8 +96,10 @@ public class FightSystem extends JavaPlugin {
|
|||||||
new WinconditionPoints();
|
new WinconditionPoints();
|
||||||
new WinconditionTimeout();
|
new WinconditionTimeout();
|
||||||
new WinconditionHeartRatioTimeout();
|
new WinconditionHeartRatioTimeout();
|
||||||
new WinconditionTechKO();
|
new WinconditionTimeTechKO();
|
||||||
new EventTeamOffWincondition();
|
new EventTeamOffWincondition();
|
||||||
|
new RankedPlayerLeftWincondition();
|
||||||
|
new WinconditionPercentTimeout();
|
||||||
|
|
||||||
new NoPlayersOnlineCountdown();
|
new NoPlayersOnlineCountdown();
|
||||||
new PreSchemPasteCountdown();
|
new PreSchemPasteCountdown();
|
||||||
|
@ -25,14 +25,11 @@ import org.bukkit.Bukkit;
|
|||||||
|
|
||||||
public class TimeOverCountdown extends Countdown {
|
public class TimeOverCountdown extends Countdown {
|
||||||
|
|
||||||
private static TimeOverCountdown instance = null;
|
|
||||||
|
|
||||||
private final Runnable timeOver;
|
private final Runnable timeOver;
|
||||||
|
|
||||||
public TimeOverCountdown(Runnable timeOver) {
|
public TimeOverCountdown(Runnable timeOver) {
|
||||||
super(Config.TimeoutTime, SWSound.BLOCK_NOTE_BASS, false);
|
super(Config.TimeoutTime, SWSound.BLOCK_NOTE_BASS, false);
|
||||||
this.timeOver = timeOver;
|
this.timeOver = timeOver;
|
||||||
instance = this;
|
|
||||||
enable();
|
enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,10 +43,4 @@ public class TimeOverCountdown extends Countdown {
|
|||||||
Bukkit.broadcastMessage(FightSystem.PREFIX +"§aZeit abgelaufen!");
|
Bukkit.broadcastMessage(FightSystem.PREFIX +"§aZeit abgelaufen!");
|
||||||
timeOver.run();
|
timeOver.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getRemainingTime(){
|
|
||||||
if(instance == null)
|
|
||||||
return -1;
|
|
||||||
return instance.getTimeLeft();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,22 @@
|
|||||||
|
/*
|
||||||
|
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.fight;
|
package de.steamwar.fightsystem.fight;
|
||||||
|
|
||||||
import com.sk89q.worldedit.EditSession;
|
import com.sk89q.worldedit.EditSession;
|
||||||
|
@ -29,7 +29,6 @@ import de.steamwar.fightsystem.states.FightState;
|
|||||||
import de.steamwar.fightsystem.utils.FightScoreboard;
|
import de.steamwar.fightsystem.utils.FightScoreboard;
|
||||||
import de.steamwar.fightsystem.utils.ItemBuilder;
|
import de.steamwar.fightsystem.utils.ItemBuilder;
|
||||||
import de.steamwar.fightsystem.utils.TechHider;
|
import de.steamwar.fightsystem.utils.TechHider;
|
||||||
import de.steamwar.fightsystem.winconditions.RankedPlayerLeftWincondition;
|
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import de.steamwar.sql.Schematic;
|
import de.steamwar.sql.Schematic;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
@ -204,9 +203,7 @@ public class FightTeam implements IFightTeam{
|
|||||||
if(!players.isEmpty()) {
|
if(!players.isEmpty()) {
|
||||||
setLeader(players.values().iterator().next());
|
setLeader(players.values().iterator().next());
|
||||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §e" + this.leader.getPlayer().getName() + " §aist nun Leader von Team " + getColoredName() + "§a!");
|
Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §e" + this.leader.getPlayer().getName() + " §aist nun Leader von Team " + getColoredName() + "§a!");
|
||||||
}else if(Config.Ranked){
|
}else if(!Config.event() && !Config.Ranked){
|
||||||
RankedPlayerLeftWincondition.leaderQuit(this);
|
|
||||||
}else if(!Config.event()){
|
|
||||||
FightSystem.shutdown(FightSystem.PREFIX + "§cTeam " + getColoredName() + " §chat keine Spieler mehr.\n Arena schließt...");
|
FightSystem.shutdown(FightSystem.PREFIX + "§cTeam " + getColoredName() + " §chat keine Spieler mehr.\n Arena schließt...");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -34,11 +34,10 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scoreboard.Scoreboard;
|
import org.bukkit.scoreboard.Scoreboard;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class FightScoreboard {
|
public class FightScoreboard {
|
||||||
|
private FightScoreboard(){}
|
||||||
|
|
||||||
private static final Set<FightState> fullScoreboard = EnumSet.of(FightState.RUNNING, FightState.SPECTATE);
|
private static final Set<FightState> fullScoreboard = EnumSet.of(FightState.RUNNING, FightState.SPECTATE);
|
||||||
private static int index = 0;
|
private static int index = 0;
|
||||||
@ -72,9 +71,7 @@ public class FightScoreboard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void teamScoreboard(FightTeam fightTeam){
|
private static void teamScoreboard(FightTeam fightTeam){
|
||||||
title = fightTeam.getColoredName();
|
setTitle(fightTeam.getColoredName());
|
||||||
if(Config.recording())
|
|
||||||
RecordSystem.scoreboardTitle(title);
|
|
||||||
fightTeam.getPlayers().forEach(fp -> {
|
fightTeam.getPlayers().forEach(fp -> {
|
||||||
if(fp.isLiving())
|
if(fp.isLiving())
|
||||||
addScore(fightTeam.getPrefix() + fp.getPlayer().getName(), (int) Math.ceil(fp.getPlayer().getHealth()));
|
addScore(fightTeam.getPrefix() + fp.getPlayer().getName(), (int) Math.ceil(fp.getPlayer().getHealth()));
|
||||||
@ -82,37 +79,31 @@ public class FightScoreboard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void generalScoreboard(){
|
private static void generalScoreboard(){
|
||||||
title = "§6Kampf";
|
setTitle("§eKampf");
|
||||||
if(Config.recording())
|
List<String> scores = new ArrayList<>();
|
||||||
RecordSystem.scoreboardTitle(title);
|
|
||||||
int fightTime = TimeOverCountdown.getRemainingTime();
|
TimeOverCountdown timeOverCountdown = TimeoutWincondition.getTimeOverCountdown();
|
||||||
if (fightTime != -1) {
|
if(timeOverCountdown != null){
|
||||||
|
int fightTime = timeOverCountdown.getTimeLeft();
|
||||||
if (fightTime >= 60)
|
if (fightTime >= 60)
|
||||||
addScore("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s", 4);
|
scores.add("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s");
|
||||||
else
|
else
|
||||||
addScore("§7Zeit: §a" + fightTime + "s", 4);
|
scores.add("§7Zeit: §a" + fightTime + "s");
|
||||||
}
|
}
|
||||||
|
|
||||||
addScore("§7TPS: §e" + TPSWatcher.getTPS(), 3);
|
scores.add("§7TPS: §e" + TPSWatcher.getTPS());
|
||||||
|
|
||||||
if(fullScoreboard.contains(FightState.getFightState())){
|
if(fullScoreboard.contains(FightState.getFightState())){
|
||||||
if (Config.PercentSystem){
|
for(PrintableWincondition wincondition : Wincondition.getPrintableWinconditions()){
|
||||||
addScore(Fight.getRedTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getRedPercent()) / 100.0) + "%", 1);
|
scores.add(wincondition.getDisplay(Fight.getRedTeam()));
|
||||||
addScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getBluePercent()) / 100.0) + "%", 0);
|
scores.add(wincondition.getDisplay(Fight.getBlueTeam()));
|
||||||
}else if(Config.WaterTechKO){
|
|
||||||
addScore(Fight.getRedTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamRedWater(), 1);
|
|
||||||
addScore(Fight.getBlueTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamBlueWater(), 0);
|
|
||||||
}else if(Config.RelativePercent){
|
|
||||||
addScore(Fight.getRedTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getRed().getPrintablePercent() + "%", 1);
|
|
||||||
addScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getBlue().getPrintablePercent() + "%", 0);
|
|
||||||
}else if(Config.Points){
|
|
||||||
addScore(Fight.getRedTeam().getPrefix() + "Punkte: " + WinconditionPoints.getRed().getPoints(), 1);
|
|
||||||
addScore(Fight.getBlueTeam().getPrefix() + "Punkte: " + WinconditionPoints.getBlue().getPoints(), 0);
|
|
||||||
}else if(Config.PumpkinTechKO){
|
|
||||||
addScore(Fight.getRedTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamRedPumpkins(), 1);
|
|
||||||
addScore(Fight.getBlueTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamBluePumpkins(), 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int value = scores.size();
|
||||||
|
for(String score : scores){
|
||||||
|
addScore(score, value--);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void nextIndexDisplay() {
|
private static void nextIndexDisplay() {
|
||||||
@ -131,6 +122,12 @@ public class FightScoreboard {
|
|||||||
generalScoreboard();
|
generalScoreboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void setTitle(String t) {
|
||||||
|
title = t;
|
||||||
|
if(Config.recording())
|
||||||
|
RecordSystem.scoreboardTitle(t);
|
||||||
|
}
|
||||||
|
|
||||||
private static void addScore(String string, int i) {
|
private static void addScore(String string, int i) {
|
||||||
if(Config.recording())
|
if(Config.recording())
|
||||||
RecordSystem.scoreboardData(string, i);
|
RecordSystem.scoreboardData(string, i);
|
||||||
|
@ -25,6 +25,7 @@ import de.steamwar.fightsystem.countdown.TimeOverCountdown;
|
|||||||
import de.steamwar.fightsystem.fight.Fight;
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
import de.steamwar.fightsystem.fight.FightPlayer;
|
import de.steamwar.fightsystem.fight.FightPlayer;
|
||||||
import de.steamwar.fightsystem.fight.FightTeam;
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
|
import de.steamwar.fightsystem.winconditions.TimeoutWincondition;
|
||||||
import de.steamwar.sql.Elo;
|
import de.steamwar.sql.Elo;
|
||||||
import de.steamwar.sql.Schematic;
|
import de.steamwar.sql.Schematic;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
@ -76,8 +77,14 @@ public class FightStatistics {
|
|||||||
redSchem = null;
|
redSchem = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int remainingTime = 0;
|
||||||
|
TimeOverCountdown timeOverCountdown = TimeoutWincondition.getTimeOverCountdown();
|
||||||
|
if(timeOverCountdown != null){
|
||||||
|
remainingTime = timeOverCountdown.getTimeLeft();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int fightId = create(gameMode, Bukkit.getWorlds().get(0).getName(), starttime, TimeOverCountdown.getRemainingTime(),
|
int fightId = create(gameMode, Bukkit.getWorlds().get(0).getName(), starttime, remainingTime,
|
||||||
blueLeader.getId(), redLeader.getId(), blueSchem, redSchem, win, windescription);
|
blueLeader.getId(), redLeader.getId(), blueSchem, redSchem, win, windescription);
|
||||||
|
|
||||||
for (FightPlayer fp : Fight.getBlueTeam().getPlayers())
|
for (FightPlayer fp : Fight.getBlueTeam().getPlayers())
|
||||||
|
@ -20,24 +20,26 @@
|
|||||||
package de.steamwar.fightsystem.winconditions;
|
package de.steamwar.fightsystem.winconditions;
|
||||||
|
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
|
||||||
import de.steamwar.fightsystem.fight.Fight;
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
import de.steamwar.fightsystem.fight.FightTeam;
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
import de.steamwar.fightsystem.states.FightState;
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
|
||||||
public class EventTeamOffWincondition extends Wincondition {
|
public class EventTeamOffWincondition extends Wincondition {
|
||||||
|
|
||||||
public EventTeamOffWincondition(){
|
public EventTeamOffWincondition(){
|
||||||
super(Config.event(), EnumSet.of(FightState.PRE_RUNNING));
|
super(Config.event(), EnumSet.of(FightState.PRE_RUNNING), "TeamOffline");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enable() {
|
public void enable() {
|
||||||
teamOff(Fight.getBlueTeam());
|
if(Fight.getBlueTeam().allPlayersOut() && Fight.getRedTeam().allPlayersOut()){
|
||||||
teamOff(Fight.getRedTeam());
|
win(null, null, null, "§cBeide Teams sind offline!");
|
||||||
|
}else{
|
||||||
|
teamOff(Fight.getBlueTeam());
|
||||||
|
teamOff(Fight.getRedTeam());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -47,8 +49,7 @@ public class EventTeamOffWincondition extends Wincondition {
|
|||||||
|
|
||||||
private void teamOff(FightTeam team){
|
private void teamOff(FightTeam team){
|
||||||
if(team.allPlayersOut()){
|
if(team.allPlayersOut()){
|
||||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§6Das Team " + team.getColoredName() + " §6ist Offline!");
|
win(Fight.getOpposite(team), "§cDas Team ", " §cist offline!");
|
||||||
FightSystem.setSpectateState(Fight.getOpposite(team), "TeamOffline");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,9 +29,12 @@ import java.util.Set;
|
|||||||
|
|
||||||
abstract class ListenerWincondition extends Wincondition implements Listener {
|
abstract class ListenerWincondition extends Wincondition implements Listener {
|
||||||
|
|
||||||
ListenerWincondition(boolean condition, Set<FightState> enabled){
|
protected ListenerWincondition(Winconditions condition, Set<FightState> enabled, String windescription){
|
||||||
//If the condition is not met, never enable
|
super(condition, enabled, windescription);
|
||||||
super(condition, enabled);
|
}
|
||||||
|
|
||||||
|
protected ListenerWincondition(boolean condition, Set<FightState> enabled, String windescription) {
|
||||||
|
super(condition, enabled, windescription);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
package de.steamwar.fightsystem.winconditions;
|
||||||
|
|
||||||
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
|
|
||||||
|
public interface PercentWincondition {
|
||||||
|
double getPercent(FightTeam team);
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
This file is a part of the SteamWar software.
|
This file is a part of the SteamWar software.
|
||||||
|
|
||||||
Copyright (C) 2020 SteamWar.de-Serverteam
|
Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
@ -19,25 +19,8 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.winconditions;
|
package de.steamwar.fightsystem.winconditions;
|
||||||
|
|
||||||
import de.steamwar.fightsystem.fight.Fight;
|
|
||||||
import de.steamwar.fightsystem.fight.FightTeam;
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
import de.steamwar.fightsystem.states.FightState;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.util.EnumSet;
|
public interface PrintableWincondition {
|
||||||
|
String getDisplay(FightTeam team);
|
||||||
abstract class PlayerWincondition extends ListenerWincondition {
|
|
||||||
|
|
||||||
PlayerWincondition(boolean condition) {
|
|
||||||
super(condition, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING));
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isTarget(Player player){
|
|
||||||
FightTeam fightTeam = Fight.getPlayerTeam(player);
|
|
||||||
if(fightTeam == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
fightTeam.getFightPlayer(player).setOut();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -19,14 +19,29 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.winconditions;
|
package de.steamwar.fightsystem.winconditions;
|
||||||
|
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
import de.steamwar.fightsystem.Config;
|
||||||
import de.steamwar.fightsystem.fight.Fight;
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
import de.steamwar.fightsystem.fight.FightTeam;
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
public class RankedPlayerLeftWincondition {
|
public class RankedPlayerLeftWincondition extends ListenerWincondition{
|
||||||
private RankedPlayerLeftWincondition(){}
|
|
||||||
|
|
||||||
public static void leaderQuit(FightTeam leaderlessTeam){
|
public RankedPlayerLeftWincondition(){
|
||||||
FightSystem.setSpectateState(Fight.getOpposite(leaderlessTeam), "LeaderQuit");
|
super(Config.Ranked, FightState.INGAME, "LeaderQuit");
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void handlePlayerQuit(PlayerQuitEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
FightTeam team = isTarget(player);
|
||||||
|
if(team == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(team.isPlayerLeader(player)) {
|
||||||
|
win(Fight.getOpposite(team), "§cDer Leader von ", " §chat den Kampf verlassen!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
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;
|
||||||
|
|
||||||
|
import de.steamwar.fightsystem.countdown.TimeOverCountdown;
|
||||||
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public abstract class TimeoutWincondition extends Wincondition {
|
||||||
|
|
||||||
|
private static TimeOverCountdown timeOverCountdown = null;
|
||||||
|
|
||||||
|
protected TimeoutWincondition(Winconditions condition, Set<FightState> enabled, String windescription) {
|
||||||
|
super(condition, enabled, windescription);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected TimeoutWincondition(Winconditions condition, String windescription) {
|
||||||
|
super(condition, EnumSet.of(FightState.RUNNING), windescription);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void timeOver();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enable() {
|
||||||
|
timeOverCountdown = new TimeOverCountdown(this::timeOver);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disable() {
|
||||||
|
if(timeOverCountdown != null)
|
||||||
|
timeOverCountdown.disable();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TimeOverCountdown getTimeOverCountdown(){
|
||||||
|
return timeOverCountdown;
|
||||||
|
}
|
||||||
|
}
|
@ -19,23 +19,66 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.winconditions;
|
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.FightState;
|
||||||
import de.steamwar.fightsystem.states.StateDependent;
|
import de.steamwar.fightsystem.states.StateDependent;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
abstract class Wincondition implements StateDependent {
|
public abstract class Wincondition implements StateDependent {
|
||||||
|
|
||||||
|
protected static PercentWincondition percentWincondition = null;
|
||||||
|
protected static final List<PrintableWincondition> printableWinconditions = new ArrayList<>();
|
||||||
|
|
||||||
private final Set<FightState> enabled;
|
private final Set<FightState> enabled;
|
||||||
|
private final String windescription;
|
||||||
|
|
||||||
Wincondition(boolean condition, Set<FightState> enabled){
|
protected Wincondition(Winconditions condition, Set<FightState> enabled, String windescription){
|
||||||
|
this(Config.ActiveWinconditions.contains(condition), enabled, windescription);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Wincondition(boolean condition, Set<FightState> enabled, String windescription){
|
||||||
this.enabled = enabled;
|
this.enabled = enabled;
|
||||||
|
this.windescription = windescription;
|
||||||
if(condition)
|
if(condition)
|
||||||
FightState.registerStateDependent(this);
|
FightState.registerStateDependent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void win(FightTeam team, String preteammessage, String postteammessage){
|
||||||
|
win(team, preteammessage, postteammessage, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void win(FightTeam team, String preteammessage, String postteammessage, String tiemessage){
|
||||||
|
if(team != null){
|
||||||
|
Bukkit.broadcastMessage(FightSystem.PREFIX + preteammessage + team.getColoredName() + postteammessage);
|
||||||
|
}else{
|
||||||
|
Bukkit.broadcastMessage(FightSystem.PREFIX + tiemessage);
|
||||||
|
}
|
||||||
|
FightSystem.setSpectateState(team, windescription);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected FightTeam isTarget(Player player){
|
||||||
|
FightTeam fightTeam = Fight.getPlayerTeam(player);
|
||||||
|
if(fightTeam == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
fightTeam.getFightPlayer(player).setOut();
|
||||||
|
return fightTeam;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<FightState> enabled(){
|
public Set<FightState> enabled(){
|
||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<PrintableWincondition> getPrintableWinconditions(){
|
||||||
|
return printableWinconditions;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,20 +19,18 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.winconditions;
|
package de.steamwar.fightsystem.winconditions;
|
||||||
|
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
|
||||||
import de.steamwar.fightsystem.fight.Fight;
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
import de.steamwar.fightsystem.fight.FightTeam;
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
public class WinconditionAllDead extends PlayerWincondition {
|
public class WinconditionAllDead extends ListenerWincondition {
|
||||||
|
|
||||||
public WinconditionAllDead(){
|
public WinconditionAllDead(){
|
||||||
super(Config.AllDead);
|
super(Winconditions.ALL_DEAD, FightState.INGAME, "AllDead");
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -46,14 +44,12 @@ public class WinconditionAllDead extends PlayerWincondition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleDeath(Player player, String message){
|
private void handleDeath(Player player, String message){
|
||||||
if(!isTarget(player))
|
FightTeam team = isTarget(player);
|
||||||
|
if(team == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FightTeam fightTeam = Fight.getPlayerTeam(player);
|
if(team.allPlayersOut()) {
|
||||||
assert fightTeam != null; // Checked with isTarget
|
win(Fight.getOpposite(team), "§cDer letzte Spieler aus ", message);
|
||||||
if(fightTeam.allPlayersOut()) {
|
|
||||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer letzte Spieler aus " + fightTeam.getColoredName() + message);
|
|
||||||
FightSystem.setSpectateState(Fight.getOpposite(fightTeam), "AllDead");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,20 +19,18 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.winconditions;
|
package de.steamwar.fightsystem.winconditions;
|
||||||
|
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
|
||||||
import de.steamwar.fightsystem.fight.Fight;
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
import de.steamwar.fightsystem.fight.FightTeam;
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
public class WinconditionCaptainDead extends PlayerWincondition {
|
public class WinconditionCaptainDead extends ListenerWincondition {
|
||||||
|
|
||||||
public WinconditionCaptainDead(){
|
public WinconditionCaptainDead(){
|
||||||
super(Config.CaptainDead);
|
super(Winconditions.CAPTAIN_DEAD, FightState.INGAME, "LeaderDead");
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -46,14 +44,12 @@ public class WinconditionCaptainDead extends PlayerWincondition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleDeath(Player player, String message){
|
private void handleDeath(Player player, String message){
|
||||||
if(!isTarget(player))
|
FightTeam team = isTarget(player);
|
||||||
|
if(team == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FightTeam fightTeam = Fight.getPlayerTeam(player);
|
if(team.isPlayerLeader(player)) {
|
||||||
assert fightTeam != null; // Checked with isTarget
|
win(Fight.getOpposite(team), "§cDer Leader von ", message);
|
||||||
if(fightTeam.isPlayerLeader(player)) {
|
|
||||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + fightTeam.getColoredName() + message);
|
|
||||||
FightSystem.setSpectateState(Fight.getOpposite(fightTeam), "LeaderDead");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,39 +19,26 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.winconditions;
|
package de.steamwar.fightsystem.winconditions;
|
||||||
|
|
||||||
import de.steamwar.fightsystem.Config;
|
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
|
||||||
import de.steamwar.fightsystem.countdown.TimeOverCountdown;
|
|
||||||
import de.steamwar.fightsystem.fight.Fight;
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
import de.steamwar.fightsystem.states.FightState;
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
public class WinconditionHeartRatioTimeout extends TimeoutWincondition {
|
||||||
|
|
||||||
public class WinconditionHeartRatioTimeout extends Wincondition {
|
|
||||||
|
|
||||||
private TimeOverCountdown countdown;
|
|
||||||
|
|
||||||
public WinconditionHeartRatioTimeout() {
|
public WinconditionHeartRatioTimeout() {
|
||||||
super(Config.HeartRatioTimeout, EnumSet.of(FightState.RUNNING));
|
super(Winconditions.HEART_RATIO_TIMEOUT, "HeartTimeout");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enable() {
|
protected void timeOver() {
|
||||||
countdown = new TimeOverCountdown(() -> {
|
double blueHeartRatio = Fight.getBlueTeam().getHeartRatio();
|
||||||
double blueHeartRatio = Fight.getBlueTeam().getHeartRatio();
|
double redHeartRatio = Fight.getRedTeam().getHeartRatio();
|
||||||
double redHeartRatio = Fight.getRedTeam().getHeartRatio();
|
|
||||||
|
|
||||||
if(blueHeartRatio > redHeartRatio)
|
FightTeam team = null;
|
||||||
FightSystem.setSpectateState(Fight.getBlueTeam(), "HeartTimeout");
|
if(blueHeartRatio > redHeartRatio)
|
||||||
else if(blueHeartRatio < redHeartRatio)
|
team = Fight.getBlueTeam();
|
||||||
FightSystem.setSpectateState(Fight.getRedTeam(), "HeartTimeout");
|
else if(blueHeartRatio < redHeartRatio)
|
||||||
else
|
team = Fight.getRedTeam();
|
||||||
FightSystem.setSpectateState(null, "HeartTimeout");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
win(team, "§cDie Zeit ist abgelaufen, und Team ", " §chatte mehr verbleibende Leben!", "§cDie Zeit ist abgelaufen, und beide Teams hatten die gleiche Anzahl an verbleibenden Leben!");
|
||||||
public void disable(){
|
|
||||||
countdown.disable();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,60 +20,66 @@
|
|||||||
package de.steamwar.fightsystem.winconditions;
|
package de.steamwar.fightsystem.winconditions;
|
||||||
|
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
|
||||||
import de.steamwar.fightsystem.fight.Fight;
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
import de.steamwar.fightsystem.states.FightState;
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import de.steamwar.fightsystem.utils.Region;
|
import de.steamwar.fightsystem.utils.Region;
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class WinconditionPercentSystem extends ListenerWincondition {
|
public class WinconditionPercentSystem extends ListenerWincondition implements PrintableWincondition, PercentWincondition {
|
||||||
|
|
||||||
private static double bluePercent = 0D;
|
private static final int SCHEMATIC_SIZE = Math.abs(Config.SchemsizeX * Config.SchemsizeY * Config.SchemsizeZ);
|
||||||
private static double redPercent = 0D;
|
|
||||||
|
|
||||||
private static int blueDestroyedBlocks;
|
private final Map<FightTeam, TeamPercent> teamMap = new HashMap<>();
|
||||||
private static int redDestroyedBlocks;
|
|
||||||
|
|
||||||
private static final int schematicSize = Math.abs(Config.SchemsizeX * Config.SchemsizeY * Config.SchemsizeZ);
|
|
||||||
|
|
||||||
public WinconditionPercentSystem() {
|
public WinconditionPercentSystem() {
|
||||||
super(Config.PercentSystem, EnumSet.of(FightState.RUNNING));
|
super(Winconditions.PERCENT_SYSTEM, EnumSet.of(FightState.RUNNING), "Percent");
|
||||||
|
printableWinconditions.add(this);
|
||||||
|
percentWincondition = this;
|
||||||
|
teamMap.put(Fight.getBlueTeam(), new TeamPercent(Fight.getBlueTeam()));
|
||||||
|
teamMap.put(Fight.getRedTeam(), new TeamPercent(Fight.getRedTeam()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void handleEntityExplode(EntityExplodeEvent event) {
|
public void handleEntityExplode(EntityExplodeEvent event) {
|
||||||
Entity entity = event.getEntity();
|
teamMap.values().forEach(teamPercent -> teamPercent.check(event));
|
||||||
|
}
|
||||||
|
|
||||||
//Team Blue
|
@Override
|
||||||
if(Region.isInRange(entity.getLocation(), Config.TeamBlueCornerX, Config.TeamBlueCornerY, Config.TeamBlueCornerZ, Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ, Config.BorderFromSchematic)){
|
public String getDisplay(FightTeam team) {
|
||||||
blueDestroyedBlocks = blueDestroyedBlocks + event.blockList().size();
|
return team.getPrefix() + "Schaden: " + (Math.round(100.0 * getPercent(team)) / 100.0) + "%";
|
||||||
double doubleBlueDestroyedBlocks = blueDestroyedBlocks;
|
}
|
||||||
double destroyPercent = doubleBlueDestroyedBlocks * 100 / schematicSize;
|
|
||||||
bluePercent = destroyPercent;
|
@Override
|
||||||
if(destroyPercent >= Config.PercentWin) {
|
public double getPercent(FightTeam team) {
|
||||||
FightSystem.setSpectateState(Fight.getRedTeam(), "Percent");
|
return teamMap.get(team).percent;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TeamPercent {
|
||||||
|
|
||||||
|
private final FightTeam team;
|
||||||
|
private double percent;
|
||||||
|
private int destroyedBlocks;
|
||||||
|
|
||||||
|
private TeamPercent(FightTeam team) {
|
||||||
|
this.team = team;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void check(EntityExplodeEvent event) {
|
||||||
|
if(!Region.isInRange(event.getEntity().getLocation(), team.getCornerX(), team.getCornerY(), team.getCornerZ(), Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ, Config.BorderFromSchematic)){
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
//Team Red
|
|
||||||
}else if(Region.isInRange(entity.getLocation(), Config.TeamRedCornerX, Config.TeamRedCornerY, Config.TeamRedCornerZ, Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ, Config.BorderFromSchematic)) {
|
destroyedBlocks += event.blockList().size();
|
||||||
redDestroyedBlocks = redDestroyedBlocks + event.blockList().size();
|
percent = (double)destroyedBlocks * 100 / SCHEMATIC_SIZE;
|
||||||
double doubleRedDestroyedBlocks = redDestroyedBlocks;
|
if(percent >= Config.PercentWin) {
|
||||||
double destroyPercent = doubleRedDestroyedBlocks * 100 / schematicSize;
|
win(Fight.getOpposite(team), "§cTeam ", " §chat den Gegnern");
|
||||||
redPercent = destroyPercent;
|
|
||||||
if(destroyPercent >= Config.PercentWin) {
|
|
||||||
FightSystem.setSpectateState(Fight.getBlueTeam(), "Percent");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getBluePercent() {
|
|
||||||
return bluePercent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getRedPercent() {
|
|
||||||
return redPercent;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,40 +1,43 @@
|
|||||||
|
/*
|
||||||
|
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;
|
package de.steamwar.fightsystem.winconditions;
|
||||||
|
|
||||||
import de.steamwar.fightsystem.Config;
|
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
|
||||||
import de.steamwar.fightsystem.countdown.TimeOverCountdown;
|
|
||||||
import de.steamwar.fightsystem.fight.Fight;
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
import de.steamwar.fightsystem.states.FightState;
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
public class WinconditionPercentTimeout extends TimeoutWincondition {
|
||||||
|
|
||||||
public class WinconditionPercentTimeout extends Wincondition {
|
|
||||||
|
|
||||||
private static final String WINDESCRIPTION = "PercentTimeout";
|
|
||||||
|
|
||||||
private TimeOverCountdown countdown;
|
|
||||||
|
|
||||||
public WinconditionPercentTimeout() {
|
public WinconditionPercentTimeout() {
|
||||||
super(Config.HeartRatioTimeout, EnumSet.of(FightState.RUNNING));
|
super(Winconditions.HEART_RATIO_TIMEOUT, "PercentTimeout");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enable() {
|
protected void timeOver() {
|
||||||
countdown = new TimeOverCountdown(() -> {
|
double bluePercent = Wincondition.percentWincondition.getPercent(Fight.getBlueTeam());
|
||||||
double bluePercent = WinconditionPercentSystem.getBluePercent();
|
double redPercent = Wincondition.percentWincondition.getPercent(Fight.getRedTeam());
|
||||||
double redPercent = WinconditionPercentSystem.getRedPercent();
|
|
||||||
|
|
||||||
if(bluePercent > redPercent)
|
FightTeam team = null;
|
||||||
FightSystem.setSpectateState(Fight.getBlueTeam(), WINDESCRIPTION);
|
if(bluePercent > redPercent)
|
||||||
else if(bluePercent < redPercent)
|
team = Fight.getRedTeam();
|
||||||
FightSystem.setSpectateState(Fight.getRedTeam(), WINDESCRIPTION);
|
else if(bluePercent < redPercent)
|
||||||
else
|
team = Fight.getBlueTeam();
|
||||||
FightSystem.setSpectateState(null, WINDESCRIPTION);
|
win(team, "§cDie Zeit ist abgelaufen, und Team ", " §chatte weniger Schaden erlitten!", "§cDie Zeit ist abgelaufen, und beide Teams hatten gleichen Schaden!");
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void disable(){
|
|
||||||
countdown.disable();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,54 +19,67 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.winconditions;
|
package de.steamwar.fightsystem.winconditions;
|
||||||
|
|
||||||
import de.steamwar.fightsystem.Config;
|
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
import de.steamwar.fightsystem.countdown.TimeOverCountdown;
|
|
||||||
import de.steamwar.fightsystem.fight.Fight;
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
import de.steamwar.fightsystem.fight.FightTeam;
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
import de.steamwar.fightsystem.states.FightState;
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
public class WinconditionPoints extends PlayerWincondition {
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
private static TeamPoints blue;
|
public class WinconditionPoints extends TimeoutWincondition implements PrintableWincondition, Listener {
|
||||||
private static TeamPoints red;
|
|
||||||
private TimeOverCountdown countdown;
|
private final Map<FightTeam, WinconditionRelativePercent.TeamPercent> percentMap = new HashMap<>();
|
||||||
|
private final Map<FightTeam, TeamPoints> teamMap = new HashMap<>();
|
||||||
|
|
||||||
public WinconditionPoints(){
|
public WinconditionPoints(){
|
||||||
super(Config.Points);
|
super(Winconditions.POINTS, FightState.INGAME, "Points");
|
||||||
|
|
||||||
|
percentMap.put(Fight.getBlueTeam(), new WinconditionRelativePercent.TeamPercent(Fight.getBlueTeam()));
|
||||||
|
percentMap.put(Fight.getRedTeam(), new WinconditionRelativePercent.TeamPercent(Fight.getRedTeam()));
|
||||||
|
|
||||||
|
teamMap.put(Fight.getBlueTeam(), new TeamPoints(Fight.getBlueTeam()));
|
||||||
|
teamMap.put(Fight.getRedTeam(), new TeamPoints(Fight.getRedTeam()));
|
||||||
|
printableWinconditions.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TeamPoints getRed(){
|
@Override
|
||||||
return red;
|
protected void timeOver() {
|
||||||
}
|
int redPoints = teamMap.get(Fight.getRedTeam()).getPoints();
|
||||||
|
int bluePoints = teamMap.get(Fight.getBlueTeam()).getPoints();
|
||||||
|
|
||||||
public static TeamPoints getBlue(){
|
FightTeam team = null;
|
||||||
return blue;
|
if(redPoints > bluePoints)
|
||||||
|
team = Fight.getRedTeam();
|
||||||
|
else if(redPoints < bluePoints)
|
||||||
|
team = Fight.getBlueTeam();
|
||||||
|
|
||||||
|
win(team, "§cDas Team ", " §chat mehr Punkte!", "§cBeide Teams haben gleich viele Punkte!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enable() {
|
public void enable() {
|
||||||
super.enable();
|
Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin());
|
||||||
blue = new TeamPoints(Fight.getRedTeam(), WinconditionRelativePercent.getBlue(), WinconditionRelativePercent.getRed());
|
teamMap.values().forEach(TeamPoints::enable);
|
||||||
red = new TeamPoints(Fight.getBlueTeam(), WinconditionRelativePercent.getRed(), WinconditionRelativePercent.getBlue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disable() {
|
public void disable() {
|
||||||
super.disable();
|
super.disable();
|
||||||
if(countdown != null)
|
HandlerList.unregisterAll(this);
|
||||||
countdown.disable();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stateChange(FightState state){
|
public void stateChange(FightState state){
|
||||||
if(state == FightState.RUNNING){
|
if(state == FightState.RUNNING){
|
||||||
countdown = new TimeOverCountdown(this::fightEnds);
|
super.enable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,73 +94,63 @@ public class WinconditionPoints extends PlayerWincondition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleDeath(Player player, String message){
|
private void handleDeath(Player player, String message){
|
||||||
if(!isTarget(player))
|
FightTeam team = isTarget(player);
|
||||||
|
if(team == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FightTeam fightTeam = Fight.getPlayerTeam(player);
|
TeamPoints enemy = teamMap.get(Fight.getOpposite(team));
|
||||||
TeamPoints enemy = getEnemyByTeam(fightTeam);
|
if(team.isPlayerLeader(player)) {
|
||||||
assert fightTeam != null; // Checked by isTarget
|
|
||||||
if(fightTeam.isPlayerLeader(player)) {
|
|
||||||
enemy.points += 500;
|
enemy.points += 500;
|
||||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + fightTeam.getPrefix() + fightTeam.getColoredName() + message);
|
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + team.getColoredName() + message);
|
||||||
fightEnds();
|
timeOver();
|
||||||
}else if(fightTeam.getPlayers().size() <= 5)
|
}else if(team.getPlayers().size() <= 5)
|
||||||
enemy.points += 300;
|
enemy.points += 300;
|
||||||
else
|
else
|
||||||
enemy.points += 200;
|
enemy.points += 200;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fightEnds(){
|
@Override
|
||||||
if(red.getPoints() > blue.getPoints())
|
public String getDisplay(FightTeam team) {
|
||||||
FightSystem.setSpectateState(blue.enemy, "Points");
|
return team.getPrefix() + "Punkte: " + teamMap.get(team).getPoints();
|
||||||
else if(red.getPoints() < blue.getPoints())
|
|
||||||
FightSystem.setSpectateState(red.enemy, "Points");
|
|
||||||
else
|
|
||||||
FightSystem.setSpectateState(null, "Points");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private TeamPoints getEnemyByTeam(FightTeam team){
|
private class TeamPoints {
|
||||||
if(team == blue.enemy)
|
private static final int MAX_POINTS = 2000;
|
||||||
return blue;
|
|
||||||
else
|
private final FightTeam team;
|
||||||
return red;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class TeamPoints {
|
|
||||||
private final FightTeam enemy;
|
|
||||||
private final WinconditionRelativePercent.TeamPercent enemyPercent;
|
|
||||||
private double factor;
|
private double factor;
|
||||||
private static final int maxPoints = 2000;
|
|
||||||
|
|
||||||
private int points;
|
private int points;
|
||||||
|
|
||||||
TeamPoints(FightTeam enemy, WinconditionRelativePercent.TeamPercent ownPercent, WinconditionRelativePercent.TeamPercent enemyPercent){
|
TeamPoints(FightTeam team){
|
||||||
this.enemy = enemy;
|
this.team = team;
|
||||||
this.enemyPercent = enemyPercent;
|
|
||||||
points = 0;
|
points = 0;
|
||||||
|
}
|
||||||
|
|
||||||
//Prevent NPE
|
public void enable() {
|
||||||
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () ->{
|
percentMap.get(team).enable();
|
||||||
if(enemyPercent.getBlockCount() < ownPercent.getBlockCount())
|
int ownBlocks = percentMap.get(team).getBlockCount();
|
||||||
this.factor = 10000; //Original mit 20 (20% = 0.2 ergeben 2000 Punkte
|
int enemyBlocks = percentMap.get(Fight.getOpposite(team)).getBlockCount();
|
||||||
else{
|
|
||||||
double f = 10000.0 * ownPercent.getBlockCount() / enemyPercent.getBlockCount();
|
|
||||||
|
|
||||||
if(f > 10000)
|
if(enemyBlocks < ownBlocks) {
|
||||||
f = 10000;
|
this.factor = 10000; //Original mit 20 (20% = 0.2 ergeben 2000 Punkte
|
||||||
else if(f < 4000)
|
} else {
|
||||||
f = 4000;
|
double f = 10000.0 * ownBlocks / enemyBlocks;
|
||||||
|
|
||||||
this.factor = f;
|
if(f > 10000)
|
||||||
}
|
f = 10000;
|
||||||
});
|
else if(f < 4000)
|
||||||
|
f = 4000;
|
||||||
|
|
||||||
|
this.factor = f;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPoints(){
|
public int getPoints(){
|
||||||
int damagePoints = (int)(enemyPercent.getPercent() * factor);
|
int damagePoints = (int)(percentMap.get(Fight.getOpposite(team)).getPercent() * factor);
|
||||||
if(damagePoints > maxPoints)
|
if(damagePoints > MAX_POINTS)
|
||||||
damagePoints = maxPoints;
|
damagePoints = MAX_POINTS;
|
||||||
return points + damagePoints;
|
return points + damagePoints;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,31 +30,26 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class WinconditionPumpkinTechKO extends Wincondition {
|
public class WinconditionPumpkinTechKO extends Wincondition implements PrintableWincondition {
|
||||||
|
|
||||||
private static int teamRedPumpkins = -1;
|
private static final World world = Bukkit.getWorlds().get(0);
|
||||||
private static int teamBluePumpkins = -1;
|
|
||||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
|
||||||
private static final Material PUMPKIN_LANTERN = SWItem.getMaterial("JACK_O_LANTERN");
|
private static final Material PUMPKIN_LANTERN = SWItem.getMaterial("JACK_O_LANTERN");
|
||||||
|
|
||||||
|
private final Map<FightTeam, TeamPumpkin> teamMap = new HashMap<>();
|
||||||
private BukkitTask task;
|
private BukkitTask task;
|
||||||
private static boolean running = false;
|
|
||||||
|
|
||||||
public WinconditionPumpkinTechKO(){
|
public WinconditionPumpkinTechKO(){
|
||||||
super(Config.PumpkinTechKO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING));
|
super(Winconditions.PUMPKIN_TECH_KO, FightState.INGAME, "PumpkinTechKO");
|
||||||
}
|
teamMap.put(Fight.getRedTeam(), new TeamPumpkin(Fight.getRedTeam()));
|
||||||
|
teamMap.put(Fight.getBlueTeam(), new TeamPumpkin(Fight.getBlueTeam()));
|
||||||
public static int getTeamBluePumpkins() {
|
|
||||||
return teamBluePumpkins;
|
|
||||||
}
|
|
||||||
public static int getTeamRedPumpkins() {
|
|
||||||
return teamRedPumpkins;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enable() {
|
public void enable() {
|
||||||
task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), WinconditionPumpkinTechKO::recursiveCheck, 0, 200);
|
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::check, 0, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -62,45 +57,38 @@ public class WinconditionPumpkinTechKO extends Wincondition {
|
|||||||
task.cancel();
|
task.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void recursiveCheck(){
|
private void check(){
|
||||||
if(running)
|
teamMap.values().forEach(TeamPumpkin::check);
|
||||||
return;
|
|
||||||
running = true;
|
|
||||||
teamRedPumpkins = getPumpkins(Config.TeamRedCornerX,
|
|
||||||
Config.TeamRedCornerY,
|
|
||||||
Config.TeamRedCornerZ,
|
|
||||||
Config.TeamRedCornerX + Config.SchemsizeX,
|
|
||||||
Config.TeamRedCornerY + Config.SchemsizeY,
|
|
||||||
Config.TeamRedCornerZ + Config.SchemsizeZ);
|
|
||||||
teamBluePumpkins = getPumpkins(Config.TeamBlueCornerX,
|
|
||||||
Config.TeamBlueCornerY,
|
|
||||||
Config.TeamBlueCornerZ,
|
|
||||||
Config.TeamBlueCornerX + Config.SchemsizeX,
|
|
||||||
Config.TeamBlueCornerY + Config.SchemsizeY,
|
|
||||||
Config.TeamBlueCornerZ + Config.SchemsizeZ);
|
|
||||||
|
|
||||||
checkKO(Fight.getRedTeam(), teamRedPumpkins);
|
|
||||||
checkKO(Fight.getBlueTeam(), teamBluePumpkins);
|
|
||||||
running = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getPumpkins(int minX, int minY, int minZ, int maxX, int maxY, int maxZ){
|
@Override
|
||||||
int pumpkins = 0;
|
public String getDisplay(FightTeam team) {
|
||||||
for(int x = minX; x <= maxX; x++) {
|
return team.getPrefix() + "Kanonen: " + teamMap.get(team).pumpkins;
|
||||||
for(int y = minY; y <= maxY; y++) {
|
}
|
||||||
for (int z = minZ; z <= maxZ; z++) {
|
|
||||||
if (WORLD.getBlockAt(x, y, z).getType() == PUMPKIN_LANTERN)
|
private class TeamPumpkin {
|
||||||
pumpkins++;
|
private final FightTeam team;
|
||||||
|
|
||||||
|
private int pumpkins;
|
||||||
|
|
||||||
|
private TeamPumpkin (FightTeam team) {
|
||||||
|
this.team = team;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void check(){
|
||||||
|
pumpkins = 0;
|
||||||
|
for(int x = team.getCornerX(); x <= team.getCornerX() + Config.SchemsizeX; x++) {
|
||||||
|
for(int y = team.getCornerY(); y <= team.getCornerY() + Config.SchemsizeY; y++) {
|
||||||
|
for (int z = team.getCornerZ(); z <= team.getCornerZ() + Config.SchemsizeZ; z++) {
|
||||||
|
if (world.getBlockAt(x, y, z).getType() == PUMPKIN_LANTERN)
|
||||||
|
pumpkins++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return pumpkins;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void checkKO(FightTeam team, int pumpkins){
|
if(pumpkins == 0) {
|
||||||
if(pumpkins == 0){
|
win(Fight.getOpposite(team), "§cDas Team ", " §cist Tech K.O.!");
|
||||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§eDas Team " + team.getColoredName() + " §eist Tech K.O.!");
|
}
|
||||||
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team), "PumpkinTechKO"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ package de.steamwar.fightsystem.winconditions;
|
|||||||
|
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
import de.steamwar.fightsystem.countdown.TimeOverCountdown;
|
|
||||||
import de.steamwar.fightsystem.fight.Fight;
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
import de.steamwar.fightsystem.fight.FightTeam;
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
import de.steamwar.fightsystem.states.FightState;
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
@ -30,16 +29,12 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class WinconditionRelativePercent extends Wincondition{
|
public class WinconditionRelativePercent extends Wincondition implements PrintableWincondition, PercentWincondition {
|
||||||
|
|
||||||
|
private static final World world = Bukkit.getWorlds().get(0);
|
||||||
private static final Set<Material> ignoredBlocks;
|
private static final Set<Material> ignoredBlocks;
|
||||||
private static TeamPercent blue = null;
|
|
||||||
private static TeamPercent red = null;
|
|
||||||
|
|
||||||
static{
|
static{
|
||||||
Set<Material> ignored = new HashSet<>();
|
Set<Material> ignored = new HashSet<>();
|
||||||
@ -48,74 +43,78 @@ public class WinconditionRelativePercent extends Wincondition{
|
|||||||
ignoredBlocks = Collections.unmodifiableSet(ignored);
|
ignoredBlocks = Collections.unmodifiableSet(ignored);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final Map<FightTeam, TeamPercent> teamMap = new HashMap<>();
|
||||||
|
|
||||||
public WinconditionRelativePercent(){
|
public WinconditionRelativePercent(){
|
||||||
super(Config.RelativePercent || Config.Points, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING));
|
super(Winconditions.RELATIVE_PERCENT, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING), "RelativePercent");
|
||||||
}
|
teamMap.put(Fight.getBlueTeam(), new TeamPercent(Fight.getBlueTeam()));
|
||||||
|
teamMap.put(Fight.getRedTeam(), new TeamPercent(Fight.getRedTeam()));
|
||||||
public static TeamPercent getBlue(){
|
printableWinconditions.add(this);
|
||||||
if(blue == null)
|
percentWincondition = this;
|
||||||
blue = new TeamPercent(Fight.getBlueTeam());
|
|
||||||
return blue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TeamPercent getRed(){
|
|
||||||
if(red == null)
|
|
||||||
red = new TeamPercent(Fight.getRedTeam());
|
|
||||||
return red;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enable() {
|
public void enable() {
|
||||||
getBlue();
|
teamMap.values().forEach(TeamPercent::enable);
|
||||||
getRed();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disable() {
|
public void disable() {
|
||||||
blue.task.cancel();
|
teamMap.values().forEach(teamPercent -> teamPercent.task.cancel());
|
||||||
red.task.cancel();
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getPercent(FightTeam team) {
|
||||||
|
return teamMap.get(team).getPercent();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDisplay(FightTeam team) {
|
||||||
|
return team.getPrefix() + "Schaden: " + (Math.round(100.0 * getPercent(team)) / 100.0) + "%";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TeamPercent {
|
public static class TeamPercent {
|
||||||
private static final World world = Bukkit.getWorlds().get(0);
|
|
||||||
private final FightTeam team;
|
private final FightTeam team;
|
||||||
private final int blockCount;
|
|
||||||
private final BukkitTask task;
|
|
||||||
private boolean running = false;
|
|
||||||
|
|
||||||
|
private int blockCount;
|
||||||
|
private BukkitTask task;
|
||||||
private int currentBlocks;
|
private int currentBlocks;
|
||||||
|
|
||||||
private TeamPercent(FightTeam team){
|
public TeamPercent(FightTeam team){
|
||||||
this.team = team;
|
this.team = team;
|
||||||
this.blockCount = currentBlocks();
|
this.currentBlocks = 1;
|
||||||
this.currentBlocks = blockCount;
|
|
||||||
|
|
||||||
task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), () -> {
|
|
||||||
if(running)
|
|
||||||
return;
|
|
||||||
running = true;
|
|
||||||
currentBlocks = currentBlocks();
|
|
||||||
checkPercentDefeat();
|
|
||||||
running = false;
|
|
||||||
}, 400, 400);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getPrintablePercent(){
|
public void enable(){
|
||||||
return Math.round(10000.0 * getPercent()) / 100.0;
|
blockCount = currentBlocks();
|
||||||
|
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::check, 400, 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
final int getBlockCount(){
|
private void check(){
|
||||||
|
currentBlocks = currentBlocks();
|
||||||
|
|
||||||
|
if(!Config.ActiveWinconditions.contains(Winconditions.RELATIVE_PERCENT))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(getPercent() >= Config.PercentWin){
|
||||||
|
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Schiff von " + team.getColoredName() + " §cwurde zu stark beschädigt!");
|
||||||
|
FightSystem.setSpectateState(Fight.getOpposite(team), "RelativePercent");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getPercent(){
|
||||||
|
if(currentBlocks > blockCount)
|
||||||
|
return 0;
|
||||||
|
return (blockCount - currentBlocks) * 100 / (double) blockCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBlockCount(){
|
||||||
return blockCount;
|
return blockCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
double getPercent(){
|
|
||||||
int blocksDestroyed = blockCount - currentBlocks;
|
|
||||||
return blocksDestroyed > 0 ? blocksDestroyed / (double) blockCount : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int currentBlocks(){
|
private int currentBlocks(){
|
||||||
// Entern active
|
// Entern active
|
||||||
if(!Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= Config.TimeoutTime - TimeOverCountdown.getRemainingTime())
|
if(!Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= Config.TimeoutTime - TimeoutWincondition.getTimeOverCountdown().getTimeLeft())
|
||||||
return currentBlocks;
|
return currentBlocks;
|
||||||
|
|
||||||
int blocks = 0;
|
int blocks = 0;
|
||||||
@ -129,14 +128,5 @@ public class WinconditionRelativePercent extends Wincondition{
|
|||||||
}
|
}
|
||||||
return blocks;
|
return blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkPercentDefeat(){
|
|
||||||
if(!Config.RelativePercent)
|
|
||||||
return;
|
|
||||||
if(getPercent() * 100 >= Config.PercentWin){
|
|
||||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Schiff von " + team.getColoredName() + " §cwurde zu stark beschädigt!");
|
|
||||||
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team), "RelativePercent"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ import org.bukkit.scheduler.BukkitTask;
|
|||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
|
||||||
public class WinconditionTechKO extends ListenerWincondition {
|
public class WinconditionTimeTechKO extends ListenerWincondition {
|
||||||
|
|
||||||
private static final int TECH_KO_TIME_IN_S = 90;
|
private static final int TECH_KO_TIME_IN_S = 90;
|
||||||
private static final int TECH_KO_HALF_TIME = TECH_KO_TIME_IN_S*10;
|
private static final int TECH_KO_HALF_TIME = TECH_KO_TIME_IN_S*10;
|
||||||
@ -51,8 +51,8 @@ public class WinconditionTechKO extends ListenerWincondition {
|
|||||||
/**
|
/**
|
||||||
* Works only for z-Axis fight direction for performance reasons
|
* Works only for z-Axis fight direction for performance reasons
|
||||||
*/
|
*/
|
||||||
public WinconditionTechKO(){
|
public WinconditionTimeTechKO(){
|
||||||
super(Config.TechKO, EnumSet.of(FightState.RUNNING));
|
super(Winconditions.TIME_TECH_KO, EnumSet.of(FightState.RUNNING), null);
|
||||||
|
|
||||||
if(Config.TeamBluetoReddistanceZ > 0) {
|
if(Config.TeamBluetoReddistanceZ > 0) {
|
||||||
smallerZteam = Fight.getBlueTeam();
|
smallerZteam = Fight.getBlueTeam();
|
@ -19,28 +19,14 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.winconditions;
|
package de.steamwar.fightsystem.winconditions;
|
||||||
|
|
||||||
import de.steamwar.fightsystem.Config;
|
public class WinconditionTimeout extends TimeoutWincondition {
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
|
||||||
import de.steamwar.fightsystem.countdown.TimeOverCountdown;
|
|
||||||
import de.steamwar.fightsystem.states.FightState;
|
|
||||||
|
|
||||||
import java.util.EnumSet;
|
|
||||||
|
|
||||||
public class WinconditionTimeout extends Wincondition {
|
|
||||||
|
|
||||||
private TimeOverCountdown countdown;
|
|
||||||
|
|
||||||
public WinconditionTimeout() {
|
public WinconditionTimeout() {
|
||||||
super(Config.Timeout, EnumSet.of(FightState.RUNNING));
|
super(Winconditions.TIMEOUT, "Timeout");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enable() {
|
protected void timeOver() {
|
||||||
countdown = new TimeOverCountdown(() -> FightSystem.setSpectateState(null, "Timeout"));
|
win(null, null, null, "§cDie Zeit ist abgelaufen!");
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void disable() {
|
|
||||||
countdown.disable();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,32 +30,26 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class WinconditionWaterTechKO extends Wincondition {
|
public class WinconditionWaterTechKO extends Wincondition implements PrintableWincondition {
|
||||||
|
|
||||||
private static int teamRedWater;
|
|
||||||
private static int teamBlueWater;
|
|
||||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
private static final World WORLD = Bukkit.getWorlds().get(0);
|
||||||
|
|
||||||
|
private final Map<FightTeam, TeamWater> teamMap = new HashMap<>();
|
||||||
private BukkitTask task;
|
private BukkitTask task;
|
||||||
private boolean running = false;
|
|
||||||
|
|
||||||
public WinconditionWaterTechKO() {
|
public WinconditionWaterTechKO() {
|
||||||
super(Config.WaterTechKO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING));
|
super(Winconditions.WATER_TECH_KO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING), "WaterTechKO");
|
||||||
}
|
teamMap.put(Fight.getBlueTeam(), new TeamWater(Fight.getBlueTeam()));
|
||||||
|
teamMap.put(Fight.getRedTeam(), new TeamWater(Fight.getRedTeam()));
|
||||||
public static int getTeamBlueWater() {
|
printableWinconditions.add(this);
|
||||||
return teamBlueWater;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getTeamRedWater() {
|
|
||||||
return teamRedWater;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enable() {
|
public void enable() {
|
||||||
checkTask();
|
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::check, 200, 200);
|
||||||
task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), this::checkTask, 200, 200);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -63,47 +57,37 @@ public class WinconditionWaterTechKO extends Wincondition {
|
|||||||
task.cancel();
|
task.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkEmpty(FightTeam team, int teamWater){
|
private void check() {
|
||||||
if(teamWater == 0){
|
teamMap.values().forEach(TeamWater::check);
|
||||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§eDas Team " + team.getColoredName() + " §eist Tech K.O.!");
|
}
|
||||||
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team), "WaterTechKO"));
|
|
||||||
|
@Override
|
||||||
|
public String getDisplay(FightTeam team) {
|
||||||
|
return team.getPrefix() + "Wasser: " + teamMap.get(team).water;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TeamWater {
|
||||||
|
private final FightTeam team;
|
||||||
|
private int water;
|
||||||
|
|
||||||
|
private TeamWater(FightTeam team) {
|
||||||
|
this.team = team;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void checkTask() {
|
private void check() {
|
||||||
if(running)
|
water = 0;
|
||||||
return;
|
for(int x = team.getCornerX(); x <= team.getCornerX() + Config.SchemsizeX; x++) {
|
||||||
running = true;
|
for(int y = team.getCornerY(); y <= team.getCornerY() + Config.SchemsizeY; y++) {
|
||||||
teamRedWater = calcWater(
|
for (int z = team.getCornerZ(); z <= team.getCornerZ() + Config.SchemsizeZ; z++) {
|
||||||
Config.TeamRedCornerX,
|
if (WaterRemover.isWater(WORLD.getBlockAt(x, y, z)))
|
||||||
Config.TeamRedCornerY,
|
water++;
|
||||||
Config.TeamRedCornerZ,
|
}
|
||||||
Config.TeamRedCornerX + Config.SchemsizeX,
|
|
||||||
Config.TeamRedCornerY + Config.SchemsizeY,
|
|
||||||
Config.TeamRedCornerZ + Config.SchemsizeZ);
|
|
||||||
teamBlueWater = calcWater(
|
|
||||||
Config.TeamBlueCornerX,
|
|
||||||
Config.TeamBlueCornerY,
|
|
||||||
Config.TeamBlueCornerZ,
|
|
||||||
Config.TeamBlueCornerX + Config.SchemsizeX,
|
|
||||||
Config.TeamBlueCornerY + Config.SchemsizeY,
|
|
||||||
Config.TeamBlueCornerZ + Config.SchemsizeZ);
|
|
||||||
|
|
||||||
checkEmpty(Fight.getRedTeam(), teamRedWater);
|
|
||||||
checkEmpty(Fight.getBlueTeam(), teamBlueWater);
|
|
||||||
running = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int calcWater(int minX, int minY, int minZ, int maxX, int maxY, int maxZ){
|
|
||||||
int teamWater = 0;
|
|
||||||
for(int x = minX; x <= maxX; x++) {
|
|
||||||
for(int y = minY; y <= maxY; y++) {
|
|
||||||
for (int z = minZ; z <= maxZ; z++) {
|
|
||||||
if (WaterRemover.isWater(WORLD.getBlockAt(x, y, z)))
|
|
||||||
teamWater++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(water == 0){
|
||||||
|
win(Fight.getOpposite(team), "§cDas Team ", " §cist Tech K.O.!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return teamWater;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren