- CheckStyle.

This commit is contained in:
Chris
2012-11-23 20:22:21 +00:00
parent df47bab393
commit cf4d65bf73
19 changed files with 156 additions and 133 deletions

View File

@@ -87,7 +87,7 @@ public enum FControl {
public static final int DRAFTING_PROCESS = 7;
private final SoundSystem soundSystem = new SoundSystem();
/**
* <p>
* FControl.
@@ -282,8 +282,9 @@ public enum FControl {
*/
private Lobby lobby = null;
public Lobby getLobby() {
if( lobby == null )
if (lobby == null) {
lobby = new Lobby();
}
return lobby;
}

View File

@@ -53,16 +53,15 @@ public class Lobby {
"Roger", "Roland", "Ronald", "Roy", "Sam", "Sebastian", "Simon", "Stanley", "Stephen",
"Stuart", "Terence", "Thomas", "Tim", "Tom", "Tony", "Victor", "Vincent", "Wallace",
"Walter", "Wilfred", "William", "Winston"
};
};
/**
* TODO: Write javadoc for this method.
* @param human
* @return
*/
public LobbyPlayer findLocalPlayer(PlayerType type, String name) {
return new LobbyPlayer(type, name);
}
@@ -72,10 +71,11 @@ public class Lobby {
* @return
*/
public LobbyPlayer findLocalPlayer(PlayerType type) {
if ( type == PlayerType.HUMAN )
if (type == PlayerType.HUMAN) {
return new LobbyPlayer(type, "Human"); // need to get name!
LobbyPlayer player = findLocalPlayer(type, getRandomName());
}
LobbyPlayer player = findLocalPlayer(type, getRandomName());
player.setAvatarIndex(MyRandom.getRandom().nextInt(FSkin.getAvatars().size()));
return player;
}
@@ -88,7 +88,7 @@ public class Lobby {
private String getRandomName() {
Random my = MyRandom.getRandom();
return opponentNames[my.nextInt(opponentNames.length)];
}
/**
@@ -99,6 +99,5 @@ public class Lobby {
return new LobbyPlayer(PlayerType.HUMAN, "Human"); // need to get name!
}
}

View File

@@ -116,12 +116,13 @@ public abstract class Input implements java.io.Serializable {
public String toString() {
return "blank";
} // returns the Input name like "EmptyStack"
/**
* This method is used to mark old descendants of Input
* TODO: Write javadoc for this method.
*/
public /*abstract */void isClassUpdated() {}//;
public /*abstract */void isClassUpdated() {
} //;
}

View File

@@ -46,9 +46,9 @@ public class InputBlock extends Input {
private static final long serialVersionUID = 6120743598368928128L;
private Card currentAttacker = null;
private final HashMap<Card,List<Card>> allBlocking = new HashMap<Card, List<Card>>();
private final HashMap<Card, List<Card>> allBlocking = new HashMap<Card, List<Card>>();
private final Player defender;
/**
* TODO: Write javadoc for Constructor.
* @param priority
@@ -110,34 +110,34 @@ public class InputBlock extends Input {
public final void selectCard(final Card card) {
// is attacking?
boolean reminder = true;
if (Singletons.getModel().getGame().getCombat().getAttackers().contains(card)) {
this.currentAttacker = card;
reminder = false;
} else {
Zone zone = Singletons.getModel().getGame().getZoneOf(card);
// Make sure this card is valid to even be a blocker
if (this.currentAttacker != null && card.isCreature() && card.getController().equals(defender)
if (this.currentAttacker != null && card.isCreature() && card.getController().equals(defender)
&& zone.is(ZoneType.Battlefield, defender)) {
// Create a new blockedBy list if it doesn't exist
if (!this.allBlocking.containsKey(card)) {
this.allBlocking.put(card, new ArrayList<Card>());
}
List<Card> attackersBlocked = this.allBlocking.get(card);
if (!attackersBlocked.contains(this.currentAttacker) &&
CombatUtil.canBlock(this.currentAttacker, card, Singletons.getModel().getGame().getCombat())) {
if (!attackersBlocked.contains(this.currentAttacker)
&& CombatUtil.canBlock(this.currentAttacker, card, Singletons.getModel().getGame().getCombat())) {
attackersBlocked.add(this.currentAttacker);
Singletons.getModel().getGame().getCombat().addBlocker(this.currentAttacker, card);
reminder = false;
}
}
}
}
if (reminder) {
SDisplayUtil.remind(VMessage.SINGLETON_INSTANCE);
}
this.showMessage();
} // selectCard()

View File

@@ -40,7 +40,7 @@ public class InputCleanup extends Input {
/** {@inheritDoc} */
@Override
public final void showMessage() {
final Player active = Singletons.getModel().getGame().getPhaseHandler().getPlayerTurn();
final Player active = Singletons.getModel().getGame().getPhaseHandler().getPlayerTurn();
if (active.isComputer()) {
this.aiCleanupDiscard(active);
Singletons.getModel().getGame().getPhaseHandler().passPriority();

View File

@@ -68,7 +68,7 @@ public class InputControl extends MyObservable implements java.io.Serializable {
if (!this.game.getStack().isResolving() && isInputEmpty) {
this.input = in;
} else {
this.inputStack.add(in);
this.inputStack.add(in);
}
this.updateObservers();
}
@@ -202,7 +202,7 @@ public class InputControl extends MyObservable implements java.io.Serializable {
return new InputAttack();
}
break;
case COMBAT_DECLARE_BLOCKERS:
stack.freezeStack();
boolean isUnderAttack = game.getCombat().isPlayerAttacked(priority);
@@ -210,14 +210,15 @@ public class InputControl extends MyObservable implements java.io.Serializable {
handler.passPriority();
return null;
}
if ( priority.isHuman() )
if (priority.isHuman()) {
return new InputBlock(priority);
}
// ai is under attack
priority.getController().getAiInput().getComputer().declareBlockers();
return null;
case CLEANUP:
// discard
if (stack.isEmpty()) {
@@ -236,9 +237,9 @@ public class InputControl extends MyObservable implements java.io.Serializable {
if (priority == null) {
return null;
} else if (priority.isHuman()) {
boolean prioritySkip = priority.getController().mayAutoPass(phase)
|| priority.getController().isUiSetToSkipPhase(playerTurn, phase);
if (this.game.getStack().isEmpty() && prioritySkip ) {
boolean prioritySkip = priority.getController().mayAutoPass(phase)
|| priority.getController().isUiSetToSkipPhase(playerTurn, phase);
if (this.game.getStack().isEmpty() && prioritySkip) {
handler.passPriority();
return null;
} else {

View File

@@ -80,7 +80,7 @@ public class InputMulligan extends Input {
@Override
public final void selectButtonCancel() {
final Player humanPlayer = Singletons.getControl().getPlayer();
final int newHand = humanPlayer.doMulligan();
@@ -90,22 +90,24 @@ public class InputMulligan extends Input {
} // selectButtonOK()
final void end() {
GameState game = Singletons.getModel().getGame();
GameState game = Singletons.getModel().getGame();
// Computer mulligan
for (Player ai : game.getPlayers()) {
if ( ai.isHuman() ) continue;
if (ai.isHuman()) {
continue;
}
boolean aiTakesMulligan = true;
// Computer mulligans if there are no cards with converted mana cost of
// 0 in its hand
while (aiTakesMulligan) {
final List<Card> handList = ai.getCardsIn(ZoneType.Hand);
final boolean hasLittleCmc0Cards = CardLists.getValidCards(handList, "Card.cmcEQ0", ai, null).size() < 2;
aiTakesMulligan = (handList.size() > InputMulligan.AI_MULLIGAN_THRESHOLD) && hasLittleCmc0Cards;
if (aiTakesMulligan) {
ai.doMulligan();
}
@@ -119,16 +121,16 @@ public class InputMulligan extends Input {
final GameAction ga = game.getAction();
for (Player p : game.getPlayers()) {
final List<Card> openingHand = new ArrayList<Card>(p.getCardsIn(ZoneType.Hand));
for (final Card c : openingHand) {
if ( p.isHuman() ) {
if (p.isHuman()) {
final ArrayList<String> kws = c.getKeyword();
for (int i = 0; i < kws.size(); i++) {
final String kw = kws.get(i);
if (kw.startsWith("MayEffectFromOpeningHand")) {
final String effName = kw.split(":")[1];
final SpellAbility effect = af.getAbility(c.getSVar(effName), c);
if (GameActionUtil.showYesNoDialog(c, "Use this card's ability?")) {
// If we ever let the AI memorize cards in the players
@@ -147,12 +149,12 @@ public class InputMulligan extends Input {
final ArrayList<String> kws = c.getKeyword();
for (int i = 0; i < kws.size(); i++) {
final String kw = kws.get(i);
if (kw.startsWith("MayEffectFromOpeningHand")) {
final String effName = kw.split(":")[1];
final SpellAbility effect = af.getAbility(c.getSVar(effName), c);
// Is there a better way for the AI to decide this?
if (effect.doTrigger(false)) {
GameActionUtil.showInfoDialg("Computer reveals " + c.getName() + "(" + c.getUniqueNumber() + ").");
@@ -161,8 +163,9 @@ public class InputMulligan extends Input {
}
}
}
if (c.getName().startsWith("Leyline") && !(c.getName().startsWith("Leyline of Singularity") &&
(Iterables.any(game.getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals("Leyline of Singularity"))))) {
if (c.getName().startsWith("Leyline")
&& !(c.getName().startsWith("Leyline of Singularity")
&& (Iterables.any(game.getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals("Leyline of Singularity"))))) {
ga.moveToPlay(c);
//ga.checkStateEffects();
}
@@ -190,7 +193,7 @@ public class InputMulligan extends Input {
SDisplayUtil.remind(VMessage.SINGLETON_INSTANCE);
}
}
@Override
public void isClassUpdated() {
}

View File

@@ -85,6 +85,7 @@ public class InputPassPriority extends Input {
SDisplayUtil.remind(VMessage.SINGLETON_INSTANCE);
}
} // selectCard()
@Override public void isClassUpdated() {}
@Override public void isClassUpdated() {
}
}

View File

@@ -186,5 +186,6 @@ public class InputPayDiscardCost extends Input {
this.unpaid.execute();
}
@Override public void isClassUpdated() {}
@Override public void isClassUpdated() {
}
}

View File

@@ -117,7 +117,7 @@ public class InputPayManaCost extends InputPayMana {
this.spell = sa;
if (Singletons.getModel().getGame() != null ) {
if (Singletons.getModel().getGame() != null) {
if (sa.getSourceCard().isCopiedSpell() && sa.isSpell()) {
if (this.spell.getAfterPayMana() != null) {
this.stopSetNext(this.spell.getAfterPayMana());
@@ -290,6 +290,7 @@ public class InputPayManaCost extends InputPayMana {
this.done();
}
}
@Override public void isClassUpdated() {}
@Override public void isClassUpdated() {
}
}

View File

@@ -12,15 +12,15 @@ import forge.gui.match.CMatchUI;
import forge.view.ButtonUtil;
public class InputPayManaCost2 extends InputPayMana {
private ManaCost manaCost;
private final CostMana costMana;
// I would kill the one who made 2 classes like above
private final String originalManaCost;
private final SpellAbility sa;
private final SpellAbility sa;
private final int manaToAdd;
private final CostPayment payment;
public InputPayManaCost2(CostMana costMana, SpellAbility spellAbility, final CostPayment payment, int toAdd) {
manaCost = new ManaCost(costMana.getManaToPay());
manaCost.increaseColorlessMana(toAdd);
@@ -30,12 +30,12 @@ public class InputPayManaCost2 extends InputPayMana {
sa = spellAbility;
manaToAdd = toAdd;
this.payment = payment;
}
private static final long serialVersionUID = 3467312982164195091L;
private int phyLifeToLose = 0;
@@ -155,6 +155,7 @@ public class InputPayManaCost2 extends InputPayMana {
this.showMessage();
}
}
@Override public void isClassUpdated() {}
}
@Override public void isClassUpdated() {
}
}

View File

@@ -184,7 +184,7 @@ public class InputPayManaCostAbility extends InputPayMana {
this.showMessage();
}
}
private void done() {
if (this.phyLifeToLose > 0) {
Singletons.getControl().getPlayer().payLife(this.phyLifeToLose, null);
@@ -247,7 +247,8 @@ public class InputPayManaCostAbility extends InputPayMana {
this.showMessage();
}
}
@Override public void isClassUpdated() {}
@Override public void isClassUpdated() {
}
}

View File

@@ -62,7 +62,6 @@ public class InputPayManaCostUtil {
return manaCost;
}
final StringBuilder cneeded = new StringBuilder();
final StringBuilder colorRequired = new StringBuilder();
boolean choice = true;
@@ -80,8 +79,8 @@ public class InputPayManaCostUtil {
List<SpellAbility> abilities = new ArrayList<SpellAbility>();
// you can't remove unneeded abilities inside a for(am:abilities) loop :(
for(SpellAbility ma : card.getManaAbility()) {
for (SpellAbility ma : card.getManaAbility()) {
ma.setActivatingPlayer(Singletons.getControl().getPlayer());
AbilityManaPart m = ma.getManaPart();
if (!ma.canPlay()) {
@@ -95,7 +94,7 @@ public class InputPayManaCostUtil {
}
abilities.add(ma);
if (!skipExpress) {
// skip express mana if the ability is not undoable
if (!ma.isUndoable()) {

View File

@@ -22,7 +22,7 @@ public class InputPayManaX extends InputPayMana {
private final SpellAbility sa;
public InputPayManaX(final SpellAbility sa0, final CostPayment payment0, final CostMana costMana0)
public InputPayManaX(final SpellAbility sa0, final CostPayment payment0, final CostMana costMana0)
{
sa = sa0;
payment = payment0;
@@ -110,5 +110,6 @@ public class InputPayManaX extends InputPayMana {
* @see forge.control.input.Input#isClassUpdated()
*/
@Override
public void isClassUpdated() {}
}
public void isClassUpdated() {
}
}

View File

@@ -185,9 +185,8 @@ public class InputPayReturnCost extends Input {
}
this.unpaid.execute();
}
@Override public void isClassUpdated() {}
@Override public void isClassUpdated() {
}
}

View File

@@ -187,5 +187,6 @@ public class InputPaySacCost extends Input {
this.unpaid.execute();
}
@Override public void isClassUpdated() {}
@Override public void isClassUpdated() {
}
}

View File

@@ -14,42 +14,52 @@ import forge.view.ButtonUtil;
public abstract class InputSelectMany<T extends GameEntity> extends Input {
private static final long serialVersionUID = -2305549394512889450L;
protected final List<T> selected = new ArrayList<T>();
protected final int min;
protected final int max;
private String message = "Source-Card-Name - Select %d more card(s)";
protected InputSelectMany(int min, int max)
{
if( min > max ) throw new IllegalArgumentException("Min must not be greater than Max");
protected InputSelectMany(int min, int max) {
if (min > max) {
throw new IllegalArgumentException("Min must not be greater than Max");
}
this.min = min;
this.max = max;
}
@Override
public final void showMessage() {
String msgToShow = getMessage();
String msgToShow = getMessage();
CMatchUI.SINGLETON_INSTANCE.showMessage(msgToShow);
boolean canCancel = (min == 0 && selected.isEmpty()) || canCancelWithSomethingSelected();
boolean canOk = hasEnoughTargets();
if (canOk && canCancel) ButtonUtil.enableAll();
if (!canOk && canCancel) ButtonUtil.enableOnlyCancel();
if (canOk && !canCancel) ButtonUtil.enableOnlyOK();
if (!canOk && !canCancel) ButtonUtil.disableAll();
if (canOk && canCancel) {
ButtonUtil.enableAll();
}
if (!canOk && canCancel) {
ButtonUtil.enableOnlyCancel();
}
if (canOk && !canCancel) {
ButtonUtil.enableOnlyOK();
}
if (!canOk && !canCancel) {
ButtonUtil.disableAll();
}
}
/**
* TODO: Write javadoc for this method.
* @return
*/
protected String getMessage() {
return max == Integer.MAX_VALUE
? String.format(message, selected.size())
? String.format(message, selected.size())
: String.format(message, max - selected.size());
}
@@ -60,68 +70,69 @@ public abstract class InputSelectMany<T extends GameEntity> extends Input {
// if ( next != null ) {
// Singletons.getModel().getMatch().getInput().setInput(next);
// }
if ( null == next )
if (null == next) {
this.stop();
else
} else {
this.stopSetNext(next);
}
// for a next use
selected.clear();
}
@Override
public final void selectButtonOK() {
// should check here if it still gets into an infinite loop
// should check here if it still gets into an infinite loop
// if an ability is put on stack before this input is stopped;
// if it does, uncomment the 5 lines below, use them as method body
// this.stop();
Input next = onDone(); // might add ability to stack from here
// if ( next != null ) {
// Singletons.getModel().getMatch().getInput().setInput(next);
// }
if ( null == next )
if (null == next) {
this.stop();
else
} else {
this.stopSetNext(next);
}
// for a next use
selected.clear();
}
@Override
public void isClassUpdated() {}
public void isClassUpdated() {
}
public void setMessage(String message0) {
this.message = message0; // TODO: Add 0 to parameter's name.
}
// must define these
protected abstract Input onDone();
protected abstract boolean isValidChoice(T choice);
// might re-define later
protected Input onCancel() { return null; }
protected boolean canCancelWithSomethingSelected() { return false; }
protected boolean hasEnoughTargets() { return selected.size() >= min; }
protected boolean hasAllTargets() { return selected.size() >= max; }
protected void selectEntity(T c)
{
if ( selected.contains(c) || !isValidChoice(c) ) return;
protected void selectEntity(T c) {
if (selected.contains(c) || !isValidChoice(c)) {
return;
}
this.selected.add(c);
this.showMessage();
if ( hasAllTargets() )
if (hasAllTargets()) {
selectButtonOK();
}
}
}

View File

@@ -4,14 +4,14 @@ import forge.Card;
public abstract class InputSelectManyCards extends InputSelectMany<Card> {
private static final long serialVersionUID = -6609493252672573139L;
protected InputSelectManyCards(int min, int max)
{
protected InputSelectManyCards(int min, int max) {
super(min, max);
}
@Override
public final void selectCard(final Card c) {
selectEntity(c);
}
}
}

View File

@@ -9,12 +9,12 @@ import forge.game.player.Player;
public class InputSelectManyPlayers extends InputSelectMany<Player> {
private static final long serialVersionUID = -8209690791522735L;
protected final Function<List<Player>, Input> onComplete;
protected final Function<List<Player>, Input> onComplete;
private final Predicate<Player> allowedFilter;
public InputSelectManyPlayers(final Predicate<Player> allowedRule, int min, int max, final Function<List<Player>, Input> onDone)
{
public InputSelectManyPlayers(final Predicate<Player> allowedRule, int min, int max, final Function<List<Player>, Input> onDone) {
super(min, max);
allowedFilter = allowedRule;
onComplete = onDone;
@@ -25,9 +25,11 @@ public class InputSelectManyPlayers extends InputSelectMany<Player> {
public void selectPlayer(final Player p) {
selectEntity(p);
}
protected boolean isValidChoice(Player choice) {
if ( allowedFilter != null && !allowedFilter.apply(choice)) return false;
if (allowedFilter != null && !allowedFilter.apply(choice)) {
return false;
}
return true;
}
@@ -35,4 +37,4 @@ public class InputSelectManyPlayers extends InputSelectMany<Player> {
protected Input onDone() {
return onComplete.apply(selected);
}
}
}