diff --git a/src/main/java/forge/ComputerAIGeneral.java b/src/main/java/forge/ComputerAIGeneral.java index 8e33fc72d4a..e959f7a9b4b 100644 --- a/src/main/java/forge/ComputerAIGeneral.java +++ b/src/main/java/forge/ComputerAIGeneral.java @@ -89,7 +89,7 @@ public class ComputerAIGeneral implements Computer { * a {@link java.lang.String} object. */ private void playCards(final String phase) { - final CardList list = phase.equals(Constant.Phase.MAIN1) ? this.getMain1() : this.getMain2(); + final CardList list = getAvailableSpellAbilities(); final boolean nextPhase = ComputerUtil.playSpellAbilities(getSpellAbilities(list)); @@ -98,105 +98,6 @@ public class ComputerAIGeneral implements Computer { } } // playCards() - /** - *

- * getMain1. - *

- * - * @return an array of {@link forge.card.spellability.SpellAbility} objects. - */ - private CardList getMain1() { - final Player computer = AllZone.getComputerPlayer(); - final Player human = AllZone.getHumanPlayer(); - // Card list of all cards to consider - CardList hand = computer.getCardsIn(Zone.Hand); - - final boolean hasACardGivingHaste = ComputerAIGeneral.hasACardGivingHaste(); - - // If mana pool is not empty try to play anything - if (computer.getManaPool().isEmpty()) { - hand = hand.filter(new CardListFilter() { - @Override - public boolean addCard(final Card c) { - - if (c.getSVar("PlayMain1").equals("TRUE")) { - return true; - } - - // timing should be handled by the AF's - if (c.isSorcery() || c.isAura()) { - return true; - } - - if ((c.isCreature() && (hasACardGivingHaste || c.hasKeyword("Haste"))) || c.hasKeyword("Exalted")) { - return true; - } - - // get all cards the computer controls with BuffedBy - final CardList buffed = computer.getCardsIn(Zone.Battlefield); - for (int j = 0; j < buffed.size(); j++) { - final Card buffedcard = buffed.get(j); - if (buffedcard.getSVar("BuffedBy").length() > 0) { - final String buffedby = buffedcard.getSVar("BuffedBy"); - final String[] bffdby = buffedby.split(","); - if (c.isValid(bffdby, c.getController(), c)) { - return true; - } - } - } // BuffedBy - - // get all cards the human controls with AntiBuffedBy - final CardList antibuffed = human.getCardsIn(Zone.Battlefield); - for (int k = 0; k < antibuffed.size(); k++) { - final Card buffedcard = antibuffed.get(k); - if (buffedcard.getSVar("AntiBuffedBy").length() > 0) { - final String buffedby = buffedcard.getSVar("AntiBuffedBy"); - final String[] bffdby = buffedby.split(","); - if (c.isValid(bffdby, c.getController(), c)) { - return true; - } - } - } // AntiBuffedBy - - if (c.isLand()) { - return false; - } - - final CardList vengevines = computer.getCardsIn(Zone.Graveyard, "Vengevine"); - if (vengevines.size() > 0) { - final CardList creatures = computer.getCardsIn(Zone.Hand); - final CardList creatures2 = new CardList(); - for (int i = 0; i < creatures.size(); i++) { - if (creatures.get(i).isCreature() - && (CardUtil.getConvertedManaCost(creatures.get(i).getManaCost()) <= 3)) { - creatures2.add(creatures.get(i)); - } - } - if (((creatures2.size() + CardUtil.getThisTurnCast("Creature.YouCtrl", vengevines.get(0)) - .size()) > 1) - && c.isCreature() - && (CardUtil.getConvertedManaCost(c.getManaCost()) <= 3)) { - return true; - } - } // AI Improvement for Vengevine - // Beached As End - return false; - } - }); - } - final CardList all = computer.getCardsIn(Zone.Battlefield); - all.addAll(computer.getCardsIn(Zone.Exile)); - all.addAll(computer.getCardsIn(Zone.Graveyard)); - if (!computer.getCardsIn(Zone.Library).isEmpty()) { - all.add(computer.getCardsIn(Zone.Library).get(0)); - } - all.addAll(human.getCardsIn(Zone.Battlefield)); - all.addAll(human.getCardsIn(Zone.Exile)); - all.addAll(hand); - - return all; - } // getMain1() - /** *

* hasACardGivingHaste. @@ -231,17 +132,6 @@ public class ComputerAIGeneral implements Computer { return false; } // hasACardGivingHaste - /** - *

- * getMain2. - *

- * - * @return an array of {@link forge.card.spellability.SpellAbility} objects. - */ - private CardList getMain2() { - return getAvailableSpellAbilities(); - } // getMain2() - /** *

* getAvailableSpellAbilities. diff --git a/src/main/java/forge/card/spellability/SpellPermanent.java b/src/main/java/forge/card/spellability/SpellPermanent.java index 74880e6af4f..2bb29747f35 100644 --- a/src/main/java/forge/card/spellability/SpellPermanent.java +++ b/src/main/java/forge/card/spellability/SpellPermanent.java @@ -25,6 +25,7 @@ import forge.AllZoneUtil; import forge.ButtonUtil; import forge.Card; import forge.CardList; +import forge.CardUtil; import forge.Command; import forge.CommandReturn; import forge.ComputerAIGeneral; @@ -275,6 +276,62 @@ public class SpellPermanent extends Spell { } card.setSVar("PayX", Integer.toString(xPay)); } + // Wait for Main2 if possible + if (AllZone.getPhaseHandler().is(Constant.Phase.MAIN1)) { + boolean wait = true; + if (card.getSVar("PlayMain1").equals("TRUE")) { + wait = false; + } + if ((card.isCreature() && (ComputerAIGeneral.hasACardGivingHaste() + || card.hasKeyword("Haste"))) || card.hasKeyword("Exalted")) { + wait = false; + } + // get all cards the computer controls with BuffedBy + final CardList buffed = AllZone.getComputerPlayer().getCardsIn(Zone.Battlefield); + for (int j = 0; j < buffed.size(); j++) { + final Card buffedcard = buffed.get(j); + if (buffedcard.getSVar("BuffedBy").length() > 0) { + final String buffedby = buffedcard.getSVar("BuffedBy"); + final String[] bffdby = buffedby.split(","); + if (card.isValid(bffdby, buffedcard.getController(), buffedcard)) { + wait = false; + } + } + } // BuffedBy + + // get all cards the human controls with AntiBuffedBy + final CardList antibuffed = AllZone.getHumanPlayer().getCardsIn(Zone.Battlefield); + for (int k = 0; k < antibuffed.size(); k++) { + final Card buffedcard = antibuffed.get(k); + if (buffedcard.getSVar("AntiBuffedBy").length() > 0) { + final String buffedby = buffedcard.getSVar("AntiBuffedBy"); + final String[] bffdby = buffedby.split(","); + if (card.isValid(bffdby, buffedcard.getController(), buffedcard)) { + wait = false; + } + } + } // AntiBuffedBy + final CardList vengevines = AllZone.getComputerPlayer().getCardsIn(Zone.Graveyard, "Vengevine"); + if (vengevines.size() > 0) { + final CardList creatures = AllZone.getComputerPlayer().getCardsIn(Zone.Hand); + final CardList creatures2 = new CardList(); + for (int i = 0; i < creatures.size(); i++) { + if (creatures.get(i).isCreature() + && (CardUtil.getConvertedManaCost(creatures.get(i).getManaCost()) <= 3)) { + creatures2.add(creatures.get(i)); + } + } + if (((creatures2.size() + CardUtil.getThisTurnCast("Creature.YouCtrl", vengevines.get(0)) + .size()) > 1) + && card.isCreature() + && (CardUtil.getConvertedManaCost(card.getManaCost()) <= 3)) { + wait = false; + } + } // AI Improvement for Vengevine Beached As End + if (wait) { + return false; + } + } // save cards with flash for surprise blocking if (card.hasKeyword("Flash") && !ComputerAIGeneral.hasETBTrigger(card)