Archiviert
1
0

Add elo calculations

Dieser Commit ist enthalten in:
yoyosource 2022-03-10 22:15:20 +01:00
Ursprung 07199cdffc
Commit 64cb91a454

Datei anzeigen

@ -20,17 +20,28 @@
package de.steamwar.bungeecore.comms.handlers;
import com.google.common.io.ByteArrayDataInput;
import de.steamwar.bungeecore.ArenaMode;
import de.steamwar.bungeecore.comms.SpigotHandler;
import de.steamwar.bungeecore.comms.packets.FightEndsPacket;
import de.steamwar.bungeecore.sql.SchemElo;
import de.steamwar.bungeecore.sql.SchemNode;
import de.steamwar.bungeecore.sql.SchematicType;
import de.steamwar.bungeecore.sql.UserElo;
import net.md_5.bungee.api.config.ServerInfo;
public class FightEndsHandler implements SpigotHandler {
private int K = 20;
@Override
public void handle(ByteArrayDataInput in, ServerInfo info) {
FightEndsPacket fightEndsPacket = new FightEndsPacket(in);
double playerRatio = Math.min(fightEndsPacket.getBluePlayers().size(), fightEndsPacket.getRedPlayers().size()) / (double )Math.max(fightEndsPacket.getBluePlayers().size(), fightEndsPacket.getRedPlayers().size());
if (!ArenaMode.getBySchemType(SchematicType.fromDB(fightEndsPacket.getGameMode())).isRanked()) {
return;
}
double playerRatio = 1 - (Math.min(fightEndsPacket.getBluePlayers().size(), fightEndsPacket.getRedPlayers().size()) / (double )Math.max(fightEndsPacket.getBluePlayers().size(), fightEndsPacket.getRedPlayers().size()));
if (playerRatio >= 0.4) {
return;
}
@ -44,5 +55,31 @@ public class FightEndsHandler implements SpigotHandler {
blueResult = 0;
}
int blueSchemOwner = SchemNode.getSchematicOwner(fightEndsPacket.getBlueSchem());
int redSchemOwner = SchemNode.getSchematicOwner(fightEndsPacket.getRedSchem());
if ((blueSchemOwner == 0 && redSchemOwner != 0) || (blueSchemOwner != 0 && redSchemOwner == 0)) {
return;
}
int blueSchemElo = SchemElo.getElo(fightEndsPacket.getBlueSchem());
int redSchemElo = SchemElo.getElo(fightEndsPacket.getRedSchem());
double blueWinExpectation = 1 / (1 + Math.pow(10, (redSchemElo - blueSchemElo) / 600f));
double redWinExpectation = 1 / (1 + Math.pow(10, (blueSchemElo - redSchemElo) / 600f));
SchemElo.setElo(fightEndsPacket.getBlueSchem(), (int) Math.round(blueSchemElo + K * (blueResult - blueWinExpectation)));
SchemElo.setElo(fightEndsPacket.getRedSchem(), (int) Math.round(redSchemElo + K * (1 - blueResult - redWinExpectation)));
if (blueSchemOwner != 0 && redSchemOwner != 0) {
for (int bluePlayer : fightEndsPacket.getBluePlayers()) {
int playerElo = UserElo.getElo(bluePlayer, fightEndsPacket.getGameMode());
UserElo.setElo(bluePlayer, fightEndsPacket.getGameMode(), (int) Math.round(playerElo + K * (blueResult - blueWinExpectation)));
}
for (int redPlayer : fightEndsPacket.getRedPlayers()) {
int playerElo = UserElo.getElo(redPlayer, fightEndsPacket.getGameMode());
UserElo.setElo(redPlayer, fightEndsPacket.getGameMode(), (int) Math.round(playerElo + K * (1 - blueResult - redWinExpectation)));
}
}
}
}