Fix crash from bad cast

This commit is contained in:
drdev
2014-10-13 23:25:07 +00:00
parent 8d71ae5cbf
commit 76ad6691a9
2 changed files with 20 additions and 22 deletions

View File

@@ -2,7 +2,6 @@ package forge.game.cost;
import forge.game.card.Card; import forge.game.card.Card;
import forge.game.card.CardCollection; import forge.game.card.CardCollection;
import forge.game.card.CardCollectionView;
import forge.game.card.CounterType; import forge.game.card.CounterType;
import forge.game.mana.Mana; import forge.game.mana.Mana;
import forge.game.player.Player; import forge.game.player.Player;
@@ -26,7 +25,7 @@ public class PaymentDecision {
c = cnt; c = cnt;
} }
private PaymentDecision(CardCollectionView chosen, List<Mana> manaProduced, List<Player> players, private PaymentDecision(Iterable<Card> chosen, List<Mana> manaProduced, List<Player> players,
List<SpellAbility> sp) { List<SpellAbility> sp) {
if (chosen != null) { if (chosen != null) {
cards.addAll(chosen); cards.addAll(chosen);
@@ -61,11 +60,11 @@ public class PaymentDecision {
return new PaymentDecision(c); return new PaymentDecision(c);
} }
public static PaymentDecision card(CardCollectionView chosen) { public static PaymentDecision card(Iterable<Card> chosen) {
return new PaymentDecision(chosen, null, null, null); return new PaymentDecision(chosen, null, null, null);
} }
public static PaymentDecision card(CardCollectionView chosen, int n) { public static PaymentDecision card(Iterable<Card> chosen, int n) {
PaymentDecision res = new PaymentDecision(chosen, null, null, null); PaymentDecision res = new PaymentDecision(chosen, null, null, null);
res.c = n; res.c = n;
return res; return res;

View File

@@ -169,8 +169,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
if (inp.hasCancelled() || inp.getSelected().size() != c) { if (inp.hasCancelled() || inp.getSelected().size() != c) {
return null; return null;
} }
return PaymentDecision.card(inp.getSelected());
return PaymentDecision.card((CardCollection)inp.getSelected());
} }
@Override @Override
@@ -263,7 +262,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
inp.setMessage("Exile %d card(s) from your" + cost.from); inp.setMessage("Exile %d card(s) from your" + cost.from);
inp.setCancelAllowed(true); inp.setCancelAllowed(true);
inp.showAndWait(); inp.showAndWait();
return inp.hasCancelled() ? null : PaymentDecision.card(new CardCollection(inp.getSelected())); return inp.hasCancelled() ? null : PaymentDecision.card(inp.getSelected());
} }
if (cost.from == ZoneType.Library) { return exileFromTop(cost, ability, player, c); } if (cost.from == ZoneType.Library) { return exileFromTop(cost, ability, player, c); }
@@ -402,7 +401,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
if (typeList.size() < nNeeded) { return null; } if (typeList.size() < nNeeded) { return null; }
Collections.reverse(typeList); Collections.reverse(typeList);
return PaymentDecision.card(new CardCollection(Iterables.limit(typeList, nNeeded))); return PaymentDecision.card(Iterables.limit(typeList, nNeeded));
} }
@Override @Override
@@ -457,7 +456,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
if (inp.hasCancelled()) { if (inp.hasCancelled()) {
return null; return null;
} }
return PaymentDecision.card(new CardCollection(inp.getSelected())); return PaymentDecision.card(inp.getSelected());
} }
@Override @Override
@@ -573,7 +572,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
inp.setMessage("Put %d card(s) from your " + cost.from); inp.setMessage("Put %d card(s) from your " + cost.from);
inp.setCancelAllowed(true); inp.setCancelAllowed(true);
inp.showAndWait(); inp.showAndWait();
return inp.hasCancelled() ? null : PaymentDecision.card(new CardCollection(inp.getSelected())); return inp.hasCancelled() ? null : PaymentDecision.card(inp.getSelected());
} }
if (cost.sameZone){ if (cost.sameZone){
@@ -657,7 +656,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
if (inp.hasCancelled()) if (inp.hasCancelled())
return null; return null;
return PaymentDecision.card(new CardCollection(inp.getSelected())); return PaymentDecision.card(inp.getSelected());
} }
@Override @Override
@@ -691,7 +690,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
if (inp.hasCancelled()) { if (inp.hasCancelled()) {
return null; return null;
} }
return PaymentDecision.card(new CardCollection(inp.getSelected())); return PaymentDecision.card(inp.getSelected());
} }
return null; return null;
} }
@@ -761,10 +760,10 @@ public class HumanCostDecision extends CostDecisionMakerBase {
} }
inp.setCancelAllowed(true); inp.setCancelAllowed(true);
inp.showAndWait(); inp.showAndWait();
if (inp.hasCancelled()) if (inp.hasCancelled()) {
return null; return null;
}
return PaymentDecision.card(new CardCollection(inp.getSelected())); return PaymentDecision.card(inp.getSelected());
} }
@Override @Override
@@ -936,7 +935,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
int oldVal = crd.getCounters().get(cost.counter).intValue(); int oldVal = crd.getCounters().get(cost.counter).intValue();
crd.getCounters().put(cost.counter, Integer.valueOf(oldVal - removed + 1)); crd.getCounters().put(cost.counter, Integer.valueOf(oldVal - removed + 1));
} }
return PaymentDecision.card(new CardCollection(inp.getSelected()), 1); return PaymentDecision.card(inp.getSelected(), 1);
} }
// Rift Elemental only - always removes 1 counter, so there will be no code for N counters. // Rift Elemental only - always removes 1 counter, so there will be no code for N counters.
@@ -997,7 +996,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
if (inp.hasCancelled()) if (inp.hasCancelled())
return null; return null;
return PaymentDecision.card(new CardCollection(inp.getSelected())); return PaymentDecision.card(inp.getSelected());
} }
@@ -1086,9 +1085,8 @@ public class HumanCostDecision extends CostDecisionMakerBase {
if (inp.hasCancelled() || CardLists.getTotalPower(inp.getSelected()) < i) { if (inp.hasCancelled() || CardLists.getTotalPower(inp.getSelected()) < i) {
return null; return null;
} else {
return PaymentDecision.card(new CardCollection(inp.getSelected()));
} }
return PaymentDecision.card(inp.getSelected());
} }
InputSelectCardsFromList inp = new InputSelectCardsFromList(controller, c, c, typeList); InputSelectCardsFromList inp = new InputSelectCardsFromList(controller, c, c, typeList);
@@ -1097,7 +1095,7 @@ public class HumanCostDecision extends CostDecisionMakerBase {
if (inp.hasCancelled()) { if (inp.hasCancelled()) {
return null; return null;
} }
return PaymentDecision.card(new CardCollection(inp.getSelected())); return PaymentDecision.card(inp.getSelected());
} }
@Override @Override
@@ -1122,9 +1120,10 @@ public class HumanCostDecision extends CostDecisionMakerBase {
InputSelectCardsFromList inp = new InputSelectCardsFromList(controller, c, c, typeList); InputSelectCardsFromList inp = new InputSelectCardsFromList(controller, c, c, typeList);
inp.setMessage("Select a " + cost.getDescriptiveType() + " to untap (%d left)"); inp.setMessage("Select a " + cost.getDescriptiveType() + " to untap (%d left)");
inp.showAndWait(); inp.showAndWait();
if (inp.hasCancelled() || inp.getSelected().size() != c) if (inp.hasCancelled() || inp.getSelected().size() != c) {
return null; return null;
return PaymentDecision.card(new CardCollection(inp.getSelected())); }
return PaymentDecision.card(inp.getSelected());
} }
@Override @Override