mirror of
https://github.com/correl/mage.git
synced 2024-12-29 19:15:06 +00:00
Dev: added additional info to some classes for easy debug;
This commit is contained in:
parent
bde6222ea6
commit
0e916b6e29
19 changed files with 133 additions and 19 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -4201,4 +4201,8 @@ public class TestPlayer implements Player {
|
|||
return rollbackActions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return computerPlayer.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -339,4 +339,9 @@ public abstract class MageObjectImpl implements MageObject {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getIdName() + " (" + super.getClass().getSuperclass().getSimpleName() + " -> " + this.getClass().getSimpleName() + ")";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,6 +100,15 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
|
|||
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);
|
||||
|
|
|
@ -75,5 +75,4 @@ public class GenericManaCost extends ManaCostImpl {
|
|||
public boolean containsColor(ColoredManaSymbol coloredManaSymbol) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -284,4 +284,8 @@ public abstract class ManaCostImpl extends CostImpl implements ManaCost {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getText();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,5 +54,4 @@ public interface ManaCosts<T extends ManaCost> extends List<T>, ManaCost {
|
|||
.collect(Collectors.toCollection(ManaCostsImpl::new));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1498,4 +1498,8 @@ public class ContinuousEffects implements Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Effects: " + allEffectsLists.stream().mapToInt(ContinuousEffectsList::size).sum();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -120,4 +120,12 @@ public class Exile implements Serializable, Copyable<Exile> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Cards: " + exileZones.values()
|
||||
.stream()
|
||||
.mapToInt(ExileZone::size)
|
||||
.sum();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<GameState> {
|
|||
public boolean isManaBurn() {
|
||||
return manaBurn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return CardUtil.getTurnInfo(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -382,4 +382,9 @@ public class Battlefield implements Serializable {
|
|||
.mapToInt(x -> x ? 1 : 0)
|
||||
.sum();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Permanents: " + field.size();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -144,4 +144,8 @@ public class SpellStack extends ArrayDeque<StackObject> {
|
|||
return dateLastAdded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.size() + (this.isEmpty() ? "" : " (top: " + this.getFirst().toString() + ")");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -251,4 +251,9 @@ public class Library implements Serializable {
|
|||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Cards: " + library.size();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -531,4 +531,9 @@ public class ManaPool implements Serializable {
|
|||
public boolean getLastPaymentWasSnow() {
|
||||
return lastPaymentWasSnow;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getMana().toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4706,7 +4706,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName() + " " + super.toString();
|
||||
return getName() + " (" + super.getClass().getSimpleName() + ")";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue