mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28: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) {
|
||||
int bonus = 0;
|
||||
for (Card c : player.getCardsIn(ZoneType.Battlefield)) {
|
||||
bonus += c.getKeywordAmount("Exalted");
|
||||
bonus += c.getAmountOfKeyword("Exalted");
|
||||
}
|
||||
|
||||
return bonus;
|
||||
|
||||
@@ -1140,7 +1140,7 @@ public class ComputerUtilCombat {
|
||||
//check Exalted only for the first attacker
|
||||
if (combat != null && combat.getAttackers().isEmpty()) {
|
||||
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
|
||||
if (combat != null && combat.getAttackers().isEmpty()) {
|
||||
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)) {
|
||||
return false;
|
||||
}
|
||||
int canBlockNum = 1 + card.getKeywordAmount("CARDNAME can block an additional creature.") +
|
||||
card.getKeywordAmount("CARDNAME can block an additional ninety-nine creatures.") * 99;
|
||||
int canBlockNum = 1 + card.getAmountOfKeyword("CARDNAME can block an additional creature.") +
|
||||
card.getAmountOfKeyword("CARDNAME can block an additional ninety-nine creatures.") * 99;
|
||||
int possibleBlockNum = 0;
|
||||
for (Card attacker : game.getCombat().getAttackers()) {
|
||||
if (CombatUtil.canBlock(attacker, card)) {
|
||||
|
||||
@@ -2754,16 +2754,6 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
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
|
||||
public final boolean hasKeyword(String keyword) {
|
||||
return hasKeyword(keyword, currentState);
|
||||
@@ -3334,26 +3324,18 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
return hasStartOfKeyword(keyword, currentState);
|
||||
}
|
||||
public final boolean hasStartOfKeyword(String keyword, CardState state) {
|
||||
final List<String> a = getKeywords(state);
|
||||
for (int i = 0; i < a.size(); i++) {
|
||||
if (a.get(i).toString().startsWith(keyword)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
CountKeywordVisitor visitor = new CountKeywordVisitor(keyword, true);
|
||||
visitKeywords(state, visitor);
|
||||
return visitor.getCount() > 0;
|
||||
}
|
||||
|
||||
public final boolean hasStartOfUnHiddenKeyword(String keyword) {
|
||||
return hasStartOfUnHiddenKeyword(keyword, currentState);
|
||||
}
|
||||
public final boolean hasStartOfUnHiddenKeyword(String keyword, CardState state) {
|
||||
final List<String> a = getUnhiddenKeywords(state);
|
||||
for (int i = 0; i < a.size(); i++) {
|
||||
if (a.get(i).toString().startsWith(keyword)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
CountKeywordVisitor visitor = new CountKeywordVisitor(keyword, true);
|
||||
visitUnhiddenKeywords(state, visitor);
|
||||
return visitor.getCount() > 0;
|
||||
}
|
||||
|
||||
public final int getKeywordPosition(String k) {
|
||||
@@ -3386,13 +3368,9 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
return getAmountOfKeyword(k, currentState);
|
||||
}
|
||||
public final int getAmountOfKeyword(final String k, CardState state) {
|
||||
int count = 0;
|
||||
for (String kw : getKeywords(state)) {
|
||||
if (kw.equals(k)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
CountKeywordVisitor visitor = new CountKeywordVisitor(k);
|
||||
visitKeywords(state, visitor);
|
||||
return visitor.getCount();
|
||||
}
|
||||
|
||||
// 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 String keyword;
|
||||
private int count;
|
||||
private boolean startOf;
|
||||
|
||||
public CountKeywordVisitor(String keyword) {
|
||||
this.keyword = keyword;
|
||||
this.count = 0;
|
||||
this.startOf = false;
|
||||
}
|
||||
|
||||
public CountKeywordVisitor(String keyword, boolean startOf) {
|
||||
this(keyword);
|
||||
this.startOf = startOf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(String kw) {
|
||||
if (kw.equals(keyword)) {
|
||||
if ((startOf && kw.startsWith(keyword)) || kw.equals(keyword)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -437,8 +437,8 @@ public class CombatUtil {
|
||||
if (blockedBy.isEmpty() || blocker.hasKeyword("CARDNAME can block any number of creatures.")) {
|
||||
return true;
|
||||
}
|
||||
int canBlockMore = blocker.getKeywordAmount("CARDNAME can block an additional creature.")
|
||||
+ blocker.getKeywordAmount("CARDNAME can block an additional ninety-nine creatures.") * 99;
|
||||
int canBlockMore = blocker.getAmountOfKeyword("CARDNAME can block an additional creature.")
|
||||
+ blocker.getAmountOfKeyword("CARDNAME can block an additional ninety-nine creatures.") * 99;
|
||||
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) {
|
||||
for (final Card blocker : blockers) {
|
||||
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.
|
||||
for (int i = 0; i < flankingMagnitude; i++) {
|
||||
|
||||
@@ -386,7 +386,7 @@ public class SpellAbilityRestriction extends SpellAbilityVariables {
|
||||
&& !activator.canCastSorcery()) {
|
||||
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;
|
||||
for (final SpellAbility pwAbs : c.getAllSpellAbilities()) {
|
||||
// check all abilities on card that have their planeswalker
|
||||
|
||||
Reference in New Issue
Block a user