From 203a432255c0652fb1561cb0fe441ef4673d8d52 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 27 Nov 2012 15:08:04 +0000 Subject: [PATCH] - CheckStyle. --- src/main/java/forge/game/player/Player.java | 161 ++++++++++-------- .../forge/game/player/PlayerController.java | 21 +-- .../java/forge/game/player/PlayerOutcome.java | 14 +- .../forge/game/player/PlayerStatistics.java | 6 +- 4 files changed, 106 insertions(+), 96 deletions(-) diff --git a/src/main/java/forge/game/player/Player.java b/src/main/java/forge/game/player/Player.java index 2f4d98c397f..9e247d0e7d1 100644 --- a/src/main/java/forge/game/player/Player.java +++ b/src/main/java/forge/game/player/Player.java @@ -140,12 +140,12 @@ public abstract class Player extends GameEntity implements Comparable { public static final List ALL_ZONES = Collections.unmodifiableList(Arrays.asList(ZoneType.Battlefield, ZoneType.Library, ZoneType.Graveyard, ZoneType.Hand, ZoneType.Exile, ZoneType.Command, ZoneType.Ante)); - + private final PlayerController controller; - + protected final LobbyPlayer lobbyPlayer; - protected final GameState game; - + protected final GameState game; + public final PlayerOutcome getOutcome() { return stats.getOutcome(); } @@ -166,7 +166,7 @@ public abstract class Player extends GameEntity implements Comparable { lobbyPlayer = lobbyPlayer0; game = game0; for (final ZoneType z : Player.ALL_ZONES) { - final PlayerZone toPut = z == ZoneType.Battlefield + final PlayerZone toPut = z == ZoneType.Battlefield ? new PlayerZoneBattlefield(z, this) : new PlayerZone(z, this); this.zones.put(z, toPut); @@ -201,7 +201,7 @@ public abstract class Player extends GameEntity implements Comparable { /** *

- * getOpponent. Used by current-generation AI. + * getOpponent. Used by current-generation AI. *

* * @return a {@link forge.game.player.Player} object. @@ -210,45 +210,51 @@ public abstract class Player extends GameEntity implements Comparable { Player otherType = null; Player justAnyone = null; for (Player p : game.getPlayers()) { - if ( p == this ) continue; + if (p == this) { + continue; + } justAnyone = p; - if( otherType == null && p.getType() != this.getType() ) otherType = p; + if (otherType == null && p.getType() != this.getType()) { + otherType = p; + } } - return otherType != null ? otherType : justAnyone; + return otherType != null ? otherType : justAnyone; } - + /** * - * returns all opponents - * Should keep player relations somewhere in the match structure + * returns all opponents. + * Should keep player relations somewhere in the match structure * @return */ public final List getOpponents() { List result = new ArrayList(); for (Player p : game.getPlayers()) { - if (p == this || p.getType() == this.getType()) + if (p == this || p.getType() == this.getType()) { continue; + } result.add(p); } return result; } - + /** - * returns allied players + * returns allied players. * Should keep player relations somewhere in the match structure * @return */ public final List getAllies() { List result = new ArrayList(); for (Player p : game.getPlayers()) { - if (p == this || p.getType() != this.getType()) + if (p == this || p.getType() != this.getType()) { continue; + } result.add(p); } return result; } - - + + // //////////////////////// // @@ -588,7 +594,7 @@ public abstract class Player extends GameEntity implements Comparable { // Predict replacement effects for (final Card ca : game.getCardsIn(ZoneType.Battlefield)) { for (final ReplacementEffect re : ca.getReplacementEffects()) { - HashMap params = re.getMapParams(); + HashMap params = re.getMapParams(); if (!"DamageDone".equals(params.get("Event")) || !params.containsKey("PreventionEffect")) { continue; } @@ -610,7 +616,7 @@ public abstract class Player extends GameEntity implements Comparable { continue; } } - + } return 0; } @@ -966,7 +972,7 @@ public abstract class Player extends GameEntity implements Comparable { public final void addPoisonCounters(final int num, final Card source) { if (!this.hasKeyword("You can't get poison counters")) { this.poisonCounters += num; - + game.getEvents().post(new PoisonCounterEvent(this, source, num)); game.getGameLog().add("Poison", this + " receives a poison counter from " + source, 3); @@ -1264,7 +1270,7 @@ public abstract class Player extends GameEntity implements Comparable { return drawn; } - + /** * * TODO Write javadoc for this method. @@ -1289,7 +1295,7 @@ public abstract class Player extends GameEntity implements Comparable { stats.notifyHasMulliganed(); stats.notifyOpeningHandSize(newHand); return newHand; - } + } /** *

@@ -1367,7 +1373,7 @@ public abstract class Player extends GameEntity implements Comparable { public final PlayerZone getZone(final ZoneType zone) { return this.zones.get(zone); } - + public final List getCardsIn(final ZoneType zoneType) { return getCardsIn(zoneType, true); } @@ -1442,7 +1448,7 @@ public abstract class Player extends GameEntity implements Comparable { } return result; } - + /** * gets a list of all cards with requested cardName in a given player's * requested zone. This function makes a List from Card[]. @@ -1480,7 +1486,7 @@ public abstract class Player extends GameEntity implements Comparable { int cntLibrary = this.getCardsIn(ZoneType.Library).size(); for (final Card c : this.getCardsIn(ZoneType.Graveyard)) { int nDr = getDredgeNumber(c); - if ( nDr > 0 && cntLibrary >= nDr) { + if (nDr > 0 && cntLibrary >= nDr) { dredge.add(c); } } @@ -1598,16 +1604,16 @@ public abstract class Player extends GameEntity implements Comparable { }*/ game.getAction().discardMadness(c); - - boolean hasPutIntoPlayInsteadOfDiscard = c.hasKeyword("If a spell or ability an opponent controls causes you " + - "to discard CARDNAME, put it onto the battlefield instead of putting it into your graveyard."); + + boolean hasPutIntoPlayInsteadOfDiscard = c.hasKeyword("If a spell or ability an opponent controls causes you " + + "to discard CARDNAME, put it onto the battlefield instead of putting it into your graveyard."); boolean hasPutIntoPlayWith2xP1P1InsteadOfDiscard = c.hasKeyword("If a spell or ability an opponent controls causes you to discard CARDNAME, " + "put it onto the battlefield with two +1/+1 counters on it instead of putting it into your graveyard."); - - if ( ( hasPutIntoPlayInsteadOfDiscard || hasPutIntoPlayWith2xP1P1InsteadOfDiscard ) + + if ((hasPutIntoPlayInsteadOfDiscard || hasPutIntoPlayWith2xP1P1InsteadOfDiscard) && null != sa && sa.getSourceCard().getController().isHostileTo(c.getController())) { game.getAction().moveToPlay(c); - + if (hasPutIntoPlayWith2xP1P1InsteadOfDiscard) { c.addCounter(CounterType.P1P1, 2, false); } @@ -1692,7 +1698,7 @@ public abstract class Player extends GameEntity implements Comparable { public final List discardRandom(final int num, final SpellAbility sa, final String valid) { final List discarded = new ArrayList(); for (int i = 0; i < num; i++) { - final List list = + final List list = CardLists.getValidCards(this.getCardsIn(ZoneType.Hand), valid, sa.getSourceCard().getController(), sa.getSourceCard()); if (list.size() != 0) { final Card disc = CardUtil.getRandom(list); @@ -1786,7 +1792,7 @@ public abstract class Player extends GameEntity implements Comparable { int s = list.size(); for (int i = 0; i < s; i++) { - list.add(random.nextInt(s-1), list.remove(random.nextInt(s))); + list.add(random.nextInt(s - 1), list.remove(random.nextInt(s))); } Collections.shuffle(list, random); @@ -2169,17 +2175,17 @@ public abstract class Player extends GameEntity implements Comparable { * @return a boolean. */ public final boolean loseConditionMet(final GameLossReason state, final String spellName) { - if ( state != GameLossReason.OpponentWon ) { + if (state != GameLossReason.OpponentWon) { if (this.cantLose()) { System.out.println("Tried to lose, but currently can't."); return false; } - + // Replacement effects final HashMap runParams = new HashMap(); runParams.put("Affected", this); runParams.put("Event", "GameLoss"); - + if (game.getReplacementHandler().run(runParams) != ReplacementResult.NotReplaced) { return false; } @@ -2231,8 +2237,11 @@ public abstract class Player extends GameEntity implements Comparable { */ public final boolean cantWin() { boolean isAnyOppLoseProof = false; - for( Player p : game.getPlayers() ) { - if ( p == this || p.getOutcome() != null ) continue; // except self and already dead + for (Player p : game.getPlayers()) { + if (p == this || p.getOutcome() != null) { + + continue; // except self and already dead + } isAnyOppLoseProof |= p.hasKeyword("You can't lose the game."); } return this.hasKeyword("You can't win the game.") || isAnyOppLoseProof; @@ -2246,9 +2255,10 @@ public abstract class Player extends GameEntity implements Comparable { * @return a boolean. */ public final boolean checkLoseCondition() { - - if ( this.getOutcome() != null ) + + if (this.getOutcome() != null) { return this.getOutcome().lossState != null; + } if (this.poisonCounters >= 10) { return this.loseConditionMet(GameLossReason.Poisoned, null); @@ -2324,7 +2334,7 @@ public abstract class Player extends GameEntity implements Comparable { final List list = this.getZone(ZoneType.Battlefield).getCardsAddedThisTurn(null); return Iterables.any(list, CardPredicates.Presets.LANDS); } - + /** *

* hasBloodthirst. @@ -2340,7 +2350,7 @@ public abstract class Player extends GameEntity implements Comparable { } return false; } - + /** *

* getBloodthirstAmount. @@ -2727,17 +2737,17 @@ public abstract class Player extends GameEntity implements Comparable { if (subtractedHash == 0) { return 0; } - - return Math.abs(subtractedHash)/subtractedHash; + + return Math.abs(subtractedHash) / subtractedHash; } - + /** {@inheritDoc} */ @Override public int hashCode() { return (41 * (41 + this.getName().hashCode())); } - public static class Predicates { + public static class Predicates { public static final Predicate NOT_LOST = new Predicate() { @Override @@ -2749,44 +2759,44 @@ public abstract class Player extends GameEntity implements Comparable { public static Predicate isType(final PlayerType type) { return new Predicate() { @Override - public boolean apply(Player input){ + public boolean apply(Player input) { return input.getType() == type; } }; } } - + public static class Accessors { - public static Function FN_GET_LOBBY_PLAYER = new Function(){ + public static Function FN_GET_LOBBY_PLAYER = new Function() { @Override public LobbyPlayer apply(Player input) { return input.getLobbyPlayer(); } }; - - public static Function FN_GET_LIFE = new Function(){ + + public static Function FN_GET_LIFE = new Function() { @Override public Integer apply(Player input) { return input.getLife(); } }; - public static Function FN_GET_TYPE = new Function(){ + public static Function FN_GET_TYPE = new Function() { @Override public PlayerType apply(Player input) { return input.getType(); } }; - public static Function FN_GET_NAME = new Function(){ + public static Function FN_GET_NAME = new Function() { @Override public String apply(Player input) { return input.getName(); } }; - - public static Function countCardsInZone(final ZoneType zone){ - return new Function(){ + + public static Function countCardsInZone(final ZoneType zone) { + return new Function() { @Override public Integer apply(Player input) { return input.getZone(zone).size(); @@ -2804,15 +2814,17 @@ public abstract class Player extends GameEntity implements Comparable { } private void setOutcome(PlayerOutcome outcome) { - stats.setOutcome(outcome); + stats.setOutcome(outcome); } /** * TODO: Write javadoc for this method. */ public void onGameOver() { - if ( null == stats.getOutcome() ) // not lost? + if (null == stats.getOutcome()) { + setOutcome(PlayerOutcome.win()); // then won! + } } /** @@ -2840,7 +2852,7 @@ public abstract class Player extends GameEntity implements Comparable { return Iterables.any(getZone(ZoneType.Battlefield), CardPredicates.nameEquals(cardName)); } - + public List getColoredCardsInPlay(final String color) { return CardLists.filter(getCardsIn(ZoneType.Battlefield), new Predicate() { @Override @@ -2852,12 +2864,12 @@ public abstract class Player extends GameEntity implements Comparable { public int getCounterDoublersMagnitude(final CounterType type) { int counterDoublers = getCardsIn(ZoneType.Battlefield, "Doubling Season").size(); - if(type == CounterType.P1P1) { + if (type == CounterType.P1P1) { counterDoublers += getCardsIn(ZoneType.Battlefield, "Corpsejack Menace").size(); } return 1 << counterDoublers; } - + public int getTokenDoublersMagnitude() { final int tokenDoublers = getCardsIn(ZoneType.Battlefield, "Parallel Lives").size() + getCardsIn(ZoneType.Battlefield, "Doubling Season").size(); @@ -2865,9 +2877,9 @@ public abstract class Player extends GameEntity implements Comparable { } public void onCleanupPhase() { - for (Card c : getCardsIn(ZoneType.Hand)) + for (Card c : getCardsIn(ZoneType.Hand)) { c.setDrawnThisTurn(false); - + } resetPreventNextDamage(); resetNumDrawnThisTurn(); setAttackedWithCreatureThisTurn(false); @@ -2880,8 +2892,8 @@ public abstract class Player extends GameEntity implements Comparable { PhaseHandler now = game.getPhaseHandler(); return now.isPlayerTurn(this) && now.getPhase().isMain() && game.getStack().size() == 0; } - - + + /** *

* couldCastSorcery. @@ -2905,7 +2917,7 @@ public abstract class Player extends GameEntity implements Comparable { //System.out.println("StackCard: " + card + " vs SourceCard: " + source); } } - + PhaseHandler now = game.getPhaseHandler(); //System.out.println("now.isPlayerTurn(player) - " + now.isPlayerTurn(player)); //System.out.println("now.getPhase().isMain() - " + now.getPhase().isMain()); @@ -2929,7 +2941,7 @@ public abstract class Player extends GameEntity implements Comparable { * @return a boolean. */ public boolean isSkippingCombat() { - + if (hasKeyword("Skip your next combat phase.")) { return true; } @@ -2944,7 +2956,7 @@ public abstract class Player extends GameEntity implements Comparable { if (hasKeyword("Skip all combat phases of this turn.")) { return true; } - + return false; } @@ -2959,10 +2971,10 @@ public abstract class Player extends GameEntity implements Comparable { // time vault: List vaults = getCardsIn(ZoneType.Battlefield, "Time Vault"); vaults = CardLists.filter(vaults, Presets.TAPPED); - + if (vaults.size() > 0) { final Card crd = vaults.get(0); - + if (isHuman()) { if (GameActionUtil.showYesNoDialog(crd, "Untap " + crd + "?")) { crd.untap(); @@ -2981,10 +2993,11 @@ public abstract class Player extends GameEntity implements Comparable { * @return */ public boolean isHostileTo(Player other) { - if ( other.equals(getOpponent()) ) + if (other.equals(getOpponent())) { return true; - + } + return other.getType() != this.getType(); } - + } diff --git a/src/main/java/forge/game/player/PlayerController.java b/src/main/java/forge/game/player/PlayerController.java index 2dcbda26af5..1c8f9b77858 100644 --- a/src/main/java/forge/game/player/PlayerController.java +++ b/src/main/java/forge/game/player/PlayerController.java @@ -12,10 +12,10 @@ import forge.gui.match.CMatchUI; */ public class PlayerController { - // Should keep some 'Model' of player here. + // Should keep some 'Model' of player here. // Yet I have little idea of what is model now. private final Player player; - + private PhaseType autoPassUntil = null; private ComputerAIInput aiInput; @@ -38,14 +38,14 @@ public class PlayerController { public void autoPassCancel() { autoPassUntil = null; } - - - public boolean mayAutoPass(PhaseType phase) - { - return phase.isBefore(autoPassUntil); + + + public boolean mayAutoPass(PhaseType phase) { + + return phase.isBefore(autoPassUntil); } - + public boolean isUiSetToSkipPhase(final Player turn, final PhaseType phase) { return player.equals(Singletons.getControl().getPlayer()) && !CMatchUI.SINGLETON_INSTANCE.stopAtPhase(turn, phase); } @@ -55,10 +55,7 @@ public class PlayerController { * @param computerAIInput */ public void setAiInput(ComputerAIInput computerAIInput) { - aiInput = computerAIInput; + aiInput = computerAIInput; } - - - } diff --git a/src/main/java/forge/game/player/PlayerOutcome.java b/src/main/java/forge/game/player/PlayerOutcome.java index 8de14a65bb8..efc22833d2d 100644 --- a/src/main/java/forge/game/player/PlayerOutcome.java +++ b/src/main/java/forge/game/player/PlayerOutcome.java @@ -12,9 +12,9 @@ public class PlayerOutcome { public final GameLossReason lossState; /** The lose condition spell. */ public final String loseConditionSpell; - + private PlayerOutcome(String altWinSourceName, GameLossReason lossState, String loseConditionSpell) { - this.altWinSourceName= altWinSourceName; + this.altWinSourceName = altWinSourceName; this.loseConditionSpell = loseConditionSpell; this.lossState = lossState; } @@ -26,8 +26,8 @@ public class PlayerOutcome { */ public static PlayerOutcome win() { return new PlayerOutcome(null, null, null); - } - + } + public static PlayerOutcome altWin(String sourceName) { return new PlayerOutcome(sourceName, null, null); } @@ -49,9 +49,9 @@ public class PlayerOutcome { public static PlayerOutcome concede() { return new PlayerOutcome(null, GameLossReason.Conceded, null); } - - public boolean hasWon() { + + public boolean hasWon() { return lossState == null; } -} \ No newline at end of file +} diff --git a/src/main/java/forge/game/player/PlayerStatistics.java b/src/main/java/forge/game/player/PlayerStatistics.java index d36ba41a219..10ac5f566ca 100644 --- a/src/main/java/forge/game/player/PlayerStatistics.java +++ b/src/main/java/forge/game/player/PlayerStatistics.java @@ -32,7 +32,7 @@ public class PlayerStatistics { private int turnsPlayed = 0; - + private PlayerOutcome outcome; /** @@ -75,7 +75,7 @@ public class PlayerStatistics { } public void nextTurn() { - this.turnsPlayed++; + this.turnsPlayed++; } public PlayerOutcome getOutcome() { @@ -83,7 +83,7 @@ public class PlayerStatistics { } public void setOutcome(PlayerOutcome gameOutcome) { - this.outcome = gameOutcome; + this.outcome = gameOutcome; } }