SteamWar/FightSystem
Archiviert
13
1

Finishing SG.eu Points Wincondition implementation

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2019-12-22 15:20:50 +01:00
Ursprung 09acb366d3
Commit dbae65bf82
7 geänderte Dateien mit 103 neuen und 40 gelöschten Zeilen

Datei anzeigen

@ -6,8 +6,11 @@ import org.bukkit.Bukkit;
public class TimeOverCountdown extends Countdown {
public TimeOverCountdown() {
private final Runnable timeOver;
public TimeOverCountdown(Runnable timeOver) {
super(Config.TimeoutTime, "BLOCK_NOTE_BASS", false);
this.timeOver = timeOver;
}
@Override
@ -18,7 +21,7 @@ public class TimeOverCountdown extends Countdown {
@Override
public void countdownFinished() {
Bukkit.broadcastMessage(FightSystem.PREFIX +"§aZeit abgelaufen!");
FightSystem.setSpectateState(null);
timeOver.run();
}
@Override

Datei anzeigen

@ -5,6 +5,7 @@ import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.winconditions.WinconditionPercentSystem;
import de.steamwar.fightsystem.winconditions.WinconditionPoints;
import de.steamwar.fightsystem.winconditions.WinconditionRelativePercent;
import de.steamwar.fightsystem.winconditions.WinconditionWaterTechKO;
import org.bukkit.Bukkit;
@ -12,16 +13,19 @@ import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
import java.util.Objects;
public class FightScoreboard {
private FightScoreboard(){}
private static final Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
private static final Scoreboard scoreboard = Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard();
private static final Objective objective;
private static int index = 0;
static{
if(scoreboard.getObjective("AAA") == null)
//noinspection deprecation
objective = scoreboard.registerNewObjective("AAA", "BBB");
else
objective = scoreboard.getObjective("AAA");
@ -30,6 +34,7 @@ public class FightScoreboard {
public static void init(){
Bukkit.getScheduler().scheduleSyncRepeatingTask(FightSystem.getPlugin(), () -> {
objective.unregister();
//noinspection deprecation
scoreboard.registerNewObjective("AAA", "BBB");
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
@ -75,6 +80,9 @@ public class FightScoreboard {
}else if(Config.RelativePercent){
objective.getScore(Fight.getRedTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getRed().getPrintablePercent() + "%").setScore(1);
objective.getScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getBlue().getPrintablePercent() + "%").setScore(0);
}else if(Config.Points){
objective.getScore(Fight.getRedTeam().getPrefix() + "Punkte: " + WinconditionPoints.getRed().getPoints()).setScore(1);
objective.getScore(Fight.getBlueTeam().getPrefix() + "Punkte: " + WinconditionPoints.getBlue().getPoints()).setScore(0);
}
}

Datei anzeigen

@ -18,28 +18,22 @@ public class WinconditionAllDead extends PlayerWincondition {
@EventHandler
public void handlePlayerDeath(PlayerDeathEvent event) {
Player player = event.getEntity().getPlayer();
if(!isTarget(player))
return;
FightTeam fightTeam = Fight.getPlayerTeam(player);
if(fightTeam.allPlayersOut()) {
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer letzte Spieler aus " + fightTeam.getPrefix() + fightTeam.getColoredName() + " §cist gestorben!");
FightSystem.setSpectateState(Fight.getOpposite(fightTeam));
}
handleDeath(event.getEntity().getPlayer(), " §cist gestorben!");
}
@EventHandler
public void handlePlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
handleDeath(event.getPlayer(), " §chat den Kampf verlassen!");
}
private void handleDeath(Player player, String message){
if(!isTarget(player))
return;
FightTeam fightTeam = Fight.getPlayerTeam(player);
assert fightTeam != null; // Checked with isTarget
if(fightTeam.allPlayersOut()) {
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer letzte Spieler aus §6" + fightTeam.getPrefix() + fightTeam.getColoredName() + " §chat den Kampf verlassen!");
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer letzte Spieler aus " + fightTeam.getColoredName() + message);
FightSystem.setSpectateState(Fight.getOpposite(fightTeam));
}
}

Datei anzeigen

@ -18,28 +18,22 @@ public class WinconditionCaptainDead extends PlayerWincondition {
@EventHandler
public void handlePlayerDeath(PlayerDeathEvent event) {
Player player = event.getEntity().getPlayer();
if(!isTarget(player))
return;
FightTeam fightTeam = Fight.getPlayerTeam(player);
if(fightTeam.isPlayerLeader(player)) {
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + fightTeam.getPrefix() + fightTeam.getColoredName() + " §cist gestorben!");
FightSystem.setSpectateState(Fight.getOpposite(fightTeam));
}
handleDeath(event.getEntity().getPlayer(), " §cist gestorben!");
}
@EventHandler
public void handlePlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
handleDeath(event.getPlayer(), " §chat den Kampf verlassen!");
}
private void handleDeath(Player player, String message){
if(!isTarget(player))
return;
FightTeam fightTeam = Fight.getPlayerTeam(player);
assert fightTeam != null; // Checked with isTarget
if(fightTeam.isPlayerLeader(player)) {
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + fightTeam.getPrefix() + fightTeam.getColoredName() + " §chat den Kampf verlassen!");
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + fightTeam.getColoredName() + message);
FightSystem.setSpectateState(Fight.getOpposite(fightTeam));
}
}

Datei anzeigen

@ -1,10 +1,17 @@
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.FightTeam;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class WinconditionPoints {
public class WinconditionPoints extends PlayerWincondition {
private static TeamPoints blue;
private static TeamPoints red;
@ -13,22 +20,69 @@ public class WinconditionPoints {
if(!Config.Points)
return;
init(true);
blue = new TeamPoints(Fight.getRedTeam(), WinconditionRelativePercent.getBlue(), WinconditionRelativePercent.getRed());
red = new TeamPoints(Fight.getBlueTeam(), WinconditionRelativePercent.getRed(), WinconditionRelativePercent.getBlue());
new TimeOverCountdown(this::fightEnds);
}
public TeamPoints getRed(){
@EventHandler
public void handlePlayerDeath(PlayerDeathEvent event) {
handleDeath(event.getEntity().getPlayer(), " §cist gestorben!");
}
@EventHandler
public void handlePlayerQuit(PlayerQuitEvent event) {
handleDeath(event.getPlayer(), " §chat den Kampf verlassen!");
}
private void handleDeath(Player player, String message){
if(!isTarget(player))
return;
FightTeam fightTeam = Fight.getPlayerTeam(player);
TeamPoints enemy = getEnemyByTeam(fightTeam);
assert fightTeam != null; // Checked by isTarget
if(fightTeam.isPlayerLeader(player)) {
enemy.points += 500;
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + fightTeam.getPrefix() + fightTeam.getColoredName() + message);
FightSystem.setSpectateState(Fight.getOpposite(fightTeam));
}else if(fightTeam.getPlayers().size() <= 5)
enemy.points += 300;
else
enemy.points += 200;
}
public static TeamPoints getRed(){
return red;
}
public TeamPoints getBlue(){
public static TeamPoints getBlue(){
return blue;
}
private void fightEnds(){
if(red.getPoints() > blue.getPoints())
FightSystem.setSpectateState(blue.enemy);
else if(red.getPoints() < blue.getPoints())
FightSystem.setSpectateState(red.enemy);
else
FightSystem.setSpectateState(null);
}
private TeamPoints getEnemyByTeam(FightTeam team){
if(team == blue.enemy)
return blue;
else
return red;
}
public static class TeamPoints extends PlayerWincondition {
private final FightTeam enemy;
private final WinconditionRelativePercent.TeamPercent enemyPercent;
private final double factor;
private static final int maxPoints = 2000;
private int points;
@ -39,14 +93,24 @@ public class WinconditionPoints {
points = 0;
if(enemyPercent.getBlockCount() < ownPercent.getBlockCount())
factor = 20;
this.factor = 10000; //Original mit 20 (20% = 0.2 ergeben 2000 Punkte
else{
double f = 10000 * ownPercent.getBlockCount() / enemyPercent.getBlockCount();
if(f > 10000)
f = 10000;
else if(f < 4000)
f = 4000;
this.factor = f;
}
}
public int getPoints(){
return points;
int damagePoints = (int)(enemyPercent.getPercent() * factor);
if(damagePoints > maxPoints)
damagePoints = maxPoints;
return points + damagePoints;
}
}
}

Datei anzeigen

@ -62,20 +62,19 @@ public class WinconditionRelativePercent{
return Math.round(10000.0 * getPercent()) / 100.0;
}
public final int getBlockCount(){
final int getBlockCount(){
return blockCount;
}
public int getCurrentBlocks(){
return currentBlocks;
}
private double getPercent(){
double getPercent(){
int blocksDestroyed = blockCount - currentBlocks;
return blocksDestroyed > 0 ? blocksDestroyed / (double) blockCount : 0;
}
private int currentBlocks(){
if(FightSystem.isEntern())
return currentBlocks;
int blocks = 0;
for(int x = team.getCornerX(); x < team.getCornerX() + Config.SchemsizeX; x++){
for(int y = team.getCornerY(); y < team.getCornerY() + Config.SchemsizeY; y++){
@ -91,7 +90,7 @@ public class WinconditionRelativePercent{
private void checkPercentDefeat(){
if(!Config.RelativePercent)
return;
if(getPercent() >= Config.PercentWin){
if(getPercent() * 100 >= Config.PercentWin){
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Schiff von " + team.getColoredName() + " §cwurde zu stark beschädigt!");
FightSystem.setSpectateState(Fight.getOpposite(team));
}

Datei anzeigen

@ -1,5 +1,6 @@
package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.countdown.TimeOverCountdown;
import de.steamwar.fightsystem.Config;
@ -8,6 +9,6 @@ public class WinconditionTimeout {
if(!Config.Timeout)
return;
new TimeOverCountdown();
new TimeOverCountdown(() -> FightSystem.setSpectateState(null));
}
}