From 7811880919abe0dbcf18fa2eedbd92912cae92c6 Mon Sep 17 00:00:00 2001 From: Maxmtg Date: Mon, 1 Apr 2013 18:02:48 +0000 Subject: [PATCH] Simplified and partially inlined chooseCardFromStack changed return type of zone.getPosition to unboxed int --- .../card/spellability/TargetSelection.java | 73 +++++-------------- src/main/java/forge/game/zone/IZone.java | 10 --- src/main/java/forge/game/zone/Zone.java | 14 +--- 3 files changed, 21 insertions(+), 76 deletions(-) diff --git a/src/main/java/forge/card/spellability/TargetSelection.java b/src/main/java/forge/card/spellability/TargetSelection.java index 29595cff2f2..36414ec9e29 100644 --- a/src/main/java/forge/card/spellability/TargetSelection.java +++ b/src/main/java/forge/card/spellability/TargetSelection.java @@ -344,68 +344,33 @@ public class TargetSelection { private final void chooseCardFromStack(final boolean mandatory) { final Target tgt = this.getTgt(); final String message = tgt.getVTSelection(); - final String doneDummy = "[FINISH TARGETING]"; - // Find what's targetable, then allow human to choose - final ArrayList choosables = getTargetableOnStack(); - - final HashMap map = new HashMap(); - - for (final SpellAbility sa : choosables) { - if (!tgt.getTargetSAs().contains(sa)) { - map.put(choosables.indexOf(sa) + ". " + sa.getStackDescription(), sa); - } - } - - if (tgt.isMinTargetsChosen(this.ability.getSourceCard(), this.ability)) { - map.put(doneDummy, null); - } - - - if (map.isEmpty()) { - setCancel(true); - } else { - final String madeChoice = GuiChoose.oneOrNone(message, map.keySet()); - if (madeChoice != null) { - if (madeChoice.equals(doneDummy)) { - bTargetingDone = true; - } else { - tgt.addTarget(map.get(madeChoice)); - } - } else { - setCancel(true); - } - } - } - - // TODO The following three functions are Utility functions for - // TargetOnStack, probably should be moved - // The following should be select.getTargetableOnStack() - /** - *

- * getTargetableOnStack. - *

- * - * @param sa - * a {@link forge.card.spellability.SpellAbility} object. - * @param tgt - * a {@link forge.card.spellability.Target} object. - * @return a {@link java.util.ArrayList} object. - */ - private ArrayList getTargetableOnStack() { - final ArrayList choosables = new ArrayList(); + final List selectOptions = new ArrayList(); final GameState game = ability.getActivatingPlayer().getGame(); for (int i = 0; i < game.getStack().size(); i++) { - choosables.add(game.getStack().peekAbility(i)); + SpellAbility stackItem = game.getStack().peekAbility(i); + if( ability.canTargetSpellAbility(stackItem)) + selectOptions.add(stackItem); + } + + if (tgt.isMinTargetsChosen(this.ability.getSourceCard(), this.ability)) { + selectOptions.add("[FINISH TARGETING]"); } - for (int i = 0; i < choosables.size(); i++) { - if (!ability.canTargetSpellAbility(choosables.get(i))) { - choosables.remove(i); + if (selectOptions.isEmpty()) { + setCancel(true); + } else { + final Object madeChoice = GuiChoose.oneOrNone(message, selectOptions); + if (madeChoice == null) { + setCancel(true); + return; } + if (madeChoice instanceof SpellAbility) { + tgt.addTarget(madeChoice); + } else // only 'FINISH TARGETING' remains + bTargetingDone = true; } - return choosables; } /** diff --git a/src/main/java/forge/game/zone/IZone.java b/src/main/java/forge/game/zone/IZone.java index 4f5252416fd..c537e03fa56 100644 --- a/src/main/java/forge/game/zone/IZone.java +++ b/src/main/java/forge/game/zone/IZone.java @@ -121,16 +121,6 @@ interface IZone { * @return true, if successful */ boolean contains(Card c); - - /** - * gets the positon of a specific card in this zone, null if it doesn't exist. - * - * @param c - * the card - * @return position - */ - Integer getPosition(Card c); - /** * isEmpty returns true if given zone contains no cards. * diff --git a/src/main/java/forge/game/zone/Zone.java b/src/main/java/forge/game/zone/Zone.java index 9e84ec4e44d..8f8d88b0735 100644 --- a/src/main/java/forge/game/zone/Zone.java +++ b/src/main/java/forge/game/zone/Zone.java @@ -171,18 +171,8 @@ public class Zone extends MyObservable implements IZone, Observer, java.io.Seria return this.cardList.contains(c); } - /* - * (non-Javadoc) - * - * @see forge.IPlayerZone#getPosition(forge.Card) - */ - @Override - public final Integer getPosition(final Card c) { - int index = this.cardList.indexOf(c); - if (index == -1) { - return null; - } - return index; + public final int getPosition(final Card c) { + return this.cardList.indexOf(c); } /**