mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 03:38:01 +00:00
More visitors for keywords and merge duplicate keyword amount methods.
This commit is contained in:
@@ -857,7 +857,7 @@ public class AiAttackController {
|
|||||||
public final static int countExaltedBonus(final Player player) {
|
public final static int countExaltedBonus(final Player player) {
|
||||||
int bonus = 0;
|
int bonus = 0;
|
||||||
for (Card c : player.getCardsIn(ZoneType.Battlefield)) {
|
for (Card c : player.getCardsIn(ZoneType.Battlefield)) {
|
||||||
bonus += c.getKeywordAmount("Exalted");
|
bonus += c.getAmountOfKeyword("Exalted");
|
||||||
}
|
}
|
||||||
|
|
||||||
return bonus;
|
return bonus;
|
||||||
|
|||||||
@@ -1140,7 +1140,7 @@ public class ComputerUtilCombat {
|
|||||||
//check Exalted only for the first attacker
|
//check Exalted only for the first attacker
|
||||||
if (combat != null && combat.getAttackers().isEmpty()) {
|
if (combat != null && combat.getAttackers().isEmpty()) {
|
||||||
for (Card card : attacker.getController().getCardsIn(ZoneType.Battlefield)) {
|
for (Card card : attacker.getController().getCardsIn(ZoneType.Battlefield)) {
|
||||||
power += card.getKeywordAmount("Exalted");
|
power += card.getAmountOfKeyword("Exalted");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1323,7 +1323,7 @@ public class ComputerUtilCombat {
|
|||||||
//check Exalted only for the first attacker
|
//check Exalted only for the first attacker
|
||||||
if (combat != null && combat.getAttackers().isEmpty()) {
|
if (combat != null && combat.getAttackers().isEmpty()) {
|
||||||
for (Card card : attacker.getController().getCardsIn(ZoneType.Battlefield)) {
|
for (Card card : attacker.getController().getCardsIn(ZoneType.Battlefield)) {
|
||||||
toughness += card.getKeywordAmount("Exalted");
|
toughness += card.getAmountOfKeyword("Exalted");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -362,8 +362,8 @@ public abstract class PumpAiBase extends SpellAbilityAi {
|
|||||||
|| !ph.getPhase().equals(PhaseType.COMBAT_DECLARE_ATTACKERS)) {
|
|| !ph.getPhase().equals(PhaseType.COMBAT_DECLARE_ATTACKERS)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int canBlockNum = 1 + card.getKeywordAmount("CARDNAME can block an additional creature.") +
|
int canBlockNum = 1 + card.getAmountOfKeyword("CARDNAME can block an additional creature.") +
|
||||||
card.getKeywordAmount("CARDNAME can block an additional ninety-nine creatures.") * 99;
|
card.getAmountOfKeyword("CARDNAME can block an additional ninety-nine creatures.") * 99;
|
||||||
int possibleBlockNum = 0;
|
int possibleBlockNum = 0;
|
||||||
for (Card attacker : game.getCombat().getAttackers()) {
|
for (Card attacker : game.getCombat().getAttackers()) {
|
||||||
if (CombatUtil.canBlock(attacker, card)) {
|
if (CombatUtil.canBlock(attacker, card)) {
|
||||||
|
|||||||
@@ -2754,16 +2754,6 @@ public class Card extends GameEntity implements Comparable<Card> {
|
|||||||
visitHiddenExtreinsicKeywords(visitor);
|
visitHiddenExtreinsicKeywords(visitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final int getKeywordAmount(String keyword) {
|
|
||||||
return getKeywordAmount(currentState, keyword);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final int getKeywordAmount(CardState state, String keyword) {
|
|
||||||
CountKeywordVisitor visitor = new CountKeywordVisitor(keyword);
|
|
||||||
visitKeywords(state, visitor);
|
|
||||||
return visitor.getCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean hasKeyword(String keyword) {
|
public final boolean hasKeyword(String keyword) {
|
||||||
return hasKeyword(keyword, currentState);
|
return hasKeyword(keyword, currentState);
|
||||||
@@ -3334,26 +3324,18 @@ public class Card extends GameEntity implements Comparable<Card> {
|
|||||||
return hasStartOfKeyword(keyword, currentState);
|
return hasStartOfKeyword(keyword, currentState);
|
||||||
}
|
}
|
||||||
public final boolean hasStartOfKeyword(String keyword, CardState state) {
|
public final boolean hasStartOfKeyword(String keyword, CardState state) {
|
||||||
final List<String> a = getKeywords(state);
|
CountKeywordVisitor visitor = new CountKeywordVisitor(keyword, true);
|
||||||
for (int i = 0; i < a.size(); i++) {
|
visitKeywords(state, visitor);
|
||||||
if (a.get(i).toString().startsWith(keyword)) {
|
return visitor.getCount() > 0;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean hasStartOfUnHiddenKeyword(String keyword) {
|
public final boolean hasStartOfUnHiddenKeyword(String keyword) {
|
||||||
return hasStartOfUnHiddenKeyword(keyword, currentState);
|
return hasStartOfUnHiddenKeyword(keyword, currentState);
|
||||||
}
|
}
|
||||||
public final boolean hasStartOfUnHiddenKeyword(String keyword, CardState state) {
|
public final boolean hasStartOfUnHiddenKeyword(String keyword, CardState state) {
|
||||||
final List<String> a = getUnhiddenKeywords(state);
|
CountKeywordVisitor visitor = new CountKeywordVisitor(keyword, true);
|
||||||
for (int i = 0; i < a.size(); i++) {
|
visitUnhiddenKeywords(state, visitor);
|
||||||
if (a.get(i).toString().startsWith(keyword)) {
|
return visitor.getCount() > 0;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final int getKeywordPosition(String k) {
|
public final int getKeywordPosition(String k) {
|
||||||
@@ -3386,13 +3368,9 @@ public class Card extends GameEntity implements Comparable<Card> {
|
|||||||
return getAmountOfKeyword(k, currentState);
|
return getAmountOfKeyword(k, currentState);
|
||||||
}
|
}
|
||||||
public final int getAmountOfKeyword(final String k, CardState state) {
|
public final int getAmountOfKeyword(final String k, CardState state) {
|
||||||
int count = 0;
|
CountKeywordVisitor visitor = new CountKeywordVisitor(k);
|
||||||
for (String kw : getKeywords(state)) {
|
visitKeywords(state, visitor);
|
||||||
if (kw.equals(k)) {
|
return visitor.getCount();
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is for keywords with a number like Bushido, Annihilator and Rampage.
|
// This is for keywords with a number like Bushido, Annihilator and Rampage.
|
||||||
@@ -6404,15 +6382,22 @@ public class Card extends GameEntity implements Comparable<Card> {
|
|||||||
private static final class CountKeywordVisitor extends Visitor<String> {
|
private static final class CountKeywordVisitor extends Visitor<String> {
|
||||||
private String keyword;
|
private String keyword;
|
||||||
private int count;
|
private int count;
|
||||||
|
private boolean startOf;
|
||||||
|
|
||||||
public CountKeywordVisitor(String keyword) {
|
public CountKeywordVisitor(String keyword) {
|
||||||
this.keyword = keyword;
|
this.keyword = keyword;
|
||||||
this.count = 0;
|
this.count = 0;
|
||||||
|
this.startOf = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CountKeywordVisitor(String keyword, boolean startOf) {
|
||||||
|
this(keyword);
|
||||||
|
this.startOf = startOf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(String kw) {
|
public void visit(String kw) {
|
||||||
if (kw.equals(keyword)) {
|
if ((startOf && kw.startsWith(keyword)) || kw.equals(keyword)) {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -437,8 +437,8 @@ public class CombatUtil {
|
|||||||
if (blockedBy.isEmpty() || blocker.hasKeyword("CARDNAME can block any number of creatures.")) {
|
if (blockedBy.isEmpty() || blocker.hasKeyword("CARDNAME can block any number of creatures.")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
int canBlockMore = blocker.getKeywordAmount("CARDNAME can block an additional creature.")
|
int canBlockMore = blocker.getAmountOfKeyword("CARDNAME can block an additional creature.")
|
||||||
+ blocker.getKeywordAmount("CARDNAME can block an additional ninety-nine creatures.") * 99;
|
+ blocker.getAmountOfKeyword("CARDNAME can block an additional ninety-nine creatures.") * 99;
|
||||||
return canBlockMore >= blockedBy.size();
|
return canBlockMore >= blockedBy.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1029,7 +1029,7 @@ public class CombatUtil {
|
|||||||
public static void handleFlankingKeyword(final Game game, final Card attacker, final List<Card> blockers) {
|
public static void handleFlankingKeyword(final Game game, final Card attacker, final List<Card> blockers) {
|
||||||
for (final Card blocker : blockers) {
|
for (final Card blocker : blockers) {
|
||||||
if (attacker.hasKeyword("Flanking") && !blocker.hasKeyword("Flanking")) {
|
if (attacker.hasKeyword("Flanking") && !blocker.hasKeyword("Flanking")) {
|
||||||
final int flankingMagnitude = attacker.getKeywordAmount("Flanking");
|
final int flankingMagnitude = attacker.getAmountOfKeyword("Flanking");
|
||||||
|
|
||||||
// Rule 702.23b: If a creature has multiple instances of flanking, each triggers separately.
|
// Rule 702.23b: If a creature has multiple instances of flanking, each triggers separately.
|
||||||
for (int i = 0; i < flankingMagnitude; i++) {
|
for (int i = 0; i < flankingMagnitude; i++) {
|
||||||
|
|||||||
@@ -386,7 +386,7 @@ public class SpellAbilityRestriction extends SpellAbilityVariables {
|
|||||||
&& !activator.canCastSorcery()) {
|
&& !activator.canCastSorcery()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final int limits = c.getKeywordAmount("May activate CARDNAME's loyalty abilities once");
|
final int limits = c.getAmountOfKeyword("May activate CARDNAME's loyalty abilities once");
|
||||||
int numActivates = 0;
|
int numActivates = 0;
|
||||||
for (final SpellAbility pwAbs : c.getAllSpellAbilities()) {
|
for (final SpellAbility pwAbs : c.getAllSpellAbilities()) {
|
||||||
// check all abilities on card that have their planeswalker
|
// check all abilities on card that have their planeswalker
|
||||||
|
|||||||
Reference in New Issue
Block a user