From 1340d2c1f7195264c311c5076d06250fb5b3c715 Mon Sep 17 00:00:00 2001 From: melvin Date: Thu, 31 Jul 2014 10:51:53 +0800 Subject: [PATCH] MagicDiscardEvent cannot discard the source --- src/magic/model/choice/MagicCardChoice.java | 2 ++ src/magic/model/choice/MagicRandomCardChoice.java | 1 + src/magic/model/event/MagicDiscardEvent.java | 4 +++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/magic/model/choice/MagicCardChoice.java b/src/magic/model/choice/MagicCardChoice.java index 3cbd4eb2ca..5485afff95 100644 --- a/src/magic/model/choice/MagicCardChoice.java +++ b/src/magic/model/choice/MagicCardChoice.java @@ -67,6 +67,7 @@ public class MagicCardChoice extends MagicChoice { final List options = new ArrayList(); final MagicCardList hand = new MagicCardList(player.getHand()); + hand.remove(source); Collections.sort(hand); final int actualAmount = Math.min(amount,hand.size()); if (actualAmount > 0) { @@ -86,6 +87,7 @@ public class MagicCardChoice extends MagicChoice { final MagicCardChoiceResult result=new MagicCardChoiceResult(); final Set validCards=new HashSet(player.getHand()); + validCards.remove(source); int actualAmount=Math.min(amount,validCards.size()); for (;actualAmount>0;actualAmount--) { final String message=result.size()>0?result.toString()+"|"+MESSAGE:MESSAGE; diff --git a/src/magic/model/choice/MagicRandomCardChoice.java b/src/magic/model/choice/MagicRandomCardChoice.java index 66c20e953a..e43bfa627f 100644 --- a/src/magic/model/choice/MagicRandomCardChoice.java +++ b/src/magic/model/choice/MagicRandomCardChoice.java @@ -22,6 +22,7 @@ public class MagicRandomCardChoice extends MagicChoice { private MagicCardChoiceResult discard(final MagicPlayer player, final MagicSource source) { final MagicCardChoiceResult result=new MagicCardChoiceResult(); final MagicCardList hand=new MagicCardList(player.getHand()); + hand.remove(source); hand.shuffle(); final int actualAmount=Math.min(hand.size(),amount); for (int i = 0; i < actualAmount; i++) { diff --git a/src/magic/model/event/MagicDiscardEvent.java b/src/magic/model/event/MagicDiscardEvent.java index a266ef29f7..40c5eb208c 100644 --- a/src/magic/model/event/MagicDiscardEvent.java +++ b/src/magic/model/event/MagicDiscardEvent.java @@ -55,8 +55,10 @@ public class MagicDiscardEvent extends MagicEvent { EVENT_ACTION, "PN " + genDescription(player,amount) ); + //check if source is in player's hand + final int minHandSize = player.getHand().contains(source) ? amount + 1 : amount; conds = new MagicCondition[]{ - MagicConditionFactory.HandAtLeast(amount) + MagicConditionFactory.HandAtLeast(minHandSize) }; }