mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 03:38:01 +00:00
Code cleanup: make a lot of methods static and remove some unnecessary interface implements and casts.
This commit is contained in:
@@ -93,7 +93,7 @@ public class AiAttackController {
|
|||||||
attackers.add(c);
|
attackers.add(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.blockers = this.getPossibleBlockers(oppList, this.attackers);
|
this.blockers = getPossibleBlockers(oppList, this.attackers);
|
||||||
} // constructor
|
} // constructor
|
||||||
|
|
||||||
public AiAttackController(final Player ai, Card attacker) {
|
public AiAttackController(final Player ai, Card attacker) {
|
||||||
@@ -105,7 +105,7 @@ public class AiAttackController {
|
|||||||
if (CombatUtil.canAttack(attacker, this.defendingOpponent)) {
|
if (CombatUtil.canAttack(attacker, this.defendingOpponent)) {
|
||||||
attackers.add(attacker);
|
attackers.add(attacker);
|
||||||
}
|
}
|
||||||
this.blockers = this.getPossibleBlockers(oppList, this.attackers);
|
this.blockers = getPossibleBlockers(oppList, this.attackers);
|
||||||
} // overloaded constructor to evaluate single specified attacker
|
} // overloaded constructor to evaluate single specified attacker
|
||||||
|
|
||||||
public static List<Card> getOpponentCreatures(final Player defender) {
|
public static List<Card> getOpponentCreatures(final Player defender) {
|
||||||
@@ -156,7 +156,7 @@ public class AiAttackController {
|
|||||||
* a {@link forge.CardList} object.
|
* a {@link forge.CardList} object.
|
||||||
* @return a {@link forge.CardList} object.
|
* @return a {@link forge.CardList} object.
|
||||||
*/
|
*/
|
||||||
public final List<Card> sortAttackers(final List<Card> in) {
|
public final static List<Card> sortAttackers(final List<Card> in) {
|
||||||
final List<Card> list = new ArrayList<Card>();
|
final List<Card> list = new ArrayList<Card>();
|
||||||
|
|
||||||
// Cards with triggers should come first (for Battle Cry)
|
// Cards with triggers should come first (for Battle Cry)
|
||||||
@@ -219,7 +219,7 @@ public class AiAttackController {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final List<Card> getPossibleBlockers(final List<Card> blockers, final List<Card> attackers) {
|
public final static List<Card> getPossibleBlockers(final List<Card> blockers, final List<Card> attackers) {
|
||||||
List<Card> possibleBlockers = new ArrayList<Card>(blockers);
|
List<Card> possibleBlockers = new ArrayList<Card>(blockers);
|
||||||
possibleBlockers = CardLists.filter(possibleBlockers, new Predicate<Card>() {
|
possibleBlockers = CardLists.filter(possibleBlockers, new Predicate<Card>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -230,7 +230,7 @@ public class AiAttackController {
|
|||||||
return possibleBlockers;
|
return possibleBlockers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean canBlockAnAttacker(final Card c, final List<Card> attackers) {
|
public final static boolean canBlockAnAttacker(final Card c, final List<Card> attackers) {
|
||||||
final List<Card> attackerList = new ArrayList<Card>(attackers);
|
final List<Card> attackerList = new ArrayList<Card>(attackers);
|
||||||
if (!c.isCreature()) {
|
if (!c.isCreature()) {
|
||||||
return false;
|
return false;
|
||||||
@@ -277,7 +277,7 @@ public class AiAttackController {
|
|||||||
int blockersNeeded = this.oppList.size();
|
int blockersNeeded = this.oppList.size();
|
||||||
|
|
||||||
// don't hold back creatures that can't block any of the human creatures
|
// don't hold back creatures that can't block any of the human creatures
|
||||||
final List<Card> list = this.getPossibleBlockers(attackers, this.oppList);
|
final List<Card> list = getPossibleBlockers(attackers, this.oppList);
|
||||||
|
|
||||||
//Calculate the amount of creatures necessary
|
//Calculate the amount of creatures necessary
|
||||||
for (int i = 0; i < list.size(); i++) {
|
for (int i = 0; i < list.size(); i++) {
|
||||||
@@ -307,7 +307,7 @@ public class AiAttackController {
|
|||||||
// In addition, if the computer guesses it needs no blockers, make sure
|
// In addition, if the computer guesses it needs no blockers, make sure
|
||||||
// that
|
// that
|
||||||
// it won't be surprised by Exalted
|
// it won't be surprised by Exalted
|
||||||
final int humanExaltedBonus = this.countExaltedBonus(opp);
|
final int humanExaltedBonus = countExaltedBonus(opp);
|
||||||
|
|
||||||
if (humanExaltedBonus > 0) {
|
if (humanExaltedBonus > 0) {
|
||||||
final boolean finestHour = opp.isCardInPlay("Finest Hour");
|
final boolean finestHour = opp.isCardInPlay("Finest Hour");
|
||||||
@@ -316,7 +316,7 @@ public class AiAttackController {
|
|||||||
//
|
//
|
||||||
// total attack = biggest creature + exalted, *2 if Rafiq is in
|
// total attack = biggest creature + exalted, *2 if Rafiq is in
|
||||||
// play
|
// play
|
||||||
int humanBasePower = this.getAttack(this.oppList.get(0)) + humanExaltedBonus;
|
int humanBasePower = getAttack(this.oppList.get(0)) + humanExaltedBonus;
|
||||||
if (finestHour) {
|
if (finestHour) {
|
||||||
// For Finest Hour, one creature could attack and get the
|
// For Finest Hour, one creature could attack and get the
|
||||||
// bonus TWICE
|
// bonus TWICE
|
||||||
@@ -490,18 +490,6 @@ public class AiAttackController {
|
|||||||
|
|
||||||
final boolean LOG_AI_ATTACKS = false;
|
final boolean LOG_AI_ATTACKS = false;
|
||||||
|
|
||||||
|
|
||||||
public final List<Player> getDefendingPlayers(Combat combat) {
|
|
||||||
final List<Player> defending = new ArrayList<Player>();
|
|
||||||
for (final GameEntity o : combat.getDefenders()) {
|
|
||||||
if (o instanceof Player) {
|
|
||||||
defending.add((Player) o);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return defending;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Getter for the field <code>attackers</code>.
|
* Getter for the field <code>attackers</code>.
|
||||||
@@ -806,7 +794,7 @@ public class AiAttackController {
|
|||||||
System.out.println("Normal attack");
|
System.out.println("Normal attack");
|
||||||
|
|
||||||
attackersLeft = this.notNeededAsBlockers(ai, attackersLeft);
|
attackersLeft = this.notNeededAsBlockers(ai, attackersLeft);
|
||||||
attackersLeft = this.sortAttackers(attackersLeft);
|
attackersLeft = sortAttackers(attackersLeft);
|
||||||
|
|
||||||
if ( LOG_AI_ATTACKS )
|
if ( LOG_AI_ATTACKS )
|
||||||
System.out.println("attackersLeft = " + attackersLeft);
|
System.out.println("attackersLeft = " + attackersLeft);
|
||||||
@@ -849,7 +837,7 @@ public class AiAttackController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
defender = getDefendingPlayers(combat).get(0);
|
defender = combat.getDefendingPlayers().get(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -866,7 +854,7 @@ public class AiAttackController {
|
|||||||
* a {@link forge.game.player.Player} object.
|
* a {@link forge.game.player.Player} object.
|
||||||
* @return a int.
|
* @return a int.
|
||||||
*/
|
*/
|
||||||
public final 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.getKeywordAmount("Exalted");
|
||||||
@@ -884,7 +872,7 @@ public class AiAttackController {
|
|||||||
* a {@link forge.game.card.Card} object.
|
* a {@link forge.game.card.Card} object.
|
||||||
* @return a int.
|
* @return a int.
|
||||||
*/
|
*/
|
||||||
public final int getAttack(final Card c) {
|
public final static int getAttack(final Card c) {
|
||||||
int n = c.getNetCombatDamage();
|
int n = c.getNetCombatDamage();
|
||||||
|
|
||||||
if (c.hasKeyword("Double Strike")) {
|
if (c.hasKeyword("Double Strike")) {
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public class AiBlockController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// finds the creatures able to block the attacker
|
// finds the creatures able to block the attacker
|
||||||
private List<Card> getPossibleBlockers(final Combat combat, final Card attacker, final List<Card> blockersLeft, final boolean solo) {
|
private static List<Card> getPossibleBlockers(final Combat combat, final Card attacker, final List<Card> blockersLeft, final boolean solo) {
|
||||||
final List<Card> blockers = new ArrayList<Card>();
|
final List<Card> blockers = new ArrayList<Card>();
|
||||||
|
|
||||||
for (final Card blocker : blockersLeft) {
|
for (final Card blocker : blockersLeft) {
|
||||||
@@ -120,7 +120,7 @@ public class AiBlockController {
|
|||||||
return blockers;
|
return blockers;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<CardCollection> sortAttackerByDefender(final Combat combat) {
|
private static List<CardCollection> sortAttackerByDefender(final Combat combat) {
|
||||||
FCollectionView<GameEntity> defenders = combat.getDefenders();
|
FCollectionView<GameEntity> defenders = combat.getDefenders();
|
||||||
final ArrayList<CardCollection> attackers = new ArrayList<CardCollection>(defenders.size());
|
final ArrayList<CardCollection> attackers = new ArrayList<CardCollection>(defenders.size());
|
||||||
for (GameEntity defender : defenders) {
|
for (GameEntity defender : defenders) {
|
||||||
|
|||||||
@@ -362,7 +362,7 @@ public class AiController {
|
|||||||
return spellAbilities;
|
return spellAbilities;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<SpellAbility> getPlayableCounters(final CardCollection l) {
|
private static ArrayList<SpellAbility> getPlayableCounters(final CardCollection l) {
|
||||||
final ArrayList<SpellAbility> spellAbility = new ArrayList<SpellAbility>();
|
final ArrayList<SpellAbility> spellAbility = new ArrayList<SpellAbility>();
|
||||||
for (final Card c : l) {
|
for (final Card c : l) {
|
||||||
for (final SpellAbility sa : c.getNonManaAbilities()) {
|
for (final SpellAbility sa : c.getNonManaAbilities()) {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AiCostDecision extends CostDecisionMakerBase implements ICostVisitor<PaymentDecision> {
|
public class AiCostDecision extends CostDecisionMakerBase {
|
||||||
private final SpellAbility ability;
|
private final SpellAbility ability;
|
||||||
private final Card source;
|
private final Card source;
|
||||||
|
|
||||||
@@ -593,7 +593,7 @@ public class AiCostDecision extends CostDecisionMakerBase implements ICostVisito
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PaymentDecision visit(CostUnattach cost) {
|
public PaymentDecision visit(CostUnattach cost) {
|
||||||
Card cardToUnattach = cost.findCardToUnattach(source, (Player) player, ability);
|
final Card cardToUnattach = cost.findCardToUnattach(source, player, ability);
|
||||||
if (cardToUnattach == null) {
|
if (cardToUnattach == null) {
|
||||||
// We really shouldn't be able to get here if there's nothing to unattach
|
// We really shouldn't be able to get here if there's nothing to unattach
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -185,9 +185,9 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private PaperCard getFirstWithImage(Collection<PaperCard> cards) {
|
private static PaperCard getFirstWithImage(final Collection<PaperCard> cards) {
|
||||||
//NOTE: this is written this way to avoid checking final card in list
|
//NOTE: this is written this way to avoid checking final card in list
|
||||||
Iterator<PaperCard> iterator = cards.iterator();
|
final Iterator<PaperCard> iterator = cards.iterator();
|
||||||
PaperCard pc = iterator.next();
|
PaperCard pc = iterator.next();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
if (pc.hasImage()) {
|
if (pc.hasImage()) {
|
||||||
|
|||||||
@@ -17,13 +17,13 @@
|
|||||||
*/
|
*/
|
||||||
package forge.card;
|
package forge.card;
|
||||||
|
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import forge.card.mana.IParserManaCost;
|
import forge.card.mana.IParserManaCost;
|
||||||
import forge.card.mana.ManaCost;
|
import forge.card.mana.ManaCost;
|
||||||
import forge.card.mana.ManaCostShard;
|
import forge.card.mana.ManaCostShard;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.StringTokenizer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A collection of methods containing full
|
* A collection of methods containing full
|
||||||
@@ -65,7 +65,7 @@ public final class CardRules implements ICardCharacteristics {
|
|||||||
colorIdentity = newRules.colorIdentity;
|
colorIdentity = newRules.colorIdentity;
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte calculateColorIdentity(ICardFace face) {
|
private static byte calculateColorIdentity(final ICardFace face) {
|
||||||
byte res = face.getColor().getColor();
|
byte res = face.getColor().getColor();
|
||||||
boolean isReminder = false;
|
boolean isReminder = false;
|
||||||
boolean isSymbol = false;
|
boolean isSymbol = false;
|
||||||
@@ -154,7 +154,7 @@ public final class CardRules implements ICardCharacteristics {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean canCastFace(ICardFace face, byte colorCode) {
|
private static boolean canCastFace(final ICardFace face, final byte colorCode) {
|
||||||
if (face.getManaCost().isNoCost()) {
|
if (face.getManaCost().isNoCost()) {
|
||||||
//if card face has no cost, assume castable only by mana of its defined color
|
//if card face has no cost, assume castable only by mana of its defined color
|
||||||
return face.getColor().hasNoColorsExcept(colorCode);
|
return face.getColor().hasNoColorsExcept(colorCode);
|
||||||
@@ -214,22 +214,6 @@ public final class CardRules implements ICardCharacteristics {
|
|||||||
public String getPictureUrl(boolean backface ) { return backface ? dlUrlOtherSide : dlUrl; }
|
public String getPictureUrl(boolean backface ) { return backface ? dlUrlOtherSide : dlUrl; }
|
||||||
public void setDlUrls(String[] dlUrls) { this.dlUrl = dlUrls[0]; this.dlUrlOtherSide = dlUrls[1]; }
|
public void setDlUrls(String[] dlUrls) { this.dlUrl = dlUrls[0]; this.dlUrlOtherSide = dlUrls[1]; }
|
||||||
|
|
||||||
public final List<String> getReplacements() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final List<String> getTriggers() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final List<String> getStaticAbilities() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final List<String> getAbilities() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ColorSet getColorIdentity() {
|
public ColorSet getColorIdentity() {
|
||||||
return colorIdentity;
|
return colorIdentity;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -248,7 +248,7 @@ public final class CardType implements Comparable<CardType>, CardTypeView {
|
|||||||
|
|
||||||
return subtypes.contains(creatureType) || subtypes.contains("AllCreatureTypes");
|
return subtypes.contains(creatureType) || subtypes.contains("AllCreatureTypes");
|
||||||
}
|
}
|
||||||
private String toMixedCase(final String s) {
|
private static String toMixedCase(final String s) {
|
||||||
if (s.equals("")) {
|
if (s.equals("")) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ public enum DeckFormat {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPlaneSectionConformanceProblem(CardPool planes) {
|
public static String getPlaneSectionConformanceProblem(final CardPool planes) {
|
||||||
//Must contain at least 10 planes/phenomenons, but max 2 phenomenons. Singleton.
|
//Must contain at least 10 planes/phenomenons, but max 2 phenomenons. Singleton.
|
||||||
if (planes == null || planes.countAll() < 10) {
|
if (planes == null || planes.countAll() < 10) {
|
||||||
return "should have at least 10 planes";
|
return "should have at least 10 planes";
|
||||||
@@ -214,7 +214,7 @@ public enum DeckFormat {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSchemeSectionConformanceProblem(CardPool schemes) {
|
public static String getSchemeSectionConformanceProblem(final CardPool schemes) {
|
||||||
//Must contain at least 20 schemes, max 2 of each.
|
//Must contain at least 20 schemes, max 2 of each.
|
||||||
if (schemes == null || schemes.countAll() < 20) {
|
if (schemes == null || schemes.countAll() < 20) {
|
||||||
return "must contain at least 20 schemes";
|
return "must contain at least 20 schemes";
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ public class DeckStorage extends StorageReaderFolder<Deck> implements IItemSeria
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void adjustFileLocation(final File file, final Deck result) {
|
private static void adjustFileLocation(final File file, final Deck result) {
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
file.delete();
|
file.delete();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -272,7 +272,7 @@ public final class NameGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Generates a specified number of random names. */
|
/** Generates a specified number of random names. */
|
||||||
public List<String> getRandomNames(int generateAmount, final List<String> excludeNames) {
|
public static List<String> getRandomNames(final int generateAmount, final List<String> excludeNames) {
|
||||||
usedNames = excludeNames;
|
usedNames = excludeNames;
|
||||||
final List<String> names = new ArrayList<String>(generateAmount);
|
final List<String> names = new ArrayList<String>(generateAmount);
|
||||||
for (int i = 0; i < generateAmount; i++) {
|
for (int i = 0; i < generateAmount; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user