SteamWar/FightSystem
Archiviert
13
1

Merge pull request 'Add ranked rework' (#336) from Ranked into master
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Reviewed-on: #336
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Lixfel 2022-03-10 12:07:23 +01:00
Commit 6ce1be850a
7 geänderte Dateien mit 26 neuen und 144 gelöschten Zeilen

Datei anzeigen

@ -25,7 +25,6 @@ import java.util.Set;
public enum ArenaMode {
NORMAL,
RANKED,
EVENT,
TEST,
CHECK,
@ -38,7 +37,6 @@ public enum ArenaMode {
public static final Set<ArenaMode> Check = Collections.unmodifiableSet(EnumSet.of(CHECK));
public static final Set<ArenaMode> Event = Collections.unmodifiableSet(EnumSet.of(EVENT));
public static final Set<ArenaMode> Test = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK));
public static final Set<ArenaMode> Ranked = Collections.unmodifiableSet(EnumSet.of(RANKED));
public static final Set<ArenaMode> Prepare = Collections.unmodifiableSet(EnumSet.of(PREPARE));
public static final Set<ArenaMode> Replay = Collections.unmodifiableSet(EnumSet.of(REPLAY, TEST));
@ -46,9 +44,9 @@ public enum ArenaMode {
public static final Set<ArenaMode> AntiTest = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK)));
public static final Set<ArenaMode> AntiEvent = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(EVENT)));
public static final Set<ArenaMode> AntiPrepare = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(PREPARE)));
public static final Set<ArenaMode> VariableTeams = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(RANKED, EVENT, REPLAY)));
public static final Set<ArenaMode> RankedEvent = Collections.unmodifiableSet(EnumSet.of(RANKED, EVENT, REPLAY));
public static final Set<ArenaMode> Restartable = Collections.unmodifiableSet(EnumSet.of(NORMAL, RANKED));
public static final Set<ArenaMode> VariableTeams = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(EVENT, REPLAY)));
public static final Set<ArenaMode> RankedEvent = Collections.unmodifiableSet(EnumSet.of(EVENT, REPLAY));
public static final Set<ArenaMode> Restartable = Collections.unmodifiableSet(EnumSet.of(NORMAL));
public static final Set<ArenaMode> NotRestartable = Collections.unmodifiableSet(EnumSet.of(EVENT, REPLAY));
public static final Set<ArenaMode> SoloLeader = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK, PREPARE));
public static final Set<ArenaMode> NotOnBau = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK, PREPARE, REPLAY)));

Datei anzeigen

@ -92,7 +92,6 @@ public class Config {
public static final String TeamChatDetection;
public static final UUID BlueLeader;
public static final UUID RedLeader;
public static final boolean Ranked;
//Active win conditions
public static final Set<Winconditions> ActiveWinconditions;
@ -370,12 +369,9 @@ public class Config {
CheckSchemID = Integer.parseInt(System.getProperty("checkSchemID", "0"));
PrepareSchemID = Integer.parseInt(System.getProperty("prepareSchemID", "0"));
Ranked = Boolean.parseBoolean(System.getProperty("ranked", "false"));
ReplayID = Integer.parseInt(System.getProperty("replay", "0"));
if(Ranked){
mode = ArenaMode.RANKED;
}else if(CheckSchemID != 0){
if(CheckSchemID != 0){
mode = ArenaMode.CHECK;
}else if(PrepareSchemID != 0){
mode = ArenaMode.PREPARE;

Datei anzeigen

@ -87,7 +87,6 @@ public class FightSystem extends JavaPlugin {
new PrepareSchem();
new TestJoin();
new NormalJoin();
new RankedJoin();
new RunningWorldInteraction();
new PersonalKitCreator();
new ArrowStopper();
@ -114,7 +113,6 @@ public class FightSystem extends JavaPlugin {
new WinconditionHeartRatioTimeout();
new WinconditionTimeTechKO();
new EventTeamOffWincondition();
new RankedPlayerLeftWincondition();
new WinconditionPercentTimeout();
new HellsBells();

Datei anzeigen

@ -180,7 +180,6 @@ UI_PLAYER_LEAVES=
UI_LEADER_JOINS=§a§l» {0}Leader {1}
UI_PLAYER_DEATH={0}{1} §7ist gestorben
UI_PLAYER_LEAVE={0}{1} §7hat den Kampf verlassen
UI_ELO=§7ELO von {0}{1}§8: §7{2}§8»§e{3}
UI_WIN={0}Sieg {1}
UI_DRAW=§7Unentschieden
@ -232,7 +231,6 @@ WIN_FIGHTLEADER=
WIN_PERCENT={0} §7zu beschädigt
WIN_OFFLINE_BOTH=§7Beide Teams offline
WIN_OFFLINE={0} §7offline
WIN_RANKED_LEFT={0} §7hat den Kampf verlassen
WIN_ALL_DEAD={0}Alle Spieler kampfunfähig
WIN_LEADER_DEAD={0} kampfunfähig
WIN_TIME_OVER=§7Zeit abgelaufen

Datei anzeigen

@ -1,52 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
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.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class RankedJoin implements Listener {
public RankedJoin() {
new StateDependentListener(ArenaMode.Ranked, FightState.PreLeaderSetup, this);
}
@EventHandler
public void handlePlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
FightTeam fightTeam = Fight.getPlayerTeam(player);
if (fightTeam == null) {
if(!player.getUniqueId().equals(Config.RedLeader) && Fight.getBlueTeam().canbeLeader(player)) {
Fight.getBlueTeam().addMember(player);
}else if(Fight.getRedTeam().canbeLeader(player)) {
Fight.getRedTeam().addMember(player);
}
}
}
}

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.fightsystem.utils;
import de.steamwar.comms.packets.FightEndsPacket;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
@ -30,16 +31,17 @@ import de.steamwar.fightsystem.record.FileRecorder;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.OneShotStateDependent;
import de.steamwar.fightsystem.winconditions.Wincondition;
import de.steamwar.sql.Elo;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.io.FileInputStream;
import java.sql.Timestamp;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.logging.Level;
import java.util.stream.Collectors;
import static de.steamwar.sql.Fight.create;
import static de.steamwar.sql.Fight.setReplay;
@ -61,7 +63,7 @@ public class FightStatistics {
new OneShotStateDependent(ArenaMode.SeriousFight, FightState.Spectate, () -> Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::disable));
}
private void enable(){
private void enable() {
starttime = Timestamp.from(Instant.now());
}
@ -84,32 +86,32 @@ public class FightStatistics {
int win = 0;
double blueResult;
if(winner == Fight.getBlueTeam()) {
if (winner == Fight.getBlueTeam()) {
win = 1;
blueResult = 1;
}else if(winner == Fight.getRedTeam()) {
} else if (winner == Fight.getRedTeam()) {
win = 2;
blueResult = 0;
}else{
} else {
blueResult = 0.5;
}
Integer blueSchem;
Integer redSchem;
try{
try {
blueSchem = SchematicNode.getSchematicNode(Fight.getBlueTeam().getSchematic()).getId();
}catch(SecurityException e){
} catch (SecurityException e) {
blueSchem = null;
}
try{
try {
redSchem = SchematicNode.getSchematicNode(Fight.getRedTeam().getSchematic()).getId();
}catch(SecurityException e){
} catch (SecurityException e) {
redSchem = null;
}
int remainingTime = 0;
Countdown timeOverCountdown = Wincondition.getTimeOverCountdown();
if(timeOverCountdown != null){
if (timeOverCountdown != null) {
remainingTime = timeOverCountdown.getTimeLeft();
}
@ -122,43 +124,35 @@ public class FightStatistics {
for (FightPlayer fp : Fight.getRedTeam().getPlayers())
savePlayerStats(fp, fightId);
if(ArenaMode.Event.contains(Config.mode)) {
if (ArenaMode.Event.contains(Config.mode)) {
FightSystem.getEventFight().setFight(fightId);
}
try {
setReplay(fightId, new FileInputStream(FileRecorder.getFile()));
}catch(Exception e){
} catch (Exception e) {
Bukkit.getLogger().log(Level.INFO, "Failed to save replay", e);
}
}catch(Exception e){
} catch (Exception e) {
Bukkit.getLogger().log(Level.SEVERE, "Failed to save statistics", e);
}
replayLock = false;
if(Config.Ranked){
int blueElo = Elo.getElo(blueLeader, gameMode);
int redElo = Elo.getElo(redLeader, gameMode);
double redWinExpectation = 1 / (1 + Math.pow(10, (blueElo - redElo) / 400f));
double blueWinExpectation = 1 / (1 + Math.pow(10, (redElo - blueElo) / 400f));
int newBlueElo = (int) Math.round(blueElo + K * (blueResult - blueWinExpectation));
int newRedElo = (int) Math.round(redElo + K * (1 - blueResult - redWinExpectation));
Elo.setElo(blueLeader, gameMode, newBlueElo);
Elo.setElo(redLeader, gameMode, newRedElo);
FightSystem.broadcast("UI_ELO", Fight.getBlueTeam().getPrefix(), SteamwarUser.get(blueLeader).getUserName(), blueElo, newBlueElo);
FightSystem.broadcast("UI_ELO", Fight.getRedTeam().getPrefix(), SteamwarUser.get(redLeader).getUserName(), redElo, newRedElo);
if (!Bukkit.getOnlinePlayers().isEmpty()) {
Player p = Bukkit.getOnlinePlayers().iterator().next();
new FightEndsPacket((byte) win, blueSchem == null ? 0 : blueSchem, redSchem == null ? 0 : redSchem, Fight.getBlueTeam().getPlayers().stream().map(FightPlayer::getPlayer).map(SteamwarUser::get).map(SteamwarUser::getId).collect(Collectors.toList()), Fight.getRedTeam().getPlayers().stream().map(FightPlayer::getPlayer).map(SteamwarUser::get).map(SteamwarUser::getId).collect(Collectors.toList())).send(p);
}
}
private int getLeader(FightTeam team){
if(team.getLeader() != null)
private int getLeader(FightTeam team) {
if (team.getLeader() != null)
return SteamwarUser.get(team.getLeader().getPlayer().getUniqueId()).getId();
else if(team.getDesignatedLeader() != null)
else if (team.getDesignatedLeader() != null)
return SteamwarUser.get(team.getDesignatedLeader()).getId();
return 0;
}
private void savePlayerStats(FightPlayer fp, int fightId){
private void savePlayerStats(FightPlayer fp, int fightId) {
SteamwarUser user = SteamwarUser.get(fp.getPlayer().getUniqueId());
de.steamwar.sql.FightPlayer.create(fightId, user.getId(), fp.getTeam().isBlue(), fp.getKit().getName(), fp.getKills(), !fp.isLiving());
}

Datei anzeigen

@ -1,50 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.ArenaMode;
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.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
public class RankedPlayerLeftWincondition extends Wincondition implements Listener {
public RankedPlayerLeftWincondition(){
super("LeaderQuit");
new StateDependentListener(ArenaMode.Ranked, FightState.Setup, this);
}
@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), "WIN_RANKED_LEFT", team.getPrefix() + team.getLeader().getPlayer().getName());
}
}
}