AiAttackController > declareAttackers() convert keywords to MustAttack static checks

This commit is contained in:
Northmoc
2022-04-21 13:57:56 -04:00
parent 848387dc7a
commit 8a1479d9fe

View File

@@ -20,6 +20,8 @@ package forge.ai;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import forge.game.Game;
import forge.game.staticability.StaticAbility;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
@@ -798,11 +800,37 @@ public class AiAttackController {
// TODO: if there are other ways to tap this creature (like mana creature), then don't need to attack // TODO: if there are other ways to tap this creature (like mana creature), then don't need to attack
mustAttack = true; mustAttack = true;
} else { } else {
// TODO move to static Ability final Game game = attacker.getGame();
if (attacker.hasKeyword("CARDNAME attacks each combat if able.") || attacker.hasStartOfKeyword("CARDNAME attacks specific player each combat if able")) { for (final Card ca : game.getCardsIn(ZoneType.STATIC_ABILITIES_SOURCE_ZONES)) {
// TODO switch defender if there's one without a cost or it's not the specific player for (final StaticAbility stAb : ca.getStaticAbilities()) {
mustAttack = true; if (stAb.isSuppressed() || !stAb.checkConditions()) {
} else if (attacker.getController().getMustAttackEntityThisTurn() != null && CombatUtil.getAttackCost(ai.getGame(), attacker, defender) == null) { continue;
}
if (stAb.getParam("Mode").equals("MustAttack")) {
if (stAb.matchesValid(attacker, stAb.getParam("Affected").split(","))) {
if (stAb.hasParam("MustAttack")) {
GameEntity e = AbilityUtils.getDefinedEntities(attacker,
stAb.getParam("MustAttack"), stAb).get(0);
if (e instanceof Player) {
Player attackPl = (Player) e;
if (!game.getPhaseHandler().isPlayerTurn(attackPl)) { //CR 506.2
mustAttack = true;
}
} else if (e instanceof Card) {
Card attackPW = (Card) e;
if (!game.getPhaseHandler().isPlayerTurn(attackPW.getController())) {
mustAttack = true; // CR 506.2
}
}
} else {
// TODO switch defender if there's one without a cost or it's not the specific player
mustAttack = true;
}
}
}
}
}
if (attacker.getController().getMustAttackEntityThisTurn() != null && CombatUtil.getAttackCost(ai.getGame(), attacker, defender) == null) {
mustAttack = true; mustAttack = true;
} }
} }