From e519bbe0c49ccd1642bc19bac9753b2ca3d14324 Mon Sep 17 00:00:00 2001 From: Sloth Date: Thu, 23 Feb 2012 11:58:19 +0000 Subject: [PATCH] - Expanded isUsefulKeyword. --- src/main/java/forge/ComputerUtil.java | 43 ++++++++++++++----- .../abilityfactory/AbilityFactoryPump.java | 10 ----- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/main/java/forge/ComputerUtil.java b/src/main/java/forge/ComputerUtil.java index 68ab5085c79..7777493b557 100644 --- a/src/main/java/forge/ComputerUtil.java +++ b/src/main/java/forge/ComputerUtil.java @@ -1964,35 +1964,58 @@ public class ComputerUtil { * @return true, if is useful keyword */ public static boolean isUsefulKeyword(final String keyword, final Card card) { + PhaseHandler ph = AllZone.getPhaseHandler(); + Player computer = AllZone.getComputerPlayer(); + Player human = AllZone.getHumanPlayer(); + final boolean evasive = (keyword.endsWith("Flying") || keyword.endsWith("Horsemanship") + || keyword.endsWith("Unblockable") || keyword.endsWith("Fear") + || keyword.endsWith("Intimidate")); if (!CardUtil.isStackingKeyword(keyword) && card.hasKeyword(keyword)) { return false; } - if (keyword.equals("Defender") || keyword.endsWith("CARDNAME can't attack.")) { + // give evasive keywords to creatures that can attack + if (evasive) { + if (ph.isPlayerTurn(human) || !CombatUtil.canAttack(card) + || ph.isAfter(Constant.Phase.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY) + || (card.getNetCombatDamage() <= 0) + || AllZoneUtil.getCreaturesInPlay(human).size() < 1) { + return false; + } + } else if (keyword.equals("Defender") || keyword.endsWith("CARDNAME can't attack.")) { if (card.getController().isComputer() - || AllZone.getPhaseHandler().isPlayerTurn(AllZone.getComputerPlayer()) + || ph.isPlayerTurn(computer) || !CombatUtil.canAttack(card) || (card.getNetCombatDamage() <= 0)) { return false; } - } else if (keyword.contains("CARDNAME can't block.")) { - if (card.getController().isComputer() || AllZone.getPhaseHandler().isPlayerTurn(AllZone.getHumanPlayer()) + } else if (keyword.endsWith("CARDNAME can't block.")) { + if (card.getController().isComputer() || ph.isPlayerTurn(human) || !CombatUtil.canBlock(card)) { return false; } } else if (keyword.endsWith("This card doesn't untap during your next untap step.")) { - if (AllZone.getPhaseHandler().isBefore(Constant.Phase.MAIN2) - || AllZone.getPhaseHandler().isPlayerTurn(AllZone.getHumanPlayer())) { + if (ph.isBefore(Constant.Phase.MAIN2) || card.isUntapped() + || ph.isPlayerTurn(human)) { return false; } } else if (keyword.endsWith("CARDNAME attacks each turn if able.")) { - if (AllZone.getPhaseHandler().isPlayerTurn(AllZone.getComputerPlayer()) || !CombatUtil.canAttack(card) + if (ph.isPlayerTurn(human) || !CombatUtil.canAttack(card) || !CombatUtil.canBeBlocked(card)) { return false; } - } else if (keyword.endsWith("Haste")) { - if (!card.hasSickness() || AllZone.getPhaseHandler().isPlayerTurn(AllZone.getHumanPlayer()) + } else if (keyword.endsWith("Shroud")) { + //TODO: check stack for spells and abilities + return false; + } else if (keyword.startsWith("Rampage")) { + if (ph.isPlayerTurn(human) || !CombatUtil.canAttack(card) + || !CombatUtil.canBeBlocked(card) + || AllZoneUtil.getCreaturesInPlay(human).size() < 2) { + return false; + } + } else if (keyword.endsWith("Haste")) { + if (!card.hasSickness() || ph.isPlayerTurn(human) || !CombatUtil.canAttackNextTurn(card) || card.isTapped() || card.hasKeyword("CARDNAME can attack as though it had haste.") - || AllZone.getPhaseHandler().isAfter(Constant.Phase.COMBAT_DECLARE_ATTACKERS)) { + || ph.isAfter(Constant.Phase.COMBAT_DECLARE_ATTACKERS)) { return false; } } diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryPump.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryPump.java index 9c0659e37e1..e27eb003931 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryPump.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryPump.java @@ -260,9 +260,6 @@ public class AbilityFactoryPump { */ private CardList getPumpCreatures(final int defense, final int attack, final SpellAbility sa) { - final boolean evasive = (this.keywords.contains("Flying") || this.keywords.contains("Horsemanship") - || this.keywords.contains("HIDDEN Unblockable") || this.keywords.contains("Fear") || this.keywords - .contains("Intimidate")); final ArrayList keywords = this.keywords; CardList list = AllZoneUtil.getCreaturesInPlay(AllZone.getComputerPlayer()); @@ -281,13 +278,6 @@ public class AbilityFactoryPump { return false; } - // give evasive keywords to creatures that can attack - if (evasive && AllZone.getPhaseHandler().isPlayerTurn(AllZone.getComputerPlayer()) && CombatUtil.canAttack(c) - && AllZone.getPhaseHandler().isBefore(Constant.Phase.COMBAT_DECLARE_ATTACKERS) - && (c.getNetCombatDamage() > 0)) { - return true; - } - // will the creature attack (only relevant for sorcery speed)? if (CardFactoryUtil.doesCreatureAttackAI(c) && AllZone.getPhaseHandler().isBefore(Constant.Phase.COMBAT_DECLARE_ATTACKERS)