diff --git a/Mage.Common/src/main/java/mage/view/ChatMessage.java b/Mage.Common/src/main/java/mage/view/ChatMessage.java index de0db28809..adf541553c 100644 --- a/Mage.Common/src/main/java/mage/view/ChatMessage.java +++ b/Mage.Common/src/main/java/mage/view/ChatMessage.java @@ -1,6 +1,7 @@ package mage.view; import mage.game.Game; +import mage.util.CardUtil; import java.io.Serializable; import java.util.Date; @@ -43,27 +44,12 @@ public class ChatMessage implements Serializable { this.username = username; this.message = message; this.time = time; - this.turnInfo = prepareTurnInfo(game); + this.turnInfo = CardUtil.getTurnInfo(game); this.color = color; this.messageType = messageType; this.soundToPlay = soundToPlay; } - private String prepareTurnInfo(Game game) { - // no turn info - if (game == null) { - return null; - } - - // not started game - if (game.getStep() == null) { - return "T0"; - } - - // normal game - return "T" + game.getTurnNum() + "." + game.getStep().getType().getStepShortText(); - } - public String getMessage() { return message; } diff --git a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java index 1b97fb3b71..020d86780d 100644 --- a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java +++ b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java @@ -4201,4 +4201,8 @@ public class TestPlayer implements Player { return rollbackActions; } + @Override + public String toString() { + return computerPlayer.toString(); + } } diff --git a/Mage/src/main/java/mage/MageObjectImpl.java b/Mage/src/main/java/mage/MageObjectImpl.java index 47110ebef0..0e77ca1074 100644 --- a/Mage/src/main/java/mage/MageObjectImpl.java +++ b/Mage/src/main/java/mage/MageObjectImpl.java @@ -339,4 +339,9 @@ public abstract class MageObjectImpl implements MageObject { } } } + + @Override + public String toString() { + return getIdName() + " (" + super.getClass().getSuperclass().getSimpleName() + " -> " + this.getClass().getSimpleName() + ")"; + } } diff --git a/Mage/src/main/java/mage/Mana.java b/Mage/src/main/java/mage/Mana.java index d9f11a8aec..556f5d7c46 100644 --- a/Mage/src/main/java/mage/Mana.java +++ b/Mage/src/main/java/mage/Mana.java @@ -100,6 +100,15 @@ public class Mana implements Comparable, Serializable, Copyable { public int hashCode() { return Objects.hash(amount, snowAmount); } + + @Override + public String toString() { + if (amount != 0 || snowAmount != 0) { + return amount + "/" + snowAmount; + } else { + return ""; + } + } } private static final transient Logger logger = Logger.getLogger(Mana.class); diff --git a/Mage/src/main/java/mage/abilities/costs/mana/GenericManaCost.java b/Mage/src/main/java/mage/abilities/costs/mana/GenericManaCost.java index 53baaa9cfa..579ad25699 100644 --- a/Mage/src/main/java/mage/abilities/costs/mana/GenericManaCost.java +++ b/Mage/src/main/java/mage/abilities/costs/mana/GenericManaCost.java @@ -75,5 +75,4 @@ public class GenericManaCost extends ManaCostImpl { public boolean containsColor(ColoredManaSymbol coloredManaSymbol) { return false; } - } diff --git a/Mage/src/main/java/mage/abilities/costs/mana/ManaCostImpl.java b/Mage/src/main/java/mage/abilities/costs/mana/ManaCostImpl.java index 056480b9a6..2848529896 100644 --- a/Mage/src/main/java/mage/abilities/costs/mana/ManaCostImpl.java +++ b/Mage/src/main/java/mage/abilities/costs/mana/ManaCostImpl.java @@ -284,4 +284,8 @@ public abstract class ManaCostImpl extends CostImpl implements ManaCost { } } + @Override + public String toString() { + return getText(); + } } diff --git a/Mage/src/main/java/mage/abilities/costs/mana/ManaCosts.java b/Mage/src/main/java/mage/abilities/costs/mana/ManaCosts.java index 2abafdfa68..c1196269e3 100644 --- a/Mage/src/main/java/mage/abilities/costs/mana/ManaCosts.java +++ b/Mage/src/main/java/mage/abilities/costs/mana/ManaCosts.java @@ -54,5 +54,4 @@ public interface ManaCosts extends List, ManaCost { .collect(Collectors.toCollection(ManaCostsImpl::new)); } - } diff --git a/Mage/src/main/java/mage/abilities/effects/ContinuousEffects.java b/Mage/src/main/java/mage/abilities/effects/ContinuousEffects.java index 5560e5fa3c..776b6912f4 100644 --- a/Mage/src/main/java/mage/abilities/effects/ContinuousEffects.java +++ b/Mage/src/main/java/mage/abilities/effects/ContinuousEffects.java @@ -1498,4 +1498,8 @@ public class ContinuousEffects implements Serializable { } } + @Override + public String toString() { + return "Effects: " + allEffectsLists.stream().mapToInt(ContinuousEffectsList::size).sum(); + } } diff --git a/Mage/src/main/java/mage/game/CardState.java b/Mage/src/main/java/mage/game/CardState.java index ad89663885..8302c100a1 100644 --- a/Mage/src/main/java/mage/game/CardState.java +++ b/Mage/src/main/java/mage/game/CardState.java @@ -1,11 +1,16 @@ package mage.game; import java.io.Serializable; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; + import mage.abilities.Abilities; import mage.abilities.AbilitiesImpl; import mage.abilities.Ability; +import mage.counters.Counter; import mage.counters.Counters; /** @@ -127,4 +132,30 @@ public class CardState implements Serializable { this.melded = melded; } + @Override + public String toString() { + List info = new ArrayList<>(); + + if (this.faceDown) { + info.add("face down"); + } + if (this.counters != null && !this.counters.isEmpty()) { + info.add("counters: " + this.counters.values().stream().mapToInt(Counter::getCount).sum()); + } + if (this.abilities != null && !this.abilities.isEmpty()) { + info.add("abilities: " + abilities.size()); + } + if (this.lostAllAbilities) { + info.add("lost all"); + } + if (this.melded) { + info.add("melded"); + } + + if (info.isEmpty()) { + return ""; + } else { + return String.join("; ", info); + } + } } diff --git a/Mage/src/main/java/mage/game/Exile.java b/Mage/src/main/java/mage/game/Exile.java index a8a4474e40..0ffaf01f1b 100644 --- a/Mage/src/main/java/mage/game/Exile.java +++ b/Mage/src/main/java/mage/game/Exile.java @@ -120,4 +120,12 @@ public class Exile implements Serializable, Copyable { } } } + + @Override + public String toString() { + return "Cards: " + exileZones.values() + .stream() + .mapToInt(ExileZone::size) + .sum(); + } } diff --git a/Mage/src/main/java/mage/game/GameImpl.java b/Mage/src/main/java/mage/game/GameImpl.java index 77f8e052e1..e725c6ff25 100644 --- a/Mage/src/main/java/mage/game/GameImpl.java +++ b/Mage/src/main/java/mage/game/GameImpl.java @@ -3476,4 +3476,14 @@ public abstract class GameImpl implements Game, Serializable { return gameStopped; } + @Override + public String toString() { + Player activePayer = this.getPlayer(this.getActivePlayerId()); + StringBuilder sb = new StringBuilder() + .append(this.getGameType().toString()) + .append("; ").append(CardUtil.getTurnInfo(this)) + .append("; active: ").append((activePayer == null ? "none" : activePayer.getName())) + .append("; stack: ").append(this.getStack().toString()); + return sb.toString(); + } } diff --git a/Mage/src/main/java/mage/game/GameState.java b/Mage/src/main/java/mage/game/GameState.java index bc89379638..8ff30e43cf 100644 --- a/Mage/src/main/java/mage/game/GameState.java +++ b/Mage/src/main/java/mage/game/GameState.java @@ -28,6 +28,7 @@ import mage.players.Player; import mage.players.PlayerList; import mage.players.Players; import mage.target.Target; +import mage.util.CardUtil; import mage.util.Copyable; import mage.util.ThreadLocalStringBuilder; import mage.watchers.Watcher; @@ -1384,4 +1385,9 @@ public class GameState implements Serializable, Copyable { public boolean isManaBurn() { return manaBurn; } + + @Override + public String toString() { + return CardUtil.getTurnInfo(this); + } } diff --git a/Mage/src/main/java/mage/game/permanent/Battlefield.java b/Mage/src/main/java/mage/game/permanent/Battlefield.java index 4e63f57498..a472258683 100644 --- a/Mage/src/main/java/mage/game/permanent/Battlefield.java +++ b/Mage/src/main/java/mage/game/permanent/Battlefield.java @@ -382,4 +382,9 @@ public class Battlefield implements Serializable { .mapToInt(x -> x ? 1 : 0) .sum(); } + + @Override + public String toString() { + return "Permanents: " + field.size(); + } } diff --git a/Mage/src/main/java/mage/game/stack/Spell.java b/Mage/src/main/java/mage/game/stack/Spell.java index 6907bbbb58..135980b6cc 100644 --- a/Mage/src/main/java/mage/game/stack/Spell.java +++ b/Mage/src/main/java/mage/game/stack/Spell.java @@ -1131,4 +1131,8 @@ public class Spell extends StackObjImpl implements Card { throw new UnsupportedOperationException("Spells should not loose all abilities. Check if this operation is correct."); } + @Override + public String toString() { + return ability.toString(); + } } diff --git a/Mage/src/main/java/mage/game/stack/SpellStack.java b/Mage/src/main/java/mage/game/stack/SpellStack.java index 7a8bb227ea..8a355a85dc 100644 --- a/Mage/src/main/java/mage/game/stack/SpellStack.java +++ b/Mage/src/main/java/mage/game/stack/SpellStack.java @@ -144,4 +144,8 @@ public class SpellStack extends ArrayDeque { return dateLastAdded; } + @Override + public String toString() { + return this.size() + (this.isEmpty() ? "" : " (top: " + this.getFirst().toString() + ")"); + } } diff --git a/Mage/src/main/java/mage/players/Library.java b/Mage/src/main/java/mage/players/Library.java index 5ff04b98e9..e08aab6741 100644 --- a/Mage/src/main/java/mage/players/Library.java +++ b/Mage/src/main/java/mage/players/Library.java @@ -251,4 +251,9 @@ public class Library implements Serializable { } return -1; } + + @Override + public String toString() { + return "Cards: " + library.size(); + } } diff --git a/Mage/src/main/java/mage/players/ManaPool.java b/Mage/src/main/java/mage/players/ManaPool.java index 187c65f126..a68d1edc4f 100644 --- a/Mage/src/main/java/mage/players/ManaPool.java +++ b/Mage/src/main/java/mage/players/ManaPool.java @@ -531,4 +531,9 @@ public class ManaPool implements Serializable { public boolean getLastPaymentWasSnow() { return lastPaymentWasSnow; } + + @Override + public String toString() { + return getMana().toString(); + } } diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index bd2f38fb15..a0665d5037 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -4706,7 +4706,7 @@ public abstract class PlayerImpl implements Player, Serializable { @Override public String toString() { - return getName() + " " + super.toString(); + return getName() + " (" + super.getClass().getSimpleName() + ")"; } } diff --git a/Mage/src/main/java/mage/util/CardUtil.java b/Mage/src/main/java/mage/util/CardUtil.java index 97a5c7f6e9..5a181ca973 100644 --- a/Mage/src/main/java/mage/util/CardUtil.java +++ b/Mage/src/main/java/mage/util/CardUtil.java @@ -21,6 +21,7 @@ import mage.filter.Filter; import mage.filter.predicate.mageobject.NamePredicate; import mage.game.CardState; import mage.game.Game; +import mage.game.GameState; import mage.game.command.Commander; import mage.game.events.GameEvent; import mage.game.permanent.Permanent; @@ -1290,4 +1291,29 @@ public final class CardUtil { } return mapOldToNew; } + + /** + * Return turn info for game. Uses in game logs and debug. + * + * @param game + * @return + */ + public static String getTurnInfo(Game game) { + return getTurnInfo(game == null ? null : game.getState()); + } + + public static String getTurnInfo(GameState gameState) { + // no turn info + if (gameState == null) { + return null; + } + + // not started game + if (gameState.getTurn().getStep() == null) { + return "T0"; + } + + // normal game + return "T" + gameState.getTurnNum() + "." + gameState.getTurn().getStep().getType().getStepShortText(); + } }