diff --git a/Mage/src/mage/game/GameImpl.java b/Mage/src/mage/game/GameImpl.java index e5c6bce989..263ab6a80b 100644 --- a/Mage/src/mage/game/GameImpl.java +++ b/Mage/src/mage/game/GameImpl.java @@ -82,7 +82,7 @@ public abstract class GameImpl implements Game, Serializable { protected GameState state; protected UUID startingPlayerId; protected UUID choosingPlayerId; - protected String winner; + protected Player winner; protected GameStates gameStates; public GameImpl() { @@ -147,7 +147,9 @@ public abstract class GameImpl implements Game, Serializable { @Override public String getWinner() { - return winner; + if (winner == null) + return "Game is a draw"; + return "Player " + winner.getName() + " is the winner"; } @Override @@ -225,16 +227,18 @@ public abstract class GameImpl implements Game, Serializable { } } + winner = findWinner(); + + saveState(); + } + + protected Player findWinner() { for (Player player: state.getPlayers().values()) { if (player.hasWon() || (!player.hasLost() && !player.hasLeft())) { - winner = "Player " + player.getName() + " is the winner"; - break; + return player; } } - - if (winner == null) - winner = "Game is a draw"; - saveState(); + return null; } protected void endOfTurn() { diff --git a/Mage/src/mage/players/Library.java b/Mage/src/mage/players/Library.java index a2cd115433..e0c8461a0a 100644 --- a/Mage/src/mage/players/Library.java +++ b/Mage/src/mage/players/Library.java @@ -30,7 +30,6 @@ package mage.players; import java.io.Serializable; import java.util.ArrayDeque; -import java.util.ArrayList; import java.util.Arrays; import java.util.Deque; import java.util.Iterator; @@ -49,6 +48,8 @@ import mage.util.Copier; */ public class Library implements Serializable { +// private static final transient Copier copier = new Copier(); + private static Random rnd = new Random(); private boolean emptyDraw = false; @@ -81,6 +82,10 @@ public class Library implements Serializable { return card; } + public Card getFromTop(Game game) { + return library.peekFirst(); + } + public void putOnTop(Card card, Game game) { if (card.getOwnerId().equals(playerId)) library.addFirst(card); diff --git a/Mage/src/mage/players/Player.java b/Mage/src/mage/players/Player.java index 13efff23b6..e19e138d9f 100644 --- a/Mage/src/mage/players/Player.java +++ b/Mage/src/mage/players/Player.java @@ -136,6 +136,7 @@ public interface Player extends MageItem { public void declareAttacker(UUID attackerId, UUID defenderId, Game game); public void declareBlocker(UUID blockerId, UUID attackerId, Game game); + public boolean hasAvailableAttackers(Game game); public void beginTurn(); public void endOfTurn(Game game); diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index befb8eb350..659813673d 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -51,6 +51,7 @@ import mage.cards.Cards; import mage.cards.CardsImpl; import mage.cards.decks.Deck; import mage.counters.Counters; +import mage.filter.common.FilterCreatureForAttack; import mage.game.Game; import mage.game.combat.CombatGroup; import mage.game.permanent.Permanent; @@ -67,6 +68,7 @@ import mage.util.Copier; public abstract class PlayerImpl implements Player, Serializable { +// private static final transient Copier copier = new Copier(); private static final long serialVersionUID = 1L; protected UUID playerId; @@ -661,4 +663,16 @@ public abstract class PlayerImpl implements Player, Serializable { return false; } + @Override + public boolean hasAvailableAttackers(Game game) { + return getAvailableAttackers(game).size() > 0; + } + + protected List getAvailableAttackers(Game game) { + FilterCreatureForAttack attackFilter = new FilterCreatureForAttack(); + attackFilter.getControllerId().add(playerId); + List attackers = game.getBattlefield().getActivePermanents(attackFilter); + return attackers; + } + } diff --git a/Mage/src/mage/target/TargetImpl.java b/Mage/src/mage/target/TargetImpl.java index 1fe13aa953..4d2859cb42 100644 --- a/Mage/src/mage/target/TargetImpl.java +++ b/Mage/src/mage/target/TargetImpl.java @@ -128,7 +128,7 @@ public abstract class TargetImpl implements Target { @Override public boolean choose(Outcome outcome, Game game) { Player player = game.getPlayer(this.source.getControllerId()); - while (!isChosen()) { + while (!isChosen() && !doneChosing()) { chosen = targets.size() >= minNumberOfTargets; if (!player.chooseTarget(outcome, this, game)) { return chosen; @@ -140,7 +140,7 @@ public abstract class TargetImpl implements Target { break; } } - return true; + return chosen = true; } diff --git a/Mage/src/mage/target/TargetPermanent.java b/Mage/src/mage/target/TargetPermanent.java index c49c02fbf0..691a4b5521 100644 --- a/Mage/src/mage/target/TargetPermanent.java +++ b/Mage/src/mage/target/TargetPermanent.java @@ -85,6 +85,10 @@ public class TargetPermanent extends TargetObject { return false; } + public void setTargetController(TargetController controller) { + this.controller = controller; + } + protected void setController(UUID controllerId, Game game) { filter.getControllerId().clear(); switch (controller) { diff --git a/Mage/src/mage/util/Copier.java b/Mage/src/mage/util/Copier.java index 524ef3451c..6b023ec7b2 100644 --- a/Mage/src/mage/util/Copier.java +++ b/Mage/src/mage/util/Copier.java @@ -32,7 +32,6 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -import java.net.URLClassLoader; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; @@ -97,7 +96,7 @@ public class Copier { public T uncompressCopy(byte[] buffer) { T copy = null; try { - ObjectInputStream in = new ObjectInputStream(new GZIPInputStream(new ByteArrayInputStream(buffer))); + ObjectInputStream in = new CopierObjectInputStream(loader, new GZIPInputStream(new ByteArrayInputStream(buffer))); copy = (T) in.readObject(); } catch(IOException e) { diff --git a/Mage/src/mage/util/Logging.java b/Mage/src/mage/util/Logging.java index 0fe7860a96..d2b645d4f7 100644 --- a/Mage/src/mage/util/Logging.java +++ b/Mage/src/mage/util/Logging.java @@ -36,6 +36,7 @@ import java.util.Date; import java.util.logging.ConsoleHandler; import java.util.logging.Formatter; import java.util.logging.Handler; +import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.Logger; @@ -54,6 +55,14 @@ public class Logging { return logger; } + public static Level getLevel(Logger logger) { + Level level = logger.getLevel(); + while (level == null && logger.getParent() != null) { + logger = logger.getParent(); + level = logger.getLevel(); + } + return level; + } } class LogFormatter extends Formatter { diff --git a/Mage/src/mage/watchers/Watchers.java b/Mage/src/mage/watchers/Watchers.java index 83a8730e3c..eb132c7581 100644 --- a/Mage/src/mage/watchers/Watchers.java +++ b/Mage/src/mage/watchers/Watchers.java @@ -29,6 +29,7 @@ package mage.watchers; import java.util.ArrayList; +import java.util.UUID; import mage.game.Game; import mage.game.events.GameEvent; @@ -50,9 +51,9 @@ public class Watchers extends ArrayList { } } - public Watcher get(String key) { + public Watcher get(UUID controllerId, String key) { for (Watcher watcher: this) { - if (watcher.getKey().equals(key)) + if (watcher.getControllerId().equals(controllerId) && watcher.getKey().equals(key)) return watcher; } return null;