Get rid of global static Card cache and hang it off the Game instead.

This paves the way for having multiple simulataneous game objects (e.g. for simulation).
This commit is contained in:
Myrd
2014-12-28 16:31:23 +00:00
parent 5fe82c5758
commit bf34aec4fc
17 changed files with 115 additions and 109 deletions

View File

@@ -171,7 +171,7 @@ public class AnimateAi extends SpellAbilityAi {
}
if (!SpellAbilityAi.isSorcerySpeed(sa)) {
Card animatedCopy = CardFactory.getCard(c.getPaperCard(), aiPlayer);
Card animatedCopy = CardFactory.getCard(c.getPaperCard(), aiPlayer, c.getGame());
AnimateAi.becomeAnimated(animatedCopy, c.hasSickness(), sa);
if (ph.isPlayerTurn(aiPlayer) && !ComputerUtilCard.doesSpecifiedCreatureAttackAI(aiPlayer, animatedCopy)) {
return false;

View File

@@ -42,6 +42,7 @@ import forge.game.card.CardCollection;
import forge.game.card.CardCollectionView;
import forge.game.card.CardLists;
import forge.game.card.CardPredicates;
import forge.game.card.CardView;
import forge.game.combat.Combat;
import forge.game.event.GameEvent;
import forge.game.event.GameEventGameOutcome;
@@ -110,9 +111,20 @@ public class Game {
playerCache.put(id, player);
}
public Game(List<RegisteredPlayer> players0, GameRules rules0, Match match0) { /* no more zones to map here */
Card.clearCache();
public GameEntityCache<Card, CardView> cardCache = new GameEntityCache<>();
public Card getCard(CardView cardView) {
return cardCache.get(cardView);
}
public void addCard(Integer id, Card card) {
cardCache.put(id, card);
}
public CardCollection getCardList(Iterable<CardView> cardViews) {
CardCollection list = new CardCollection();
cardCache.addToList(cardViews, list);
return list;
}
public Game(List<RegisteredPlayer> players0, GameRules rules0, Match match0) { /* no more zones to map here */
rules = rules0;
match = match0;
@@ -127,7 +139,7 @@ public class Game {
int plId = 0;
for (RegisteredPlayer psc : players0) {
IGameEntitiesFactory factory = (IGameEntitiesFactory)psc.getPlayer();
IGameEntitiesFactory factory = (IGameEntitiesFactory)psc.getPlayer();
Player pl = factory.createIngamePlayer(this, plId++);
allPlayers.add(pl);
ingamePlayers.add(pl);

View File

@@ -97,13 +97,13 @@ public class ChooseSourceEffect extends SpellAbilityEffect {
commandZoneSources = CardLists.filterControlledBy(commandZoneSources, tgtPlayers.get(0));
}
Card divPermanentSources = new Card(-1);
Card divPermanentSources = new Card(-1, game);
divPermanentSources.setName("--PERMANENTS:--");
Card divStackSources = new Card(-2);
Card divStackSources = new Card(-2, game);
divStackSources.setName("--SPELLS ON THE STACK:--");
Card divReferencedSources = new Card(-3);
Card divReferencedSources = new Card(-3, game);
divReferencedSources.setName("--OBJECTS REFERRED TO ON THE STACK:--");
Card divCommandZoneSources = new Card(-4);
Card divCommandZoneSources = new Card(-4, game);
divCommandZoneSources.setName("--CARDS IN THE COMMAND ZONE:--");
if (permanentSources.size() > 0) {

View File

@@ -27,13 +27,12 @@ public class DamageDealEffect extends SpellAbilityEffect {
final String damage = sa.getParam("NumDmg");
final int dmg = AbilityUtils.calculateAmount(sa.getHostCard(), damage, sa);
List<GameObject> tgts = getTargets(sa);
if (tgts.isEmpty())
return "";
final List<Card> definedSources = AbilityUtils.getDefinedCards(sa.getHostCard(), sa.getParam("DamageSource"), sa);
Card source = definedSources.isEmpty() ? new Card(-1) : definedSources.get(0);
Card source = definedSources.isEmpty() ? new Card(-1, sa.getHostCard().getGame()) : definedSources.get(0);
if (source != sa.getHostCard()) {
sb.append(source.toString()).append(" deals");

View File

@@ -8,7 +8,7 @@ public class DetachedCardEffect extends Card {
private Card card; //card linked to effect
public DetachedCardEffect(Card card0, String name0) {
super(card0.getOwner().getGame().nextCardId(), card0.getPaperCard());
super(card0.getOwner().getGame().nextCardId(), card0.getPaperCard(), card0.getOwner().getGame());
card = card0;
setName(name0);

View File

@@ -106,7 +106,7 @@ public class EffectEffect extends SpellAbilityEffect {
}
final Player controller = sa.hasParam("EffectOwner") ? ownerEff : sa.getActivatingPlayer();
final Card eff = new Card(controller.getGame().nextCardId());
final Card eff = new Card(game.nextCardId(), game);
eff.setName(name);
eff.addType("Effect"); // Or Emblem
eff.setToken(true); // Set token to true, so when leaving play it gets nuked

View File

@@ -65,13 +65,13 @@ public class PlayLandVariantEffect extends SpellAbilityEffect {
cards = Lists.newArrayList(Iterables.filter(cards, cp));
// get a random basic land
PaperCard ran = Aggregates.random(cards);
Card random = CardFactory.getCard(ran, activator);
Card random = CardFactory.getCard(ran, activator, source.getGame());
// if activator cannot play the random land, loop
while (!activator.canPlayLand(random, false) && !cards.isEmpty()) {
cards.remove(ran);
if (cards.isEmpty()) return;
ran = Aggregates.random(cards);
random = CardFactory.getCard(ran, activator);
random = CardFactory.getCard(ran, activator, game);
}
String imageFileName = game.getRules().canCloneUseTargetsImage ? source.getImageKey() : random.getImageKey();

View File

@@ -90,25 +90,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
* @version $Id$
*/
public class Card extends GameEntity implements Comparable<Card> {
private static HashMap<Integer, Card> cardCache = new HashMap<Integer, Card>();
public static Card get(CardView cardView) {
if (cardView == null) { return null; }
return cardCache.get(cardView.getId());
}
public static CardCollection getList(Iterable<CardView> cardViews) {
CardCollection list = new CardCollection();
for (CardView cv : cardViews) {
Card c = get(cv);
if (c != null) {
list.add(c);
}
}
return list;
}
public static void clearCache() {
cardCache.clear();
}
private final Game game;
private final IPaperCard paperCard;
private final Map<CardStateName, CardState> states = new EnumMap<CardStateName, CardState>(CardStateName.class);
@@ -264,8 +246,8 @@ public class Card extends GameEntity implements Comparable<Card> {
* Instantiates a new card not associated to any paper card.
* @param id the unique id of the new card.
*/
public Card(final int id0) {
this(id0, null, true);
public Card(final int id0, final Game game0) {
this(id0, null, true, game0);
}
/**
@@ -276,18 +258,19 @@ public class Card extends GameEntity implements Comparable<Card> {
* card.
* @see IPaperCard
*/
public Card(final int id0, final IPaperCard paperCard0) {
this(id0, paperCard0, true);
public Card(final int id0, final IPaperCard paperCard0, final Game game0) {
this(id0, paperCard0, true, game0);
}
public Card(final int id0, final IPaperCard paperCard0, final boolean allowCache) {
public Card(final int id0, final IPaperCard paperCard0, final boolean allowCache, final Game game0) {
super(id0);
if (id0 >= 0 && allowCache) {
cardCache.put(id0, this);
game = game0;
if (id0 >= 0 && allowCache && game != null) {
game.addCard(id0, this);
}
paperCard = paperCard0;
view = new CardView(id0);
currentState = new CardState(view.getCurrentState());
currentState = new CardState(view.getCurrentState(), this);
states.put(CardStateName.Original, currentState);
states.put(CardStateName.FaceDown, CardUtil.getFaceDownCharacteristic(this));
view.updateChangedColorWords(this);
@@ -399,7 +382,7 @@ public class Card extends GameEntity implements Comparable<Card> {
}
public final void addAlternateState(final CardStateName state, final boolean updateView) {
states.put(state, new CardState(view.createAlternateState(state)));
states.put(state, new CardState(view.createAlternateState(state), this));
if (updateView) {
view.updateState(this);
}
@@ -2103,6 +2086,10 @@ public class Card extends GameEntity implements Comparable<Card> {
}
public final void setOwner(final Player owner0) {
if (owner == owner0) { return; }
if (owner != null && owner.getGame() != this.getGame()) {
// Sanity check.
throw new RuntimeException();
}
owner = owner0;
view.updateOwner(this);
view.updateController(this);
@@ -6258,20 +6245,9 @@ public class Card extends GameEntity implements Comparable<Card> {
public Iterable<OptionalCost> getOptionalCostsPaid() { return costsPaid; }
public boolean isOptionalCostPaid(OptionalCost cost) { return costsPaid.contains(cost); }
/**
* Fetch GameState for this card from references to players who may own or control this card.
*/
@Override
public Game getGame() {
Player controller = getController();
if (controller != null) {
return controller.getGame();
}
Player owner = getOwner();
if (owner != null) {
return owner.getGame();
}
return null;
return game;
}
public List<SpellAbility> getAllPossibleAbilities(final Player player, final boolean removeUnplayable) {
@@ -6308,7 +6284,7 @@ public class Card extends GameEntity implements Comparable<Card> {
}
public static Card fromPaperCard(IPaperCard pc, Player owner) {
return CardFactory.getCard(pc, owner);
return CardFactory.getCard(pc, owner, owner == null ? null : owner.getGame());
}
private static final Map<PaperCard, Card> cp2card = new HashMap<PaperCard, Card>();

View File

@@ -24,6 +24,7 @@ import forge.card.CardSplitType;
import forge.card.CardType;
import forge.card.ICardFace;
import forge.card.mana.ManaCost;
import forge.game.Game;
import forge.game.ability.AbilityFactory;
import forge.game.ability.AbilityUtils;
import forge.game.ability.ApiType;
@@ -75,10 +76,11 @@ public class CardFactory {
public final static Card copyCard(final Card in, boolean assignNewId) {
Card out;
if (!(in.isToken() || in.getCopiedPermanent() != null)) {
out = assignNewId ? getCard(in.getPaperCard(), in.getOwner())
: getCard(in.getPaperCard(), in.getOwner(), in.getId());
out = assignNewId ? getCard(in.getPaperCard(), in.getOwner(), in.getGame())
: getCard(in.getPaperCard(), in.getOwner(), in.getId(), in.getGame());
} else { // token
out = assignNewId ? new Card(in.getGame().nextCardId(), in.getPaperCard()) : new Card(in.getId(), in.getPaperCard());
int id = assignNewId ? in.getGame().nextCardId() : in.getId();
out = new Card(id, in.getPaperCard(), in.getGame());
out = CardFactory.copyStats(in, in.getController());
out.setToken(true);
@@ -89,7 +91,7 @@ public class CardFactory {
}
for (final CardStateName state : in.getStates()) {
CardFactory.copyState(in, state, out, state);
CardFactory.copyState(in, state, out, state);
}
out.setState(in.getCurrentStateName(), true);
@@ -210,13 +212,13 @@ public class CardFactory {
return copySA;
}
public final static Card getCard(final IPaperCard cp, final Player owner) {
return getCard(cp, owner, owner == null ? -1 : owner.getGame().nextCardId());
public final static Card getCard(final IPaperCard cp, final Player owner, final Game game) {
return getCard(cp, owner, owner == null ? -1 : owner.getGame().nextCardId(), game);
}
public final static Card getCard(final IPaperCard cp, final Player owner, final int cardId) {
public final static Card getCard(final IPaperCard cp, final Player owner, final int cardId, final Game game) {
//System.out.println(cardName);
CardRules cardRules = cp.getRules();
final Card c = readCard(cardRules, cp, cardId);
final Card c = readCard(cardRules, cp, cardId, game);
c.setRules(cardRules);
c.setOwner(owner);
buildAbilities(c);
@@ -341,8 +343,8 @@ public class CardFactory {
card.setSVar("DamagePWY", "Count$YourLifeTotal");
}
private static Card readCard(final CardRules rules, final IPaperCard paperCard, int cardId) {
final Card card = new Card(cardId, paperCard);
private static Card readCard(final CardRules rules, final IPaperCard paperCard, int cardId, Game game) {
final Card card = new Card(cardId, paperCard, game);
// 1. The states we may have:
CardSplitType st = rules.getSplitType();
@@ -428,7 +430,7 @@ public class CardFactory {
*/
public static Card copyCopiableCharacteristics(final Card from, final Player newOwner) {
int id = newOwner == null ? 0 : newOwner.getGame().nextCardId();
final Card c = new Card(id, from.getPaperCard());
final Card c = new Card(id, from.getPaperCard(), from.getGame());
c.setOwner(newOwner);
c.setSetCode(from.getSetCode());
@@ -511,7 +513,7 @@ public class CardFactory {
*/
public static Card copyStats(final Card in, final Player newOwner) {
int id = newOwner == null ? 0 : newOwner.getGame().nextCardId();
final Card c = new Card(id, in.getPaperCard());
final Card c = new Card(id, in.getPaperCard(), in.getGame());
c.setOwner(newOwner);
c.setSetCode(in.getSetCode());
@@ -607,7 +609,7 @@ public class CardFactory {
final String manaCost, final String[] types, final int basePower, final int baseToughness,
final String[] intrinsicKeywords) {
final List<Card> list = new ArrayList<Card>();
final Card c = new Card(controller.getGame().nextCardId());
final Card c = new Card(controller.getGame().nextCardId(), controller.getGame());
c.setName(name);
c.setImageKey(ImageKeys.getTokenKey(imageName));

View File

@@ -64,9 +64,11 @@ public class CardState {
private String setCode = CardEdition.UNKNOWN.getCode();
private final CardStateView view;
private final Card card;
public CardState(CardStateView view0) {
public CardState(CardStateView view0, Card card0) {
view = view0;
card = card0;
view.updateRarity(this);
view.updateSetCode(this);
}
@@ -75,6 +77,10 @@ public class CardState {
return view;
}
public Card getCard() {
return card;
}
public final String getName() {
return name;
}

View File

@@ -213,7 +213,7 @@ public final class CardUtil {
* @return a copy of C with LastKnownInfo stuff retained.
*/
public static Card getLKICopy(final Card in) {
final Card newCopy = new Card(in.getId(), in.getPaperCard(), false);
final Card newCopy = new Card(in.getId(), in.getPaperCard(), false, in.getGame());
newCopy.setSetCode(in.getSetCode());
newCopy.setOwner(in.getOwner());
newCopy.setController(in.getController(), 0);
@@ -285,7 +285,7 @@ public final class CardUtil {
final CardType type = new CardType();
type.add("Creature");
final CardState ret = new CardState(c.getView().createAlternateState(CardStateName.FaceDown));
final CardState ret = new CardState(c.getView().createAlternateState(CardStateName.FaceDown), c);
ret.setBasePower(2);
ret.setBaseToughness(2);

View File

@@ -752,7 +752,7 @@ public class CardView extends GameEntityView {
setName(c.getName());
if (CardView.this.getCurrentState() == this) {
Card card = Card.get(CardView.this);
Card card = c.getCard();
if (card != null) {
CardView.this.updateName(card);
}
@@ -794,7 +794,7 @@ public class CardView extends GameEntityView {
void updateType(CardState c) {
CardTypeView type = c.getType();
if (CardView.this.getCurrentState() == this) {
Card card = Card.get(CardView.this);
Card card = c.getCard();
if (card != null) {
type = type.getTypeWithChanges(card.getChangedCardTypes()); //TODO: find a better way to do this
updateRulesText(card.getRules(), type);
@@ -842,7 +842,7 @@ public class CardView extends GameEntityView {
}
}
void updatePower(CardState c) {
Card card = Card.get(CardView.this);
Card card = c.getCard();
if (card != null) {
updatePower(card); //TODO: find a better way to do this
return;
@@ -862,7 +862,7 @@ public class CardView extends GameEntityView {
}
}
void updateToughness(CardState c) {
Card card = Card.get(CardView.this);
Card card = c.getCard();
if (card != null) {
updateToughness(card); //TODO: find a better way to do this
return;
@@ -878,7 +878,7 @@ public class CardView extends GameEntityView {
}
void updateLoyalty(CardState c) {
if (CardView.this.getCurrentState() == this) {
Card card = Card.get(CardView.this);
Card card = c.getCard();
if (card != null) {
updateLoyalty(card); //TODO: find a better way to do this
return;

View File

@@ -234,15 +234,15 @@ public class RunTest {
* false);
*/
c = new Card(1);
Card c2 = new Card(2);
c = new Card(1, null);
Card c2 = new Card(2, null);
c.addIntrinsicKeyword("Flying");
c2.addIntrinsicKeyword("Flying");
// check("107", CombatUtil.canBlock(c, c2));
// check("108", CombatUtil.canBlock(c2, c));
c = new Card(1);
c2 = new Card(2);
c = new Card(1, null);
c2 = new Card(2, null);
c2.addIntrinsicKeyword("Flying");
this.check("109", CombatUtil.canBlock(c, c2));
this.check("110", !CombatUtil.canBlock(c2, c));

View File

@@ -107,10 +107,14 @@ public class InputProxy implements Observer {
}
}
private Card getCard(final CardView cardView) {
return controller.getGame().getCard(cardView);
}
public final String getActivateAction(final CardView cardView) {
final Input inp = getInput();
if (inp != null) {
final Card card = Card.get(cardView);
final Card card = getCard(cardView);
if (card != null) {
return inp.getActivateAction(card);
}
@@ -120,13 +124,14 @@ public class InputProxy implements Observer {
public final boolean selectCard(final CardView cardView, final List<CardView> otherCardViewsToSelect, final ITriggerEvent triggerEvent) {
final Input inp = getInput();
System.out.println("Selectcard " +cardView + " input: " +inp);
if (inp != null) {
final Card card = Card.get(cardView);
final Card card = getCard(cardView);
if (card != null) {
List<Card> otherCardsToSelect = null;
if (otherCardViewsToSelect != null) {
for (CardView cv : otherCardViewsToSelect) {
final Card c = Card.get(cv);
final Card c = getCard(cv);
if (c != null) {
if (otherCardsToSelect == null) {
otherCardsToSelect = new ArrayList<Card>();

View File

@@ -297,7 +297,8 @@ public class HumanCostDecision extends CostDecisionMakerBase {
if (nNeeded == 0) {
return PaymentDecision.number(0);
}
final Player p = controller.getGame().getPlayer(SGuiChoose.oneOrNone(String.format("Exile from whose %s?", cost.getFrom()), PlayerView.getCollection(payableZone)));
final Game game = controller.getGame();
final Player p = game.getPlayer(SGuiChoose.oneOrNone(String.format("Exile from whose %s?", cost.getFrom()), PlayerView.getCollection(payableZone)));
if (p == null) {
return null;
}
@@ -308,7 +309,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
return null;
}
CardCollection toExile = Card.getList(SGuiChoose.many("Exile from " + cost.getFrom(), "To be exiled", nNeeded, CardView.getCollection(typeList), null));
CardCollection toExile = game.getCardList(SGuiChoose.many("Exile from " + cost.getFrom(), "To be exiled", nNeeded, CardView.getCollection(typeList), null));
return PaymentDecision.card(toExile);
}
@@ -382,13 +383,17 @@ public class HumanCostDecision extends CostDecisionMakerBase {
}
return PaymentDecision.card(list);
}
private Card getCard(CardView cardView) {
return controller.getGame().getCard(cardView);
}
private PaymentDecision exileFromMiscZone(CostExile cost, SpellAbility sa, int nNeeded, CardCollection typeList) {
if (typeList.size() < nNeeded) { return null; }
CardCollection exiled = new CardCollection();
for (int i = 0; i < nNeeded; i++) {
final Card c = Card.get(SGuiChoose.oneOrNone("Exile from " + cost.getFrom(), CardView.getCollection(typeList)));
final Card c = getCard(SGuiChoose.oneOrNone("Exile from " + cost.getFrom(), CardView.getCollection(typeList)));
if (c == null) { return null; }
typeList.remove(c);
@@ -417,7 +422,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
if (list.size() < c) {
return null;
}
final CardCollection choice = Card.getList(SGuiChoose.many("Choose an exiled card to put into graveyard", "To graveyard", c, CardView.getCollection(list), CardView.get(source)));
final CardCollection choice = controller.getGame().getCardList(SGuiChoose.many("Choose an exiled card to put into graveyard", "To graveyard", c, CardView.getCollection(list), CardView.get(source)));
return PaymentDecision.card(choice);
}
@@ -599,7 +604,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
CardCollection chosen = new CardCollection();
for (int i = 0; i < nNeeded; i++) {
final Card c = Card.get(SGuiChoose.oneOrNone("Put from " + fromZone + " to library", CardView.getCollection(typeList)));
final Card c = getCard(SGuiChoose.oneOrNone("Put from " + fromZone + " to library", CardView.getCollection(typeList)));
if (c == null) {
return null;
}
@@ -626,7 +631,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
CardCollection chosen = new CardCollection();
for (int i = 0; i < nNeeded; i++) {
final Card c = Card.get(SGuiChoose.oneOrNone("Put cards from " + fromZone + " to Library", CardView.getCollection(typeList)));
final Card c = getCard(SGuiChoose.oneOrNone("Put cards from " + fromZone + " to Library", CardView.getCollection(typeList)));
if (c == null) {
return null;
}
@@ -954,7 +959,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
}
}
final Card card = Card.get(SGuiChoose.oneOrNone("Remove counter(s) from a card in " + cost.zone, suspended));
final Card card = getCard(SGuiChoose.oneOrNone("Remove counter(s) from a card in " + cost.zone, suspended));
return null == card ? null : PaymentDecision.card(card, c);
}

View File

@@ -490,7 +490,7 @@ public class HumanPlay {
}
// replace this with input
for (int i = 0; i < nNeeded; i++) {
final Card c = Card.get(SGuiChoose.oneOrNone("Exile from " + from, CardView.getCollection(list)));
final Card c = p.getGame().getCard(SGuiChoose.oneOrNone("Exile from " + from, CardView.getCollection(list)));
if (c == null) {
return false;
}
@@ -536,7 +536,7 @@ public class HumanPlay {
return false;
}
final Card c = Card.get(SGuiChoose.oneOrNone("Put cards to Library", CardView.getCollection(typeList)));
final Card c = p.getGame().getCard(SGuiChoose.oneOrNone("Put cards to Library", CardView.getCollection(typeList)));
if (c != null) {
typeList.remove(c);

View File

@@ -285,7 +285,7 @@ public class PlayerControllerHuman extends PlayerController {
final GameEntityView vDefender = GameEntityView.get(defender);
final Map<CardView, Integer> result = MatchUtil.getDamageToAssign(vAttacker, vBlockers, damageDealt, vDefender, overrideOrder);
for (final Entry<CardView, Integer> e : result.entrySet()) {
map.put(Card.get(e.getKey()), e.getValue());
map.put(game.getCard(e.getKey()), e.getValue());
}
}
else {
@@ -369,7 +369,7 @@ public class PlayerControllerHuman extends PlayerController {
}
tempShowCards(sourceList);
final CardCollection choices = Card.getList(SGuiChoose.many(title, "Chosen Cards", min, max, CardView.getCollection(sourceList), CardView.get(sa.getHostCard())));
final CardCollection choices = getGame().getCardList(SGuiChoose.many(title, "Chosen Cards", min, max, CardView.getCollection(sourceList), CardView.get(sa.getHostCard())));
endTempShowCards();
return choices;
@@ -420,7 +420,7 @@ public class PlayerControllerHuman extends PlayerController {
final GameEntityView result = GuiBase.getInterface().chooseSingleEntityForEffect(title, optionList, delayedReveal, isOptional, this);
endTempShowCards(); //assume tempShow called by GuiBase.getInterface().chooseSingleEntityForEffect
if (result instanceof CardView) {
return (T) Card.get((CardView)result);
return (T) game.getCard((CardView)result);
}
if (result instanceof PlayerView) {
return (T) game.getPlayer((PlayerView)result);
@@ -536,21 +536,21 @@ public class PlayerControllerHuman extends PlayerController {
public CardCollection orderBlockers(final Card attacker, final CardCollection blockers) {
final CardView vAttacker = CardView.get(attacker);
MatchUtil.getController().setPanelSelection(vAttacker);
return Card.getList(SGuiChoose.order("Choose Damage Order for " + vAttacker, "Damaged First", CardView.getCollection(blockers), vAttacker));
return game.getCardList(SGuiChoose.order("Choose Damage Order for " + vAttacker, "Damaged First", CardView.getCollection(blockers), vAttacker));
}
@Override
public CardCollection orderBlocker(final Card attacker, final Card blocker, final CardCollection oldBlockers) {
final CardView vAttacker = CardView.get(attacker);
MatchUtil.getController().setPanelSelection(vAttacker);
return Card.getList(SGuiChoose.insertInList("Choose blocker after which to place " + vAttacker + " in damage order; cancel to place it first", CardView.get(blocker), CardView.getCollection(oldBlockers)));
return game.getCardList(SGuiChoose.insertInList("Choose blocker after which to place " + vAttacker + " in damage order; cancel to place it first", CardView.get(blocker), CardView.getCollection(oldBlockers)));
}
@Override
public CardCollection orderAttackers(final Card blocker, final CardCollection attackers) {
final CardView vBlocker = CardView.get(blocker);
MatchUtil.getController().setPanelSelection(vBlocker);
return Card.getList(SGuiChoose.order("Choose Damage Order for " + vBlocker, "Damaged First", CardView.getCollection(attackers), vBlocker));
return game.getCardList(SGuiChoose.order("Choose Damage Order for " + vBlocker, "Damaged First", CardView.getCollection(attackers), vBlocker));
}
@Override
@@ -588,7 +588,7 @@ public class PlayerControllerHuman extends PlayerController {
}
}
else {
toBottom = Card.getList(SGuiChoose.many("Select cards to be put on the bottom of your library", "Cards to put on the bottom", -1, CardView.getCollection(topN), null));
toBottom = game.getCardList(SGuiChoose.many("Select cards to be put on the bottom of your library", "Cards to put on the bottom", -1, CardView.getCollection(topN), null));
topN.removeAll((Collection<?>)toBottom);
if (topN.isEmpty()) {
toTop = null;
@@ -597,7 +597,7 @@ public class PlayerControllerHuman extends PlayerController {
toTop = topN;
}
else {
toTop = Card.getList(SGuiChoose.order("Arrange cards to be put on top of your library", "Top of Library", CardView.getCollection(topN), null));
toTop = game.getCardList(SGuiChoose.order("Arrange cards to be put on top of your library", "Top of Library", CardView.getCollection(topN), null));
}
}
endTempShowCards();
@@ -639,14 +639,14 @@ public class PlayerControllerHuman extends PlayerController {
return cards;
}
endTempShowCards();
return Card.getList(choices);
return game.getCardList(choices);
}
@Override
public CardCollectionView chooseCardsToDiscardFrom(Player p, SpellAbility sa, CardCollection valid, int min, int max) {
if (p != player) {
tempShowCards(valid);
final CardCollection choices = Card.getList(SGuiChoose.many("Choose " + min + " card" + (min != 1 ? "s" : "") + " to discard",
final CardCollection choices = game.getCardList(SGuiChoose.many("Choose " + min + " card" + (min != 1 ? "s" : "") + " to discard",
"Discarded", min, min, CardView.getCollection(valid), null));
endTempShowCards();
return choices;
@@ -687,8 +687,9 @@ public class PlayerControllerHuman extends PlayerController {
break;
}
grave.remove(Card.get(nowChosen));
toExile.add(Card.get(nowChosen));
Card card = game.getCard(nowChosen);
grave.remove(card);
toExile.add(card);
}
return toExile;
}
@@ -941,7 +942,7 @@ public class PlayerControllerHuman extends PlayerController {
}
final List<CardView> chosen = SGuiChoose.many("Choose cards to activate from opening hand and their order", "Activate first", -1, CardView.getCollection(srcCards), null);
for (final CardView view : chosen) {
final Card c = Card.get(view);
final Card c = game.getCard(view);
for (SpellAbility sa : usableFromOpeningHand) {
if (sa.getHostCard() == c) {
result.add(sa);
@@ -1418,7 +1419,7 @@ public class PlayerControllerHuman extends PlayerController {
return;
}
final Card dummy = new Card(-777777);
final Card dummy = new Card(-777777, game);
dummy.setOwner(pPriority);
Map<String, String> produced = new HashMap<String, String>();
produced.put("Produced", "W W W W W W W U U U U U U U B B B B B B B G G G G G G G R R R R R R R 7");
@@ -1500,7 +1501,7 @@ public class PlayerControllerHuman extends PlayerController {
final CardCollection lib = (CardCollection)pPriority.getCardsIn(ZoneType.Library);
final List<ZoneType> origin = new ArrayList<ZoneType>();
origin.add(ZoneType.Library);
SpellAbility sa = new SpellAbility.EmptySa(new Card(-1));
SpellAbility sa = new SpellAbility.EmptySa(new Card(-1, game));
final Card card = chooseSingleCardForZoneChange(ZoneType.Hand, origin, sa, lib, null, "Choose a card", true, pPriority);
if (card == null) { return; }
@@ -1514,7 +1515,7 @@ public class PlayerControllerHuman extends PlayerController {
public void addCountersToPermanent() {
final CardCollectionView cards = game.getCardsIn(ZoneType.Battlefield);
final Card card = Card.get(SGuiChoose.oneOrNone("Add counters to which card?", CardView.getCollection(cards)));
final Card card = game.getCard(SGuiChoose.oneOrNone("Add counters to which card?", CardView.getCollection(cards)));
if (card == null) { return; }
final CounterType counter = SGuiChoose.oneOrNone("Which type of counter?", CounterType.values());