several Checkstyle fixes in Input_Mulligan

This commit is contained in:
slapshot5
2011-09-15 00:56:17 +00:00
parent 42ebac91ff
commit e31e445a0d

View File

@@ -2,7 +2,16 @@ package forge.gui.input;
import java.util.ArrayList; import java.util.ArrayList;
import forge.*; import forge.AllZone;
import forge.AllZoneUtil;
import forge.ButtonUtil;
import forge.Card;
import forge.CardList;
import forge.ComputerUtil;
import forge.Constant;
import forge.GameActionUtil;
import forge.Phase;
import forge.Player;
import forge.card.abilityFactory.AbilityFactory; import forge.card.abilityFactory.AbilityFactory;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.game.GamePlayerRating; import forge.game.GamePlayerRating;
@@ -16,15 +25,15 @@ import forge.quest.data.QuestData;
* @version $Id$ * @version $Id$
*/ */
public class Input_Mulligan extends Input { public class Input_Mulligan extends Input {
/** Constant <code>serialVersionUID=-8112954303001155622L</code> */ /** Constant <code>serialVersionUID=-8112954303001155622L</code>. */
private static final long serialVersionUID = -8112954303001155622L; private static final long serialVersionUID = -8112954303001155622L;
private static final int MAGIC_NUMBER_OF_SHUFFLES = 100; private static final int MAGIC_NUMBER_OF_SHUFFLES = 100;
private static final int AI_MULLIGAN_THRESHOLD = 5; private static final int AI_MULLIGAN_THRESHOLD = 5;
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void showMessage() { public final void showMessage() {
ButtonUtil.enableAll(); ButtonUtil.enableAll();
AllZone.getDisplay().getButtonOK().setText("No"); AllZone.getDisplay().getButtonOK().setText("No");
AllZone.getDisplay().getButtonCancel().setText("Yes"); AllZone.getDisplay().getButtonCancel().setText("Yes");
@@ -33,11 +42,18 @@ public class Input_Mulligan extends Input {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void selectButtonOK() { public final void selectButtonOK() {
end(); end();
} }
public int doMulligan( Player player, GamePlayerRating playerRating ) { /**
*
* TODO Write javadoc for this method.
* @param player a Player object
* @param playerRating a GamePlayerRating object
* @return an int
*/
public final int doMulligan(final Player player, final GamePlayerRating playerRating) {
CardList hand = AllZoneUtil.getPlayerHand(player); CardList hand = AllZoneUtil.getPlayerHand(player);
for (Card c : hand) { AllZone.getGameAction().moveToLibrary(c); } for (Card c : hand) { AllZone.getGameAction().moveToLibrary(c); }
for (int i = 0; i < MAGIC_NUMBER_OF_SHUFFLES; i++) { player.shuffle(); } for (int i = 0; i < MAGIC_NUMBER_OF_SHUFFLES; i++) { player.shuffle(); }
@@ -47,10 +63,10 @@ public class Input_Mulligan extends Input {
playerRating.notifyOpeningHandSize(newHand); playerRating.notifyOpeningHandSize(newHand);
return newHand; return newHand;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void selectButtonCancel() { public final void selectButtonCancel() {
GamePlayerRating humanRating = AllZone.getGameInfo().getPlayerRating(PlayerIndex.HUMAN); GamePlayerRating humanRating = AllZone.getGameInfo().getPlayerRating(PlayerIndex.HUMAN);
Player humanPlayer = AllZone.getHumanPlayer(); Player humanPlayer = AllZone.getHumanPlayer();
@@ -65,17 +81,17 @@ public class Input_Mulligan extends Input {
if (newHand == 0) { if (newHand == 0) {
end(); end();
} }
}//selectButtonOK() } //selectButtonOK()
/** /**
* <p>end.</p> * <p>end.</p>
*/ */
void end() { final void end() {
//Computer mulligan //Computer mulligan
Player aiPlayer = AllZone.getComputerPlayer(); Player aiPlayer = AllZone.getComputerPlayer();
GamePlayerRating aiRating = AllZone.getGameInfo().getPlayerRating(PlayerIndex.AI); GamePlayerRating aiRating = AllZone.getGameInfo().getPlayerRating(PlayerIndex.AI);
boolean aiTakesMulligan = true; boolean aiTakesMulligan = true;
//Computer mulligans if there are no cards with converted mana cost of 0 in its hand //Computer mulligans if there are no cards with converted mana cost of 0 in its hand
while (aiTakesMulligan) { while (aiTakesMulligan) {
@@ -85,34 +101,33 @@ public class Input_Mulligan extends Input {
if (aiTakesMulligan) { if (aiTakesMulligan) {
doMulligan(aiPlayer, aiRating); doMulligan(aiPlayer, aiRating);
} }
} }
//Human Leylines & Chancellors //Human Leylines & Chancellors
ButtonUtil.reset(); ButtonUtil.reset();
AbilityFactory af = new AbilityFactory(); AbilityFactory af = new AbilityFactory();
CardList humanOpeningHand = AllZoneUtil.getPlayerHand(AllZone.getHumanPlayer()); CardList humanOpeningHand = AllZoneUtil.getPlayerHand(AllZone.getHumanPlayer());
for (Card c : humanOpeningHand) { for (Card c : humanOpeningHand) {
ArrayList<String> kws = c.getKeyword(); ArrayList<String> kws = c.getKeyword();
for(int i = 0;i<kws.size();i++) { for (int i = 0; i < kws.size(); i++) {
String kw = kws.get(i); String kw = kws.get(i);
if(kw.startsWith("MayEffectFromOpeningHand")) if (kw.startsWith("MayEffectFromOpeningHand")) {
{
String effName = kw.split(":")[1]; String effName = kw.split(":")[1];
SpellAbility effect = af.getAbility(c.getSVar(effName), c); SpellAbility effect = af.getAbility(c.getSVar(effName), c);
if(GameActionUtil.showYesNoDialog(c, "Use this card's ability?")) if (GameActionUtil.showYesNoDialog(c, "Use this card's ability?")) {
{
//If we ever let the AI memorize cards in the players hand, this would be a place to do so. //If we ever let the AI memorize cards in the players hand, this would be a place to do so.
AllZone.getGameAction().playSpellAbility_NoStack(effect, false); AllZone.getGameAction().playSpellAbility_NoStack(effect, false);
} }
} }
} }
if (c.getName().startsWith("Leyline")) { if (c.getName().startsWith("Leyline")) {
if (GameActionUtil.showYesNoDialog(c, "Use this card's ability?")) if (GameActionUtil.showYesNoDialog(c, "Use this card's ability?")) {
AllZone.getGameAction().moveToPlay(c); AllZone.getGameAction().moveToPlay(c);
}
} }
} }
@@ -120,37 +135,41 @@ public class Input_Mulligan extends Input {
CardList aiOpeningHand = AllZoneUtil.getPlayerHand(AllZone.getComputerPlayer()); CardList aiOpeningHand = AllZoneUtil.getPlayerHand(AllZone.getComputerPlayer());
for (Card c : aiOpeningHand) { for (Card c : aiOpeningHand) {
if (!c.getName().startsWith("Leyline")) { if (!c.getName().startsWith("Leyline")) {
ArrayList<String> kws = c.getKeyword(); ArrayList<String> kws = c.getKeyword();
for(int i = 0;i<kws.size();i++) { for (int i = 0; i < kws.size(); i++) {
String kw = kws.get(i); String kw = kws.get(i);
if(kw.startsWith("MayEffectFromOpeningHand")) if (kw.startsWith("MayEffectFromOpeningHand")) {
{
String effName = kw.split(":")[1]; String effName = kw.split(":")[1];
SpellAbility effect = af.getAbility(c.getSVar(effName), c); SpellAbility effect = af.getAbility(c.getSVar(effName), c);
if(effect.doTrigger(false)) //Is there a better way for the AI to decide this? //Is there a better way for the AI to decide this?
{ if (effect.doTrigger(false)) {
GameActionUtil.showInfoDialg("Computer reveals " + c.getName() + "(" + c.getUniqueNumber() + ")."); GameActionUtil.showInfoDialg("Computer reveals "
+ c.getName() + "(" + c.getUniqueNumber() + ").");
ComputerUtil.playNoStack(effect); ComputerUtil.playNoStack(effect);
} }
} }
} }
} }
if (c.getName().startsWith("Leyline") && !(c.getName().startsWith("Leyline of Singularity") if (c.getName().startsWith("Leyline") && !(c.getName().startsWith("Leyline of Singularity")
&& AllZoneUtil.getCardsInPlay("Leyline of Singularity").size() > 0)) { && AllZoneUtil.getCardsInPlay("Leyline of Singularity").size() > 0))
{
AllZone.getGameAction().moveToPlay(c); AllZone.getGameAction().moveToPlay(c);
AllZone.getGameAction().checkStateEffects(); AllZone.getGameAction().checkStateEffects();
} }
} }
AllZone.getGameAction().checkStateEffects(); AllZone.getGameAction().checkStateEffects();
if (AllZone.getGameAction().isStartCut() && !(humanOpeningHand.contains(AllZone.getGameAction().getHumanCut()) if (AllZone.getGameAction().isStartCut() && !(humanOpeningHand.contains(AllZone.getGameAction().getHumanCut())
|| aiOpeningHand.contains(AllZone.getGameAction().getComputerCut()))) { || aiOpeningHand.contains(AllZone.getGameAction().getComputerCut())))
AllZone.getGameAction().moveTo(AllZone.getZone(Constant.Zone.Library, AllZone.getHumanPlayer()), AllZone.getGameAction().getHumanCut()); {
AllZone.getGameAction().moveTo(AllZone.getZone(Constant.Zone.Library, AllZone.getComputerPlayer()), AllZone.getGameAction().getComputerCut()); AllZone.getGameAction().moveTo(AllZone.getZone(Constant.Zone.Library, AllZone.getHumanPlayer()),
AllZone.getGameAction().getHumanCut());
AllZone.getGameAction().moveTo(AllZone.getZone(Constant.Zone.Library, AllZone.getComputerPlayer()),
AllZone.getGameAction().getComputerCut());
} }
AllZone.getGameAction().checkStateEffects(); AllZone.getGameAction().checkStateEffects();
Phase.setGameBegins(1); Phase.setGameBegins(1);