Prevent crash when canceling prompt for card or player

This commit is contained in:
drdev
2014-10-13 23:13:13 +00:00
parent 1b70875b40
commit 8d71ae5cbf
3 changed files with 19 additions and 11 deletions

View File

@@ -92,12 +92,16 @@ import java.util.concurrent.CopyOnWriteArrayList;
public class Card extends GameEntity implements Comparable<Card>, IIdentifiable { public class Card extends GameEntity implements Comparable<Card>, IIdentifiable {
private static HashMap<Integer, Card> cardCache = new HashMap<Integer, Card>(); private static HashMap<Integer, Card> cardCache = new HashMap<Integer, Card>();
public static Card get(CardView cardView) { public static Card get(CardView cardView) {
if (cardView == null) { return null; }
return cardCache.get(cardView.getId()); return cardCache.get(cardView.getId());
} }
public static CardCollection getList(Iterable<CardView> cardViews) { public static CardCollection getList(Iterable<CardView> cardViews) {
CardCollection list = new CardCollection(); CardCollection list = new CardCollection();
for (CardView cv : cardViews) { for (CardView cv : cardViews) {
list.add(get(cv)); Card c = get(cv);
if (c != null) {
list.add(c);
}
} }
return list; return list;
} }

View File

@@ -399,17 +399,17 @@ public class CardFactory {
} }
private static void readCardFace(Card c, ICardFace face) { private static void readCardFace(Card c, ICardFace face) {
for(String a : face.getAbilities()) c.addIntrinsicAbility(a); for (String a : face.getAbilities()) c.addIntrinsicAbility(a);
for(String k : face.getKeywords()) c.addIntrinsicKeyword(k); for (String k : face.getKeywords()) c.addIntrinsicKeyword(k);
for(String r : face.getReplacements()) c.addReplacementEffect(ReplacementHandler.parseReplacement(r, c, true)); for (String r : face.getReplacements()) c.addReplacementEffect(ReplacementHandler.parseReplacement(r, c, true));
for(String s : face.getStaticAbilities()) c.addStaticAbilityString(s); for (String s : face.getStaticAbilities()) c.addStaticAbilityString(s);
for(String t : face.getTriggers()) c.addTrigger(TriggerHandler.parseTrigger(t, c, true)); for (String t : face.getTriggers()) c.addTrigger(TriggerHandler.parseTrigger(t, c, true));
for(Entry<String, String> v : face.getVariables()) c.setSVar(v.getKey(), v.getValue()); for (Entry<String, String> v : face.getVariables()) c.setSVar(v.getKey(), v.getValue());
c.setName(face.getName()); c.setName(face.getName());
c.setManaCost(face.getManaCost()); c.setManaCost(face.getManaCost());
c.setText(face.getNonAbilityText()); c.setText(face.getNonAbilityText());
if( face.getInitialLoyalty() > 0 ) c.setBaseLoyalty(face.getInitialLoyalty()); if (face.getInitialLoyalty() > 0) c.setBaseLoyalty(face.getInitialLoyalty());
c.getCurrentState().setOracleText(face.getOracleText().replace("\\n", "\r\n")); c.getCurrentState().setOracleText(face.getOracleText().replace("\\n", "\r\n"));
@@ -422,11 +422,11 @@ public class CardFactory {
ccc.add(col1); ccc.add(col1);
c.setColor(ccc); c.setColor(ccc);
if ( face.getIntPower() >= 0 ) { if (face.getIntPower() >= 0) {
c.setBasePower(face.getIntPower()); c.setBasePower(face.getIntPower());
c.setBasePowerString(face.getPower()); c.setBasePowerString(face.getPower());
} }
if ( face.getIntToughness() >= 0 ) { if (face.getIntToughness() >= 0) {
c.setBaseToughness(face.getIntToughness()); c.setBaseToughness(face.getIntToughness());
c.setBaseToughnessString(face.getToughness()); c.setBaseToughnessString(face.getToughness());
} }

View File

@@ -83,12 +83,16 @@ public class Player extends GameEntity implements Comparable<Player> {
private static HashMap<Integer, Player> playerCache = new HashMap<Integer, Player>(); private static HashMap<Integer, Player> playerCache = new HashMap<Integer, Player>();
public static Player get(PlayerView playerView) { public static Player get(PlayerView playerView) {
if (playerView == null) { return null; }
return playerCache.get(playerView.getId()); return playerCache.get(playerView.getId());
} }
public static List<Player> getList(Iterable<PlayerView> playerViews) { public static List<Player> getList(Iterable<PlayerView> playerViews) {
List<Player> list = new ArrayList<Player>(); List<Player> list = new ArrayList<Player>();
for (PlayerView pv : playerViews) { for (PlayerView pv : playerViews) {
list.add(get(pv)); Player p = get(pv);
if (p != null) {
list.add(p);
}
} }
return list; return list;
} }