* UI: added turn number and step info in game logs

This commit is contained in:
Oleg Agafonov 2020-02-28 20:27:07 +04:00
parent 190c3ecc00
commit 2e73f9d1c5
21 changed files with 546 additions and 529 deletions

View file

@ -1,44 +1,45 @@
package mage.constants;
/**
*
* @author North
*/
public enum PhaseStep {
UNTAP ("Untap", 0, "untap step"),
UPKEEP ("Upkeep", 1, "upkeep"), // card texts don't use the word "step" for this phase step
DRAW ("Draw", 2, "draw step"),
PRECOMBAT_MAIN ("Precombat Main", 3,"precombat main step"),
BEGIN_COMBAT ("Begin Combat", 4, "begin combat step"),
DECLARE_ATTACKERS ("Declare Attackers", 5, "declare attackers step"),
DECLARE_BLOCKERS ("Declare Blockers", 6, "declare blockers step"),
FIRST_COMBAT_DAMAGE ("First Combat Damage", 7, "first combat damage"),
COMBAT_DAMAGE ("Combat Damage", 8, "combat damage step"),
END_COMBAT ("End Combat", 9, "end combat step"),
POSTCOMBAT_MAIN ("Postcombat Main", 10, "postcombat main step"),
END_TURN ("End Turn", 11, "end turn step"),
CLEANUP ("Cleanup", 12, "cleanup step");
UNTAP("Untap", 0, "untap step", "UN"),
UPKEEP("Upkeep", 1, "upkeep", "UP"), // card texts don't use the word "step" for this phase step
DRAW("Draw", 2, "draw step", "DR"),
PRECOMBAT_MAIN("Precombat Main", 3, "precombat main step", "PM"),
BEGIN_COMBAT("Begin Combat", 4, "begin combat step", "BC"),
DECLARE_ATTACKERS("Declare Attackers", 5, "declare attackers step", "DA"),
DECLARE_BLOCKERS("Declare Blockers", 6, "declare blockers step", "DB"),
FIRST_COMBAT_DAMAGE("First Combat Damage", 7, "first combat damage", "FCD"),
COMBAT_DAMAGE("Combat Damage", 8, "combat damage step", "CD"),
END_COMBAT("End Combat", 9, "end combat step", "EC"),
POSTCOMBAT_MAIN("Postcombat Main", 10, "postcombat main step", "PM"),
END_TURN("End Turn", 11, "end turn step", "ET"),
CLEANUP("Cleanup", 12, "cleanup step", "CL");
private final String text;
private final String stepText;
private final String stepShortText; // for chats/logs
/**
* Index is used for game state scoring system.
*/
private final int index;
PhaseStep(String text, int index, String stepText) {
PhaseStep(String text, int index, String stepText, String stepShortText) {
this.text = text;
this.index = index;
this.stepText = stepText;
this.stepShortText = stepShortText;
}
public boolean isBefore(PhaseStep other){
return this.getIndex()<other.getIndex();
public boolean isBefore(PhaseStep other) {
return this.getIndex() < other.getIndex();
}
public boolean isAfter(PhaseStep other){
return this.getIndex()>other.getIndex();
public boolean isAfter(PhaseStep other) {
return this.getIndex() > other.getIndex();
}
public int getIndex() {
@ -54,4 +55,7 @@ public enum PhaseStep {
return stepText;
}
public String getStepShortText() {
return stepShortText;
}
}

View file

@ -1,8 +1,5 @@
package mage.game;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
import mage.MageItem;
import mage.MageObject;
import mage.abilities.Ability;
@ -44,6 +41,10 @@ import mage.players.Players;
import mage.util.MessageToClient;
import mage.util.functions.ApplyToPermanent;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
public interface Game extends MageItem, Serializable {
MatchType getGameType();
@ -266,7 +267,7 @@ public interface Game extends MageItem, Serializable {
void fireInformEvent(String message);
void fireStatusEvent(String message, boolean withTime);
void fireStatusEvent(String message, boolean withTime, boolean withTurnInfo);
void fireUpdatePlayersEvent();
@ -299,9 +300,9 @@ public interface Game extends MageItem, Serializable {
/**
* Creates and fires an damage prevention event
*
* @param damageEvent damage event that will be replaced (instanceof check
* will be done)
* @param source ability that's the source of the prevention effect
* @param damageEvent damage event that will be replaced (instanceof check
* will be done)
* @param source ability that's the source of the prevention effect
* @param game
* @param amountToPrevent max preventable amount
* @return true prevention was successfull / false prevention was replaced
@ -311,12 +312,12 @@ public interface Game extends MageItem, Serializable {
/**
* Creates and fires an damage prevention event
*
* @param event damage event that will be replaced (instanceof check will be
* done)
* @param source ability that's the source of the prevention effect
* @param event damage event that will be replaced (instanceof check will be
* done)
* @param source ability that's the source of the prevention effect
* @param game
* @param preventAllDamage true if there is no limit to the damage that can
* be prevented
* be prevented
* @return true prevention was successfull / false prevention was replaced
*/
PreventionEffectData preventDamage(GameEvent event, Ability source, Game game, boolean preventAllDamage);

View file

@ -921,7 +921,7 @@ public abstract class GameImpl implements Game, Serializable {
if (startMessage == null || startMessage.isEmpty()) {
startMessage = "Game has started";
}
fireStatusEvent(startMessage, false);
fireStatusEvent(startMessage, false, false);
saveState(false);
@ -2369,11 +2369,11 @@ public abstract class GameImpl implements Game, Serializable {
}
@Override
public void fireStatusEvent(String message, boolean withTime) {
public void fireStatusEvent(String message, boolean withTime, boolean withTurnInfo) {
if (simulation) {
return;
}
tableEventSource.fireTableEvent(EventType.STATUS, message, withTime, this);
tableEventSource.fireTableEvent(EventType.STATUS, message, withTime, withTurnInfo, this);
}
@Override

View file

@ -1,10 +1,5 @@
package mage.game.events;
import java.io.Serializable;
import java.util.EventObject;
import java.util.UUID;
import mage.cards.Cards;
import mage.cards.decks.Deck;
import mage.game.Game;
@ -13,8 +8,11 @@ import mage.game.match.MatchOptions;
import mage.game.tournament.MultiplayerRound;
import mage.game.tournament.TournamentPairing;
import java.io.Serializable;
import java.util.EventObject;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TableEvent extends EventObject implements ExternalEvent, Serializable {
@ -37,6 +35,7 @@ public class TableEvent extends EventObject implements ExternalEvent, Serializab
private MatchOptions options;
private int timeout;
private boolean withTime;
private boolean withTurnInfo;
public TableEvent(EventType eventType) {
super(eventType);
@ -48,11 +47,16 @@ public class TableEvent extends EventObject implements ExternalEvent, Serializab
}
public TableEvent(EventType eventType, String message, boolean withTime, Game game) {
this(eventType, message, withTime, withTime, game); // turn info with time always (exception: start turn message)
}
public TableEvent(EventType eventType, String message, boolean withTime, boolean withTurnInfo, Game game) {
super(game);
this.game = game;
this.message = message;
this.eventType = eventType;
this.withTime = withTime;
this.withTurnInfo = withTurnInfo;
}
public TableEvent(EventType eventType, String message, Cards cards, Game game) {
@ -91,7 +95,7 @@ public class TableEvent extends EventObject implements ExternalEvent, Serializab
this.options = options;
this.eventType = eventType;
}
public TableEvent(EventType eventType, MultiplayerRound round, MatchOptions options) {
super(options);
this.round = round;
@ -134,7 +138,7 @@ public class TableEvent extends EventObject implements ExternalEvent, Serializab
public TournamentPairing getPair() {
return pair;
}
public MultiplayerRound getMultiplayerRound() {
return round;
}
@ -150,4 +154,8 @@ public class TableEvent extends EventObject implements ExternalEvent, Serializab
public boolean getWithTime() {
return withTime;
}
public boolean getWithTurnInfo() {
return withTurnInfo;
}
}

View file

@ -1,5 +1,3 @@
package mage.game.events;
import mage.cards.Cards;
@ -8,19 +6,19 @@ import mage.game.Game;
import mage.game.draft.Draft;
import mage.game.events.TableEvent.EventType;
import mage.game.match.MatchOptions;
import mage.game.tournament.MultiplayerRound;
import mage.game.tournament.TournamentPairing;
import java.io.Serializable;
import java.util.UUID;
import mage.game.tournament.MultiplayerRound;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TableEventSource implements EventSource<TableEvent>, Serializable {
protected final EventDispatcher<TableEvent> dispatcher = new EventDispatcher<TableEvent>() {};
protected final EventDispatcher<TableEvent> dispatcher = new EventDispatcher<TableEvent>() {
};
@Override
public void addListener(Listener<TableEvent> listener) {
@ -31,7 +29,7 @@ public class TableEventSource implements EventSource<TableEvent>, Serializable {
public void removeAllListener() {
dispatcher.removeAllListener();
}
public void fireTableEvent(EventType eventType) {
dispatcher.fireEvent(new TableEvent(eventType));
@ -41,8 +39,8 @@ public class TableEventSource implements EventSource<TableEvent>, Serializable {
dispatcher.fireEvent(new TableEvent(eventType, message, game));
}
public void fireTableEvent(EventType eventType, String message, boolean withTime, Game game) {
dispatcher.fireEvent(new TableEvent(eventType, message, withTime, game));
public void fireTableEvent(EventType eventType, String message, boolean withTime, boolean withTurnInfo, Game game) {
dispatcher.fireEvent(new TableEvent(eventType, message, withTime, withTurnInfo, game));
}
public void fireTableEvent(EventType eventType, UUID playerId, String message, Game game) {
@ -68,7 +66,7 @@ public class TableEventSource implements EventSource<TableEvent>, Serializable {
public void fireTableEvent(EventType eventType, TournamentPairing pair, MatchOptions options) {
dispatcher.fireEvent(new TableEvent(eventType, pair, options));
}
public void fireTableEvent(EventType eventType, MultiplayerRound round, MatchOptions options) {
dispatcher.fireEvent(new TableEvent(eventType, round, options));
}

View file

@ -333,6 +333,6 @@ public class Turn implements Serializable {
}
}
sb.append(')');
game.fireStatusEvent(sb.toString(), true);
game.fireStatusEvent(sb.toString(), true, false);
}
}