checkstyle

This commit is contained in:
jendave
2011-10-26 07:49:44 +00:00
parent 81244734dd
commit 8a6bde480f
15 changed files with 2762 additions and 1482 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,16 +1,18 @@
package forge; package forge;
import forge.Constant.Zone;
import forge.card.cardFactory.CardFactoryUtil;
import forge.card.trigger.Trigger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Random; import java.util.Random;
import forge.Constant.Zone;
import forge.card.cardFactory.CardFactoryUtil;
import forge.card.trigger.Trigger;
//doesHumanAttackAndWin() uses the global variable AllZone.getComputerPlayer() //doesHumanAttackAndWin() uses the global variable AllZone.getComputerPlayer()
/** /**
* <p>ComputerUtil_Attack2 class.</p> * <p>
* ComputerUtil_Attack2 class.
* </p>
* *
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
@@ -29,27 +31,39 @@ public class ComputerUtil_Attack2 {
private CardList humanList; // holds human player creatures private CardList humanList; // holds human player creatures
private CardList computerList; // holds computer creatures private CardList computerList; // holds computer creatures
private int aiAggression = 0; // added by Masher, how aggressive the ai attack will be depending on circumstances private int aiAggression = 0; // added by Masher, how aggressive the ai
// attack will be depending on circumstances
/** /**
* <p>Constructor for ComputerUtil_Attack2.</p> * <p>
* Constructor for ComputerUtil_Attack2.
* </p>
* *
* @param possibleAttackers an array of {@link forge.Card} objects. * @param possibleAttackers
* @param possibleBlockers an array of {@link forge.Card} objects. * an array of {@link forge.Card} objects.
* @param blockerLife a int. * @param possibleBlockers
* an array of {@link forge.Card} objects.
* @param blockerLife
* a int.
*/ */
public ComputerUtil_Attack2(Card[] possibleAttackers, Card[] possibleBlockers, int blockerLife) { public ComputerUtil_Attack2(final Card[] possibleAttackers, final Card[] possibleBlockers, final int blockerLife) {
this(new CardList(possibleAttackers), new CardList(possibleBlockers), blockerLife); this(new CardList(possibleAttackers), new CardList(possibleBlockers), blockerLife);
} }
/** /**
* <p>Constructor for ComputerUtil_Attack2.</p> * <p>
* Constructor for ComputerUtil_Attack2.
* </p>
* *
* @param possibleAttackers a {@link forge.CardList} object. * @param possibleAttackers
* @param possibleBlockers a {@link forge.CardList} object. * a {@link forge.CardList} object.
* @param blockerLife a int. * @param possibleBlockers
* a {@link forge.CardList} object.
* @param blockerLife
* a int.
*/ */
public ComputerUtil_Attack2(final CardList possibleAttackers, CardList possibleBlockers, int blockerLife) { public ComputerUtil_Attack2(final CardList possibleAttackers,
final CardList possibleBlockers, final int blockerLife) {
humanList = new CardList(possibleBlockers.toArray()); humanList = new CardList(possibleBlockers.toArray());
humanList = humanList.getType("Creature"); humanList = humanList.getType("Creature");
@@ -64,9 +78,12 @@ public class ComputerUtil_Attack2 {
} // constructor } // constructor
/** /**
* <p>sortAttackers.</p> * <p>
* sortAttackers.
* </p>
* *
* @param in a {@link forge.CardList} object. * @param in
* a {@link forge.CardList} object.
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
public final CardList sortAttackers(final CardList in) { public final CardList sortAttackers(final CardList in) {
@@ -94,13 +111,17 @@ public class ComputerUtil_Attack2 {
// Is there any reward for attacking? (for 0/1 creatures there is not) // Is there any reward for attacking? (for 0/1 creatures there is not)
/** /**
* <p>isEffectiveAttacker.</p> * <p>
* isEffectiveAttacker.
* </p>
* *
* @param attacker a {@link forge.Card} object. * @param attacker
* @param combat a {@link forge.Combat} object. * a {@link forge.Card} object.
* @param combat
* a {@link forge.Combat} object.
* @return a boolean. * @return a boolean.
*/ */
public final boolean isEffectiveAttacker(final Card attacker, Combat combat) { public final boolean isEffectiveAttacker(final Card attacker, final Combat combat) {
// if the attacker will die when attacking don't attack // if the attacker will die when attacking don't attack
if (attacker.getNetDefense() + CombatUtil.predictToughnessBonusOfAttacker(attacker, null, combat) <= 0) { if (attacker.getNetDefense() + CombatUtil.predictToughnessBonusOfAttacker(attacker, null, combat) <= 0) {
@@ -128,12 +149,15 @@ public class ComputerUtil_Attack2 {
} }
/** /**
* <p>getPossibleAttackers.</p> * <p>
* getPossibleAttackers.
* </p>
* *
* @param in a {@link forge.CardList} object. * @param in
* a {@link forge.CardList} object.
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
public CardList getPossibleAttackers(CardList in) { public final CardList getPossibleAttackers(final CardList in) {
CardList list = new CardList(in.toArray()); CardList list = new CardList(in.toArray());
list = list.filter(new CardListFilter() { list = list.filter(new CardListFilter() {
public boolean addCard(final Card c) { public boolean addCard(final Card c) {
@@ -144,13 +168,17 @@ public class ComputerUtil_Attack2 {
} // getPossibleAttackers() } // getPossibleAttackers()
/** /**
* <p>getPossibleBlockers.</p> * <p>
* getPossibleBlockers.
* </p>
* *
* @param blockers a {@link forge.CardList} object. * @param blockers
* @param attackers a {@link forge.CardList} object. * a {@link forge.CardList} object.
* @param attackers
* a {@link forge.CardList} object.
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
public final CardList getPossibleBlockers(CardList blockers, CardList attackers) { public final CardList getPossibleBlockers(final CardList blockers, CardList attackers) {
CardList possibleBlockers = new CardList(blockers.toArray()); CardList possibleBlockers = new CardList(blockers.toArray());
final CardList attackerList = new CardList(attackers.toArray()); final CardList attackerList = new CardList(attackers.toArray());
possibleBlockers = possibleBlockers.filter(new CardListFilter() { possibleBlockers = possibleBlockers.filter(new CardListFilter() {
@@ -173,13 +201,17 @@ public class ComputerUtil_Attack2 {
// doesn't lose when the human player attacks // doesn't lose when the human player attacks
// this method is used by getAttackers() // this method is used by getAttackers()
/** /**
* <p>notNeededAsBlockers.</p> * <p>
* notNeededAsBlockers.
* </p>
* *
* @param attackers a {@link forge.CardList} object. * @param attackers
* @param combat a {@link forge.Combat} object. * a {@link forge.CardList} object.
* @param combat
* a {@link forge.Combat} object.
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
public final CardList notNeededAsBlockers(CardList attackers, Combat combat) { public final CardList notNeededAsBlockers(final CardList attackers, Combat combat) {
CardList notNeededAsBlockers = new CardList(attackers.toArray()); CardList notNeededAsBlockers = new CardList(attackers.toArray());
CardListUtil.sortAttackLowFirst(attackers); CardListUtil.sortAttackLowFirst(attackers);
int blockersNeeded = attackers.size(); int blockersNeeded = attackers.size();
@@ -201,9 +233,11 @@ public class ComputerUtil_Attack2 {
return notNeededAsBlockers; return notNeededAsBlockers;
} }
// Increase the total number of blockers needed by 1 if Finest Hour in play // Increase the total number of blockers needed by 1 if Finest Hour in
// play
// (human will get an extra first attack with a creature that untaps) // (human will get an extra first attack with a creature that untaps)
// In addition, if the computer guesses it needs no blockers, make sure that // In addition, if the computer guesses it needs no blockers, make sure
// that
// it won't be surprised by Exalted // it won't be surprised by Exalted
int humanExaltedBonus = countExaltedBonus(AllZone.getHumanPlayer()); int humanExaltedBonus = countExaltedBonus(AllZone.getHumanPlayer());
@@ -212,48 +246,59 @@ public class ComputerUtil_Attack2 {
if ((blockersNeeded == 0 || nFinestHours > 0) && humanList.size() > 0) { if ((blockersNeeded == 0 || nFinestHours > 0) && humanList.size() > 0) {
// //
// total attack = biggest creature + exalted, *2 if Rafiq is in play // total attack = biggest creature + exalted, *2 if Rafiq is in
// play
int humanBaseAttack = getAttack(humanList.get(0)) + humanExaltedBonus; int humanBaseAttack = getAttack(humanList.get(0)) + humanExaltedBonus;
if (nFinestHours > 0) { if (nFinestHours > 0) {
// For Finest Hour, one creature could attack and get the bonus TWICE // For Finest Hour, one creature could attack and get the
// bonus TWICE
humanBaseAttack = humanBaseAttack + humanExaltedBonus; humanBaseAttack = humanBaseAttack + humanExaltedBonus;
} }
int totalExaltedAttack = AllZoneUtil.isCardInPlay("Rafiq of the Many", AllZone.getHumanPlayer()) ? int totalExaltedAttack = AllZoneUtil.isCardInPlay("Rafiq of the Many",
2 * humanBaseAttack : humanBaseAttack; AllZone.getHumanPlayer()) ? 2 * humanBaseAttack : humanBaseAttack;
if ((AllZone.getComputerPlayer().getLife() - 3) <= totalExaltedAttack) { if ((AllZone.getComputerPlayer().getLife() - 3) <= totalExaltedAttack) {
// We will lose if there is an Exalted attack -- keep one blocker // We will lose if there is an Exalted attack -- keep one
if (blockersNeeded == 0 && notNeededAsBlockers.size() > 0) // blocker
if (blockersNeeded == 0 && notNeededAsBlockers.size() > 0) {
notNeededAsBlockers.remove(0); notNeededAsBlockers.remove(0);
}
// Finest Hour allows a second Exalted attack: keep a blocker for that too // Finest Hour allows a second Exalted attack: keep a
if (nFinestHours > 0 && notNeededAsBlockers.size() > 0) // blocker for that too
if (nFinestHours > 0 && notNeededAsBlockers.size() > 0) {
notNeededAsBlockers.remove(0); notNeededAsBlockers.remove(0);
} }
} }
} }
}
// re-add creatures with vigilance // re-add creatures with vigilance
for (Card c : attackers) { for (Card c : attackers) {
if (c.hasKeyword("Vigilance")) if (c.hasKeyword("Vigilance")) {
notNeededAsBlockers.add(c); notNeededAsBlockers.add(c);
} }
}
return notNeededAsBlockers; return notNeededAsBlockers;
} }
// this uses a global variable, which isn't perfect // this uses a global variable, which isn't perfect
/** /**
* <p>doesHumanAttackAndWin.</p> * <p>
* doesHumanAttackAndWin.
* </p>
* *
* @param nBlockingCreatures a int. * @param nBlockingCreatures
* a int.
* @return a boolean. * @return a boolean.
*/ */
public boolean doesHumanAttackAndWin(int nBlockingCreatures) { public final boolean doesHumanAttackAndWin(final int nBlockingCreatures) {
int totalAttack = 0; int totalAttack = 0;
int stop = humanList.size() - nBlockingCreatures; int stop = humanList.size() - nBlockingCreatures;
for (int i = 0; i < stop; i++) for (int i = 0; i < stop; i++) {
totalAttack += getAttack(humanList.get(i)); totalAttack += getAttack(humanList.get(i));
}
// originally -3 so the computer will try to stay at 3 life // originally -3 so the computer will try to stay at 3 life
// 0 now to prevent the AI from not attacking when it's got low life // 0 now to prevent the AI from not attacking when it's got low life
@@ -262,43 +307,51 @@ public class ComputerUtil_Attack2 {
} }
/** /**
* <p>doAssault.</p> * <p>
* doAssault.
* </p>
* *
* @return a boolean. * @return a boolean.
*/ */
private boolean doAssault() { private boolean doAssault() {
// Beastmaster Ascension // Beastmaster Ascension
if (AllZoneUtil.isCardInPlay("Beastmaster Ascension", AllZone.getComputerPlayer()) && attackers.size() > 1) { if (AllZoneUtil.isCardInPlay("Beastmaster Ascension", AllZone.getComputerPlayer()) && attackers.size() > 1) {
CardList beastions = AllZone.getComputerPlayer().getCardsIn(Constant.Zone.Battlefield). CardList beastions = AllZone.getComputerPlayer().getCardsIn(Constant.Zone.Battlefield)
getName("Beastmaster Ascension"); .getName("Beastmaster Ascension");
int minCreatures = 7; int minCreatures = 7;
for (Card beastion : beastions) { for (Card beastion : beastions) {
int counters = beastion.getCounters(Counters.QUEST); int counters = beastion.getCounters(Counters.QUEST);
minCreatures = Math.min(minCreatures, 7 - counters); minCreatures = Math.min(minCreatures, 7 - counters);
} }
if (attackers.size() >= minCreatures) if (attackers.size() >= minCreatures) {
return true; return true;
} }
}
// I think this is right but the assault code may still be a little off // I think this is right but the assault code may still be a little off
CardListUtil.sortAttackLowFirst(attackers); CardListUtil.sortAttackLowFirst(attackers);
int totalAttack = 0; int totalAttack = 0;
// presumes the Human will block // presumes the Human will block
for (int i = 0; i < (attackers.size() - blockers.size()); i++) for (int i = 0; i < (attackers.size() - blockers.size()); i++) {
totalAttack += getAttack(attackers.get(i)); totalAttack += getAttack(attackers.get(i));
}
return blockerLife <= totalAttack; return blockerLife <= totalAttack;
} // doAssault() } // doAssault()
/** /**
* <p>chooseDefender.</p> * <p>
* chooseDefender.
* </p>
* *
* @param c a {@link forge.Combat} object. * @param c
* @param bAssault a boolean. * a {@link forge.Combat} object.
* @param bAssault
* a boolean.
*/ */
public void chooseDefender(Combat c, boolean bAssault) { public final void chooseDefender(final Combat c, final boolean bAssault) {
// TODO: split attackers to different planeswalker/human // TODO split attackers to different planeswalker/human
// AI will only attack one Defender per combat for now // AI will only attack one Defender per combat for now
ArrayList<Object> defs = c.getDefenders(); ArrayList<Object> defs = c.getDefenders();
@@ -313,24 +366,24 @@ public class ComputerUtil_Attack2 {
if (-1 == n) { if (-1 == n) {
System.out.println("getMustAttackEntity() returned something not in defenders."); System.out.println("getMustAttackEntity() returned something not in defenders.");
c.setCurrentDefender(0); c.setCurrentDefender(0);
} } else {
else {
c.setCurrentDefender(n); c.setCurrentDefender(n);
} }
} } else {
else {
if (defs.size() == 1 || bAssault) { if (defs.size() == 1 || bAssault) {
c.setCurrentDefender(0); c.setCurrentDefender(0);
} else {
c.setCurrentDefender(n);
} }
else c.setCurrentDefender(n);
} }
return; return;
} }
/** /**
* <p>Getter for the field <code>attackers</code>.</p> * <p>
* Getter for the field <code>attackers</code>.
* </p>
* *
* @return a {@link forge.Combat} object. * @return a {@link forge.Combat} object.
*/ */
@@ -360,10 +413,9 @@ public class ComputerUtil_Attack2 {
|| attacker.hasKeyword("At the beginning of the end step, destroy CARDNAME.") || attacker.hasKeyword("At the beginning of the end step, destroy CARDNAME.")
|| attacker.hasKeyword("At the beginning of the end step, exile CARDNAME.") || attacker.hasKeyword("At the beginning of the end step, exile CARDNAME.")
|| attacker.hasKeyword("At the beginning of the end step, sacrifice CARDNAME.") || attacker.hasKeyword("At the beginning of the end step, sacrifice CARDNAME.")
|| attacker.getSacrificeAtEOT() || attacker.getSacrificeAtEOT() || attacker.getSirenAttackOrDestroy() || (attacker.getController()
|| attacker.getSirenAttackOrDestroy() .getMustAttackEntity() != null)) && CombatUtil.canAttack(attacker, combat))
|| (attacker.getController().getMustAttackEntity() != null)) {
&& CombatUtil.canAttack(attacker, combat)) {
combat.addAttacker(attacker); combat.addAttacker(attacker);
attackersLeft.remove(attacker); attackersLeft.remove(attacker);
} }
@@ -383,7 +435,8 @@ public class ComputerUtil_Attack2 {
// int candidateTotalBlockDamage = 0; // int candidateTotalBlockDamage = 0;
for (Card pCard : playerCreatures) { for (Card pCard : playerCreatures) {
// if the creature can attack next turn add it to counter attackers list // if the creature can attack next turn add it to counter attackers
// list
if (CombatUtil.canAttackNextTurn(pCard)) { if (CombatUtil.canAttackNextTurn(pCard)) {
nextTurnAttackers.add(pCard); nextTurnAttackers.add(pCard);
if (pCard.getNetCombatDamage() > 0) { if (pCard.getNetCombatDamage() > 0) {
@@ -392,7 +445,8 @@ public class ComputerUtil_Attack2 {
playerForces += 1; // player forces they might use to attack playerForces += 1; // player forces they might use to attack
} }
} }
// increment player forces that are relevant to an attritional attack - includes walls // increment player forces that are relevant to an attritional
// attack - includes walls
if (CombatUtil.canBlock(pCard)) { if (CombatUtil.canBlock(pCard)) {
playerForcesForAttritionalAttack += 1; playerForcesForAttritionalAttack += 1;
} }
@@ -408,7 +462,8 @@ public class ComputerUtil_Attack2 {
CardList candidateAttackers = new CardList(); CardList candidateAttackers = new CardList();
int candidateUnblockedDamage = 0; int candidateUnblockedDamage = 0;
for (Card pCard : computerList) { for (Card pCard : computerList) {
// if the creature can attack then it's a potential attacker this turn, assume summoning sickness creatures will be able to // if the creature can attack then it's a potential attacker this
// turn, assume summoning sickness creatures will be able to
if (CombatUtil.canAttackNextTurn(pCard)) { if (CombatUtil.canAttackNextTurn(pCard)) {
candidateAttackers.add(pCard); candidateAttackers.add(pCard);
@@ -422,24 +477,36 @@ public class ComputerUtil_Attack2 {
// find the potential damage ratio the AI can cause // find the potential damage ratio the AI can cause
double playerLifeToDamageRatio = 1000000; double playerLifeToDamageRatio = 1000000;
if (candidateUnblockedDamage > 0) if (candidateUnblockedDamage > 0) {
playerLifeToDamageRatio = (double) AllZone.getHumanPlayer().life / candidateUnblockedDamage; playerLifeToDamageRatio = (double) AllZone.getHumanPlayer().life / candidateUnblockedDamage;
}
/*System.out.println(String.valueOf(aiLifeToPlayerDamageRatio) + " = ai life to player damage ratio"); /*
System.out.println(String.valueOf(playerLifeToDamageRatio) + " = player life ai player damage ratio");*/ * System.out.println(String.valueOf(aiLifeToPlayerDamageRatio) +
* " = ai life to player damage ratio");
* System.out.println(String.valueOf(playerLifeToDamageRatio) +
* " = player life ai player damage ratio");
*/
// determine if the ai outnumbers the player // determine if the ai outnumbers the player
int outNumber = computerForces - playerForces; int outNumber = computerForces - playerForces;
// compare the ratios, higher = better for ai // compare the ratios, higher = better for ai
double ratioDiff = aiLifeToPlayerDamageRatio - playerLifeToDamageRatio; double ratioDiff = aiLifeToPlayerDamageRatio - playerLifeToDamageRatio;
/* System.out.println(String.valueOf(ratioDiff) + " = ratio difference, higher = better for ai"); /*
System.out.println(String.valueOf(outNumber) + " = outNumber, higher = better for ai"); */ * System.out.println(String.valueOf(ratioDiff) +
* " = ratio difference, higher = better for ai");
* System.out.println(String.valueOf(outNumber) +
* " = outNumber, higher = better for ai");
*/
// ********************* // *********************
// if outnumber and superior ratio work out whether attritional all out attacking will work // if outnumber and superior ratio work out whether attritional all out
// attritional attack will expect some creatures to die but to achieve victory by sheer weight // attacking will work
// of numbers attacking turn after turn. It's not calculate very carefully, the accuracy // attritional attack will expect some creatures to die but to achieve
// victory by sheer weight
// of numbers attacking turn after turn. It's not calculate very
// carefully, the accuracy
// can probably be improved // can probably be improved
// ********************* // *********************
boolean doAttritionalAttack = false; boolean doAttritionalAttack = false;
@@ -462,7 +529,8 @@ public class ComputerUtil_Attack2 {
} }
// remove from player life // remove from player life
playerLife -= damageThisRound; playerLife -= damageThisRound;
// shorten attacker list by the length of the blockers - assuming all blocked are killed for convenience // shorten attacker list by the length of the blockers - assuming
// all blocked are killed for convenience
for (int z = 0; z < playerForcesForAttritionalAttack; z++) { for (int z = 0; z < playerForcesForAttritionalAttack; z++) {
if (attritionalAttackers.size() > 0) { if (attritionalAttackers.size() > 0) {
attritionalAttackers.remove(attritionalAttackers.size() - 1); attritionalAttackers.remove(attritionalAttackers.size() - 1);
@@ -486,7 +554,8 @@ public class ComputerUtil_Attack2 {
boolean doUnblockableAttack = false; boolean doUnblockableAttack = false;
for (Card attacker : attackers) { for (Card attacker : attackers) {
boolean isUnblockableCreature = true; boolean isUnblockableCreature = true;
// check blockers individually, as the bulk canBeBlocked doesn't check all circumstances // check blockers individually, as the bulk canBeBlocked doesn't
// check all circumstances
for (Card blocker : blockers) { for (Card blocker : blockers) {
if (CombatUtil.canBlock(attacker, blocker)) { if (CombatUtil.canBlock(attacker, blocker)) {
isUnblockableCreature = false; isUnblockableCreature = false;
@@ -506,22 +575,33 @@ public class ComputerUtil_Attack2 {
// end see how long until unblockable attackers will be fatal // end see how long until unblockable attackers will be fatal
// ***************** // *****************
// decide on attack aggression based on a comparison of forces, life totals and other considerations // decide on attack aggression based on a comparison of forces, life
// some bad "magic numbers" here, TODO replace with nice descriptive variable names // totals and other considerations
if ((ratioDiff > 0 && doAttritionalAttack)) { // (playerLifeToDamageRatio <= 1 && ratioDiff >= 1 && outNumber > 0) || // some bad "magic numbers" here, TODO replace with nice descriptive
// variable names
if ((ratioDiff > 0 && doAttritionalAttack)) { // (playerLifeToDamageRatio
// <= 1 && ratioDiff >= 1
// && outNumber > 0) ||
aiAggression = 5; // attack at all costs aiAggression = 5; // attack at all costs
} else if ((playerLifeToDamageRatio < 2 && ratioDiff >= 0) || ratioDiff > 3 || (ratioDiff > 0 && outNumber > 0)) { } else if ((playerLifeToDamageRatio < 2 && ratioDiff >= 0)
aiAggression = 3; // attack expecting to kill creatures or damage player. || ratioDiff > 3 || (ratioDiff > 0 && outNumber > 0)) {
aiAggression = 3; // attack expecting to kill creatures or damage
// player.
} else if (ratioDiff >= 0 || ratioDiff + outNumber >= -1) { } else if (ratioDiff >= 0 || ratioDiff + outNumber >= -1) {
// at 0 ratio expect to potentially gain an advantage by attacking first // at 0 ratio expect to potentially gain an advantage by attacking
// first
// if the ai has a slight advantage // if the ai has a slight advantage
// or the ai has a significant advantage numerically but only a slight disadvantage damage/life // or the ai has a significant advantage numerically but only a
aiAggression = 2; // attack expecting to destroy creatures/be unblockable // slight disadvantage damage/life
aiAggression = 2; // attack expecting to destroy creatures/be
// unblockable
} else if (ratioDiff < 0 && aiLifeToPlayerDamageRatio > 1) { } else if (ratioDiff < 0 && aiLifeToPlayerDamageRatio > 1) {
// the player is overmatched but there are a few turns before death // the player is overmatched but there are a few turns before death
aiAggression = 2; // attack expecting to destroy creatures/be unblockable aiAggression = 2; // attack expecting to destroy creatures/be
// unblockable
} else if (doUnblockableAttack || ((ratioDiff * -1) < turnsUntilDeathByUnblockable)) { } else if (doUnblockableAttack || ((ratioDiff * -1) < turnsUntilDeathByUnblockable)) {
aiAggression = 1; // look for unblockable creatures that might be able to attack for a bit of aiAggression = 1; // look for unblockable creatures that might be
// able to attack for a bit of
// fatal damage even if the player is significantly better // fatal damage even if the player is significantly better
} else if (ratioDiff < 0) { } else if (ratioDiff < 0) {
aiAggression = 0; aiAggression = 0;
@@ -533,12 +613,14 @@ public class ComputerUtil_Attack2 {
// **************** // ****************
// Exalted // Exalted
if (combat.getAttackers().length == 0 && (countExaltedBonus(AllZone.getComputerPlayer()) >= 3 || if (combat.getAttackers().length == 0
AllZoneUtil.isCardInPlay("Rafiq of the Many", AllZone.getComputerPlayer()) || && (countExaltedBonus(AllZone.getComputerPlayer()) >= 3
AllZone.getComputerPlayer().getCardsIn(Zone.Battlefield, "Battlegrace Angel").size() >= 2 || || AllZoneUtil.isCardInPlay("Rafiq of the Many", AllZone.getComputerPlayer())
(AllZone.getComputerPlayer().getCardsIn(Zone.Battlefield, "Finest Hour").size() >= 1) && || AllZone.getComputerPlayer()
AllZone.getPhase().isFirstCombat()) .getCardsIn(Zone.Battlefield, "Battlegrace Angel").size() >= 2 || (AllZone
&& !bAssault) { .getComputerPlayer().getCardsIn(Zone.Battlefield, "Finest Hour").size() >= 1)
&& AllZone.getPhase().isFirstCombat()) && !bAssault)
{
int biggest = 0; int biggest = 0;
Card att = null; Card att = null;
for (int i = 0; i < attackersLeft.size(); i++) { for (int i = 0; i < attackersLeft.size(); i++) {
@@ -547,8 +629,9 @@ public class ComputerUtil_Attack2 {
att = attackersLeft.get(i); att = attackersLeft.get(i);
} }
} }
if (att != null && CombatUtil.canAttack(att, combat)) if (att != null && CombatUtil.canAttack(att, combat)) {
combat.addAttacker(att); combat.addAttacker(att);
}
System.out.println("Exalted"); System.out.println("Exalted");
} }
@@ -558,8 +641,11 @@ public class ComputerUtil_Attack2 {
else if (bAssault) { else if (bAssault) {
System.out.println("Assault"); System.out.println("Assault");
CardListUtil.sortAttack(attackersLeft); CardListUtil.sortAttack(attackersLeft);
for (int i = 0; i < attackersLeft.size(); i++) for (int i = 0; i < attackersLeft.size(); i++) {
if (CombatUtil.canAttack(attackersLeft.get(i), combat)) combat.addAttacker(attackersLeft.get(i)); if (CombatUtil.canAttack(attackersLeft.get(i), combat)) {
combat.addAttacker(attackersLeft.get(i));
}
}
} else { } else {
System.out.println("Normal attack"); System.out.println("Normal attack");
@@ -571,28 +657,36 @@ public class ComputerUtil_Attack2 {
for (int i = 0; i < attackersLeft.size(); i++) { for (int i = 0; i < attackersLeft.size(); i++) {
Card attacker = attackersLeft.get(i); Card attacker = attackersLeft.get(i);
int totalFirstStrikeBlockPower = 0; int totalFirstStrikeBlockPower = 0;
if (!attacker.hasFirstStrike() && !attacker.hasDoubleStrike()) if (!attacker.hasFirstStrike() && !attacker.hasDoubleStrike()) {
totalFirstStrikeBlockPower = CombatUtil.getTotalFirstStrikeBlockPower(attacker, AllZone.getHumanPlayer()); totalFirstStrikeBlockPower = CombatUtil.getTotalFirstStrikeBlockPower(attacker,
AllZone.getHumanPlayer());
}
if (shouldAttack(attacker, blockers, combat) && (totalFirstStrikeBlockPower < attacker.getKillDamage() || aiAggression == 5) if (shouldAttack(attacker, blockers, combat)
&& (totalFirstStrikeBlockPower < attacker.getKillDamage() || aiAggression == 5)
&& CombatUtil.canAttack(attacker, combat)) && CombatUtil.canAttack(attacker, combat))
{
combat.addAttacker(attacker); combat.addAttacker(attacker);
} }
}
} // getAttackers() } // getAttackers()
return combat; return combat;
} // getAttackers() } // getAttackers()
/** /**
* <p>countExaltedBonus.</p> * <p>
* countExaltedBonus.
* </p>
* *
* @param player a {@link forge.Player} object. * @param player
* a {@link forge.Player} object.
* @return a int. * @return a int.
*/ */
public int countExaltedBonus(Player player) { public final int countExaltedBonus(final Player player) {
CardList list = player.getCardsIn(Zone.Battlefield); CardList list = player.getCardsIn(Zone.Battlefield);
list = list.filter(new CardListFilter() { list = list.filter(new CardListFilter() {
public boolean addCard(Card c) { public boolean addCard(final Card c) {
return c.hasKeyword("Exalted"); return c.hasKeyword("Exalted");
} }
}); });
@@ -601,66 +695,93 @@ public class ComputerUtil_Attack2 {
} }
/** /**
* <p>getAttack.</p> * <p>
* getAttack.
* </p>
* *
* @param c a {@link forge.Card} object. * @param c
* a {@link forge.Card} object.
* @return a int. * @return a int.
*/ */
public int getAttack(Card c) { public final int getAttack(final Card c) {
int n = c.getNetCombatDamage(); int n = c.getNetCombatDamage();
if (c.hasKeyword("Double Strike")) if (c.hasKeyword("Double Strike")) {
n *= 2; n *= 2;
}
return n; return n;
} }
/** /**
* <p>shouldAttack.</p> * <p>
* shouldAttack.
* </p>
* *
* @param attacker a {@link forge.Card} object. * @param attacker
* @param defenders a {@link forge.CardList} object. * a {@link forge.Card} object.
* @param combat a {@link forge.Combat} object. * @param defenders
* a {@link forge.CardList} object.
* @param combat
* a {@link forge.Combat} object.
* @return a boolean. * @return a boolean.
*/ */
public boolean shouldAttack(Card attacker, CardList defenders, Combat combat) { public final boolean shouldAttack(final Card attacker, final CardList defenders, final Combat combat) {
boolean canBeKilledByOne = false; // indicates if the attacker can be killed by a single blockers boolean canBeKilledByOne = false; // indicates if the attacker can be
boolean canKillAll = true; // indicates if the attacker can kill all single blockers // killed by a single blockers
boolean canKillAllDangerous = true; // indicates if the attacker can kill all single blockers with wither or infect boolean canKillAll = true; // indicates if the attacker can kill all
// single blockers
boolean canKillAllDangerous = true; // indicates if the attacker can
// kill all single blockers with
// wither or infect
boolean isWorthLessThanAllKillers = true; boolean isWorthLessThanAllKillers = true;
boolean canBeBlocked = false; boolean canBeBlocked = false;
if (!isEffectiveAttacker(attacker, combat)) return false; if (!isEffectiveAttacker(attacker, combat)) {
return false;
}
// look at the attacker in relation to the blockers to establish a number of factors about the attacking // look at the attacker in relation to the blockers to establish a
// context that will be relevant to the attackers decision according to the selected strategy // number of factors about the attacking
// context that will be relevant to the attackers decision according to
// the selected strategy
for (Card defender : defenders) { for (Card defender : defenders) {
if (CombatUtil.canBlock(attacker, defender)) { // , combat )) { if (CombatUtil.canBlock(attacker, defender)) { // , combat )) {
canBeBlocked = true; canBeBlocked = true;
if (CombatUtil.canDestroyAttacker(attacker, defender, combat, false)) { if (CombatUtil.canDestroyAttacker(attacker, defender, combat, false)) {
canBeKilledByOne = true; // there is a single creature on the battlefield that can kill the creature canBeKilledByOne = true; // there is a single creature on
// see if the defending creature is of higher or lower value. We don't want to attack only to lose value // the battlefield that can kill
// the creature
// see if the defending creature is of higher or lower
// value. We don't want to attack only to lose value
if (CardFactoryUtil.evaluateCreature(defender) <= CardFactoryUtil.evaluateCreature(attacker)) { if (CardFactoryUtil.evaluateCreature(defender) <= CardFactoryUtil.evaluateCreature(attacker)) {
isWorthLessThanAllKillers = false; isWorthLessThanAllKillers = false;
} }
} }
// see if this attacking creature can destroy this defender, if not record that it can't kill everything // see if this attacking creature can destroy this defender, if
// not record that it can't kill everything
if (!CombatUtil.canDestroyBlocker(defender, attacker, combat, false)) { if (!CombatUtil.canDestroyBlocker(defender, attacker, combat, false)) {
canKillAll = false; canKillAll = false;
if (defender.hasKeyword("Wither") || defender.hasKeyword("Infect")) { if (defender.hasKeyword("Wither") || defender.hasKeyword("Infect")) {
canKillAllDangerous = false; // there is a dangerous creature that can survive an attack from this creature canKillAllDangerous = false; // there is a dangerous
// creature that can
// survive an attack from
// this creature
} }
} }
} }
} }
// if the creature cannot block and can kill all opponents they might as well attack, they do nothing staying back // if the creature cannot block and can kill all opponents they might as
// well attack, they do nothing staying back
if (canKillAll && !CombatUtil.canBlock(attacker) && isWorthLessThanAllKillers) { if (canKillAll && !CombatUtil.canBlock(attacker) && isWorthLessThanAllKillers) {
System.out.println(attacker.getName() + " = attacking because they can't block, expecting to kill or damage player"); System.out.println(attacker.getName()
+ " = attacking because they can't block, expecting to kill or damage player");
return true; return true;
} }
// decide if the creature should attack based on the prevailing strategy choice in aiAggression // decide if the creature should attack based on the prevailing strategy
// choice in aiAggression
switch (aiAggression) { switch (aiAggression) {
case 5: // all out attacking case 5: // all out attacking
System.out.println(attacker.getName() + " = all out attacking"); System.out.println(attacker.getName() + " = all out attacking");
@@ -670,12 +791,16 @@ public class ComputerUtil_Attack2 {
System.out.println(attacker.getName() + " = attacking expecting to at least trade with something"); System.out.println(attacker.getName() + " = attacking expecting to at least trade with something");
return true; return true;
} }
case 3: // expecting to at least kill a creature of equal value, not be blocked case 3: // expecting to at least kill a creature of equal value, not be
if ((canKillAll && isWorthLessThanAllKillers) || (canKillAllDangerous && !canBeKilledByOne) || !canBeBlocked) { // blocked
System.out.println(attacker.getName() + " = attacking expecting to kill creature or cause damage, or is unblockable"); if ((canKillAll && isWorthLessThanAllKillers) || (canKillAllDangerous && !canBeKilledByOne)
|| !canBeBlocked) {
System.out.println(attacker.getName()
+ " = attacking expecting to kill creature or cause damage, or is unblockable");
return true; return true;
} }
case 2: // attack expecting to attract a group block or destroying a single blocker and surviving case 2: // attack expecting to attract a group block or destroying a
// single blocker and surviving
if ((canKillAll && !canBeKilledByOne) || !canBeBlocked) { if ((canKillAll && !canBeKilledByOne) || !canBeBlocked) {
System.out.println(attacker.getName() + " = attacking expecting to survive or attract group block"); System.out.println(attacker.getName() + " = attacking expecting to survive or attract group block");
return true; return true;
@@ -685,6 +810,8 @@ public class ComputerUtil_Attack2 {
System.out.println(attacker.getName() + " = attacking expecting not to be blocked"); System.out.println(attacker.getName() + " = attacking expecting not to be blocked");
return true; return true;
} }
default:
break;
} }
return false; // don't attack return false; // don't attack
} }

View File

@@ -1,31 +1,43 @@
package forge; package forge;
import forge.card.cardFactory.CardFactoryUtil;
import java.util.ArrayList; import java.util.ArrayList;
import forge.card.cardFactory.CardFactoryUtil;
/** /**
* <p>ComputerUtil_Block2 class.</p> * <p>
* ComputerUtil_Block2 class.
* </p>
* *
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
public class ComputerUtil_Block2 { public class ComputerUtil_Block2 {
/** Constant <code>attackers</code> */ /** Constant <code>attackers</code>. */
private static CardList attackers = new CardList(); // all attackers private static CardList attackers = new CardList(); // all attackers
/** Constant <code>attackersLeft</code> */ /** Constant <code>attackersLeft</code>. */
private static CardList attackersLeft = new CardList(); //keeps track of all currently unblocked attackers private static CardList attackersLeft = new CardList(); // keeps track of
/** Constant <code>blockedButUnkilled</code> */ // all currently
private static CardList blockedButUnkilled = new CardList(); //blocked attackers that currently wouldn't be destroyed // unblocked
/** Constant <code>blockersLeft</code> */ // attackers
private static CardList blockersLeft = new CardList(); //keeps track of all unassigned blockers /** Constant <code>blockedButUnkilled</code>. */
/** Constant <code>diff=0</code> */ private static CardList blockedButUnkilled = new CardList(); // blocked
// attackers
// that
// currently
// wouldn't be
// destroyed
/** Constant <code>blockersLeft</code>. */
private static CardList blockersLeft = new CardList(); // keeps track of all
// unassigned
// blockers
/** Constant <code>diff=0</code>. */
private static int diff = 0; private static int diff = 0;
/** /**
* <p>Getter for the field <code>attackers</code>.</p> * <p>
* Getter for the field <code>attackers</code>.
* </p>
* *
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
@@ -34,16 +46,21 @@ public class ComputerUtil_Block2 {
} }
/** /**
* <p>Setter for the field <code>attackers</code>.</p> * <p>
* Setter for the field <code>attackers</code>.
* </p>
* *
* @param cardList a {@link forge.CardList} object. * @param cardList
* a {@link forge.CardList} object.
*/ */
private static void setAttackers(CardList cardList) { private static void setAttackers(final CardList cardList) {
attackers = (cardList); attackers = (cardList);
} }
/** /**
* <p>Getter for the field <code>attackersLeft</code>.</p> * <p>
* Getter for the field <code>attackersLeft</code>.
* </p>
* *
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
@@ -52,16 +69,21 @@ public class ComputerUtil_Block2 {
} }
/** /**
* <p>Setter for the field <code>attackersLeft</code>.</p> * <p>
* Setter for the field <code>attackersLeft</code>.
* </p>
* *
* @param cardList a {@link forge.CardList} object. * @param cardList
* a {@link forge.CardList} object.
*/ */
private static void setAttackersLeft(CardList cardList) { private static void setAttackersLeft(final CardList cardList) {
attackersLeft = (cardList); attackersLeft = (cardList);
} }
/** /**
* <p>Getter for the field <code>blockedButUnkilled</code>.</p> * <p>
* Getter for the field <code>blockedButUnkilled</code>.
* </p>
* *
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
@@ -71,16 +93,21 @@ public class ComputerUtil_Block2 {
} }
/** /**
* <p>Setter for the field <code>blockedButUnkilled</code>.</p> * <p>
* Setter for the field <code>blockedButUnkilled</code>.
* </p>
* *
* @param cardList a {@link forge.CardList} object. * @param cardList
* a {@link forge.CardList} object.
*/ */
private static void setBlockedButUnkilled(CardList cardList) { private static void setBlockedButUnkilled(final CardList cardList) {
blockedButUnkilled = (cardList); blockedButUnkilled = (cardList);
} }
/** /**
* <p>Getter for the field <code>blockersLeft</code>.</p> * <p>
* Getter for the field <code>blockersLeft</code>.
* </p>
* *
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
@@ -89,16 +116,21 @@ public class ComputerUtil_Block2 {
} }
/** /**
* <p>Setter for the field <code>blockersLeft</code>.</p> * <p>
* Setter for the field <code>blockersLeft</code>.
* </p>
* *
* @param cardList a {@link forge.CardList} object. * @param cardList
* a {@link forge.CardList} object.
*/ */
private static void setBlockersLeft(CardList cardList) { private static void setBlockersLeft(final CardList cardList) {
blockersLeft = (cardList); blockersLeft = (cardList);
} }
/** /**
* <p>Getter for the field <code>diff</code>.</p> * <p>
* Getter for the field <code>diff</code>.
* </p>
* *
* @return a int. * @return a int.
*/ */
@@ -107,30 +139,40 @@ public class ComputerUtil_Block2 {
} }
/** /**
* <p>Setter for the field <code>diff</code>.</p> * <p>
* Setter for the field <code>diff</code>.
* </p>
* *
* @param diff a int. * @param diff
* a int.
*/ */
private static void setDiff(int diff) { private static void setDiff(final int diff) {
ComputerUtil_Block2.diff = (diff); ComputerUtil_Block2.diff = (diff);
} }
// finds the creatures able to block the attacker // finds the creatures able to block the attacker
/** /**
* <p>getPossibleBlockers.</p> * <p>
* getPossibleBlockers.
* </p>
* *
* @param attacker a {@link forge.Card} object. * @param attacker
* @param blockersLeft a {@link forge.CardList} object. * a {@link forge.Card} object.
* @param combat a {@link forge.Combat} object. * @param blockersLeft
* a {@link forge.CardList} object.
* @param combat
* a {@link forge.Combat} object.
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
private static CardList getPossibleBlockers(Card attacker, CardList blockersLeft, Combat combat) { private static CardList getPossibleBlockers(final Card attacker, final CardList blockersLeft, Combat combat) {
CardList blockers = new CardList(); CardList blockers = new CardList();
for (Card blocker : blockersLeft) { for (Card blocker : blockersLeft) {
//if the blocker can block a creature with lure it can't block a creature without // if the blocker can block a creature with lure it can't block a
if (CombatUtil.canBlock(attacker, blocker, combat)) blockers.add(blocker); // creature without
if (CombatUtil.canBlock(attacker, blocker, combat)) {
blockers.add(blocker);
}
} }
return blockers; return blockers;
@@ -138,18 +180,25 @@ public class ComputerUtil_Block2 {
// finds blockers that won't be destroyed // finds blockers that won't be destroyed
/** /**
* <p>getSafeBlockers.</p> * <p>
* getSafeBlockers.
* </p>
* *
* @param attacker a {@link forge.Card} object. * @param attacker
* @param blockersLeft a {@link forge.CardList} object. * a {@link forge.Card} object.
* @param combat a {@link forge.Combat} object. * @param blockersLeft
* a {@link forge.CardList} object.
* @param combat
* a {@link forge.Combat} object.
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
private static CardList getSafeBlockers(Card attacker, CardList blockersLeft, Combat combat) { private static CardList getSafeBlockers(final Card attacker, final CardList blockersLeft, Combat combat) {
CardList blockers = new CardList(); CardList blockers = new CardList();
for (Card b : blockersLeft) { for (Card b : blockersLeft) {
if (!CombatUtil.canDestroyBlocker(b, attacker, combat, false)) blockers.add(b); if (!CombatUtil.canDestroyBlocker(b, attacker, combat, false)) {
blockers.add(b);
}
} }
return blockers; return blockers;
@@ -157,30 +206,40 @@ public class ComputerUtil_Block2 {
// finds blockers that destroy the attacker // finds blockers that destroy the attacker
/** /**
* <p>getKillingBlockers.</p> * <p>
* getKillingBlockers.
* </p>
* *
* @param attacker a {@link forge.Card} object. * @param attacker
* @param blockersLeft a {@link forge.CardList} object. * a {@link forge.Card} object.
* @param combat a {@link forge.Combat} object. * @param blockersLeft
* a {@link forge.CardList} object.
* @param combat
* a {@link forge.Combat} object.
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
private static CardList getKillingBlockers(Card attacker, CardList blockersLeft, Combat combat) { private static CardList getKillingBlockers(final Card attacker, final CardList blockersLeft, Combat combat) {
CardList blockers = new CardList(); CardList blockers = new CardList();
for (Card b : blockersLeft) { for (Card b : blockersLeft) {
if (CombatUtil.canDestroyAttacker(attacker, b, combat, false)) blockers.add(b); if (CombatUtil.canDestroyAttacker(attacker, b, combat, false)) {
blockers.add(b);
}
} }
return blockers; return blockers;
} }
/** /**
* <p>sortPotentialAttackers.</p> * <p>
* sortPotentialAttackers.
* </p>
* *
* @param combat a {@link forge.Combat} object. * @param combat
* a {@link forge.Combat} object.
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
public static CardList sortPotentialAttackers(Combat combat) { public static CardList sortPotentialAttackers(final Combat combat) {
CardList[] attackerLists = combat.sortAttackerByDefender(); CardList[] attackerLists = combat.sortAttackerByDefender();
CardList sortedAttackers = new CardList(); CardList sortedAttackers = new CardList();
@@ -191,45 +250,55 @@ public class ComputerUtil_Block2 {
CardListUtil.sortAttack(attackerLists[0]); CardListUtil.sortAttack(attackerLists[0]);
// If I don't have any planeswalkers than sorting doesn't really matter // If I don't have any planeswalkers than sorting doesn't really matter
if (defenders.size() == 1) if (defenders.size() == 1) {
return attackerLists[0]; return attackerLists[0];
}
boolean bLifeInDanger = CombatUtil.lifeInDanger(combat); boolean bLifeInDanger = CombatUtil.lifeInDanger(combat);
// TODO: Add creatures attacking Planeswalkers in order of which we want to protect // TODO Add creatures attacking Planeswalkers in order of which we want
// defend planeswalkers with more loyalty before planeswalkers with less loyalty // to protect
// defend planeswalkers with more loyalty before planeswalkers with less
// loyalty
// if planeswalker will be too difficult to defend don't even bother // if planeswalker will be too difficult to defend don't even bother
for (int i = 1; i < attackerLists.length; i++) { for (int i = 1; i < attackerLists.length; i++) {
// Begin with the attackers that pose the biggest threat // Begin with the attackers that pose the biggest threat
CardListUtil.sortAttack(attackerLists[i]); CardListUtil.sortAttack(attackerLists[i]);
for (Card c : attackerLists[i]) for (Card c : attackerLists[i]) {
sortedAttackers.add(c); sortedAttackers.add(c);
} }
}
if (bLifeInDanger) { if (bLifeInDanger) {
// add creatures attacking the Player to the front of the list // add creatures attacking the Player to the front of the list
for (Card c : attackerLists[0]) for (Card c : attackerLists[0]) {
sortedAttackers.add(0, c); sortedAttackers.add(0, c);
}
} else { } else {
// add creatures attacking the Player to the back of the list // add creatures attacking the Player to the back of the list
for (Card c : attackerLists[0]) for (Card c : attackerLists[0]) {
sortedAttackers.add(c); sortedAttackers.add(c);
} }
}
return sortedAttackers; return sortedAttackers;
} }
// ======================= block assignment functions ================================ // ======================= block assignment functions
// ================================
// Good Blocks means a good trade or no trade // Good Blocks means a good trade or no trade
/** /**
* <p>makeGoodBlocks.</p> * <p>
* makeGoodBlocks.
* </p>
* *
* @param combat a {@link forge.Combat} object. * @param combat
* a {@link forge.Combat} object.
* @return a {@link forge.Combat} object. * @return a {@link forge.Combat} object.
*/ */
private static Combat makeGoodBlocks(Combat combat) { private static Combat makeGoodBlocks(final Combat combat) {
CardList currentAttackers = new CardList(getAttackersLeft().toArray()); CardList currentAttackers = new CardList(getAttackersLeft().toArray());
@@ -243,12 +312,12 @@ public class ComputerUtil_Block2 {
CardList killingBlockers; CardList killingBlockers;
if (safeBlockers.size() > 0) { if (safeBlockers.size() > 0) {
// 1.Blockers that can destroy the attacker but won't get destroyed // 1.Blockers that can destroy the attacker but won't get
// destroyed
killingBlockers = getKillingBlockers(attacker, safeBlockers, combat); killingBlockers = getKillingBlockers(attacker, safeBlockers, combat);
if (killingBlockers.size() > 0) blocker = CardFactoryUtil.AI_getWorstCreature(killingBlockers); if (killingBlockers.size() > 0) {
blocker = CardFactoryUtil.AI_getWorstCreature(killingBlockers);
// 2.Blockers that won't get destroyed } else {
else {
blocker = CardFactoryUtil.AI_getWorstCreature(safeBlockers); blocker = CardFactoryUtil.AI_getWorstCreature(safeBlockers);
getBlockedButUnkilled().add(attacker); getBlockedButUnkilled().add(attacker);
} }
@@ -256,10 +325,13 @@ public class ComputerUtil_Block2 {
else { else {
killingBlockers = getKillingBlockers(attacker, blockers, combat); killingBlockers = getKillingBlockers(attacker, blockers, combat);
if (killingBlockers.size() > 0) { if (killingBlockers.size() > 0) {
// 3.Blockers that can destroy the attacker and are worth less // 3.Blockers that can destroy the attacker and are worth
// less
Card worst = CardFactoryUtil.AI_getWorstCreature(killingBlockers); Card worst = CardFactoryUtil.AI_getWorstCreature(killingBlockers);
if (CardFactoryUtil.evaluateCreature(worst) + getDiff() < CardFactoryUtil.evaluateCreature(attacker)) { if (CardFactoryUtil.evaluateCreature(worst) + getDiff() < CardFactoryUtil
.evaluateCreature(attacker))
{
blocker = worst; blocker = worst;
} }
} }
@@ -276,34 +348,43 @@ public class ComputerUtil_Block2 {
// Good Gang Blocks means a good trade or no trade // Good Gang Blocks means a good trade or no trade
/** /**
* <p>makeGangBlocks.</p> * <p>
* makeGangBlocks.
* </p>
* *
* @param combat a {@link forge.Combat} object. * @param combat
* a {@link forge.Combat} object.
* @return a {@link forge.Combat} object. * @return a {@link forge.Combat} object.
*/ */
private static Combat makeGangBlocks(Combat combat) { private static Combat makeGangBlocks(final Combat combat) {
CardList currentAttackers = new CardList(getAttackersLeft().toArray()); CardList currentAttackers = new CardList(getAttackersLeft().toArray());
currentAttackers = currentAttackers.getKeywordsDontContain("Rampage"); currentAttackers = currentAttackers.getKeywordsDontContain("Rampage");
currentAttackers = currentAttackers.getKeywordsDontContain("CARDNAME can't be blocked by more than one creature."); currentAttackers = currentAttackers
.getKeywordsDontContain("CARDNAME can't be blocked by more than one creature.");
CardList blockers; CardList blockers;
//Try to block an attacker without first strike with a gang of first strikers // Try to block an attacker without first strike with a gang of first
// strikers
for (Card attacker : getAttackersLeft()) { for (Card attacker : getAttackersLeft()) {
if (!attacker.hasKeyword("First Strike") if (!attacker.hasKeyword("First Strike") && !attacker.hasKeyword("Double Strike")) {
&& !attacker.hasKeyword("Double Strike")) {
blockers = getPossibleBlockers(attacker, getBlockersLeft(), combat); blockers = getPossibleBlockers(attacker, getBlockersLeft(), combat);
CardList firstStrikeBlockers = new CardList(); CardList firstStrikeBlockers = new CardList();
CardList blockGang = new CardList(); CardList blockGang = new CardList();
for (int i = 0; i < blockers.size(); i++) for (int i = 0; i < blockers.size(); i++) {
if (blockers.get(i).hasFirstStrike() || blockers.get(i).hasDoubleStrike()) if (blockers.get(i).hasFirstStrike() || blockers.get(i).hasDoubleStrike()) {
firstStrikeBlockers.add(blockers.get(i)); firstStrikeBlockers.add(blockers.get(i));
}
}
if (firstStrikeBlockers.size() > 1) { if (firstStrikeBlockers.size() > 1) {
CardListUtil.sortAttack(firstStrikeBlockers); CardListUtil.sortAttack(firstStrikeBlockers);
for (Card blocker : firstStrikeBlockers) { for (Card blocker : firstStrikeBlockers) {
int damageNeeded = attacker.getKillDamage() + CombatUtil.predictToughnessBonusOfAttacker(attacker, blocker, combat); int damageNeeded = attacker.getKillDamage()
//if the total damage of the blockgang was not enough without but is enough with this blocker finish the blockgang + CombatUtil.predictToughnessBonusOfAttacker(attacker, blocker, combat);
// if the total damage of the blockgang was not enough
// without but is enough with this blocker finish the
// blockgang
if (CombatUtil.totalDamageOfBlockers(attacker, blockGang) < damageNeeded) { if (CombatUtil.totalDamageOfBlockers(attacker, blockGang) < damageNeeded) {
blockGang.add(blocker); blockGang.add(blocker);
if (CombatUtil.totalDamageOfBlockers(attacker, blockGang) >= damageNeeded) { if (CombatUtil.totalDamageOfBlockers(attacker, blockGang) >= damageNeeded) {
@@ -327,21 +408,27 @@ public class ComputerUtil_Block2 {
blockers = getPossibleBlockers(attacker, getBlockersLeft(), combat); blockers = getPossibleBlockers(attacker, getBlockersLeft(), combat);
CardList usableBlockers; CardList usableBlockers;
CardList blockGang = new CardList(); CardList blockGang = new CardList();
int absorbedDamage = 0; //The amount of damage needed to kill the first blocker int absorbedDamage = 0; // The amount of damage needed to kill the
// first blocker
int currentValue = 0; // The value of the creatures in the blockgang int currentValue = 0; // The value of the creatures in the blockgang
//Try to add blockers that could be destroyed, but are worth less than the attacker // Try to add blockers that could be destroyed, but are worth less
//Don't use blockers without First Strike or Double Strike if attacker has it // than the attacker
// Don't use blockers without First Strike or Double Strike if
// attacker has it
usableBlockers = blockers.filter(new CardListFilter() { usableBlockers = blockers.filter(new CardListFilter() {
public boolean addCard(Card c) { public boolean addCard(final Card c) {
if ((attacker.hasKeyword("First Strike") || attacker.hasKeyword("Double Strike")) if ((attacker.hasKeyword("First Strike") || attacker.hasKeyword("Double Strike"))
&& !(c.hasKeyword("First Strike") || c.hasKeyword("Double Strike"))) && !(c.hasKeyword("First Strike") || c.hasKeyword("Double Strike")))
{
return false; return false;
}
return CardFactoryUtil.evaluateCreature(c) + getDiff() < CardFactoryUtil.evaluateCreature(attacker); return CardFactoryUtil.evaluateCreature(c) + getDiff() < CardFactoryUtil.evaluateCreature(attacker);
} }
}); });
if (usableBlockers.size() < 2) if (usableBlockers.size() < 2) {
return combat; return combat;
}
Card leader = CardFactoryUtil.AI_getBestCreature(usableBlockers); Card leader = CardFactoryUtil.AI_getBestCreature(usableBlockers);
blockGang.add(leader); blockGang.add(leader);
@@ -350,17 +437,23 @@ public class ComputerUtil_Block2 {
currentValue = CardFactoryUtil.evaluateCreature(leader); currentValue = CardFactoryUtil.evaluateCreature(leader);
for (Card blocker : usableBlockers) { for (Card blocker : usableBlockers) {
//Add an additional blocker if the current blockers are not enough and the new one would deal the remaining damage // Add an additional blocker if the current blockers are not
// enough and the new one would deal the remaining damage
int currentDamage = CombatUtil.totalDamageOfBlockers(attacker, blockGang); int currentDamage = CombatUtil.totalDamageOfBlockers(attacker, blockGang);
int additionalDamage = CombatUtil.dealsDamageAsBlocker(attacker, blocker); int additionalDamage = CombatUtil.dealsDamageAsBlocker(attacker, blocker);
int absorbedDamage2 = blocker.getEnoughDamageToKill(attacker.getNetCombatDamage(), attacker, true); int absorbedDamage2 = blocker.getEnoughDamageToKill(attacker.getNetCombatDamage(), attacker, true);
int addedValue = CardFactoryUtil.evaluateCreature(blocker); int addedValue = CardFactoryUtil.evaluateCreature(blocker);
int damageNeeded = attacker.getKillDamage() + CombatUtil.predictToughnessBonusOfAttacker(attacker, blocker, combat); int damageNeeded = attacker.getKillDamage()
if (damageNeeded > currentDamage + CombatUtil.predictToughnessBonusOfAttacker(attacker, blocker, combat);
&& !(damageNeeded > currentDamage + additionalDamage) //The attacker will be killed if (damageNeeded > currentDamage && !(damageNeeded > currentDamage + additionalDamage)
&& (absorbedDamage2 + absorbedDamage > attacker.getNetCombatDamage() //only one blocker can be killed // The attacker will be killed
|| currentValue + addedValue - 50 <= CardFactoryUtil.evaluateCreature(attacker)) //attacker is worth more && (absorbedDamage2 + absorbedDamage > attacker.getNetCombatDamage()
&& CombatUtil.canBlock(attacker, blocker, combat)) {//this is needed for attackers that can't be blocked by more than 1 // only one blocker can be killed
|| currentValue + addedValue - 50 <= CardFactoryUtil.evaluateCreature(attacker))
// attacker is worth more
&& CombatUtil.canBlock(attacker, blocker, combat))
{
// this is needed for attackers that can't be blocked by more than 1
currentAttackers.remove(attacker); currentAttackers.remove(attacker);
combat.addBlocker(attacker, blocker); combat.addBlocker(attacker, blocker);
combat.addBlocker(attacker, leader); combat.addBlocker(attacker, leader);
@@ -377,19 +470,22 @@ public class ComputerUtil_Block2 {
// Bad Trade Blocks (should only be made if life is in danger) // Bad Trade Blocks (should only be made if life is in danger)
/** /**
* <p>makeTradeBlocks.</p> * <p>
* makeTradeBlocks.
* </p>
* *
* @param combat a {@link forge.Combat} object. * @param combat
* a {@link forge.Combat} object.
* @return a {@link forge.Combat} object. * @return a {@link forge.Combat} object.
*/ */
private static Combat makeTradeBlocks(Combat combat) { private static Combat makeTradeBlocks(final Combat combat) {
CardList currentAttackers = new CardList(getAttackersLeft().toArray()); CardList currentAttackers = new CardList(getAttackersLeft().toArray());
CardList killingBlockers; CardList killingBlockers;
for (Card attacker : getAttackersLeft()) { for (Card attacker : getAttackersLeft()) {
killingBlockers = killingBlockers = getKillingBlockers(attacker, getPossibleBlockers(attacker, getBlockersLeft(), combat),
getKillingBlockers(attacker, getPossibleBlockers(attacker, getBlockersLeft(), combat), combat); combat);
if (killingBlockers.size() > 0 && CombatUtil.lifeInDanger(combat)) { if (killingBlockers.size() > 0 && CombatUtil.lifeInDanger(combat)) {
Card blocker = CardFactoryUtil.AI_getWorstCreature(killingBlockers); Card blocker = CardFactoryUtil.AI_getWorstCreature(killingBlockers);
combat.addBlocker(attacker, blocker); combat.addBlocker(attacker, blocker);
@@ -403,12 +499,15 @@ public class ComputerUtil_Block2 {
// Chump Blocks (should only be made if life is in danger) // Chump Blocks (should only be made if life is in danger)
/** /**
* <p>makeChumpBlocks.</p> * <p>
* makeChumpBlocks.
* </p>
* *
* @param combat a {@link forge.Combat} object. * @param combat
* a {@link forge.Combat} object.
* @return a {@link forge.Combat} object. * @return a {@link forge.Combat} object.
*/ */
private static Combat makeChumpBlocks(Combat combat) { private static Combat makeChumpBlocks(final Combat combat) {
CardList currentAttackers = new CardList(getAttackersLeft().toArray()); CardList currentAttackers = new CardList(getAttackersLeft().toArray());
CardList chumpBlockers; CardList chumpBlockers;
@@ -427,30 +526,42 @@ public class ComputerUtil_Block2 {
return combat; return combat;
} }
//Reinforce blockers blocking attackers with trample (should only be made if life is in danger) // Reinforce blockers blocking attackers with trample (should only be made
// if life is in danger)
/** /**
* <p>reinforceBlockersAgainstTrample.</p> * <p>
* reinforceBlockersAgainstTrample.
* </p>
* *
* @param combat a {@link forge.Combat} object. * @param combat
* a {@link forge.Combat} object.
* @return a {@link forge.Combat} object. * @return a {@link forge.Combat} object.
*/ */
private static Combat reinforceBlockersAgainstTrample(Combat combat) { private static Combat reinforceBlockersAgainstTrample(final Combat combat) {
CardList chumpBlockers; CardList chumpBlockers;
CardList tramplingAttackers = getAttackers().getKeyword("Trample"); CardList tramplingAttackers = getAttackers().getKeyword("Trample");
tramplingAttackers = tramplingAttackers.getKeywordsDontContain("Rampage"); //Don't make it worse tramplingAttackers = tramplingAttackers.getKeywordsDontContain("Rampage"); // Don't
tramplingAttackers = tramplingAttackers.getKeywordsDontContain("CARDNAME can't be blocked by more than one creature."); // make
//TODO - should check here for a "rampage-like" trigger that replaced the keyword: // it
// worse
tramplingAttackers = tramplingAttackers
.getKeywordsDontContain("CARDNAME can't be blocked by more than one creature.");
// TODO - should check here for a "rampage-like" trigger that replaced
// the keyword:
// "Whenever CARDNAME becomes blocked, it gets +1/+1 until end of turn for each creature blocking it." // "Whenever CARDNAME becomes blocked, it gets +1/+1 until end of turn for each creature blocking it."
for (Card attacker : tramplingAttackers) { for (Card attacker : tramplingAttackers) {
chumpBlockers = getPossibleBlockers(attacker, getBlockersLeft(), combat); chumpBlockers = getPossibleBlockers(attacker, getBlockersLeft(), combat);
for (Card blocker : chumpBlockers) { for (Card blocker : chumpBlockers) {
//Add an additional blocker if the current blockers are not enough and the new one would suck some of the damage // Add an additional blocker if the current blockers are not
if (CombatUtil.getAttack(attacker) > CombatUtil.totalShieldDamage(attacker, combat.getBlockers(attacker)) // enough and the new one would suck some of the damage
&& CombatUtil.shieldDamage(attacker, blocker) > 0 && CombatUtil.canBlock(attacker, blocker, combat) if (CombatUtil.getAttack(attacker) > CombatUtil.totalShieldDamage(attacker,
&& CombatUtil.lifeInDanger(combat)) { combat.getBlockers(attacker))
&& CombatUtil.shieldDamage(attacker, blocker) > 0
&& CombatUtil.canBlock(attacker, blocker, combat) && CombatUtil.lifeInDanger(combat))
{
combat.addBlocker(attacker, blocker); combat.addBlocker(attacker, blocker);
getBlockersLeft().remove(blocker); getBlockersLeft().remove(blocker);
} }
@@ -460,20 +571,29 @@ public class ComputerUtil_Block2 {
return combat; return combat;
} }
//Support blockers not destroying the attacker with more blockers to try to kill the attacker // Support blockers not destroying the attacker with more blockers to try to
// kill the attacker
/** /**
* <p>reinforceBlockersToKill.</p> * <p>
* reinforceBlockersToKill.
* </p>
* *
* @param combat a {@link forge.Combat} object. * @param combat
* a {@link forge.Combat} object.
* @return a {@link forge.Combat} object. * @return a {@link forge.Combat} object.
*/ */
private static Combat reinforceBlockersToKill(Combat combat) { private static Combat reinforceBlockersToKill(final Combat combat) {
CardList safeBlockers; CardList safeBlockers;
CardList blockers; CardList blockers;
CardList targetAttackers = getBlockedButUnkilled().getKeywordsDontContain("Rampage"); //Don't make it worse CardList targetAttackers = getBlockedButUnkilled().getKeywordsDontContain("Rampage"); // Don't
targetAttackers = targetAttackers.getKeywordsDontContain("CARDNAME can't be blocked by more than one creature."); // make
//TODO - should check here for a "rampage-like" trigger that replaced the keyword: // it
// worse
targetAttackers = targetAttackers
.getKeywordsDontContain("CARDNAME can't be blocked by more than one creature.");
// TODO - should check here for a "rampage-like" trigger that replaced
// the keyword:
// "Whenever CARDNAME becomes blocked, it gets +1/+1 until end of turn for each creature blocking it." // "Whenever CARDNAME becomes blocked, it gets +1/+1 until end of turn for each creature blocking it."
for (Card attacker : targetAttackers) { for (Card attacker : targetAttackers) {
@@ -482,32 +602,43 @@ public class ComputerUtil_Block2 {
// Try to use safe blockers first // Try to use safe blockers first
safeBlockers = getSafeBlockers(attacker, blockers, combat); safeBlockers = getSafeBlockers(attacker, blockers, combat);
for (Card blocker : safeBlockers) { for (Card blocker : safeBlockers) {
int damageNeeded = attacker.getKillDamage() + CombatUtil.predictToughnessBonusOfAttacker(attacker, blocker, combat); int damageNeeded = attacker.getKillDamage()
//Add an additional blocker if the current blockers are not enough and the new one would deal additional damage + CombatUtil.predictToughnessBonusOfAttacker(attacker, blocker, combat);
// Add an additional blocker if the current blockers are not
// enough and the new one would deal additional damage
if (damageNeeded > CombatUtil.totalDamageOfBlockers(attacker, combat.getBlockers(attacker)) if (damageNeeded > CombatUtil.totalDamageOfBlockers(attacker, combat.getBlockers(attacker))
&& CombatUtil.dealsDamageAsBlocker(attacker, blocker) > 0 && CombatUtil.canBlock(attacker, blocker, combat)) { && CombatUtil.dealsDamageAsBlocker(attacker, blocker) > 0
&& CombatUtil.canBlock(attacker, blocker, combat))
{
combat.addBlocker(attacker, blocker); combat.addBlocker(attacker, blocker);
getBlockersLeft().remove(blocker); getBlockersLeft().remove(blocker);
} }
blockers.remove(blocker); // Don't check them again next blockers.remove(blocker); // Don't check them again next
} }
//Try to add blockers that could be destroyed, but are worth less than the attacker // Try to add blockers that could be destroyed, but are worth less
//Don't use blockers without First Strike or Double Strike if attacker has it // than the attacker
// Don't use blockers without First Strike or Double Strike if
// attacker has it
if (attacker.hasKeyword("First Strike") || attacker.hasKeyword("Double Strike")) { if (attacker.hasKeyword("First Strike") || attacker.hasKeyword("Double Strike")) {
safeBlockers = blockers.getKeyword("First Strike"); safeBlockers = blockers.getKeyword("First Strike");
safeBlockers.addAll(blockers.getKeyword("Double Strike")); safeBlockers.addAll(blockers.getKeyword("Double Strike"));
} else safeBlockers = new CardList(blockers.toArray()); } else {
safeBlockers = new CardList(blockers.toArray());
}
for (Card blocker : safeBlockers) { for (Card blocker : safeBlockers) {
int damageNeeded = attacker.getKillDamage() + CombatUtil.predictToughnessBonusOfAttacker(attacker, blocker, combat); int damageNeeded = attacker.getKillDamage()
//Add an additional blocker if the current blockers are not enough and the new one would deal the remaining damage + CombatUtil.predictToughnessBonusOfAttacker(attacker, blocker, combat);
// Add an additional blocker if the current blockers are not
// enough and the new one would deal the remaining damage
int currentDamage = CombatUtil.totalDamageOfBlockers(attacker, combat.getBlockers(attacker)); int currentDamage = CombatUtil.totalDamageOfBlockers(attacker, combat.getBlockers(attacker));
int additionalDamage = CombatUtil.dealsDamageAsBlocker(attacker, blocker); int additionalDamage = CombatUtil.dealsDamageAsBlocker(attacker, blocker);
if (damageNeeded > currentDamage if (damageNeeded > currentDamage
&& !(damageNeeded > currentDamage + additionalDamage) && !(damageNeeded > currentDamage + additionalDamage)
&& CardFactoryUtil.evaluateCreature(blocker) + getDiff() < CardFactoryUtil.evaluateCreature(attacker) && CardFactoryUtil.evaluateCreature(blocker) + getDiff() < CardFactoryUtil
&& CombatUtil.canBlock(attacker, blocker, combat)) { .evaluateCreature(attacker) && CombatUtil.canBlock(attacker, blocker, combat))
{
combat.addBlocker(attacker, blocker); combat.addBlocker(attacker, blocker);
getBlockersLeft().removeAll(blocker); getBlockersLeft().removeAll(blocker);
} }
@@ -518,50 +649,83 @@ public class ComputerUtil_Block2 {
} }
/** /**
* <p>resetBlockers.</p> * <p>
* resetBlockers.
* </p>
* *
* @param combat a {@link forge.Combat} object. * @param combat
* @param possibleBlockers a {@link forge.CardList} object. * a {@link forge.Combat} object.
* @param possibleBlockers
* a {@link forge.CardList} object.
* @return a {@link forge.Combat} object. * @return a {@link forge.Combat} object.
*/ */
private static Combat resetBlockers(Combat combat, CardList possibleBlockers) { private static Combat resetBlockers(final Combat combat, final CardList possibleBlockers) {
CardList oldBlockers = combat.getAllBlockers(); CardList oldBlockers = combat.getAllBlockers();
for (Card blocker : oldBlockers) { for (Card blocker : oldBlockers) {
combat.removeFromCombat(blocker); combat.removeFromCombat(blocker);
} }
setAttackersLeft(new CardList(getAttackers().toArray())); //keeps track of all currently unblocked attackers setAttackersLeft(new CardList(getAttackers().toArray())); // keeps track
setBlockersLeft(new CardList(possibleBlockers.toArray())); //keeps track of all unassigned blockers // of all
setBlockedButUnkilled(new CardList()); //keeps track of all blocked attackers that currently wouldn't be destroyed // currently
// unblocked
// attackers
setBlockersLeft(new CardList(possibleBlockers.toArray())); // keeps
// track of
// all
// unassigned
// blockers
setBlockedButUnkilled(new CardList()); // keeps track of all blocked
// attackers that currently
// wouldn't be destroyed
return combat; return combat;
} }
// Main function // Main function
/** /**
* <p>getBlockers.</p> * <p>
* getBlockers.
* </p>
* *
* @param originalCombat a {@link forge.Combat} object. * @param originalCombat
* @param possibleBlockers a {@link forge.CardList} object. * a {@link forge.Combat} object.
* @param possibleBlockers
* a {@link forge.CardList} object.
* @return a {@link forge.Combat} object. * @return a {@link forge.Combat} object.
*/ */
static public Combat getBlockers(Combat originalCombat, CardList possibleBlockers) { public static Combat getBlockers(final Combat originalCombat, final CardList possibleBlockers) {
Combat combat = originalCombat; Combat combat = originalCombat;
setAttackers(sortPotentialAttackers(combat)); setAttackers(sortPotentialAttackers(combat));
if (getAttackers().size() == 0) if (getAttackers().size() == 0) {
return combat; return combat;
}
setAttackersLeft(new CardList(getAttackers().toArray())); //keeps track of all currently unblocked attackers setAttackersLeft(new CardList(getAttackers().toArray())); // keeps track
setBlockersLeft(new CardList(possibleBlockers.toArray())); //keeps track of all unassigned blockers // of all
setBlockedButUnkilled(new CardList()); //keeps track of all blocked attackers that currently wouldn't be destroyed // currently
// unblocked
// attackers
setBlockersLeft(new CardList(possibleBlockers.toArray())); // keeps
// track of
// all
// unassigned
// blockers
setBlockedButUnkilled(new CardList()); // keeps track of all blocked
// attackers that currently
// wouldn't be destroyed
CardList blockers; CardList blockers;
CardList chumpBlockers; CardList chumpBlockers;
setDiff(AllZone.getComputerPlayer().getLife() * 2 - 5); //This is the minimal gain for an unnecessary trade setDiff(AllZone.getComputerPlayer().getLife() * 2 - 5); // This is the
// minimal gain
// for an
// unnecessary
// trade
// remove all attackers that can't be blocked anyway // remove all attackers that can't be blocked anyway
for (Card a : getAttackers()) { for (Card a : getAttackers()) {
@@ -572,11 +736,14 @@ public class ComputerUtil_Block2 {
// remove all blockers that can't block anyway // remove all blockers that can't block anyway
for (Card b : possibleBlockers) { for (Card b : possibleBlockers) {
if (!CombatUtil.canBlock(b, combat)) getBlockersLeft().remove(b); if (!CombatUtil.canBlock(b, combat)) {
getBlockersLeft().remove(b);
}
} }
if (getAttackersLeft().size() == 0) if (getAttackersLeft().size() == 0) {
return combat; return combat;
}
// Begin with the weakest blockers // Begin with the weakest blockers
CardListUtil.sortAttackLowFirst(getBlockersLeft()); CardListUtil.sortAttackLowFirst(getBlockersLeft());
@@ -584,40 +751,70 @@ public class ComputerUtil_Block2 {
// == 1. choose best blocks first == // == 1. choose best blocks first ==
combat = makeGoodBlocks(combat); combat = makeGoodBlocks(combat);
combat = makeGangBlocks(combat); combat = makeGangBlocks(combat);
if (CombatUtil.lifeInDanger(combat))
combat = makeTradeBlocks(combat); //choose necessary trade blocks if life is in danger
if (CombatUtil.lifeInDanger(combat))
combat = makeChumpBlocks(combat); //choose necessary chump blocks if life is still in danger
//Reinforce blockers blocking attackers with trample if life is still in danger
if (CombatUtil.lifeInDanger(combat)) combat = reinforceBlockersAgainstTrample(combat);
//Support blockers not destroying the attacker with more blockers to try to kill the attacker
if (!CombatUtil.lifeInDanger(combat)) combat = reinforceBlockersToKill(combat);
//== 2. If the AI life would still be in danger make a safer approach ==
if (CombatUtil.lifeInDanger(combat)) { if (CombatUtil.lifeInDanger(combat)) {
combat = resetBlockers(combat, possibleBlockers); // reset every block assignment combat = makeTradeBlocks(combat); // choose necessary trade blocks
combat = makeTradeBlocks(combat); //choose necessary trade blocks if life is in danger }
// if life is in danger
if (CombatUtil.lifeInDanger(combat)) {
combat = makeChumpBlocks(combat); // choose necessary chump blocks
}
// if life is still in danger
// Reinforce blockers blocking attackers with trample if life is still
// in danger
if (CombatUtil.lifeInDanger(combat)) {
combat = reinforceBlockersAgainstTrample(combat);
}
// Support blockers not destroying the attacker with more blockers to
// try to kill the attacker
if (!CombatUtil.lifeInDanger(combat)) {
combat = reinforceBlockersToKill(combat);
}
// == 2. If the AI life would still be in danger make a safer approach
// ==
if (CombatUtil.lifeInDanger(combat)) {
combat = resetBlockers(combat, possibleBlockers); // reset every
// block
// assignment
combat = makeTradeBlocks(combat); // choose necessary trade blocks
// if life is in danger
combat = makeGoodBlocks(combat); combat = makeGoodBlocks(combat);
if (CombatUtil.lifeInDanger(combat)) if (CombatUtil.lifeInDanger(combat)) {
combat = makeChumpBlocks(combat); //choose necessary chump blocks if life is still in danger combat = makeChumpBlocks(combat); // choose necessary chump
//Reinforce blockers blocking attackers with trample if life is still in danger }
if (CombatUtil.lifeInDanger(combat)) combat = reinforceBlockersAgainstTrample(combat); // blocks if life is still in
// danger
// Reinforce blockers blocking attackers with trample if life is
// still in danger
if (CombatUtil.lifeInDanger(combat)) {
combat = reinforceBlockersAgainstTrample(combat);
}
combat = makeGangBlocks(combat); combat = makeGangBlocks(combat);
combat = reinforceBlockersToKill(combat); combat = reinforceBlockersToKill(combat);
} }
//== 3. If the AI life would be in serious danger make an even safer approach == // == 3. If the AI life would be in serious danger make an even safer
// approach ==
if (CombatUtil.lifeInSeriousDanger(combat)) { if (CombatUtil.lifeInSeriousDanger(combat)) {
combat = resetBlockers(combat, possibleBlockers); // reset every block assignment combat = resetBlockers(combat, possibleBlockers); // reset every
// block
// assignment
combat = makeChumpBlocks(combat); // choose chump blocks combat = makeChumpBlocks(combat); // choose chump blocks
if (CombatUtil.lifeInDanger(combat)) if (CombatUtil.lifeInDanger(combat)) {
combat = makeTradeBlocks(combat); //choose necessary trade blocks if life is in danger combat = makeTradeBlocks(combat); // choose necessary trade
if (!CombatUtil.lifeInDanger(combat)) combat = makeGoodBlocks(combat); }
//Reinforce blockers blocking attackers with trample if life is still in danger // blocks if life is in danger
if (CombatUtil.lifeInDanger(combat)) combat = reinforceBlockersAgainstTrample(combat); if (!CombatUtil.lifeInDanger(combat)) {
combat = makeGoodBlocks(combat);
}
// Reinforce blockers blocking attackers with trample if life is
// still in danger
if (CombatUtil.lifeInDanger(combat)) {
combat = reinforceBlockersAgainstTrample(combat);
}
combat = makeGangBlocks(combat); combat = makeGangBlocks(combat);
//Support blockers not destroying the attacker with more blockers to try to kill the attacker // Support blockers not destroying the attacker with more blockers
// to try to kill the attacker
combat = reinforceBlockersToKill(combat); combat = reinforceBlockersToKill(combat);
} }
@@ -625,7 +822,9 @@ public class ComputerUtil_Block2 {
chumpBlockers = getBlockersLeft().getKeyword("CARDNAME blocks each turn if able."); chumpBlockers = getBlockersLeft().getKeyword("CARDNAME blocks each turn if able.");
// if an attacker with lure attacks - all that can block // if an attacker with lure attacks - all that can block
for (Card blocker : getBlockersLeft()) { for (Card blocker : getBlockersLeft()) {
if (CombatUtil.mustBlockAnAttacker(blocker, combat)) chumpBlockers.add(blocker); if (CombatUtil.mustBlockAnAttacker(blocker, combat)) {
chumpBlockers.add(blocker);
}
} }
if (!chumpBlockers.isEmpty()) { if (!chumpBlockers.isEmpty()) {
getAttackers().shuffle(); getAttackers().shuffle();

View File

@@ -1,42 +1,69 @@
package forge; package forge;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import forge.deck.Deck; import forge.deck.Deck;
import forge.game.GameType; import forge.game.GameType;
/** /**
* <p>Constant interface.</p> * <p>
* Constant interface.
* </p>
* *
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
public interface Constant { public interface Constant {
/** Constant <code>ProgramName="Forge - http://cardforge.org"</code> */ /** Constant <code>ProgramName="Forge - http://cardforge.org"</code> */
public static final String ProgramName = "Forge - http://cardforge.org"; String ProgramName = "Forge - http://cardforge.org";
// used to pass information between the GUI screens // used to pass information between the GUI screens
/**
* The Class Runtime.
*/
public abstract class Runtime { public abstract class Runtime {
/** The Constant HumanDeck. */
public static final Deck[] HumanDeck = new Deck[1]; public static final Deck[] HumanDeck = new Deck[1];
/** The Constant ComputerDeck. */
public static final Deck[] ComputerDeck = new Deck[1]; public static final Deck[] ComputerDeck = new Deck[1];
/** The game type. */
public static GameType gameType = GameType.Constructed; public static GameType gameType = GameType.Constructed;
/** The Constant Smooth. */
public static final boolean[] Smooth = new boolean[1]; public static final boolean[] Smooth = new boolean[1];
public static final boolean[] Mill = new boolean[1];
public static final boolean[] DevMode = new boolean[1]; // one for normal mode one for quest mode
/** The Constant Mill. */
public static final boolean[] Mill = new boolean[1];
/** The Constant DevMode. */
public static final boolean[] DevMode = new boolean[1]; // one for
// normal mode
// one for quest
// mode
/** The Constant NetConn. */
public static final boolean[] NetConn = new boolean[1]; public static final boolean[] NetConn = new boolean[1];
/** The Constant UpldDrft. */
public static final boolean[] UpldDrft = new boolean[1]; public static final boolean[] UpldDrft = new boolean[1];
/** The Constant RndCFoil. */
public static final boolean[] RndCFoil = new boolean[1]; public static final boolean[] RndCFoil = new boolean[1];
/** The Constant width. */
public static final int[] width = { 300 }; public static final int[] width = { 300 };
/** The Constant height. */
public static final int[] height = new int[1]; public static final int[] height = new int[1];
/** The Constant stackSize. */
public static final int[] stackSize = new int[1]; public static final int[] stackSize = new int[1];
/** The Constant stackOffset. */
public static final int[] stackOffset = new int[1]; public static final int[] stackOffset = new int[1];
} }
@@ -54,110 +81,253 @@ public interface Constant {
// public static final ImageIcon rightIcon = new ImageIcon("right.gif"); // public static final ImageIcon rightIcon = new ImageIcon("right.gif");
// } // }
/**
* The Interface Ability.
*/
public interface Ability { public interface Ability {
/** The Triggered. */
String Triggered = "Triggered"; String Triggered = "Triggered";
/** The Activated. */
String Activated = "Activated"; String Activated = "Activated";
} }
/**
* The Interface Phase.
*/
public interface Phase { public interface Phase {
public static final String Untap = "Untap";
public static final String Upkeep = "Upkeep";
public static final String Draw = "Draw";
public static final String Main1 = "Main1"; /** The Constant Untap. */
String Untap = "Untap";
public static final String Combat_Begin = "BeginCombat"; /** The Constant Upkeep. */
public static final String Combat_Declare_Attackers = "Declare Attackers"; String Upkeep = "Upkeep";
public static final String Combat_Declare_Attackers_InstantAbility = "Declare Attackers - Play Instants and Abilities";
public static final String Combat_Declare_Blockers = "Declare Blockers";
public static final String Combat_Declare_Blockers_InstantAbility = "Declare Blockers - Play Instants and Abilities";
public static final String Combat_Damage = "Combat Damage";
public static final String Combat_FirstStrikeDamage = "First Strike Damage";
public static final String Combat_End = "EndCombat";
public static final String Main2 = "Main2"; /** The Constant Draw. */
String Draw = "Draw";
public static final String End_Of_Turn = "End of Turn"; /** The Constant Main1. */
public static final String Cleanup = "Cleanup"; String Main1 = "Main1";
/** The Constant Combat_Begin. */
String Combat_Begin = "BeginCombat";
/** The Constant Combat_Declare_Attackers. */
String Combat_Declare_Attackers = "Declare Attackers";
/** The Constant Combat_Declare_Attackers_InstantAbility. */
String Combat_Declare_Attackers_InstantAbility = "Declare Attackers - Play Instants and Abilities";
/** The Constant Combat_Declare_Blockers. */
String Combat_Declare_Blockers = "Declare Blockers";
/** The Constant Combat_Declare_Blockers_InstantAbility. */
String Combat_Declare_Blockers_InstantAbility = "Declare Blockers - Play Instants and Abilities";
/** The Constant Combat_Damage. */
String Combat_Damage = "Combat Damage";
/** The Constant Combat_FirstStrikeDamage. */
String Combat_FirstStrikeDamage = "First Strike Damage";
/** The Constant Combat_End. */
String Combat_End = "EndCombat";
/** The Constant Main2. */
String Main2 = "Main2";
/** The Constant End_Of_Turn. */
String End_Of_Turn = "End of Turn";
/** The Constant Cleanup. */
String Cleanup = "Cleanup";
} }
/**
* The Enum Zone.
*/
public enum Zone { public enum Zone {
/** The Hand. */
Hand, Hand,
/** The Library. */
Library, Library,
/** The Graveyard. */
Graveyard, Graveyard,
/** The Battlefield. */
Battlefield, Battlefield,
/** The Exile. */
Exile, Exile,
/** The Command. */
Command, Command,
/** The Stack. */
Stack; Stack;
/**
* Smart value of.
*
* @param value
* the value
* @return the zone
*/
public static Zone smartValueOf(final String value) { public static Zone smartValueOf(final String value) {
if (value == null) { return null; } if (value == null) {
if ("All".equals(value)) { return null; } return null;
}
if ("All".equals(value)) {
return null;
}
String valToCompate = value.trim(); String valToCompate = value.trim();
for (Zone v : Zone.values()) { if (v.name().compareToIgnoreCase(valToCompate) == 0) { return v; } } for (Zone v : Zone.values()) {
if (v.name().compareToIgnoreCase(valToCompate) == 0) {
return v;
}
}
throw new IllegalArgumentException("No element named " + value + " in enum Zone"); throw new IllegalArgumentException("No element named " + value + " in enum Zone");
} }
/**
* List value of.
*
* @param values
* the values
* @return the list
*/
public static List<Zone> listValueOf(final String values) { public static List<Zone> listValueOf(final String values) {
List<Zone> result = new ArrayList<Constant.Zone>(); List<Zone> result = new ArrayList<Constant.Zone>();
for (String s : values.split("[, ]+")) { result.add(smartValueOf(s)); } for (String s : values.split("[, ]+")) {
result.add(smartValueOf(s));
}
return result; return result;
} }
} }
/**
* The Interface Color.
*/
public interface Color { public interface Color {
/** The Black. */
String Black = "black"; String Black = "black";
/** The Blue. */
String Blue = "blue"; String Blue = "blue";
/** The Green. */
String Green = "green"; String Green = "green";
/** The Red. */
String Red = "red"; String Red = "red";
/** The White. */
String White = "white"; String White = "white";
/** The Colorless. */
String Colorless = "colorless"; String Colorless = "colorless";
// color order "wubrg" // color order "wubrg"
/** The Colors. */
String[] Colors = { White, Blue, Black, Red, Green, Colorless }; String[] Colors = { White, Blue, Black, Red, Green, Colorless };
/** The only colors. */
String[] onlyColors = { White, Blue, Black, Red, Green }; String[] onlyColors = { White, Blue, Black, Red, Green };
/** The Snow. */
String Snow = "snow"; String Snow = "snow";
/** The Mana colors. */
String[] ManaColors = { White, Blue, Black, Red, Green, Colorless, Snow }; String[] ManaColors = { White, Blue, Black, Red, Green, Colorless, Snow };
/** The loaded. */
boolean[] loaded = { false }; boolean[] loaded = { false };
//public static final Constant_StringHashMap[] LandColor = new Constant_StringHashMap[1]; // public static final Constant_StringHashMap[] LandColor = new
// Constant_StringHashMap[1];
/** The Basic lands. */
String[] BasicLands = { "Plains", "Island", "Swamp", "Mountain", "Forest" }; String[] BasicLands = { "Plains", "Island", "Swamp", "Mountain", "Forest" };
} }
/**
* The Interface Quest.
*/
public interface Quest { public interface Quest {
/** The fantasy quest. */
boolean[] fantasyQuest = new boolean[1]; boolean[] fantasyQuest = new boolean[1];
// public static final Quest_Assignment[] qa = new Quest_Assignment[1]; // public static final Quest_Assignment[] qa = new Quest_Assignment[1];
/** The human list. */
CardList[] humanList = new CardList[1]; CardList[] humanList = new CardList[1];
/** The computer list. */
CardList[] computerList = new CardList[1]; CardList[] computerList = new CardList[1];
/** The human life. */
int[] humanLife = new int[1]; int[] humanLife = new int[1];
/** The computer life. */
int[] computerLife = new int[1]; int[] computerLife = new int[1];
/** The opp icon name. */
String[] oppIconName = new String[1]; String[] oppIconName = new String[1];
} }
/**
* The Interface CardTypes.
*/
public interface CardTypes { public interface CardTypes {
/** The loaded. */
boolean[] loaded = { false }; boolean[] loaded = { false };
/** The card types. */
Constant_StringArrayList[] cardTypes = new Constant_StringArrayList[1]; Constant_StringArrayList[] cardTypes = new Constant_StringArrayList[1];
/** The super types. */
Constant_StringArrayList[] superTypes = new Constant_StringArrayList[1]; Constant_StringArrayList[] superTypes = new Constant_StringArrayList[1];
/** The basic types. */
Constant_StringArrayList[] basicTypes = new Constant_StringArrayList[1]; Constant_StringArrayList[] basicTypes = new Constant_StringArrayList[1];
/** The land types. */
Constant_StringArrayList[] landTypes = new Constant_StringArrayList[1]; Constant_StringArrayList[] landTypes = new Constant_StringArrayList[1];
/** The creature types. */
Constant_StringArrayList[] creatureTypes = new Constant_StringArrayList[1]; Constant_StringArrayList[] creatureTypes = new Constant_StringArrayList[1];
/** The instant types. */
Constant_StringArrayList[] instantTypes = new Constant_StringArrayList[1]; Constant_StringArrayList[] instantTypes = new Constant_StringArrayList[1];
/** The sorcery types. */
Constant_StringArrayList[] sorceryTypes = new Constant_StringArrayList[1]; Constant_StringArrayList[] sorceryTypes = new Constant_StringArrayList[1];
/** The enchantment types. */
Constant_StringArrayList[] enchantmentTypes = new Constant_StringArrayList[1]; Constant_StringArrayList[] enchantmentTypes = new Constant_StringArrayList[1];
/** The artifact types. */
Constant_StringArrayList[] artifactTypes = new Constant_StringArrayList[1]; Constant_StringArrayList[] artifactTypes = new Constant_StringArrayList[1];
/** The walker types. */
Constant_StringArrayList[] walkerTypes = new Constant_StringArrayList[1]; Constant_StringArrayList[] walkerTypes = new Constant_StringArrayList[1];
} }
/**
* The Interface Keywords.
*/
public interface Keywords { public interface Keywords {
/** The loaded. */
boolean[] loaded = { false }; boolean[] loaded = { false };
/** The Non stacking list. */
Constant_StringArrayList[] NonStackingList = new Constant_StringArrayList[1]; Constant_StringArrayList[] NonStackingList = new Constant_StringArrayList[1];
} }
} // Constant } // Constant

View File

@@ -2,7 +2,12 @@ package forge;
import java.util.ArrayList; import java.util.ArrayList;
/**
* The Class Constant_StringArrayList.
*/
public class Constant_StringArrayList { public class Constant_StringArrayList {
/** The list. */
public ArrayList<String> list = new ArrayList<String>(); public ArrayList<String> list = new ArrayList<String>();
} }

View File

@@ -3,7 +3,12 @@ package forge;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
/**
* The Class Constant_StringHashMap.
*/
public class Constant_StringHashMap { public class Constant_StringHashMap {
/** The map. */
public Map<String, String> map = new HashMap<String, String>(); public Map<String, String> map = new HashMap<String, String>();
} }

View File

@@ -1,18 +1,24 @@
package forge; package forge;
import forge.properties.ForgeProps;
import forge.properties.NewConstants;
import javax.swing.*;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import javax.swing.SwingWorker;
import forge.properties.ForgeProps;
import forge.properties.NewConstants;
/** /**
* <p>CopyFiles class.</p> * <p>
* CopyFiles class.
* </p>
* *
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
@@ -20,22 +26,40 @@ import java.util.List;
public class CopyFiles extends SwingWorker<Void, Integer> implements NewConstants { public class CopyFiles extends SwingWorker<Void, Integer> implements NewConstants {
private List<File> FileList; private List<File> FileList;
/** The j lb. */
JLabel jLb; JLabel jLb;
/** The j b. */
JProgressBar jB; JProgressBar jB;
/** The j check. */
JCheckBox jCheck; JCheckBox jCheck;
/** The j source. */
JButton jSource; JButton jSource;
/** The count. */
int count; int count;
/** /**
* <p>Constructor for CopyFiles.</p> * <p>
* Constructor for CopyFiles.
* </p>
* *
* @param FileList a {@link java.util.List} object. * @param FileList
* @param jLabelTotalFiles a {@link javax.swing.JLabel} object. * a {@link java.util.List} object.
* @param Jbar a {@link javax.swing.JProgressBar} object. * @param jLabelTotalFiles
* @param jCheckBox a {@link javax.swing.JCheckBox} object. * a {@link javax.swing.JLabel} object.
* @param jButtonSource a {@link javax.swing.JButton} object. * @param Jbar
* a {@link javax.swing.JProgressBar} object.
* @param jCheckBox
* a {@link javax.swing.JCheckBox} object.
* @param jButtonSource
* a {@link javax.swing.JButton} object.
*/ */
public CopyFiles(List<File> FileList, JLabel jLabelTotalFiles, JProgressBar Jbar, JCheckBox jCheckBox, JButton jButtonSource) { public CopyFiles(final List<File> FileList, JLabel jLabelTotalFiles, JProgressBar Jbar, JCheckBox jCheckBox,
JButton jButtonSource) {
this.FileList = FileList; this.FileList = FileList;
jLb = jLabelTotalFiles; jLb = jLabelTotalFiles;
jB = Jbar; jB = Jbar;
@@ -45,7 +69,7 @@ public class CopyFiles extends SwingWorker<Void, Integer> implements NewConstant
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
protected Void doInBackground() { protected final Void doInBackground() {
for (int i = 0; i < this.FileList.size(); i++) { for (int i = 0; i < this.FileList.size(); i++) {
publish(); publish();
String cName, name, source; String cName, name, source;
@@ -66,7 +90,9 @@ public class CopyFiles extends SwingWorker<Void, Integer> implements NewConstant
int length; int length;
while (fis.available() > 0) { while (fis.available() > 0) {
length = fis.read(buff); length = fis.read(buff);
if (length > 0) fos.write(buff, 0, length); if (length > 0) {
fos.write(buff, 0, length);
}
} }
fos.flush(); fos.flush();
fis.close(); fis.close();
@@ -85,7 +111,7 @@ public class CopyFiles extends SwingWorker<Void, Integer> implements NewConstant
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
protected void done() { protected final void done() {
jLb.setText("All files were copied successfully."); jLb.setText("All files were copied successfully.");
jB.setIndeterminate(false); jB.setIndeterminate(false);
jCheck.setEnabled(true); jCheck.setEnabled(true);

View File

@@ -6,7 +6,6 @@
package forge; package forge;
/** /**
* The class Counters. * The class Counters.
* *
@@ -14,120 +13,313 @@ package forge;
* @version V0.0 17.02.2010 * @version V0.0 17.02.2010
*/ */
public enum Counters { public enum Counters {
/** The AGE. */
AGE(), AGE(),
/** The ARROW. */
ARROW(), ARROW(),
/** The ARROWHEAD. */
ARROWHEAD(), ARROWHEAD(),
/** The AWAKENING. */
AWAKENING(), AWAKENING(),
/** The BLAZE. */
BLAZE(), BLAZE(),
/** The BLOOD. */
BLOOD(), BLOOD(),
/** The BOUNTY. */
BOUNTY(), BOUNTY(),
/** The BRIBERY. */
BRIBERY(), BRIBERY(),
/** The CARRION. */
CARRION(), CARRION(),
/** The CHARGE. */
CHARGE(), CHARGE(),
/** The CORPSE. */
CORPSE(), CORPSE(),
/** The CREDIT. */
CREDIT(), CREDIT(),
/** The CURRENCY. */
CURRENCY(), CURRENCY(),
/** The DEATH. */
DEATH(), DEATH(),
/** The DELAY. */
DELAY(), DELAY(),
/** The DEPLETION. */
DEPLETION(), DEPLETION(),
/** The DEVOTION. */
DEVOTION(), DEVOTION(),
/** The DIVINITY. */
DIVINITY(), DIVINITY(),
/** The DOOM. */
DOOM(), DOOM(),
/** The ENERGY. */
ENERGY(), ENERGY(),
/** The EON. */
EON(), EON(),
/** The FADE. */
FADE(), FADE(),
/** The FATE. */
FATE(), FATE(),
/** The FEATHER. */
FEATHER(), FEATHER(),
/** The FLOOD. */
FLOOD(), FLOOD(),
/** The FUNGUS. */
FUNGUS(), FUNGUS(),
/** The FUSE. */
FUSE(), FUSE(),
/** The GLYPH. */
GLYPH(), GLYPH(),
/** The GOLD. */
GOLD(), GOLD(),
/** The GROWTH. */
GROWTH(), GROWTH(),
/** The HATCHLING. */
HATCHLING(), HATCHLING(),
/** The HEALING. */
HEALING(), HEALING(),
/** The HOOFPRINT. */
HOOFPRINT(), HOOFPRINT(),
/** The HOURGLASS. */
HOURGLASS(), HOURGLASS(),
/** The ICE. */
ICE(), ICE(),
/** The INFECTION. */
INFECTION(), INFECTION(),
/** The INTERVENTION. */
INTERVENTION(), INTERVENTION(),
/** The JAVELIN. */
JAVELIN(), JAVELIN(),
/** The KI. */
KI(), KI(),
/** The LEVEL. */
LEVEL("Level"), LEVEL("Level"),
/** The LORE. */
LORE(), LORE(),
/** The LOYALTY. */
LOYALTY(), LOYALTY(),
/** The LUCK. */
LUCK(), LUCK(),
/** The M0 m1. */
M0M1("-0/-1"), M0M1("-0/-1"),
/** The M0 m2. */
M0M2("-0/-2"), M0M2("-0/-2"),
/** The M1 m0. */
M1M0("-1/-0"), M1M0("-1/-0"),
/** The M1 m1. */
M1M1("-1/-1"), M1M1("-1/-1"),
/** The M2 m1. */
M2M1("-2/-1"), M2M1("-2/-1"),
/** The M2 m2. */
M2M2("-2/-2"), M2M2("-2/-2"),
/** The MANA. */
MANA(), MANA(),
/** The MINE. */
MINE(), MINE(),
/** The MINING. */
MINING(), MINING(),
/** The MIRE. */
MIRE(), MIRE(),
/** The OMEN. */
OMEN(), OMEN(),
/** The ORE. */
ORE(), ORE(),
/** The PAGE. */
PAGE(), PAGE(),
/** The PAIN. */
PAIN(), PAIN(),
/** The PARALYZATION. */
PARALYZATION(), PARALYZATION(),
/** The PETAL. */
PETAL(), PETAL(),
/** The PIN. */
PIN(), PIN(),
/** The PLAGUE. */
PLAGUE(), PLAGUE(),
/** The PRESSURE. */
PRESSURE(), PRESSURE(),
/** The PHYLACTERY. */
PHYLACTERY, PHYLACTERY,
/** The POLYP. */
POLYP(), POLYP(),
/** The PUPA. */
PUPA(), PUPA(),
/** The P0 p1. */
P0P1("+0/+1"), P0P1("+0/+1"),
/** The P1 p0. */
P1P0("+1/+0"), P1P0("+1/+0"),
/** The P1 p1. */
P1P1("+1/+1"), P1P1("+1/+1"),
/** The P1 p2. */
P1P2("+1/+2"), P1P2("+1/+2"),
/** The P2 p2. */
P2P2("+2/+2"), P2P2("+2/+2"),
/** The QUEST. */
QUEST(), QUEST(),
/** The SCREAM. */
SCREAM(), SCREAM(),
/** The SHELL. */
SHELL(), SHELL(),
/** The SHIELD. */
SHIELD(), SHIELD(),
/** The SHRED. */
SHRED(), SHRED(),
/** The SLEEP. */
SLEEP(), SLEEP(),
/** The SLEIGHT. */
SLEIGHT(), SLEIGHT(),
/** The SOOT. */
SOOT(), SOOT(),
/** The SPORE. */
SPORE(), SPORE(),
/** The STORAGE. */
STORAGE(), STORAGE(),
/** The STUDY. */
STUDY(), STUDY(),
/** The TIDE. */
TIDE(), TIDE(),
/** The TIME. */
TIME(), TIME(),
/** The TOWER. */
TOWER("tower"), TOWER("tower"),
/** The TRAINING. */
TRAINING(), TRAINING(),
/** The TRAP. */
TRAP(), TRAP(),
/** The TREASURE. */
TREASURE(), TREASURE(),
/** The VELOCITY. */
VELOCITY(), VELOCITY(),
/** The VERSE. */
VERSE(), VERSE(),
/** The VITALITY. */
VITALITY(), VITALITY(),
/** The WAGE. */
WAGE(), WAGE(),
/** The WIND. */
WIND(), WIND(),
/** The WISH. */
WISH(); WISH();
private String name; private String name;
/** /**
* <p>Constructor for Counters.</p> * <p>
* Constructor for Counters.
* </p>
*/ */
private Counters() { private Counters() {
this.name = name().substring(0, 1).toUpperCase() + name().substring(1).toLowerCase(); this.name = name().substring(0, 1).toUpperCase() + name().substring(1).toLowerCase();
} }
/** /**
* <p>Constructor for Counters.</p> * <p>
* Constructor for Counters.
* </p>
* *
* @param name a {@link java.lang.String} object. * @param name
* a {@link java.lang.String} object.
*/ */
private Counters(final String nameIn) { private Counters(final String nameIn) {
this.name = nameIn; this.name = nameIn;
} }
/** /**
* <p>Getter for the field <code>name</code>.</p> * <p>
* Getter for the field <code>name</code>.
* </p>
* *
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
@@ -136,9 +328,12 @@ public enum Counters {
} }
/** /**
* <p>getType.</p> * <p>
* getType.
* </p>
* *
* @param name a {@link java.lang.String} object. * @param name
* a {@link java.lang.String} object.
* @return a {@link forge.Counters} object. * @return a {@link forge.Counters} object.
*/ */
public static Counters getType(final String name) { public static Counters getType(final String name) {

View File

@@ -6,7 +6,9 @@ import forge.card.spellability.SpellAbility;
//handles "until end of turn" and "at end of turn" commands from cards //handles "until end of turn" and "at end of turn" commands from cards
/** /**
* <p>EndOfTurn class.</p> * <p>
* EndOfTurn class.
* </p>
* *
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
@@ -20,34 +22,45 @@ public class EndOfTurn implements java.io.Serializable {
private CommandList last = new CommandList(); private CommandList last = new CommandList();
/** /**
* <p>addAt.</p> * <p>
* addAt.
* </p>
* *
* @param c a {@link forge.Command} object. * @param c
* a {@link forge.Command} object.
*/ */
public final void addAt(final Command c) { public final void addAt(final Command c) {
at.add(c); at.add(c);
} }
/** /**
* <p>addUntil.</p> * <p>
* addUntil.
* </p>
* *
* @param c a {@link forge.Command} object. * @param c
* a {@link forge.Command} object.
*/ */
public final void addUntil(final Command c) { public final void addUntil(final Command c) {
until.add(c); until.add(c);
} }
/** /**
* <p>addLast.</p> * <p>
* addLast.
* </p>
* *
* @param c a {@link forge.Command} object. * @param c
* a {@link forge.Command} object.
*/ */
public final void addLast(final Command c) { public final void addLast(final Command c) {
last.add(c); last.add(c);
} }
/** /**
* <p>executeAt.</p> * <p>
* executeAt.
* </p>
*/ */
public final void executeAt() { public final void executeAt() {
@@ -65,9 +78,7 @@ public class EndOfTurn implements java.io.Serializable {
AllZone.getStaticEffects().rePopulateStateBasedList(); AllZone.getStaticEffects().rePopulateStateBasedList();
for (Card c : all) { for (Card c : all) {
if (!c.isFaceDown() if (!c.isFaceDown() && c.hasKeyword("At the beginning of the end step, sacrifice CARDNAME.")) {
&& c.hasKeyword("At the beginning of the end step, sacrifice CARDNAME."))
{
final Card card = c; final Card card = c;
final SpellAbility sac = new Ability(card, "0") { final SpellAbility sac = new Ability(card, "0") {
@Override @Override
@@ -84,9 +95,7 @@ public class EndOfTurn implements java.io.Serializable {
AllZone.getStack().addSimultaneousStackEntry(sac); AllZone.getStack().addSimultaneousStackEntry(sac);
} }
if (!c.isFaceDown() if (!c.isFaceDown() && c.hasKeyword("At the beginning of the end step, exile CARDNAME.")) {
&& c.hasKeyword("At the beginning of the end step, exile CARDNAME."))
{
final Card card = c; final Card card = c;
final SpellAbility exile = new Ability(card, "0") { final SpellAbility exile = new Ability(card, "0") {
@Override @Override
@@ -103,9 +112,7 @@ public class EndOfTurn implements java.io.Serializable {
AllZone.getStack().addSimultaneousStackEntry(exile); AllZone.getStack().addSimultaneousStackEntry(exile);
} }
if (!c.isFaceDown() if (!c.isFaceDown() && c.hasKeyword("At the beginning of the end step, destroy CARDNAME.")) {
&& c.hasKeyword("At the beginning of the end step, destroy CARDNAME."))
{
final Card card = c; final Card card = c;
final SpellAbility destroy = new Ability(card, "0") { final SpellAbility destroy = new Ability(card, "0") {
@Override @Override
@@ -152,7 +159,8 @@ public class EndOfTurn implements java.io.Serializable {
if (AllZoneUtil.isCardInPlay(vale)) { if (AllZoneUtil.isCardInPlay(vale)) {
vale.addController(vale.getController().getOpponent()); vale.addController(vale.getController().getOpponent());
// AllZone.getGameAction().changeController( // AllZone.getGameAction().changeController(
// new CardList(vale), vale.getController(), vale.getController().getOpponent()); // new CardList(vale), vale.getController(),
// vale.getController().getOpponent());
vale.removeExtrinsicKeyword("An opponent gains control of CARDNAME at the beginning of the next end step."); vale.removeExtrinsicKeyword("An opponent gains control of CARDNAME at the beginning of the next end step.");
} }
@@ -165,9 +173,8 @@ public class EndOfTurn implements java.io.Serializable {
AllZone.getStack().addSimultaneousStackEntry(change); AllZone.getStack().addSimultaneousStackEntry(change);
} }
if (c.getName().equals("Erg Raiders") && !c.getCreatureAttackedThisTurn() if (c.getName().equals("Erg Raiders") && !c.getCreatureAttackedThisTurn() && !c.hasSickness()
&& !c.hasSickness() && AllZone.getPhase().isPlayerTurn(c.getController())) && AllZone.getPhase().isPlayerTurn(c.getController())) {
{
final Card raider = c; final Card raider = c;
final SpellAbility change = new Ability(raider, "0") { final SpellAbility change = new Ability(raider, "0") {
@Override @Override
@@ -187,8 +194,7 @@ public class EndOfTurn implements java.io.Serializable {
if (c.hasKeyword("At the beginning of your end step, sacrifice this creature unless it attacked this turn.") if (c.hasKeyword("At the beginning of your end step, sacrifice this creature unless it attacked this turn.")
&& !c.getCreatureAttackedThisTurn() && !c.getCreatureAttackedThisTurn()
/* && !(c.getTurnInZone() == AllZone.getPhase().getTurn()) */ /* && !(c.getTurnInZone() == AllZone.getPhase().getTurn()) */
&& AllZone.getPhase().isPlayerTurn(c.getController())) && AllZone.getPhase().isPlayerTurn(c.getController())) {
{
final Card source = c; final Card source = c;
final SpellAbility change = new Ability(source, "0") { final SpellAbility change = new Ability(source, "0") {
@Override @Override
@@ -206,9 +212,7 @@ public class EndOfTurn implements java.io.Serializable {
} }
if (c.hasKeyword("At the beginning of your end step, destroy this creature if it didn't attack this turn.") if (c.hasKeyword("At the beginning of your end step, destroy this creature if it didn't attack this turn.")
&& !c.getCreatureAttackedThisTurn() && !c.getCreatureAttackedThisTurn() && AllZone.getPhase().isPlayerTurn(c.getController())) {
&& AllZone.getPhase().isPlayerTurn(c.getController()))
{
final Card source = c; final Card source = c;
final SpellAbility change = new Ability(source, "0") { final SpellAbility change = new Ability(source, "0") {
@Override @Override
@@ -226,8 +230,7 @@ public class EndOfTurn implements java.io.Serializable {
} }
if (c.hasKeyword("At the beginning of your end step, return CARDNAME to its owner's hand.") if (c.hasKeyword("At the beginning of your end step, return CARDNAME to its owner's hand.")
&& AllZone.getPhase().isPlayerTurn(c.getController())) && AllZone.getPhase().isPlayerTurn(c.getController())) {
{
final Card source = c; final Card source = c;
final SpellAbility change = new Ability(source, "0") { final SpellAbility change = new Ability(source, "0") {
@Override @Override
@@ -247,10 +250,8 @@ public class EndOfTurn implements java.io.Serializable {
} }
execute(at); execute(at);
CardList all2 = AllZoneUtil.getCardsIn(Zone.Battlefield); CardList all2 = AllZoneUtil.getCardsIn(Zone.Battlefield);
for (Card c : all2) { for (Card c : all2) {
c.clearMustBlockCards(); c.clearMustBlockCards();
@@ -261,9 +262,10 @@ public class EndOfTurn implements java.io.Serializable {
} // executeAt() } // executeAt()
/** /**
* <p>executeUntil.</p> * <p>
* executeUntil.
* </p>
*/ */
public final void executeUntil() { public final void executeUntil() {
execute(until); execute(until);
@@ -271,7 +273,9 @@ public class EndOfTurn implements java.io.Serializable {
} }
/** /**
* <p>sizeAt.</p> * <p>
* sizeAt.
* </p>
* *
* @return a int. * @return a int.
*/ */
@@ -280,7 +284,9 @@ public class EndOfTurn implements java.io.Serializable {
} }
/** /**
* <p>sizeUntil.</p> * <p>
* sizeUntil.
* </p>
* *
* @return a int. * @return a int.
*/ */
@@ -289,7 +295,9 @@ public class EndOfTurn implements java.io.Serializable {
} }
/** /**
* <p>sizeLast.</p> * <p>
* sizeLast.
* </p>
* *
* @return a int. * @return a int.
*/ */
@@ -298,9 +306,12 @@ public class EndOfTurn implements java.io.Serializable {
} }
/** /**
* <p>execute.</p> * <p>
* execute.
* </p>
* *
* @param c a {@link forge.CommandList} object. * @param c
* a {@link forge.CommandList} object.
*/ */
private void execute(final CommandList c) { private void execute(final CommandList c) {
int length = c.size(); int length = c.size();

View File

@@ -1,12 +1,16 @@
package forge; package forge;
import javax.swing.*; import java.awt.BorderLayout;
import java.awt.*; import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter; import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
/** /**
* ExternalPanel.java * ExternalPanel.java
@@ -14,9 +18,9 @@ import java.awt.event.WindowEvent;
* Created on 13.08.2009 * Created on 13.08.2009
*/ */
/** /**
* The class ExternalPanel. A panel with which some other component can be shown in an external window. * The class ExternalPanel. A panel with which some other component can be shown
* in an external window.
* *
* @author Clemens Koza * @author Clemens Koza
* @version V0.0 13.08.2009 * @version V0.0 13.08.2009
@@ -29,19 +33,26 @@ public class ExternalPanel extends JPanel {
private JFrame frame; private JFrame frame;
/** /**
* <p>Constructor for ExternalPanel.</p> * <p>
* Constructor for ExternalPanel.
* </p>
* *
* @param child a {@link java.awt.Component} object. * @param child
* a {@link java.awt.Component} object.
*/ */
public ExternalPanel(final Component child) { public ExternalPanel(final Component child) {
this(child, BorderLayout.EAST); this(child, BorderLayout.EAST);
} }
/** /**
* <p>Constructor for ExternalPanel.</p> * <p>
* Constructor for ExternalPanel.
* </p>
* *
* @param child a {@link java.awt.Component} object. * @param child
* @param side a {@link java.lang.String} object. * a {@link java.awt.Component} object.
* @param side
* a {@link java.lang.String} object.
*/ */
public ExternalPanel(final Component child, final String side) { public ExternalPanel(final Component child, final String side) {
super(new BorderLayout()); super(new BorderLayout());
@@ -55,9 +66,12 @@ public class ExternalPanel extends JPanel {
} }
/** /**
* <p>setHeadSide.</p> * <p>
* setHeadSide.
* </p>
* *
* @param side a {@link java.lang.String} object. * @param side
* a {@link java.lang.String} object.
*/ */
public final void setHeadSide(final String side) { public final void setHeadSide(final String side) {
remove(head); remove(head);

View File

@@ -1,9 +1,5 @@
package forge; package forge;
import forge.error.ErrorViewer;
import forge.properties.ForgeProps;
import forge.properties.NewConstants.LANG.Gui_DownloadPictures.ERRORS;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.BufferedReader; import java.io.BufferedReader;
@@ -19,9 +15,15 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import forge.error.ErrorViewer;
import forge.properties.ForgeProps;
import forge.properties.NewConstants.LANG.Gui_DownloadPictures.ERRORS;
// TODO: Auto-generated Javadoc
/** /**
* <p>FileUtil class.</p> * <p>
* FileUtil class.
* </p>
* *
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
@@ -33,9 +35,12 @@ public final class FileUtil {
} }
/** /**
* <p>doesFileExist.</p> * <p>
* doesFileExist.
* </p>
* *
* @param filename a {@link java.lang.String} object. * @param filename
* a {@link java.lang.String} object.
* @return a boolean. * @return a boolean.
*/ */
public static boolean doesFileExist(final String filename) { public static boolean doesFileExist(final String filename) {
@@ -44,10 +49,14 @@ public final class FileUtil {
} }
/** /**
* <p>writeFile.</p> * <p>
* writeFile.
* </p>
* *
* @param filename a {@link java.lang.String} object. * @param filename
* @param data a {@link java.util.List} object. * a {@link java.lang.String} object.
* @param data
* a {@link java.util.List} object.
*/ */
public static void writeFile(final String filename, final List<String> data) { public static void writeFile(final String filename, final List<String> data) {
writeFile(new File(filename), data); writeFile(new File(filename), data);
@@ -58,10 +67,14 @@ public final class FileUtil {
// this will create a new file if needed // this will create a new file if needed
// if filename already exists, it is deleted // if filename already exists, it is deleted
/** /**
* <p>writeFile.</p> * <p>
* writeFile.
* </p>
* *
* @param file a {@link java.io.File} object. * @param file
* @param data a {@link java.util.List} object. * a {@link java.io.File} object.
* @param data
* a {@link java.util.List} object.
*/ */
public static void writeFile(final File file, final List<String> data) { public static void writeFile(final File file, final List<String> data) {
try { try {
@@ -81,9 +94,12 @@ public final class FileUtil {
} // writeAllDecks() } // writeAllDecks()
/** /**
* <p>readFile.</p> * <p>
* readFile.
* </p>
* *
* @param filename a {@link java.lang.String} object. * @param filename
* a {@link java.lang.String} object.
* @return a {@link java.util.ArrayList} object. * @return a {@link java.util.ArrayList} object.
*/ */
public static ArrayList<String> readFile(final String filename) { public static ArrayList<String> readFile(final String filename) {
@@ -94,9 +110,12 @@ public final class FileUtil {
// this will return blank lines as well // this will return blank lines as well
// if filename not found, returns an empty ArrayList // if filename not found, returns an empty ArrayList
/** /**
* <p>readFile.</p> * <p>
* readFile.
* </p>
* *
* @param file a {@link java.io.File} object. * @param file
* a {@link java.io.File} object.
* @return a {@link java.util.ArrayList} object. * @return a {@link java.util.ArrayList} object.
*/ */
public static ArrayList<String> readFile(final File file) { public static ArrayList<String> readFile(final File file) {
@@ -108,7 +127,6 @@ public final class FileUtil {
return list; return list;
} }
in = new BufferedReader(new FileReader(file)); in = new BufferedReader(new FileReader(file));
String line; String line;
@@ -123,8 +141,13 @@ public final class FileUtil {
return list; return list;
} // readFile() } // readFile()
public static void downloadUrlIntoFile(final String url, final File target) /**
{ * Download url into file.
*
* @param url the url
* @param target the target
*/
public static void downloadUrlIntoFile(final String url, final File target) {
try { try {
byte[] buf = new byte[1024]; byte[] buf = new byte[1024];
int len; int len;
@@ -141,9 +164,7 @@ public final class FileUtil {
in.close(); in.close();
out.flush(); out.flush();
out.close(); out.close();
} } catch (IOException ioex) {
catch (IOException ioex)
{
ErrorViewer.showError(ioex, ForgeProps.getLocalized(ERRORS.OTHER), "deck_temp.html", url); ErrorViewer.showError(ioex, ForgeProps.getLocalized(ERRORS.OTHER), "deck_temp.html", url);
} }

View File

@@ -1,29 +1,28 @@
package forge; package forge;
import forge.Constant.Zone;
import forge.card.abilityFactory.AbilityFactory;
import forge.card.cardFactory.CardFactoryUtil;
import forge.card.cost.Cost;
import forge.card.spellability.Ability_Activated;
import forge.card.spellability.Ability_Mana;
import forge.card.spellability.SpellAbility;
import forge.card.spellability.Ability;
import forge.card.spellability.Target;
import forge.game.GameLossReason;
import forge.gui.GuiUtils;
import forge.gui.input.Input_PayManaCostUtil;
import forge.gui.input.Input_PayManaCost_Ability;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import forge.Constant.Zone;
import forge.card.abilityFactory.AbilityFactory;
import forge.card.cardFactory.CardFactoryUtil;
import forge.card.cost.Cost;
import forge.card.spellability.Ability;
import forge.card.spellability.Ability_Activated;
import forge.card.spellability.Ability_Mana;
import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target;
import forge.game.GameLossReason;
import forge.gui.GuiUtils;
import forge.gui.input.Input_PayManaCostUtil;
import forge.gui.input.Input_PayManaCost_Ability;
/** /**
* <p>GameActionUtil class.</p> * <p>
* GameActionUtil class.
* </p>
* *
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
@@ -35,9 +34,12 @@ public final class GameActionUtil {
} }
/** /**
* <p>executePlayCardEffects.</p> * <p>
* executePlayCardEffects.
* </p>
* *
* @param sa a {@link forge.card.spellability.SpellAbility} object. * @param sa
* a {@link forge.card.spellability.SpellAbility} object.
*/ */
public static void executePlayCardEffects(final SpellAbility sa) { public static void executePlayCardEffects(final SpellAbility sa) {
// experimental: // experimental:
@@ -51,9 +53,12 @@ public final class GameActionUtil {
} }
/** /**
* <p>playCard_Cascade.</p> * <p>
* playCard_Cascade.
* </p>
* *
* @param c a {@link forge.Card} object. * @param c
* a {@link forge.Card} object.
*/ */
public static void playCard_Cascade(final Card c) { public static void playCard_Cascade(final Card c) {
Command cascade = new Command() { Command cascade = new Command() {
@@ -63,21 +68,25 @@ public final class GameActionUtil {
if (!c.isCopiedSpell()) { if (!c.isCopiedSpell()) {
CardList humanNexus = AllZone.getHumanPlayer().getCardsIn(Zone.Battlefield, "Maelstrom Nexus"); CardList humanNexus = AllZone.getHumanPlayer().getCardsIn(Zone.Battlefield, "Maelstrom Nexus");
CardList computerNexus = AllZone.getComputerPlayer().getCardsIn(Zone.Battlefield, "Maelstrom Nexus"); CardList computerNexus = AllZone.getComputerPlayer()
.getCardsIn(Zone.Battlefield, "Maelstrom Nexus");
CardList maelstromNexii = new CardList(); CardList maelstromNexii = new CardList();
maelstromNexii.addAll(humanNexus); maelstromNexii.addAll(humanNexus);
maelstromNexii.addAll(computerNexus); maelstromNexii.addAll(computerNexus);
for (Card nexus : maelstromNexii) { for (Card nexus : maelstromNexii) {
if (CardUtil.getThisTurnCast("Card.YouCtrl", nexus).size() == 1) { if (CardUtil.getThisTurnCast("Card.YouCtrl", nexus).size() == 1) {
doCascade(c); doCascade(c);
} }
} }
} }
if (c.hasKeyword("Cascade") if (c.hasKeyword("Cascade") || c.getName().equals("Bituminous Blast")) // keyword
|| c.getName().equals("Bituminous Blast")) //keyword gets cleared for Bitumonous Blast // gets
// cleared
// for
// Bitumonous
// Blast
{ {
doCascade(c); doCascade(c);
} }
@@ -103,7 +112,8 @@ public final class GameActionUtil {
while (cascadedCard == null) { while (cascadedCard == null) {
crd = topOfLibrary.get(count++); crd = topOfLibrary.get(count++);
revealed.add(crd); revealed.add(crd);
if ((!crd.isLand() && CardUtil.getConvertedManaCost(crd.getManaCost()) < CardUtil.getConvertedManaCost(cascCard.getManaCost()))) if ((!crd.isLand() && CardUtil.getConvertedManaCost(crd.getManaCost()) < CardUtil
.getConvertedManaCost(cascCard.getManaCost())))
cascadedCard = crd; cascadedCard = crd;
if (count == topOfLibrary.size()) { if (count == topOfLibrary.size()) {
@@ -122,8 +132,8 @@ public final class GameActionUtil {
question.append("Cast ").append(cascadedCard.getName()); question.append("Cast ").append(cascadedCard.getName());
question.append(" without paying its mana cost?"); question.append(" without paying its mana cost?");
int answer = JOptionPane.showConfirmDialog(null, question.toString(), int answer = JOptionPane.showConfirmDialog(null, question.toString(), title.toString(),
title.toString(), JOptionPane.YES_NO_OPTION); JOptionPane.YES_NO_OPTION);
if (answer == JOptionPane.YES_OPTION) { if (answer == JOptionPane.YES_OPTION) {
AllZone.getGameAction().playCardNoCost(cascadedCard); AllZone.getGameAction().playCardNoCost(cascadedCard);
@@ -159,9 +169,12 @@ public final class GameActionUtil {
} }
/** /**
* <p>playCard_Ripple.</p> * <p>
* playCard_Ripple.
* </p>
* *
* @param c a {@link forge.Card} object. * @param c
* a {@link forge.Card} object.
*/ */
public static void playCard_Ripple(final Card c) { public static void playCard_Ripple(final Card c) {
Command ripple = new Command() { Command ripple = new Command() {
@@ -170,7 +183,8 @@ public final class GameActionUtil {
public void execute() { public void execute() {
CardList humanThrummingStone = AllZone.getHumanPlayer().getCardsIn(Zone.Battlefield, "Thrumming Stone"); CardList humanThrummingStone = AllZone.getHumanPlayer().getCardsIn(Zone.Battlefield, "Thrumming Stone");
CardList computerThrummingStone = AllZone.getComputerPlayer().getCardsIn(Zone.Battlefield, "Thrumming Stone"); CardList computerThrummingStone = AllZone.getComputerPlayer().getCardsIn(Zone.Battlefield,
"Thrumming Stone");
for (int i = 0; i < humanThrummingStone.size(); i++) { for (int i = 0; i < humanThrummingStone.size(); i++) {
if (c.getController().isHuman()) { if (c.getController().isHuman()) {
@@ -200,8 +214,8 @@ public final class GameActionUtil {
Object[] possibleValues = { "Yes", "No" }; Object[] possibleValues = { "Yes", "No" };
AllZone.getDisplay().showMessage("Activate Ripple? "); AllZone.getDisplay().showMessage("Activate Ripple? ");
Object q = JOptionPane.showOptionDialog(null, "Activate Ripple for " + c, "Ripple", Object q = JOptionPane.showOptionDialog(null, "Activate Ripple for " + c, "Ripple",
JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, possibleValues,
null, possibleValues, possibleValues[0]); possibleValues[0]);
if (q.equals(0)) { if (q.equals(0)) {
activateRipple = true; activateRipple = true;
} }
@@ -219,7 +233,8 @@ public final class GameActionUtil {
return; return;
} }
// Shouldn't Have more than Ripple 10, seeing as no cards exist with a ripple greater than 4 // Shouldn't Have more than Ripple 10, seeing as no
// cards exist with a ripple greater than 4
int rippleMax = 10; int rippleMax = 10;
Card[] rippledCards = new Card[rippleMax]; Card[] rippledCards = new Card[rippleMax];
Card crd; Card crd;
@@ -240,9 +255,10 @@ public final class GameActionUtil {
if (rippledCards[i].getController().isHuman()) { if (rippledCards[i].getController().isHuman()) {
Object[] possibleValues = { "Yes", "No" }; Object[] possibleValues = { "Yes", "No" };
Object q = JOptionPane.showOptionDialog(null, "Cast " + rippledCards[i].getName() + "?", "Ripple", Object q = JOptionPane.showOptionDialog(null,
JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, "Cast " + rippledCards[i].getName() + "?", "Ripple",
null, possibleValues, possibleValues[0]); JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null,
possibleValues, possibleValues[0]);
if (q.equals(0)) { if (q.equals(0)) {
AllZone.getGameAction().playCardNoCost(rippledCards[i]); AllZone.getGameAction().playCardNoCost(rippledCards[i]);
revealed.remove(rippledCards[i]); revealed.remove(rippledCards[i]);
@@ -279,17 +295,23 @@ public final class GameActionUtil {
} // playCard_Ripple() } // playCard_Ripple()
/** /**
* <p>payManaDuringAbilityResolve.</p> * <p>
* payManaDuringAbilityResolve.
* </p>
* *
* @param message a {@link java.lang.String} object. * @param message
* @param manaCost a {@link java.lang.String} object. * a {@link java.lang.String} object.
* @param paid a {@link forge.Command} object. * @param manaCost
* @param unpaid a {@link forge.Command} object. * a {@link java.lang.String} object.
* @param paid
* a {@link forge.Command} object.
* @param unpaid
* a {@link forge.Command} object.
*/ */
public static void payManaDuringAbilityResolve(final String message, final String manaCost, public static void payManaDuringAbilityResolve(final String message, final String manaCost, final Command paid,
final Command paid, final Command unpaid) final Command unpaid) {
{ // temporarily disable the Resolve flag, so the user can payMana for the
// temporarily disable the Resolve flag, so the user can payMana for the resolving Ability // resolving Ability
boolean bResolving = AllZone.getStack().getResolving(); boolean bResolving = AllZone.getStack().getResolving();
AllZone.getStack().setResolving(false); AllZone.getStack().setResolving(false);
AllZone.getInputControl().setInput(new Input_PayManaCost_Ability(message, manaCost, paid, unpaid)); AllZone.getInputControl().setInput(new Input_PayManaCost_Ability(message, manaCost, paid, unpaid));
@@ -299,7 +321,9 @@ public final class GameActionUtil {
// START ENDOFTURN CARDS // START ENDOFTURN CARDS
/** /**
* <p>endOfTurn_Wall_Of_Reverence.</p> * <p>
* endOfTurn_Wall_Of_Reverence.
* </p>
*/ */
public static void endOfTurn_Wall_Of_Reverence() { public static void endOfTurn_Wall_Of_Reverence() {
final Player player = AllZone.getPhase().getPlayerTurn(); final Player player = AllZone.getPhase().getPlayerTurn();
@@ -317,7 +341,8 @@ public final class GameActionUtil {
} }
if (player.isHuman()) { if (player.isHuman()) {
Object o = GuiUtils.getChoiceOptional("Select target creature for Wall of Reverence life gain", creats.toArray()); Object o = GuiUtils.getChoiceOptional("Select target creature for Wall of Reverence life gain",
creats.toArray());
if (o != null) { if (o != null) {
Card c = (Card) o; Card c = (Card) o;
int power = c.getNetAttack(); int power = c.getNetAttack();
@@ -344,7 +369,9 @@ public final class GameActionUtil {
} // endOfTurn_Wall_Of_Reverence() } // endOfTurn_Wall_Of_Reverence()
/** /**
* <p>endOfTurn_Lighthouse_Chronologist.</p> * <p>
* endOfTurn_Lighthouse_Chronologist.
* </p>
*/ */
public static void endOfTurn_Lighthouse_Chronologist() { public static void endOfTurn_Lighthouse_Chronologist() {
final Player player = AllZone.getPhase().getPlayerTurn(); final Player player = AllZone.getPhase().getPlayerTurn();
@@ -378,7 +405,9 @@ public final class GameActionUtil {
// END ENDOFTURN CARDS // END ENDOFTURN CARDS
/** /**
* <p>removeAttackedBlockedThisTurn.</p> * <p>
* removeAttackedBlockedThisTurn.
* </p>
*/ */
public static void removeAttackedBlockedThisTurn() { public static void removeAttackedBlockedThisTurn() {
// resets the status of attacked/blocked this turn // resets the status of attacked/blocked this turn
@@ -392,7 +421,8 @@ public final class GameActionUtil {
} }
if (c.getCreatureBlockedThisCombat()) { if (c.getCreatureBlockedThisCombat()) {
c.setCreatureBlockedThisCombat(false); c.setCreatureBlockedThisCombat(false);
//do not reset setCreatureAttackedThisTurn(), this appears to be combat specific // do not reset setCreatureAttackedThisTurn(), this appears to
// be combat specific
} }
if (c.getCreatureGotBlockedThisCombat()) { if (c.getCreatureGotBlockedThisCombat()) {
@@ -402,10 +432,14 @@ public final class GameActionUtil {
} }
/** /**
* <p>showYesNoDialog.</p> * <p>
* showYesNoDialog.
* </p>
* *
* @param c a {@link forge.Card} object. * @param c
* @param question a {@link java.lang.String} object. * a {@link forge.Card} object.
* @param question
* a {@link java.lang.String} object.
* @return a boolean. * @return a boolean.
*/ */
public static boolean showYesNoDialog(final Card c, final String question) { public static boolean showYesNoDialog(final Card c, final String question) {
@@ -413,11 +447,16 @@ public final class GameActionUtil {
} }
/** /**
* <p>showYesNoDialog.</p> * <p>
* showYesNoDialog.
* </p>
* *
* @param c a {@link forge.Card} object. * @param c
* @param question a {@link java.lang.String} object. * a {@link forge.Card} object.
* @param defaultNo true if the default option should be "No", false otherwise * @param question
* a {@link java.lang.String} object.
* @param defaultNo
* true if the default option should be "No", false otherwise
* @return a boolean. * @return a boolean.
*/ */
public static boolean showYesNoDialog(final Card c, String question, final boolean defaultNo) { public static boolean showYesNoDialog(final Card c, String question, final boolean defaultNo) {
@@ -434,8 +473,7 @@ public final class GameActionUtil {
Object[] options = { "Yes", "No" }; Object[] options = { "Yes", "No" };
answer = JOptionPane.showOptionDialog(null, question, title.toString(), JOptionPane.YES_NO_OPTION, answer = JOptionPane.showOptionDialog(null, question, title.toString(), JOptionPane.YES_NO_OPTION,
JOptionPane.PLAIN_MESSAGE, null, options, options[1]); JOptionPane.PLAIN_MESSAGE, null, options, options[1]);
} } else {
else {
answer = JOptionPane.showConfirmDialog(null, question, title.toString(), JOptionPane.YES_NO_OPTION); answer = JOptionPane.showConfirmDialog(null, question, title.toString(), JOptionPane.YES_NO_OPTION);
} }
@@ -447,19 +485,26 @@ public final class GameActionUtil {
} }
/** /**
* <p>showInfoDialg.</p> * <p>
* showInfoDialg.
* </p>
* *
* @param message a {@link java.lang.String} object. * @param message
* a {@link java.lang.String} object.
*/ */
public static void showInfoDialg(final String message) { public static void showInfoDialg(final String message) {
JOptionPane.showMessageDialog(null, message); JOptionPane.showMessageDialog(null, message);
} }
/** /**
* <p>flipACoin.</p> * <p>
* flipACoin.
* </p>
* *
* @param caller a {@link forge.Player} object. * @param caller
* @param source a {@link forge.Card} object. * a {@link forge.Player} object.
* @param source
* a {@link forge.Card} object.
* @return a boolean. * @return a boolean.
*/ */
public static boolean flipACoin(final Player caller, final Card source) { public static boolean flipACoin(final Player caller, final Card source) {
@@ -476,15 +521,18 @@ public final class GameActionUtil {
boolean winFlip = flip == choice.equals("heads"); boolean winFlip = flip == choice.equals("heads");
String winMsg = winFlip ? " wins flip." : " loses flip."; String winMsg = winFlip ? " wins flip." : " loses flip.";
JOptionPane.showMessageDialog(null, source.getName() + " - " + caller + winMsg, JOptionPane.showMessageDialog(null, source.getName() + " - " + caller + winMsg, source.getName(),
source.getName(), JOptionPane.PLAIN_MESSAGE); JOptionPane.PLAIN_MESSAGE);
return winFlip; return winFlip;
} }
/** /**
* <p>executeLandfallEffects.</p> * <p>
* executeLandfallEffects.
* </p>
* *
* @param c a {@link forge.Card} object. * @param c
* a {@link forge.Card} object.
*/ */
public static void executeLandfallEffects(final Card c) { public static void executeLandfallEffects(final Card c) {
if (c.getName().equals("Lotus Cobra")) { if (c.getName().equals("Lotus Cobra")) {
@@ -493,9 +541,12 @@ public final class GameActionUtil {
} }
/** /**
* <p>showLandfallDialog.</p> * <p>
* showLandfallDialog.
* </p>
* *
* @param c a {@link forge.Card} object. * @param c
* a {@link forge.Card} object.
* @return a boolean. * @return a boolean.
*/ */
private static boolean showLandfallDialog(final Card c) { private static boolean showLandfallDialog(final Card c) {
@@ -514,9 +565,12 @@ public final class GameActionUtil {
} }
/** /**
* <p>landfall_Lotus_Cobra.</p> * <p>
* landfall_Lotus_Cobra.
* </p>
* *
* @param c a {@link forge.Card} object. * @param c
* a {@link forge.Card} object.
*/ */
private static void landfall_Lotus_Cobra(final Card c) { private static void landfall_Lotus_Cobra(final Card c) {
Ability ability = new Ability(c, "0") { Ability ability = new Ability(c, "0") {
@@ -534,7 +588,6 @@ public final class GameActionUtil {
} }
}; };
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(c.getName()).append(" - add one mana of any color to your mana pool."); sb.append(c.getName()).append(" - add one mana of any color to your mana pool.");
ability.setStackDescription(sb.toString()); ability.setStackDescription(sb.toString());
@@ -544,16 +597,22 @@ public final class GameActionUtil {
AllZone.getStack().addSimultaneousStackEntry(ability); AllZone.getStack().addSimultaneousStackEntry(ability);
} }
} else { } else {
// TODO once AI has a mana pool he should choose add Ability and choose a mana as appropriate // TODO once AI has a mana pool he should choose add Ability and
// choose a mana as appropriate
} }
} }
//not restricted to combat damage, not restricted to dealing damage to creatures/players // not restricted to combat damage, not restricted to dealing damage to
// creatures/players
/** /**
* <p>executeDamageDealingEffects.</p> * <p>
* executeDamageDealingEffects.
* </p>
* *
* @param source a {@link forge.Card} object. * @param source
* @param damage a int. * a {@link forge.Card} object.
* @param damage
* a int.
*/ */
public static void executeDamageDealingEffects(final Card source, final int damage) { public static void executeDamageDealingEffects(final Card source, final int damage) {
@@ -569,11 +628,16 @@ public final class GameActionUtil {
// restricted to combat damage and dealing damage to creatures // restricted to combat damage and dealing damage to creatures
/** /**
* <p>executeCombatDamageToCreatureEffects.</p> * <p>
* executeCombatDamageToCreatureEffects.
* </p>
* *
* @param source a {@link forge.Card} object. * @param source
* @param affected a {@link forge.Card} object. * a {@link forge.Card} object.
* @param damage a int. * @param affected
* a {@link forge.Card} object.
* @param damage
* a int.
*/ */
public static void executeCombatDamageToCreatureEffects(final Card source, final Card affected, final int damage) { public static void executeCombatDamageToCreatureEffects(final Card source, final Card affected, final int damage) {
@@ -581,16 +645,23 @@ public final class GameActionUtil {
return; return;
} }
//placeholder for any future needs (everything that was here is converted to script) // placeholder for any future needs (everything that was here is
// converted to script)
} }
//not restricted to combat damage, restricted to dealing damage to creatures // not restricted to combat damage, restricted to dealing damage to
// creatures
/** /**
* <p>executeDamageToCreatureEffects.</p> * <p>
* executeDamageToCreatureEffects.
* </p>
* *
* @param source a {@link forge.Card} object. * @param source
* @param affected a {@link forge.Card} object. * a {@link forge.Card} object.
* @param damage a int. * @param affected
* a {@link forge.Card} object.
* @param damage
* a int.
*/ */
public static void executeDamageToCreatureEffects(final Card source, final Card affected, final int damage) { public static void executeDamageToCreatureEffects(final Card source, final Card affected, final int damage) {
@@ -638,7 +709,8 @@ public final class GameActionUtil {
ability2.setStackDescription(sb.toString()); ability2.setStackDescription(sb.toString());
if (affected.hasKeyword("When CARDNAME is dealt damage, destroy it. It can't be regenerated.")) { if (affected.hasKeyword("When CARDNAME is dealt damage, destroy it. It can't be regenerated.")) {
int amount = affected.getAmountOfKeyword("When CARDNAME is dealt damage, destroy it. It can't be regenerated."); int amount = affected
.getAmountOfKeyword("When CARDNAME is dealt damage, destroy it. It can't be regenerated.");
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
AllZone.getStack().addSimultaneousStackEntry(ability2); AllZone.getStack().addSimultaneousStackEntry(ability2);
@@ -660,17 +732,21 @@ public final class GameActionUtil {
// this is for cards like Sengir Vampire // this is for cards like Sengir Vampire
/** /**
* <p>executeVampiricEffects.</p> * <p>
* executeVampiricEffects.
* </p>
* *
* @param c a {@link forge.Card} object. * @param c
* a {@link forge.Card} object.
*/ */
public static void executeVampiricEffects(final Card c) { public static void executeVampiricEffects(final Card c) {
ArrayList<String> a = c.getKeyword(); ArrayList<String> a = c.getKeyword();
for (int i = 0; i < a.size(); i++) { for (int i = 0; i < a.size(); i++) {
if (AllZoneUtil.isCardInPlay(c) if (AllZoneUtil.isCardInPlay(c)
&& a.get(i).toString().startsWith( && a.get(i)
"Whenever a creature dealt damage by CARDNAME this turn is put into a graveyard, put")) .toString()
{ .startsWith(
"Whenever a creature dealt damage by CARDNAME this turn is put into a graveyard, put")) {
final Card thisCard = c; final Card thisCard = c;
final String kw = a.get(i).toString(); final String kw = a.get(i).toString();
Ability ability2 = new Ability(c, "0") { Ability ability2 = new Ability(c, "0") {
@@ -703,11 +779,16 @@ public final class GameActionUtil {
// not restricted to just combat damage, restricted to players // not restricted to just combat damage, restricted to players
/** /**
* <p>executeDamageToPlayerEffects.</p> * <p>
* executeDamageToPlayerEffects.
* </p>
* *
* @param player a {@link forge.Player} object. * @param player
* @param c a {@link forge.Card} object. * a {@link forge.Player} object.
* @param damage a int. * @param c
* a {@link forge.Card} object.
* @param damage
* a int.
*/ */
public static void executeDamageToPlayerEffects(final Player player, final Card c, final int damage) { public static void executeDamageToPlayerEffects(final Player player, final Card c, final int damage) {
if (damage <= 0) { if (damage <= 0) {
@@ -756,14 +837,18 @@ public final class GameActionUtil {
} }
} }
// restricted to combat damage, restricted to players // restricted to combat damage, restricted to players
/** /**
* <p>executeCombatDamageToPlayerEffects.</p> * <p>
* executeCombatDamageToPlayerEffects.
* </p>
* *
* @param player a {@link forge.Player} object. * @param player
* @param c a {@link forge.Card} object. * a {@link forge.Player} object.
* @param damage a int. * @param c
* a {@link forge.Card} object.
* @param damage
* a int.
*/ */
public static void executeCombatDamageToPlayerEffects(final Player player, final Card c, final int damage) { public static void executeCombatDamageToPlayerEffects(final Player player, final Card c, final int damage) {
@@ -779,7 +864,9 @@ public final class GameActionUtil {
public void resolve() { public void resolve() {
if (AllZoneUtil.isCardInPlay(zone)) { if (AllZoneUtil.isCardInPlay(zone)) {
zone.addController(c.getController()); zone.addController(c.getController());
//AllZone.getGameAction().changeController(new CardList(zone), zone.getController(), c.getController()); // AllZone.getGameAction().changeController(new
// CardList(zone), zone.getController(),
// c.getController());
} }
} }
}; };
@@ -848,9 +935,12 @@ public final class GameActionUtil {
} // executeCombatDamageToPlayerEffects } // executeCombatDamageToPlayerEffects
/** /**
* <p>execute_Celestial_Mantle.</p> * <p>
* execute_Celestial_Mantle.
* </p>
* *
* @param enchanted a {@link forge.Card} object. * @param enchanted
* a {@link forge.Card} object.
*/ */
private static void execute_Celestial_Mantle(final Card enchanted) { private static void execute_Celestial_Mantle(final Card enchanted) {
ArrayList<Card> auras = enchanted.getEnchantedBy(); ArrayList<Card> auras = enchanted.getEnchantedBy();
@@ -872,9 +962,12 @@ public final class GameActionUtil {
} }
/** /**
* <p>playerCombatDamage_Treva.</p> * <p>
* playerCombatDamage_Treva.
* </p>
* *
* @param c a {@link forge.Card} object. * @param c
* a {@link forge.Card} object.
*/ */
private static void playerCombatDamage_Treva(final Card c) { private static void playerCombatDamage_Treva(final Card c) {
SpellAbility[] sa = c.getSpellAbility(); SpellAbility[] sa = c.getSpellAbility();
@@ -887,9 +980,12 @@ public final class GameActionUtil {
} }
/** /**
* <p>playerCombatDamage_Whirling_Dervish.</p> * <p>
* playerCombatDamage_Whirling_Dervish.
* </p>
* *
* @param c a {@link forge.Card} object. * @param c
* a {@link forge.Card} object.
*/ */
private static void playerCombatDamage_Whirling_Dervish(final Card c) { private static void playerCombatDamage_Whirling_Dervish(final Card c) {
final int power = c.getNetAttack(); final int power = c.getNetAttack();
@@ -921,9 +1017,12 @@ public final class GameActionUtil {
} }
/** /**
* <p>playerCombatDamage_lose_halflife_up.</p> * <p>
* playerCombatDamage_lose_halflife_up.
* </p>
* *
* @param c a {@link forge.Card} object. * @param c
* a {@link forge.Card} object.
*/ */
private static void playerCombatDamage_lose_halflife_up(final Card c) { private static void playerCombatDamage_lose_halflife_up(final Card c) {
final Player player = c.getController(); final Player player = c.getController();
@@ -970,9 +1069,12 @@ public final class GameActionUtil {
} }
/** /**
* <p>playerCombatDamage_Scalpelexis.</p> * <p>
* playerCombatDamage_Scalpelexis.
* </p>
* *
* @param c a {@link forge.Card} object. * @param c
* a {@link forge.Card} object.
*/ */
private static void playerCombatDamage_Scalpelexis(Card c) { private static void playerCombatDamage_Scalpelexis(Card c) {
final Player player = c.getController(); final Player player = c.getController();
@@ -1014,8 +1116,7 @@ public final class GameActionUtil {
if (broken == 0) { if (broken == 0) {
if ((c1.getName().contains(c2.getName()) || c1.getName().contains(c3.getName()) if ((c1.getName().contains(c2.getName()) || c1.getName().contains(c3.getName())
|| c1.getName().contains(c4.getName()) || c2.getName().contains(c3.getName()) || c1.getName().contains(c4.getName()) || c2.getName().contains(c3.getName())
|| c2.getName().contains(c4.getName()) || c3.getName().contains(c4.getName()))) || c2.getName().contains(c4.getName()) || c3.getName().contains(c4.getName()))) {
{
count = count + 1; count = count + 1;
} else { } else {
broken = 1; broken = 1;
@@ -1048,9 +1149,12 @@ public final class GameActionUtil {
} }
/** /**
* <p>playerCombatDamage_Spawnwrithe.</p> * <p>
* playerCombatDamage_Spawnwrithe.
* </p>
* *
* @param c a {@link forge.Card} object. * @param c
* a {@link forge.Card} object.
*/ */
private static void playerCombatDamage_Spawnwrithe(final Card c) { private static void playerCombatDamage_Spawnwrithe(final Card c) {
final Player player = c.getController(); final Player player = c.getController();
@@ -1077,7 +1181,6 @@ public final class GameActionUtil {
} }
/** Constant <code>Elspeth_Emblem</code>. */ /** Constant <code>Elspeth_Emblem</code>. */
public static Command Elspeth_Emblem = new Command() { public static Command Elspeth_Emblem = new Command() {
@@ -1119,8 +1222,7 @@ public final class GameActionUtil {
} // execute() } // execute()
}; };
/** Constant <code>Koth_Emblem</code>. */
/** Constant <code>Koth_Emblem</code> */
public static Command Koth_Emblem = new Command() { public static Command Koth_Emblem = new Command() {
private static final long serialVersionUID = -3233715310427996429L; private static final long serialVersionUID = -3233715310427996429L;
@@ -1186,8 +1288,7 @@ public final class GameActionUtil {
public void resolve() { public void resolve() {
if (getTargetCard() != null) { if (getTargetCard() != null) {
if (AllZoneUtil.isCardInPlay(getTargetCard()) if (AllZoneUtil.isCardInPlay(getTargetCard())
&& CardFactoryUtil.canTarget(c, getTargetCard())) && CardFactoryUtil.canTarget(c, getTargetCard())) {
{
getTargetCard().addDamage(1, c); getTargetCard().addDamage(1, c);
} }
} else { } else {
@@ -1210,10 +1311,14 @@ public final class GameActionUtil {
// Special Conditions // Special Conditions
/** /**
* <p>specialConditionsMet.</p> * <p>
* specialConditionsMet.
* </p>
* *
* @param sourceCard a {@link forge.Card} object. * @param sourceCard
* @param specialConditions a {@link java.lang.String} object. * a {@link forge.Card} object.
* @param specialConditions
* a {@link java.lang.String} object.
* @return a boolean. * @return a boolean.
*/ */
public static boolean specialConditionsMet(final Card sourceCard, final String specialConditions) { public static boolean specialConditionsMet(final Card sourceCard, final String specialConditions) {
@@ -1294,7 +1399,8 @@ public final class GameActionUtil {
} }
} }
if (specialConditions.contains("EnchantedControllerCreaturesGE")) { if (specialConditions.contains("EnchantedControllerCreaturesGE")) {
CardList enchantedControllerInPlay = sourceCard.getEnchantingCard().getController().getCardsIn(Zone.Battlefield); CardList enchantedControllerInPlay = sourceCard.getEnchantingCard().getController()
.getCardsIn(Zone.Battlefield);
enchantedControllerInPlay = enchantedControllerInPlay.getType("Creature"); enchantedControllerInPlay = enchantedControllerInPlay.getType("Creature");
String maxnumber = specialConditions.split("/")[1]; String maxnumber = specialConditions.split("/")[1];
if (!(enchantedControllerInPlay.size() >= Integer.valueOf(maxnumber))) { if (!(enchantedControllerInPlay.size() >= Integer.valueOf(maxnumber))) {
@@ -1338,8 +1444,8 @@ public final class GameActionUtil {
} }
} }
if (specialConditions.contains("isPresent")) { // is a card of a certain
if (specialConditions.contains("isPresent")) { // is a card of a certain type/color present? // type/color present?
String requirements = specialConditions.replaceAll("isPresent ", ""); String requirements = specialConditions.replaceAll("isPresent ", "");
CardList cardsinPlay = AllZoneUtil.getCardsIn(Zone.Battlefield); CardList cardsinPlay = AllZoneUtil.getCardsIn(Zone.Battlefield);
String[] conditions = requirements.split(","); String[] conditions = requirements.split(",");
@@ -1348,7 +1454,9 @@ public final class GameActionUtil {
return false; return false;
} }
} }
if (specialConditions.contains("isInGraveyard")) { // is a card of a certain type/color present in yard? if (specialConditions.contains("isInGraveyard")) { // is a card of a
// certain type/color
// present in yard?
String requirements = specialConditions.replaceAll("isInGraveyard ", ""); String requirements = specialConditions.replaceAll("isInGraveyard ", "");
CardList cardsinYards = AllZoneUtil.getCardsIn(Zone.Graveyard); CardList cardsinYards = AllZoneUtil.getCardsIn(Zone.Graveyard);
String[] conditions = requirements.split(","); String[] conditions = requirements.split(",");
@@ -1357,7 +1465,9 @@ public final class GameActionUtil {
return false; return false;
} }
} }
if (specialConditions.contains("isNotPresent")) { // is no card of a certain type/color present? if (specialConditions.contains("isNotPresent")) { // is no card of a
// certain type/color
// present?
String requirements = specialConditions.replaceAll("isNotPresent ", ""); String requirements = specialConditions.replaceAll("isNotPresent ", "");
CardList cardsInPlay = AllZoneUtil.getCardsIn(Zone.Battlefield); CardList cardsInPlay = AllZoneUtil.getCardsIn(Zone.Battlefield);
String[] conditions = requirements.split(","); String[] conditions = requirements.split(",");
@@ -1381,7 +1491,8 @@ public final class GameActionUtil {
return false; return false;
} }
} }
if (specialConditions.contains("isValid")) { // does this card meet the valid description? if (specialConditions.contains("isValid")) { // does this card meet the
// valid description?
String requirements = specialConditions.replaceAll("isValid ", ""); String requirements = specialConditions.replaceAll("isValid ", "");
if (!sourceCard.isValid(requirements, sourceCard.getController(), sourceCard)) { if (!sourceCard.isValid(requirements, sourceCard.getController(), sourceCard)) {
return false; return false;
@@ -1429,22 +1540,18 @@ public final class GameActionUtil {
public void execute() { public void execute() {
HashMap<String, String> produces = new HashMap<String, String>(); HashMap<String, String> produces = new HashMap<String, String>();
/* /*
* for future use * for future use boolean naked =
boolean naked = AllZoneUtil.isCardInPlay("Naked Singularity"); * AllZoneUtil.isCardInPlay("Naked Singularity"); boolean twist =
boolean twist = AllZoneUtil.isCardInPlay("Reality Twist"); * AllZoneUtil.isCardInPlay("Reality Twist"); //set up what they
//set up what they produce * produce produces.put("Forest", naked || twist ? "B" : "G");
produces.put("Forest", naked || twist ? "B" : "G"); * produces.put("Island", naked == true ? "G" : "U"); if(naked)
produces.put("Island", naked == true ? "G" : "U"); * produces.put("Mountain", "U"); else if(twist)
if(naked) produces.put("Mountain", "U"); * produces.put("Mountain", "W"); else produces.put("Mountain",
else if(twist) produces.put("Mountain", "W"); * "R"); produces.put("Plains", naked || twist ? "R" : "W");
else produces.put("Mountain", "R"); * if(naked) produces.put("Swamp", "W"); else if(twist)
produces.put("Plains", naked || twist ? "R" : "W"); * produces.put("Swamp", "G"); else produces.put("Swamp", "B");
if(naked) produces.put("Swamp", "W");
else if(twist) produces.put("Swamp", "G");
else produces.put("Swamp", "B");
*/ */
produces.put("Forest", "G"); produces.put("Forest", "G");
produces.put("Island", "U"); produces.put("Island", "U");
@@ -1507,7 +1614,6 @@ public final class GameActionUtil {
}; // stLandManaAbilities }; // stLandManaAbilities
/** Constant <code>Coat_of_Arms</code>. */ /** Constant <code>Coat_of_Arms</code>. */
public static Command Coat_of_Arms = new Command() { public static Command Coat_of_Arms = new Command() {
private static final long serialVersionUID = 583505612126735693L; private static final long serialVersionUID = 583505612126735693L;
@@ -1544,10 +1650,8 @@ public final class GameActionUtil {
if (!alreadyAdded.contains(type.get(x))) { if (!alreadyAdded.contains(type.get(x))) {
if (!type.get(x).getType().get(x2).equals("Creature") if (!type.get(x).getType().get(x2).equals("Creature")
&& !type.get(x).getType().get(x2).equals("Legendary") && !type.get(x).getType().get(x2).equals("Legendary")
&& !type.get(x).getType().get(x2).equals("Artifact")) && !type.get(x).getType().get(x2).equals("Artifact")) {
{ if (crd.isType(type.get(x).getType().get(x2))) {
if (crd.isType(type.get(x).getType().get(x2)))
{
alreadyAdded.add(type.get(x)); alreadyAdded.add(type.get(x));
crd.addSemiPermanentAttackBoost(1); crd.addSemiPermanentAttackBoost(1);
crd.addSemiPermanentDefenseBoost(1); crd.addSemiPermanentDefenseBoost(1);
@@ -1613,9 +1717,7 @@ public final class GameActionUtil {
}; };
/** /** stores the Command. */
* stores the Command
*/
public static Command Umbra_Stalker = new Command() { public static Command Umbra_Stalker = new Command() {
private static final long serialVersionUID = -3500747003228938898L; private static final long serialVersionUID = -3500747003228938898L;
@@ -1641,8 +1743,7 @@ public final class GameActionUtil {
list = list.filter(new CardListFilter() { list = list.filter(new CardListFilter() {
public boolean addCard(final Card c) { public boolean addCard(final Card c) {
return c.getName().equals("Avatar") return c.getName().equals("Avatar") && c.getImageName().equals("W N N Avatar");
&& c.getImageName().equals("W N N Avatar");
} }
}); });
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
@@ -1727,7 +1828,6 @@ public final class GameActionUtil {
}; // Liu_Bei }; // Liu_Bei
/** Constant <code>Sound_the_Call_Wolf</code>. */ /** Constant <code>Sound_the_Call_Wolf</code>. */
public static Command Sound_the_Call_Wolf = new Command() { public static Command Sound_the_Call_Wolf = new Command() {
private static final long serialVersionUID = 4614281706799537283L; private static final long serialVersionUID = 4614281706799537283L;
@@ -1857,9 +1957,7 @@ public final class GameActionUtil {
for (int i = 0; i < creature.size(); i++) { for (int i = 0; i < creature.size(); i++) {
c = creature.get(i); c = creature.get(i);
if (((c.getAbilityText().trim().equals("") || c.isFaceDown()) if (((c.getAbilityText().trim().equals("") || c.isFaceDown()) && c.getUnhiddenKeyword().size() == 0)) {
&& c.getUnhiddenKeyword().size() == 0))
{
c.addSemiPermanentAttackBoost(2); c.addSemiPermanentAttackBoost(2);
c.addSemiPermanentDefenseBoost(2); c.addSemiPermanentDefenseBoost(2);
@@ -1875,9 +1973,12 @@ public final class GameActionUtil {
// if Computer has 2 Glorious Anthems, AllZone.getComputerPlay() will be // if Computer has 2 Glorious Anthems, AllZone.getComputerPlay() will be
// returned twice // returned twice
/** /**
* <p>getZone.</p> * <p>
* getZone.
* </p>
* *
* @param cardName a {@link java.lang.String} object. * @param cardName
* a {@link java.lang.String} object.
* @return an array of {@link forge.PlayerZone} objects. * @return an array of {@link forge.PlayerZone} objects.
*/ */
private static PlayerZone[] getZone(final String cardName) { private static PlayerZone[] getZone(final String cardName) {
@@ -1923,11 +2024,13 @@ public final class GameActionUtil {
// /The commands above are in alphabetical order by cardname. // /The commands above are in alphabetical order by cardname.
} }
/** /**
* <p>doPowerSink.</p> * <p>
* doPowerSink.
* </p>
* *
* @param p a {@link forge.Player} object. * @param p
* a {@link forge.Player} object.
*/ */
public static void doPowerSink(final Player p) { public static void doPowerSink(final Player p) {
// get all lands with mana abilities // get all lands with mana abilities

View File

@@ -4,9 +4,11 @@ import java.util.ArrayList;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
// TODO: Auto-generated Javadoc
/** /**
* <p>Abstract Player class.</p> * <p>
* Abstract Player class.
* </p>
* *
* @author Forge * @author Forge
* @version $Id: Player.java 10091 2011-08-30 16:11:21Z Sloth $ * @version $Id: Player.java 10091 2011-08-30 16:11:21Z Sloth $
@@ -14,10 +16,14 @@ import forge.card.spellability.SpellAbility;
public abstract class GameEntity extends MyObservable { public abstract class GameEntity extends MyObservable {
private String name = ""; private String name = "";
private int preventNextDamage = 0; private int preventNextDamage = 0;
/** The enchanted by. */
protected ArrayList<Card> enchantedBy = new ArrayList<Card>(); protected ArrayList<Card> enchantedBy = new ArrayList<Card>();
/** /**
* <p>Getter for the field <code>name</code>.</p> * <p>
* Getter for the field <code>name</code>.
* </p>
* *
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
@@ -25,11 +31,13 @@ public abstract class GameEntity extends MyObservable {
return name; return name;
} }
/** /**
* <p>Setter for the field <code>name</code>.</p> * <p>
* Setter for the field <code>name</code>.
* </p>
* *
* @param s a {@link java.lang.String} object. * @param s
* a {@link java.lang.String} object.
*/ */
public void setName(String s) { public void setName(String s) {
name = s; name = s;
@@ -42,10 +50,14 @@ public abstract class GameEntity extends MyObservable {
// //////////////////////// // ////////////////////////
/** /**
* <p>addDamage.</p> * <p>
* addDamage.
* </p>
* *
* @param damage a int. * @param damage
* @param source a {@link forge.Card} object. * a int.
* @param source
* a {@link forge.Card} object.
*/ */
public void addDamage(final int damage, final Card source) { public void addDamage(final int damage, final Card source) {
int damageToDo = damage; int damageToDo = damage;
@@ -57,10 +69,14 @@ public abstract class GameEntity extends MyObservable {
} }
/** /**
* <p>addDamageWithoutPrevention.</p> * <p>
* addDamageWithoutPrevention.
* </p>
* *
* @param damage a int. * @param damage
* @param source a {@link forge.Card} object. * a int.
* @param source
* a {@link forge.Card} object.
*/ */
public void addDamageWithoutPrevention(final int damage, final Card source) { public void addDamageWithoutPrevention(final int damage, final Card source) {
int damageToDo = damage; int damageToDo = damage;
@@ -70,27 +86,39 @@ public abstract class GameEntity extends MyObservable {
addDamageAfterPrevention(damageToDo, source, false); addDamageAfterPrevention(damageToDo, source, false);
} }
//This function handles damage after replacement and prevention effects are applied // This function handles damage after replacement and prevention effects are
// applied
/** /**
* <p>addDamageAfterPrevention.</p> * <p>
* addDamageAfterPrevention.
* </p>
* *
* @param damage a int. * @param damage
* @param source a {@link forge.Card} object. * a int.
* @param isCombat a boolean. * @param source
* a {@link forge.Card} object.
* @param isCombat
* a boolean.
*/ */
public void addDamageAfterPrevention(final int damage, final Card source, final boolean isCombat) { public void addDamageAfterPrevention(final int damage, final Card source, final boolean isCombat) {
} }
/** /**
* <p>predictDamage.</p> * <p>
* predictDamage.
* </p>
* *
* @param damage a int. * @param damage
* @param source a {@link forge.Card} object. * a int.
* @param isCombat a boolean. * @param source
* a {@link forge.Card} object.
* @param isCombat
* a boolean.
* @return a int. * @return a int.
*/ */
//This function helps the AI calculate the actual amount of damage an effect would deal // This function helps the AI calculate the actual amount of damage an
// effect would deal
public int predictDamage(final int damage, final Card source, final boolean isCombat) { public int predictDamage(final int damage, final Card source, final boolean isCombat) {
int restDamage = damage; int restDamage = damage;
@@ -101,26 +129,38 @@ public abstract class GameEntity extends MyObservable {
return restDamage; return restDamage;
} }
//This should be also usable by the AI to forecast an effect (so it must not change the game state) // This should be also usable by the AI to forecast an effect (so it must
// not change the game state)
/** /**
* <p>staticDamagePrevention.</p> * <p>
* staticDamagePrevention.
* </p>
* *
* @param damage a int. * @param damage
* @param source a {@link forge.Card} object. * a int.
* @param isCombat a boolean. * @param source
* a {@link forge.Card} object.
* @param isCombat
* a boolean.
* @return a int. * @return a int.
*/ */
public int staticDamagePrevention(final int damage, final Card source, final boolean isCombat) { public int staticDamagePrevention(final int damage, final Card source, final boolean isCombat) {
return 0; return 0;
} }
//This should be also usable by the AI to forecast an effect (so it must not change the game state) // This should be also usable by the AI to forecast an effect (so it must
// not change the game state)
/** /**
* <p>staticReplaceDamage.</p> * <p>
* staticReplaceDamage.
* </p>
* *
* @param damage a int. * @param damage
* @param source a {@link forge.Card} object. * a int.
* @param isCombat a boolean. * @param source
* a {@link forge.Card} object.
* @param isCombat
* a boolean.
* @return a int. * @return a int.
*/ */
public int staticReplaceDamage(final int damage, Card source, boolean isCombat) { public int staticReplaceDamage(final int damage, Card source, boolean isCombat) {
@@ -128,11 +168,16 @@ public abstract class GameEntity extends MyObservable {
} }
/** /**
* <p>replaceDamage.</p> * <p>
* replaceDamage.
* </p>
* *
* @param damage a int. * @param damage
* @param source a {@link forge.Card} object. * a int.
* @param isCombat a boolean. * @param source
* a {@link forge.Card} object.
* @param isCombat
* a boolean.
* @return a int. * @return a int.
*/ */
public int replaceDamage(final int damage, Card source, boolean isCombat) { public int replaceDamage(final int damage, Card source, boolean isCombat) {
@@ -140,11 +185,16 @@ public abstract class GameEntity extends MyObservable {
} }
/** /**
* <p>preventDamage.</p> * <p>
* preventDamage.
* </p>
* *
* @param damage a int. * @param damage
* @param source a {@link forge.Card} object. * a int.
* @param isCombat a boolean. * @param source
* a {@link forge.Card} object.
* @param isCombat
* a boolean.
* @return a int. * @return a int.
*/ */
public int preventDamage(final int damage, Card source, boolean isCombat) { public int preventDamage(final int damage, Card source, boolean isCombat) {
@@ -159,16 +209,21 @@ public abstract class GameEntity extends MyObservable {
// PreventNextDamage // PreventNextDamage
/** /**
* <p>Setter for the field <code>preventNextDamage</code>.</p> * <p>
* Setter for the field <code>preventNextDamage</code>.
* </p>
* *
* @param n a int. * @param n
* a int.
*/ */
public void setPreventNextDamage(int n) { public void setPreventNextDamage(int n) {
preventNextDamage = n; preventNextDamage = n;
} }
/** /**
* <p>Getter for the field <code>preventNextDamage</code>.</p> * <p>
* Getter for the field <code>preventNextDamage</code>.
* </p>
* *
* @return a int. * @return a int.
*/ */
@@ -177,64 +232,105 @@ public abstract class GameEntity extends MyObservable {
} }
/** /**
* <p>addPreventNextDamage.</p> * <p>
* addPreventNextDamage.
* </p>
* *
* @param n a int. * @param n
* a int.
*/ */
public void addPreventNextDamage(int n) { public void addPreventNextDamage(int n) {
preventNextDamage += n; preventNextDamage += n;
} }
/** /**
* <p>subtractPreventNextDamage.</p> * <p>
* subtractPreventNextDamage.
* </p>
* *
* @param n a int. * @param n
* a int.
*/ */
public void subtractPreventNextDamage(int n) { public void subtractPreventNextDamage(int n) {
preventNextDamage -= n; preventNextDamage -= n;
} }
/** /**
* <p>resetPreventNextDamage.</p> * <p>
* resetPreventNextDamage.
* </p>
*/ */
public void resetPreventNextDamage() { public void resetPreventNextDamage() {
preventNextDamage = 0; preventNextDamage = 0;
} }
/**
* Checks for keyword.
*
* @param keyword the keyword
* @return true, if successful
*/
public boolean hasKeyword(String keyword) { public boolean hasKeyword(String keyword) {
return false; return false;
} }
/** /**
* Can target.
* *
* @param sa * @param sa the sa
* @return a boolean * @return a boolean
*/ */
public boolean canTarget(SpellAbility sa) { public boolean canTarget(SpellAbility sa) {
return false; return false;
} }
/**
* Checks if is valid.
*
* @param Restrictions the restrictions
* @param sourceController the source controller
* @param source the source
* @return true, if is valid
*/
public boolean isValid(final String Restrictions[], final Player sourceController, final Card source) { public boolean isValid(final String Restrictions[], final Player sourceController, final Card source) {
for (int i = 0; i < Restrictions.length; i++) { for (int i = 0; i < Restrictions.length; i++) {
if (isValid(Restrictions[i], sourceController, source)) return true; if (isValid(Restrictions[i], sourceController, source))
return true;
} }
return false; return false;
}// isValid }// isValid
/**
* Checks if is valid.
*
* @param Restriction the restriction
* @param sourceController the source controller
* @param source the source
* @return true, if is valid
*/
public boolean isValid(final String Restriction, final Player sourceController, final Card source) { public boolean isValid(final String Restriction, final Player sourceController, final Card source) {
return false; return false;
} }
/**
* Checks for property.
*
* @param Property the property
* @param sourceController the source controller
* @param source the source
* @return true, if successful
*/
public boolean hasProperty(String Property, final Player sourceController, final Card source) { public boolean hasProperty(String Property, final Player sourceController, final Card source) {
return false; return false;
} }
// GameEntities can now be Enchanted // GameEntities can now be Enchanted
/** /**
* <p>Getter for the field <code>enchantedBy</code>.</p> * <p>
* Getter for the field <code>enchantedBy</code>.
* </p>
* *
* @return a {@link java.util.ArrayList} object. * @return a {@link java.util.ArrayList} object.
*/ */
@@ -243,16 +339,21 @@ public abstract class GameEntity extends MyObservable {
} }
/** /**
* <p>Setter for the field <code>enchantedBy</code>.</p> * <p>
* Setter for the field <code>enchantedBy</code>.
* </p>
* *
* @param list a {@link java.util.ArrayList} object. * @param list
* a {@link java.util.ArrayList} object.
*/ */
public final void setEnchantedBy(final ArrayList<Card> list) { public final void setEnchantedBy(final ArrayList<Card> list) {
enchantedBy = list; enchantedBy = list;
} }
/** /**
* <p>isEnchanted.</p> * <p>
* isEnchanted.
* </p>
* *
* @return a boolean. * @return a boolean.
*/ */
@@ -260,11 +361,13 @@ public abstract class GameEntity extends MyObservable {
return enchantedBy.size() != 0; return enchantedBy.size() != 0;
} }
/** /**
* <p>addEnchantedBy.</p> * <p>
* addEnchantedBy.
* </p>
* *
* @param c a {@link forge.Card} object. * @param c
* a {@link forge.Card} object.
*/ */
public final void addEnchantedBy(final Card c) { public final void addEnchantedBy(final Card c) {
enchantedBy.add(c); enchantedBy.add(c);
@@ -272,9 +375,12 @@ public abstract class GameEntity extends MyObservable {
} }
/** /**
* <p>removeEnchantedBy.</p> * <p>
* removeEnchantedBy.
* </p>
* *
* @param c a {@link forge.Card} object. * @param c
* a {@link forge.Card} object.
*/ */
public final void removeEnchantedBy(final Card c) { public final void removeEnchantedBy(final Card c) {
enchantedBy.remove(c); enchantedBy.remove(c);
@@ -282,7 +388,9 @@ public abstract class GameEntity extends MyObservable {
} }
/** /**
* <p>unEnchantAllCards.</p> * <p>
* unEnchantAllCards.
* </p>
*/ */
public final void unEnchantAllCards() { public final void unEnchantAllCards() {
for (int i = 0; i < enchantedBy.size(); i++) { for (int i = 0; i < enchantedBy.size(); i++) {
@@ -290,7 +398,6 @@ public abstract class GameEntity extends MyObservable {
} }
} }
// ////////////////////////////// // //////////////////////////////
// //
// generic Object overrides // generic Object overrides

View File

@@ -1,33 +1,46 @@
package forge; package forge;
import forge.properties.ForgeProps; import java.awt.Point;
import forge.properties.NewConstants.LANG.Gui_DownloadPrices.DOWNLOADPRICES; import java.io.BufferedInputStream;
import forge.properties.NewConstants.QUEST; import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import javax.swing.*; import java.io.BufferedWriter;
import java.awt.*; import java.io.File;
import java.io.*; import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.net.Proxy; import java.net.Proxy;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import forge.properties.ForgeProps;
import forge.properties.NewConstants.LANG.Gui_DownloadPrices.DOWNLOADPRICES;
import forge.properties.NewConstants.QUEST;
/** /**
* <p>Gui_DownloadPrices class.</p> * <p>
* Gui_DownloadPrices class.
* </p>
* *
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
public class Gui_DownloadPrices extends JFrame { public class Gui_DownloadPrices extends JFrame {
/** Constant <code>serialVersionUID=1L</code> */ /** Constant <code>serialVersionUID=1L</code>. */
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private JPanel jContentPane = null; private JPanel jContentPane = null;
private JButton jButton = null; private JButton jButton = null;
/** /**
* This is the default constructor * This is the default constructor.
*/ */
public Gui_DownloadPrices() { public Gui_DownloadPrices() {
super(); super();
@@ -35,7 +48,7 @@ public class Gui_DownloadPrices extends JFrame {
} }
/** /**
* This method initializes this * This method initializes this.
*/ */
private void initialize() { private void initialize() {
this.setSize(386, 200); this.setSize(386, 200);
@@ -44,7 +57,7 @@ public class Gui_DownloadPrices extends JFrame {
} }
/** /**
* This method initializes jContentPane * This method initializes jContentPane.
* *
* @return javax.swing.JPanel * @return javax.swing.JPanel
*/ */
@@ -58,7 +71,7 @@ public class Gui_DownloadPrices extends JFrame {
} }
/** /**
* This method initializes jButton * This method initializes jButton.
* *
* @return javax.swing.JButton * @return javax.swing.JButton
*/ */
@@ -70,9 +83,10 @@ public class Gui_DownloadPrices extends JFrame {
jButton.setSize(158, 89); jButton.setSize(158, 89);
jButton.addActionListener(new java.awt.event.ActionListener() { jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) { public void actionPerformed(final java.awt.event.ActionEvent e) {
if (jButton.getText().equals("Done!")) if (jButton.getText().equals("Done!")) {
Gui_DownloadPrices.this.dispose(); Gui_DownloadPrices.this.dispose();
}
BufferedInputStream in = null; BufferedInputStream in = null;
BufferedOutputStream out = null; BufferedOutputStream out = null;
@@ -85,14 +99,12 @@ public class Gui_DownloadPrices extends JFrame {
String s = "Downloading"; String s = "Downloading";
try { try {
in = new BufferedInputStream(new URL(url) in = new BufferedInputStream(new URL(url).openConnection(p).getInputStream());
.openConnection(p).getInputStream());
out = new BufferedOutputStream(new FileOutputStream(f)); out = new BufferedOutputStream(new FileOutputStream(f));
jButton.setText(ForgeProps.getLocalized(DOWNLOADPRICES.DOWNLOADING)); jButton.setText(ForgeProps.getLocalized(DOWNLOADPRICES.DOWNLOADING));
jContentPane.paintImmediately(jButton.getBounds()); jContentPane.paintImmediately(jButton.getBounds());
int len = 0; int len = 0;
while ((len = in.read(buf)) != -1) { while ((len = in.read(buf)) != -1) {
out.write(buf, 0, len); out.write(buf, 0, len);
@@ -100,8 +112,7 @@ public class Gui_DownloadPrices extends JFrame {
if (++x % 50 == 0) { if (++x % 50 == 0) {
s += "."; s += ".";
jButton.setText(s); jButton.setText(s);
jContentPane.paintImmediately(jButton jContentPane.paintImmediately(jButton.getBounds());
.getBounds());
if (x >= 300) { if (x >= 300) {
x = 0; x = 0;
@@ -116,10 +127,12 @@ public class Gui_DownloadPrices extends JFrame {
return; return;
} finally { } finally {
try { try {
if (in != null) if (in != null) {
in.close(); in.close();
if (out != null) }
if (out != null) {
out.close(); out.close();
}
} catch (IOException ex) { } catch (IOException ex) {
return; return;
} }
@@ -144,7 +157,7 @@ public class Gui_DownloadPrices extends JFrame {
x = 0; x = 0;
s = "Compiling"; s = "Compiling";
while (line != null && !line.equals("")) { while (line != null && !line.equals("")) {
String ll[] = line.split("\\|"); String[] ll = line.split("\\|");
if (ll[0].contains("(")) { if (ll[0].contains("(")) {
int indx = ll[0].indexOf(" ("); int indx = ll[0].indexOf(" (");
@@ -160,21 +173,25 @@ public class Gui_DownloadPrices extends JFrame {
if (cp >= inp) { if (cp >= inp) {
fScl = 1 - (float) inp / (float) cp; fScl = 1 - (float) inp / (float) cp;
if (fScl > .333) if (fScl > .333) {
cp = cp / 2; cp = cp / 2;
}
} else { } else {
fScl = 1 - (float) cp / (float) inp; fScl = 1 - (float) cp / (float) inp;
if (fScl > .333) if (fScl > .333) {
inp = inp / 2; inp = inp / 2;
} }
}
int ap = (cp + inp) / 2; int ap = (cp + inp) / 2;
if (ap < 7) if (ap < 7) {
ap += 10; ap += 10;
}
prices.put(ll[0], ap); prices.put(ll[0], ap);
} else { } else {
if (inp < 7) if (inp < 7) {
inp += 10; inp += 10;
}
prices.put(ll[0], inp); prices.put(ll[0], inp);
} }
@@ -185,8 +202,7 @@ public class Gui_DownloadPrices extends JFrame {
if (++x % 100 == 0) { if (++x % 100 == 0) {
s += "."; s += ".";
jButton.setText(s); jButton.setText(s);
jContentPane.paintImmediately(jButton jContentPane.paintImmediately(jButton.getBounds());
.getBounds());
if (x >= 500) { if (x >= 500) {
x = 0; x = 0;
@@ -195,14 +211,12 @@ public class Gui_DownloadPrices extends JFrame {
} }
} }
String pfn = ForgeProps.getFile(QUEST.PRICE) String pfn = ForgeProps.getFile(QUEST.PRICE).getAbsolutePath();
.getAbsolutePath();
String pfnb = pfn.replace(".txt", ".bak"); String pfnb = pfn.replace(".txt", ".bak");
File ff = new File(pfn); File ff = new File(pfn);
ff.renameTo(new File(pfnb)); ff.renameTo(new File(pfnb));
fw = new FileWriter(ForgeProps fw = new FileWriter(ForgeProps.getFile(QUEST.PRICE));
.getFile(QUEST.PRICE));
BufferedWriter outBW = new BufferedWriter(fw); BufferedWriter outBW = new BufferedWriter(fw);
// Collection<String> keys = prices.keySet(); // Collection<String> keys = prices.keySet();
@@ -213,25 +227,23 @@ public class Gui_DownloadPrices extends JFrame {
for (int i = 0; i < keys.size(); i++) { for (int i = 0; i < keys.size(); i++) {
// keys.add(key); // keys.add(key);
String k = keys.get(i); String k = keys.get(i);
if (k.equals("Plains") || k.equals("Island") if (k.equals("Plains") || k.equals("Island") || k.equals("Swamp") || k.equals("Mountain")
|| k.equals("Swamp")
|| k.equals("Mountain")
|| k.equals("Forest")) || k.equals("Forest"))
{
outBW.write(k + "=5\r\n"); outBW.write(k + "=5\r\n");
} else if (k.equals("Snow-Covered Plains") || k.equals("Snow-Covered Island")
else if (k.equals("Snow-Covered Plains") || k.equals("Snow-Covered Swamp") || k.equals("Snow-Covered Mountain")
|| k.equals("Snow-Covered Island")
|| k.equals("Snow-Covered Swamp")
|| k.equals("Snow-Covered Mountain")
|| k.equals("Snow-Covered Forest")) || k.equals("Snow-Covered Forest"))
{
outBW.write(k + "=10\r\n"); outBW.write(k + "=10\r\n");
else } else {
outBW.write(keys.get(i) + "=" outBW.write(keys.get(i) + "=" + prices.get(keys.get(i)) + "\r\n");
+ prices.get(keys.get(i)) + "\r\n"); }
if (i % 100 == 0) if (i % 100 == 0) {
outBW.flush(); outBW.flush();
} }
}
outBW.flush(); outBW.flush();
outBW.close(); outBW.close();
@@ -244,10 +256,12 @@ public class Gui_DownloadPrices extends JFrame {
return; return;
} finally { } finally {
try { try {
if (fr != null) if (fr != null) {
fr.close(); fr.close();
if (fw != null) }
if (fw != null) {
fw.close(); fw.close();
}
} catch (IOException ex) { } catch (IOException ex) {
return; return;
} }