diff --git a/src/main/java/forge/ComputerAIGeneral.java b/src/main/java/forge/ComputerAIGeneral.java index 6e49e1d5ce1..817e24762e3 100644 --- a/src/main/java/forge/ComputerAIGeneral.java +++ b/src/main/java/forge/ComputerAIGeneral.java @@ -75,7 +75,7 @@ public class ComputerAIGeneral implements Computer { * a {@link java.lang.String} object. */ private void playCards() { - final CardList list = getAvailableSpellAbilities(); + final CardList list = getAvailableCards(); final boolean nextPhase = ComputerUtil.playSpellAbilities(getSpellAbilities(list)); @@ -125,7 +125,7 @@ public class ComputerAIGeneral implements Computer { * * @return a {@link forge.CardList} object. */ - private CardList getAvailableSpellAbilities() { + private CardList getAvailableCards() { final Player computer = AllZone.getComputerPlayer(); final Player human = AllZone.getHumanPlayer(); CardList all = computer.getCardsIn(Zone.Hand); @@ -351,7 +351,7 @@ public class ComputerAIGeneral implements Computer { */ public final void stackResponse() { // if top of stack is empty - final CardList cards = getAvailableSpellAbilities(); + final CardList cards = getAvailableCards(); if (AllZone.getStack().size() == 0) { final ArrayList sas = this.getSpellAbilities(cards); boolean pass = (sas.size() == 0) diff --git a/src/main/java/forge/ComputerUtil.java b/src/main/java/forge/ComputerUtil.java index 27d93491d4e..655ceaba833 100644 --- a/src/main/java/forge/ComputerUtil.java +++ b/src/main/java/forge/ComputerUtil.java @@ -63,64 +63,21 @@ public class ComputerUtil { public static boolean playSpellAbilities(final SpellAbility[] all) { // not sure "playing biggest spell" matters? ComputerUtil.sortSpellAbilityByCost(all); - - for (final SpellAbility sa : all) { + final ArrayList abilities = new ArrayList(); + for (SpellAbility sa : all) { + //add alternative costs as additional spell abilities + abilities.addAll(GameAction.getAlternativeCosts(sa)); + abilities.add(sa); + } + for (final SpellAbility sa : abilities) { // Don't add Counterspells to the "normal" playcard lookups final AbilityFactory af = sa.getAbilityFactory(); if ((af != null) && af.getAPI().equals("Counter")) { continue; } sa.setActivatingPlayer(AllZone.getComputerPlayer()); - final Card source = sa.getSourceCard(); - boolean flashb = false; - - if (source.hasStartOfKeyword("May be played without paying its mana cost")) { - final SpellAbility newSA = sa.copy(); - final Cost cost = sa.getPayCosts(); - for (final CostPart part : cost.getCostParts()) { - if (part instanceof CostMana) { - ((CostMana) part).setMana("0"); - } - } - cost.setNoManaCostChange(true); - newSA.setManaCost("0"); - final StringBuilder sb = new StringBuilder(); - sb.append(sa.getDescription()).append(" (without paying its mana cost)"); - newSA.setDescription(sb.toString()); - if (ComputerUtil.canBePlayedAndPayedByAI(newSA)) { - ComputerUtil.handlePlayingSpellAbility(newSA); - - return false; - } - } - - // Flashback - if (source.isInZone(Constant.Zone.Graveyard) && sa.isSpell() && (source.isInstant() || source.isSorcery())) { - for (final String keyword : source.getKeyword()) { - if (keyword.startsWith("Flashback")) { - final SpellAbility flashback = sa.copy(); - flashback.setActivatingPlayer(AllZone.getComputerPlayer()); - flashback.setFlashBackAbility(true); - if (!keyword.equals("Flashback")) { // there is a - // flashback cost - // (and not the - // cards - // cost) - final Cost fbCost = new Cost(keyword.substring(10), source.getName(), false); - flashback.setPayCosts(fbCost); - } - if (ComputerUtil.canBePlayedAndPayedByAI(flashback)) { - ComputerUtil.handlePlayingSpellAbility(flashback); - - return false; - } - flashb = true; - } - } - } - - if ((!flashb || source.hasStartOfKeyword("May be played")) && ComputerUtil.canBePlayedAndPayedByAI(sa)) { + if (ComputerUtil.canBePlayedAndPayedByAI(sa)) { ComputerUtil.handlePlayingSpellAbility(sa); if (!(sa instanceof AbilityStatic)) { @@ -277,35 +234,17 @@ public class ComputerUtil { public static boolean playCounterSpell(final ArrayList possibleCounters) { SpellAbility bestSA = null; int bestRestriction = Integer.MIN_VALUE; - - for (final SpellAbility sa : possibleCounters) { + final ArrayList abilities = new ArrayList(); + for (SpellAbility sa : possibleCounters) { + //add alternative costs as additional spell abilities + abilities.addAll(GameAction.getAlternativeCosts(sa)); + abilities.add(sa); + } + for (final SpellAbility sa : abilities) { SpellAbility currentSA = sa; sa.setActivatingPlayer(AllZone.getComputerPlayer()); - final Card source = sa.getSourceCard(); - - // Flashback - if (source.isInZone(Constant.Zone.Graveyard) && sa.isSpell() && (source.isInstant() || source.isSorcery())) { - for (final String keyword : source.getKeyword()) { - if (keyword.startsWith("Flashback")) { - final SpellAbility flashback = sa.copy(); - flashback.setActivatingPlayer(AllZone.getComputerPlayer()); - flashback.setFlashBackAbility(true); - if (!keyword.equals("Flashback")) { // there is a - // flashback cost - // (and not the - // cards - // cost) - final Cost fbCost = new Cost(keyword.substring(10), source.getName(), false); - flashback.setPayCosts(fbCost); - } - currentSA = flashback; - } - } - } - - if (ComputerUtil.canBePlayedAndPayedByAI(currentSA)) { // checks - // everything - // nescessary + // check everything necessary + if (ComputerUtil.canBePlayedAndPayedByAI(currentSA)) { if (bestSA == null) { bestSA = currentSA; bestRestriction = ComputerUtil.counterSpellRestriction(currentSA); diff --git a/src/main/java/forge/GameAction.java b/src/main/java/forge/GameAction.java index 4ba91722a35..9c0fb37f275 100644 --- a/src/main/java/forge/GameAction.java +++ b/src/main/java/forge/GameAction.java @@ -1339,7 +1339,7 @@ public class GameAction { * @return an ArrayList. * get alternative costs as additional spell abilities */ - public final ArrayList getAlternativeCosts(SpellAbility sa) { + public static final ArrayList getAlternativeCosts(SpellAbility sa) { ArrayList alternatives = new ArrayList(); Card source = sa.getSourceCard(); if (!sa.isBasicSpell()) { diff --git a/src/main/java/forge/card/spellability/SpellAbilityRestriction.java b/src/main/java/forge/card/spellability/SpellAbilityRestriction.java index 35111d67b48..3a18f4099f2 100644 --- a/src/main/java/forge/card/spellability/SpellAbilityRestriction.java +++ b/src/main/java/forge/card/spellability/SpellAbilityRestriction.java @@ -269,10 +269,6 @@ public class SpellAbilityRestriction extends SpellAbilityVariables { return false; } - if (!checkZoneRestrictions(c, sa)) { - return false; - } - Player activator = sa.getActivatingPlayer(); if (activator == null) { activator = c.getController(); @@ -292,6 +288,10 @@ public class SpellAbilityRestriction extends SpellAbilityVariables { return false; } + if (!checkZoneRestrictions(c, sa)) { + return false; + } + if ((this.getActivationLimit() != -1) && (this.getNumberTurnActivations() >= this.getActivationLimit())) { return false; }