feat: trace win reason for logging

This commit is contained in:
punchready 2021-06-05 04:19:37 +02:00
parent f2a961d159
commit 2cbd86b725
2 changed files with 19 additions and 5 deletions

View File

@ -841,17 +841,19 @@ public class GameLogic {
}
if(character.inventory.getFreeSlots() == 0) { // no slots => has all infinity stones
result.addAll(handlePlayerWin(state, character.id.type));
result.addAll(handlePlayerWin(state, character.id.type, "collected all infinity stones"));
return result;
}
}
if(!anyAlive) {
EntityType winner = state.winConditions.getWinner();
String[] reason = new String[1];
EntityType winner = state.winConditions.getWinner(reason);
if(winner == EntityType.None) {
winner = rand.nextBoolean() ? EntityType.P1 : EntityType.P2;
reason[0] = "determined by lot as tiebreaker";
}
result.addAll(handlePlayerWin(state, winner));
result.addAll(handlePlayerWin(state, winner, reason[0]));
return result;
}
@ -1224,8 +1226,8 @@ public class GameLogic {
* @param winner The winning character
* @return The list of resulting {@link Event Events}
*/
private static ArrayList<Event> handlePlayerWin(GameState state, EntityType winner) {
Logger.trace("Player " + winner + " won");
private static ArrayList<Event> handlePlayerWin(GameState state, EntityType winner, String reason) {
Logger.trace("Player " + winner + " won: " + reason);
ArrayList<Event> result = new ArrayList<>();

View File

@ -15,9 +15,20 @@ public class WinConditionManager {
* @return The {@link EntityType} that is currently winning the game according to overtime ruling
*/
public EntityType getWinner() {
return getWinner(new String[1]);
}
/**
* Returns the current winner
* @param reason Will be filled in with the deciding {@link WinCondition}
* @return The {@link EntityType} that is currently winning the game according to overtime ruling
*/
public EntityType getWinner(String[] reason) {
int value1;
int value2;
for(WinCondition condition: WinCondition.values()) {
reason[0] = condition.name();
value1 = getValue(EntityType.P1, condition);
value2 = getValue(EntityType.P2, condition);
@ -29,6 +40,7 @@ public class WinConditionManager {
}
}
reason[0] = "";
return EntityType.None;
}