diff --git a/src/main/java/forge/card/CardRules.java b/src/main/java/forge/card/CardRules.java
index 2eb63c92df0..093581f542c 100644
--- a/src/main/java/forge/card/CardRules.java
+++ b/src/main/java/forge/card/CardRules.java
@@ -23,7 +23,6 @@ import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
-import forge.CardColor;
import forge.card.mana.ManaCost;
/**
@@ -76,32 +75,28 @@ public final class CardRules implements ICardCharacteristics {
byte res = face.getManaCost() == null ? 0 : face.getManaCost().getColorProfile();
boolean isReminder = false;
boolean isSymbol = false;
- for(char c : face.getOracleText().toCharArray()) {
- switch(c)
- {
- case('('): isReminder = true; break;
- case(')'): isReminder = false; break;
- case('{'): isSymbol = true; break;
- case('}'): isSymbol = false; break;
- default:
+ String oracleText = face.getOracleText();
+ int len = oracleText.length();
+ for(int i = 0; i < len; i++) {
+ char c = oracleText.charAt(i); // This is to avoid needless allocations performed by toCharArray()
+ switch(c) {
+ case('('): isReminder = true; break;
+ case(')'): isReminder = false; break;
+ case('{'): isSymbol = true; break;
+ case('}'): isSymbol = false; break;
+ default:
if(isSymbol && !isReminder) {
- switch(c)
- {
- case('W'): res |= MagicColor.WHITE; break;
- case('U'): res |= MagicColor.BLUE; break;
- case('B'): res |= MagicColor.BLACK; break;
- case('R'): res |= MagicColor.RED; break;
- case('G'): res |= MagicColor.GREEN; break;
+ switch(c) {
+ case('W'): res |= MagicColor.WHITE; break;
+ case('U'): res |= MagicColor.BLUE; break;
+ case('B'): res |= MagicColor.BLACK; break;
+ case('R'): res |= MagicColor.RED; break;
+ case('G'): res |= MagicColor.GREEN; break;
}
}
- else
- {
- continue;
- }
break;
}
}
-
return res;
}
diff --git a/src/main/java/forge/card/spellability/SpellAbility.java b/src/main/java/forge/card/spellability/SpellAbility.java
index e8b29b17765..872e0de87ea 100644
--- a/src/main/java/forge/card/spellability/SpellAbility.java
+++ b/src/main/java/forge/card/spellability/SpellAbility.java
@@ -1687,16 +1687,15 @@ public abstract class SpellAbility implements ISpellAbility {
* the ability
* @return the unique targets
*/
- public final ArrayList
* @return
*/
- private final List chooseValidInput() {
+ private final List getValidCardsToTarget() {
final Target tgt = this.getTgt();
final GameState game = ability.getActivatingPlayer().getGame();
final List zone = tgt.getZone();
final boolean canTgtStack = zone.contains(ZoneType.Stack);
- List choices = CardLists.getTargetableCards(CardLists.getValidCards(game.getCardsIn(zone), tgt.getValidTgts(), this.ability.getActivatingPlayer(), this.ability.getSourceCard()), this.ability);
+ List validCards = CardLists.getValidCards(game.getCardsIn(zone), tgt.getValidTgts(), this.ability.getActivatingPlayer(), this.ability.getSourceCard());
+ List choices = CardLists.getTargetableCards(validCards, this.ability);
if (canTgtStack) {
// Since getTargetableCards doesn't have additional checks if one of the Zones is stack
// Remove the activating card from targeting itself if its on the Stack
@@ -186,11 +141,11 @@ public class TargetSelection {
choices.remove(tgt.getSourceCard());
}
}
- ArrayList objects = this.ability.getUniqueTargets();
+ List targetedObjects = this.ability.getUniqueTargets();
if (tgt.isUniqueTargets()) {
- for (final Object o : objects) {
- if ((o instanceof Card) && objects.contains(o)) {
+ for (final Object o : targetedObjects) {
+ if ((o instanceof Card) && targetedObjects.contains(o)) {
choices.remove(o);
}
}
@@ -205,9 +160,9 @@ public class TargetSelection {
}
// If all cards (including subability targets) must have the same controller
- if (tgt.isSameController() && !objects.isEmpty()) {
+ if (tgt.isSameController() && !targetedObjects.isEmpty()) {
final List list = new ArrayList();
- for (final Object o : objects) {
+ for (final Object o : targetedObjects) {
if (o instanceof Card) {
list.add((Card) o);
}
@@ -251,7 +206,7 @@ public class TargetSelection {
}
// If the cards must have a specific controller
if (tgt.getDefinedController() != null) {
- List pl = AbilityUtils.getDefinedPlayers(getCard(), tgt.getDefinedController(), this.ability);
+ List pl = AbilityUtils.getDefinedPlayers(ability.getSourceCard(), tgt.getDefinedController(), this.ability);
if (pl != null && !pl.isEmpty()) {
Player controller = pl.get(0);
choices = CardLists.filterControlledBy(choices, controller);
@@ -260,7 +215,7 @@ public class TargetSelection {
}
}
return choices;
- } // input_targetValid
+ }
/**
*
@@ -274,7 +229,7 @@ public class TargetSelection {
* @param mandatory
* a boolean.
*/
- private final void chooseCardFromList(final List choices, final boolean targeted, final boolean mandatory) {
+ private final boolean chooseCardFromList(final List choices, final boolean targeted, final boolean mandatory) {
// Send in a list of valid cards, and popup a choice box to target
final GameState game = ability.getActivatingPlayer().getGame();
@@ -321,16 +276,16 @@ public class TargetSelection {
final Object chosen = GuiChoose.oneOrNone(getTgt().getVTSelection(), choicesFiltered);
if (chosen == null) {
- this.setCancel(true);
- return;
+ return false;
}
if (msgDone.equals(chosen)) {
bTargetingDone = true;
- return;
+ return true;
}
if (chosen instanceof Card )
this.getTgt().addTarget(chosen);
+ return true;
}
/**
@@ -341,7 +296,7 @@ public class TargetSelection {
* @param mandatory
* a boolean.
*/
- private final void chooseCardFromStack(final boolean mandatory) {
+ private final boolean chooseCardFromStack(final boolean mandatory) {
final Target tgt = this.getTgt();
final String message = tgt.getVTSelection();
// Find what's targetable, then allow human to choose
@@ -359,18 +314,18 @@ public class TargetSelection {
}
if (selectOptions.isEmpty()) {
- setCancel(true);
+ return false;
} else {
final Object madeChoice = GuiChoose.oneOrNone(message, selectOptions);
if (madeChoice == null) {
- setCancel(true);
- return;
+ return false;
}
if (madeChoice instanceof SpellAbility) {
tgt.addTarget(madeChoice);
} else // only 'FINISH TARGETING' remains
bTargetingDone = true;
}
+ return true;
}
/**
diff --git a/src/main/java/forge/control/input/InputSelectTargets.java b/src/main/java/forge/control/input/InputSelectTargets.java
index 3d5462a7a0b..91e16e00d23 100644
--- a/src/main/java/forge/control/input/InputSelectTargets.java
+++ b/src/main/java/forge/control/input/InputSelectTargets.java
@@ -207,6 +207,6 @@ public final class InputSelectTargets extends InputSyncronizedBase {
}
boolean hasAllTargets() {
- return tgt.isMaxTargetsChosen(sa.getSourceCard(), sa);
+ return tgt.isMaxTargetsChosen(sa.getSourceCard(), sa) || tgt.getStillToDivide() == 0;
}
}
\ No newline at end of file