diff --git a/src/main/java/forge/card/staticAbility/StaticAbility.java b/src/main/java/forge/card/staticAbility/StaticAbility.java index ad553e03dcc..d1685bb2b6b 100644 --- a/src/main/java/forge/card/staticAbility/StaticAbility.java +++ b/src/main/java/forge/card/staticAbility/StaticAbility.java @@ -21,10 +21,10 @@ public class StaticAbility { private HashMap mapParams = new HashMap(); /** The temporarily suppressed. */ - protected boolean temporarilySuppressed = false; + private boolean temporarilySuppressed = false; /** The suppressed. */ - protected boolean suppressed = false; + private boolean suppressed = false; /** *

@@ -34,7 +34,7 @@ public class StaticAbility { * @return a {@link forge.Card} object. */ public final Card getHostCard() { - return hostCard; + return this.hostCard; } /** @@ -45,7 +45,7 @@ public class StaticAbility { * @return a {@link java.util.HashMap} object. */ public final HashMap getMapParams() { - return mapParams; + return this.mapParams; } // ******************************************************* @@ -62,14 +62,14 @@ public class StaticAbility { * @return a {@link java.util.HashMap} object. */ public final HashMap getMapParams(final String abString, final Card hostCard) { - HashMap mapParameters = new HashMap(); + final HashMap mapParameters = new HashMap(); if (!(abString.length() > 0)) { throw new RuntimeException("StaticEffectFactory : getAbility -- abString too short in " + hostCard.getName() + ": [" + abString + "]"); } - String[] a = abString.split("\\|"); + final String[] a = abString.split("\\|"); for (int aCnt = 0; aCnt < a.length; aCnt++) { a[aCnt] = a[aCnt].trim(); @@ -79,17 +79,17 @@ public class StaticAbility { throw new RuntimeException("StaticEffectFactory : getAbility -- a[] too short in " + hostCard.getName()); } - for (int i = 0; i < a.length; i++) { - String[] aa = a[i].split("\\$"); + for (final String element : a) { + final String[] aa = element.split("\\$"); for (int aaCnt = 0; aaCnt < aa.length; aaCnt++) { aa[aaCnt] = aa[aaCnt].trim(); } if (aa.length != 2) { - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); sb.append("StaticEffectFactory Parsing Error: Split length of "); - sb.append(a[i]).append(" in ").append(hostCard.getName()).append(" is not 2."); + sb.append(element).append(" in ").append(hostCard.getName()).append(" is not 2."); throw new RuntimeException(sb.toString()); } @@ -108,46 +108,41 @@ public class StaticAbility { */ public final int getLayer() { - if (!mapParams.get("Mode").equals("Continuous")) { + if (!this.mapParams.get("Mode").equals("Continuous")) { return 0; } - if (mapParams.containsKey("AddType") || mapParams.containsKey("RemoveType") - || mapParams.containsKey("RemoveCardType") || mapParams.containsKey("RemoveSubType") - || mapParams.containsKey("RemoveSuperType")) { + if (this.mapParams.containsKey("AddType") || this.mapParams.containsKey("RemoveType") + || this.mapParams.containsKey("RemoveCardType") || this.mapParams.containsKey("RemoveSubType") + || this.mapParams.containsKey("RemoveSuperType")) { return 4; } - if (mapParams.containsKey("AddColor") || mapParams.containsKey("RemoveColor") - || mapParams.containsKey("SetColor")) { + if (this.mapParams.containsKey("AddColor") || this.mapParams.containsKey("RemoveColor") + || this.mapParams.containsKey("SetColor")) { return 5; } - if (mapParams.containsKey("RemoveAllAbilities")) - { + if (this.mapParams.containsKey("RemoveAllAbilities")) { return 6; // Layer 6 } - if (mapParams.containsKey("AddKeyword") || mapParams.containsKey("AddAbility") - || mapParams.containsKey("AddTrigger") || mapParams.containsKey("RemoveTriggers") - || mapParams.containsKey("RemoveKeyword")) - { + if (this.mapParams.containsKey("AddKeyword") || this.mapParams.containsKey("AddAbility") + || this.mapParams.containsKey("AddTrigger") || this.mapParams.containsKey("RemoveTriggers") + || this.mapParams.containsKey("RemoveKeyword")) { return 7; // Layer 6 (dependent) } - if (mapParams.containsKey("CharacteristicDefining")) - { + if (this.mapParams.containsKey("CharacteristicDefining")) { return 8; // Layer 7a } - if (mapParams.containsKey("AddPower") || mapParams.containsKey("AddToughness") - || mapParams.containsKey("SetPower") || mapParams.containsKey("SetToughness")) - { + if (this.mapParams.containsKey("AddPower") || this.mapParams.containsKey("AddToughness") + || this.mapParams.containsKey("SetPower") || this.mapParams.containsKey("SetToughness")) { return 9; // This is the collection of 7b and 7c } - if (mapParams.containsKey("AddHiddenKeyword")) - { + if (this.mapParams.containsKey("AddHiddenKeyword")) { return 10; // rules change } @@ -163,9 +158,10 @@ public class StaticAbility { * * @return a {@link java.lang.String} object. */ + @Override public final String toString() { - if (mapParams.containsKey("Description") && !isSuppressed()) { - return mapParams.get("Description").replace("CARDNAME", hostCard.getName()); + if (this.mapParams.containsKey("Description") && !this.isSuppressed()) { + return this.mapParams.get("Description").replace("CARDNAME", this.hostCard.getName()); } else { return ""; } @@ -181,8 +177,8 @@ public class StaticAbility { * the host */ public StaticAbility(final String params, final Card host) { - mapParams = getMapParams(params, host); - hostCard = host; + this.mapParams = this.getMapParams(params, host); + this.hostCard = host; } /** @@ -194,11 +190,11 @@ public class StaticAbility { * the host */ public StaticAbility(final HashMap params, final Card host) { - mapParams = new HashMap(); - for (Map.Entry entry : params.entrySet()) { - mapParams.put(entry.getKey(), entry.getValue()); + this.mapParams = new HashMap(); + for (final Map.Entry entry : params.entrySet()) { + this.mapParams.put(entry.getKey(), entry.getValue()); } - hostCard = host; + this.hostCard = host; } // apply the ability if it has the right mode @@ -211,11 +207,11 @@ public class StaticAbility { public final void applyAbility(final String mode) { // don't apply the ability if it hasn't got the right mode - if (!mapParams.get("Mode").equals(mode)) { + if (!this.mapParams.get("Mode").equals(mode)) { return; } - if (isSuppressed() || !checkConditions()) { + if (this.isSuppressed() || !this.checkConditions()) { return; } @@ -240,15 +236,15 @@ public class StaticAbility { * the b * @return the int */ - public final int applyAbility(final String mode, final Card source, - final GameEntity target, final int in, final boolean b) { + public final int applyAbility(final String mode, final Card source, final GameEntity target, final int in, + final boolean b) { // don't apply the ability if it hasn't got the right mode - if (!mapParams.get("Mode").equals(mode)) { + if (!this.mapParams.get("Mode").equals(mode)) { return in; } - if (isSuppressed() || !checkConditions()) { + if (this.isSuppressed() || !this.checkConditions()) { return in; } @@ -274,11 +270,11 @@ public class StaticAbility { public final boolean applyAbility(final String mode, final Card card, final Player activator) { // don't apply the ability if it hasn't got the right mode - if (!mapParams.get("Mode").equals(mode)) { + if (!this.mapParams.get("Mode").equals(mode)) { return false; } - if (isSuppressed() || !checkConditions()) { + if (this.isSuppressed() || !this.checkConditions()) { return false; } @@ -299,42 +295,42 @@ public class StaticAbility { * @return true, if successful */ public final boolean checkConditions() { - Player controller = hostCard.getController(); + final Player controller = this.hostCard.getController(); Zone effectZone = Zone.Battlefield; // default - if (mapParams.containsKey("EffectZone")) { - effectZone = Zone.smartValueOf(mapParams.get("EffectZone")); + if (this.mapParams.containsKey("EffectZone")) { + effectZone = Zone.smartValueOf(this.mapParams.get("EffectZone")); } - if (effectZone != null - && (!AllZone.getZoneOf(hostCard).getZoneType().equals(effectZone) || hostCard.isPhasedOut())) { + if ((effectZone != null) + && (!AllZone.getZoneOf(this.hostCard).getZoneType().equals(effectZone) || this.hostCard.isPhasedOut())) { return false; } - if (mapParams.containsKey("Threshold") && !controller.hasThreshold()) { + if (this.mapParams.containsKey("Threshold") && !controller.hasThreshold()) { return false; } - if (mapParams.containsKey("Hellbent") && !controller.hasHellbent()) { + if (this.mapParams.containsKey("Hellbent") && !controller.hasHellbent()) { return false; } - if (mapParams.containsKey("Metalcraft") && !controller.hasMetalcraft()) { + if (this.mapParams.containsKey("Metalcraft") && !controller.hasMetalcraft()) { return false; } - if (mapParams.containsKey("PlayerTurn") && !AllZone.getPhase().isPlayerTurn(controller)) { + if (this.mapParams.containsKey("PlayerTurn") && !AllZone.getPhase().isPlayerTurn(controller)) { return false; } - if (mapParams.containsKey("OpponentTurn") && !AllZone.getPhase().isPlayerTurn(controller.getOpponent())) { + if (this.mapParams.containsKey("OpponentTurn") && !AllZone.getPhase().isPlayerTurn(controller.getOpponent())) { return false; } - if (mapParams.containsKey("TopCardOfLibraryIs")) { - Card topCard = controller.getCardsIn(Zone.Library).get(0); - if (!topCard.isValid(mapParams.get("TopCardOfLibraryIs").split(","), controller, hostCard)) { + if (this.mapParams.containsKey("TopCardOfLibraryIs")) { + final Card topCard = controller.getCardsIn(Zone.Library).get(0); + if (!topCard.isValid(this.mapParams.get("TopCardOfLibraryIs").split(","), controller, this.hostCard)) { return false; } } @@ -350,15 +346,15 @@ public class StaticAbility { * } */ - if (mapParams.containsKey("CheckSVar")) { - int sVar = AbilityFactory.calculateAmount(hostCard, mapParams.get("CheckSVar"), null); + if (this.mapParams.containsKey("CheckSVar")) { + final int sVar = AbilityFactory.calculateAmount(this.hostCard, this.mapParams.get("CheckSVar"), null); String comparator = "GE1"; - if (mapParams.containsKey("SVarCompare")) { - comparator = mapParams.get("SVarCompare"); + if (this.mapParams.containsKey("SVarCompare")) { + comparator = this.mapParams.get("SVarCompare"); } - String svarOperator = comparator.substring(0, 2); - String svarOperand = comparator.substring(2); - int operandValue = AbilityFactory.calculateAmount(hostCard, svarOperand, null); + final String svarOperator = comparator.substring(0, 2); + final String svarOperand = comparator.substring(2); + final int operandValue = AbilityFactory.calculateAmount(this.hostCard, svarOperand, null); if (!AllZoneUtil.compare(sVar, svarOperator, operandValue)) { return false; } @@ -374,7 +370,7 @@ public class StaticAbility { * the new temporarily suppressed */ public final void setTemporarilySuppressed(final boolean supp) { - temporarilySuppressed = supp; + this.temporarilySuppressed = supp; } /** @@ -383,7 +379,7 @@ public class StaticAbility { * @return true, if is suppressed */ public final boolean isSuppressed() { - return (suppressed || temporarilySuppressed); + return (this.suppressed || this.temporarilySuppressed); } } // end class StaticEffectFactory diff --git a/src/main/java/forge/card/staticAbility/StaticAbility_CantBeCast.java b/src/main/java/forge/card/staticAbility/StaticAbility_CantBeCast.java index c5b9f66b5cd..673f604f38f 100644 --- a/src/main/java/forge/card/staticAbility/StaticAbility_CantBeCast.java +++ b/src/main/java/forge/card/staticAbility/StaticAbility_CantBeCast.java @@ -23,20 +23,20 @@ public class StaticAbility_CantBeCast { * @return true, if successful */ public static boolean applyCantBeCastAbility(final StaticAbility stAb, final Card card, final Player activator) { - HashMap params = stAb.getMapParams(); - Card hostCard = stAb.getHostCard(); + final HashMap params = stAb.getMapParams(); + final Card hostCard = stAb.getHostCard(); if (params.containsKey("ValidCard") && !card.isValid(params.get("ValidCard").split(","), hostCard.getController(), hostCard)) { return false; } - if (params.containsKey("Caster") && activator != null + if (params.containsKey("Caster") && (activator != null) && !activator.isValid(params.get("Caster"), hostCard.getController(), hostCard)) { return false; } - if (params.containsKey("OnlySorcerySpeed") && activator != null && Phase.canCastSorcery(activator)) { + if (params.containsKey("OnlySorcerySpeed") && (activator != null) && Phase.canCastSorcery(activator)) { return false; } @@ -54,17 +54,16 @@ public class StaticAbility_CantBeCast { * the activator * @return true, if successful */ - public static boolean applyCantBeActivatedAbility(final StaticAbility stAb, - final Card card, final Player activator) { - HashMap params = stAb.getMapParams(); - Card hostCard = stAb.getHostCard(); + public static boolean applyCantBeActivatedAbility(final StaticAbility stAb, final Card card, final Player activator) { + final HashMap params = stAb.getMapParams(); + final Card hostCard = stAb.getHostCard(); if (params.containsKey("ValidCard") && !card.isValid(params.get("ValidCard").split(","), hostCard.getController(), hostCard)) { return false; } - if (params.containsKey("Activator") && activator != null + if (params.containsKey("Activator") && (activator != null) && !activator.isValid(params.get("Activator"), hostCard.getController(), hostCard)) { return false; } diff --git a/src/main/java/forge/card/staticAbility/StaticAbility_Continuous.java b/src/main/java/forge/card/staticAbility/StaticAbility_Continuous.java index 383594e2c5f..1d2d1e6352d 100644 --- a/src/main/java/forge/card/staticAbility/StaticAbility_Continuous.java +++ b/src/main/java/forge/card/staticAbility/StaticAbility_Continuous.java @@ -31,12 +31,12 @@ public class StaticAbility_Continuous { * a StaticAbility */ public static void applyContinuousAbility(final StaticAbility stAb) { - HashMap params = stAb.getMapParams(); - Card hostCard = stAb.getHostCard(); + final HashMap params = stAb.getMapParams(); + final Card hostCard = stAb.getHostCard(); - StaticEffect se = new StaticEffect(); - CardList affectedCards = getAffectedCards(stAb); - ArrayList affectedPlayers = getAffectedPlayers(stAb); + final StaticEffect se = new StaticEffect(); + final CardList affectedCards = StaticAbility_Continuous.getAffectedCards(stAb); + final ArrayList affectedPlayers = StaticAbility_Continuous.getAffectedPlayers(stAb); se.setAffectedCards(affectedCards); se.setAffectedPlayers(affectedPlayers); @@ -118,7 +118,7 @@ public class StaticAbility_Continuous { } if (params.containsKey("AddAbility")) { - String[] sVars = params.get("AddAbility").split(" & "); + final String[] sVars = params.get("AddAbility").split(" & "); for (int i = 0; i < sVars.length; i++) { sVars[i] = hostCard.getSVar(sVars[i]); } @@ -132,7 +132,7 @@ public class StaticAbility_Continuous { if (params.containsKey("AddType")) { addTypes = params.get("AddType").split(" & "); if (addTypes[0].equals("ChosenType")) { - String chosenType = hostCard.getChosenType(); + final String chosenType = hostCard.getChosenType(); addTypes[0] = chosenType; se.setChosenType(chosenType); } @@ -141,7 +141,7 @@ public class StaticAbility_Continuous { if (params.containsKey("RemoveType")) { removeTypes = params.get("RemoveType").split(" & "); if (removeTypes[0].equals("ChosenType")) { - String chosenType = hostCard.getChosenType(); + final String chosenType = hostCard.getChosenType(); removeTypes[0] = chosenType; se.setChosenType(chosenType); } @@ -175,7 +175,7 @@ public class StaticAbility_Continuous { } if (params.containsKey("AddTrigger")) { - String[] sVars = params.get("AddTrigger").split(" & "); + final String[] sVars = params.get("AddTrigger").split(" & "); for (int i = 0; i < sVars.length; i++) { sVars[i] = hostCard.getSVar(sVars[i]); } @@ -183,11 +183,11 @@ public class StaticAbility_Continuous { } // modify players - for (Player p : affectedPlayers) { + for (final Player p : affectedPlayers) { // add keywords if (addKeywords != null) { - for (String keyword : addKeywords) { + for (final String keyword : addKeywords) { p.addKeyword(keyword); } } @@ -195,7 +195,7 @@ public class StaticAbility_Continuous { // start modifying the cards for (int i = 0; i < affectedCards.size(); i++) { - Card affectedCard = affectedCards.get(i); + final Card affectedCard = affectedCards.get(i); // set P/T if (params.containsKey("CharacteristicDefining")) { @@ -206,7 +206,7 @@ public class StaticAbility_Continuous { affectedCard.setBaseDefense(setToughness); } } else // non CharacteristicDefining - if (setPower != -1 || setToughness != -1) { + if ((setPower != -1) || (setToughness != -1)) { if (setP.startsWith("AffectedX")) { setPower = CardFactoryUtil.xCount(affectedCard, hostCard.getSVar(setP)); } @@ -221,24 +221,24 @@ public class StaticAbility_Continuous { affectedCard.addSemiPermanentDefenseBoost(toughnessBonus); // add keywords - if (addKeywords != null || removeKeywords != null || removeAllAbilities) { + if ((addKeywords != null) || (removeKeywords != null) || removeAllAbilities) { affectedCard.addChangedCardKeywords(addKeywords, removeKeywords, removeAllAbilities, hostCard.getTimestamp()); } // add HIDDEN keywords if (addHiddenKeywords != null) { - for (String k : addHiddenKeywords) { + for (final String k : addHiddenKeywords) { affectedCard.addExtrinsicKeyword(k); } } // add abilities if (addAbilities != null) { - for (String abilty : addAbilities) { + for (final String abilty : addAbilities) { if (abilty.startsWith("AB")) { // grant the ability - AbilityFactory af = new AbilityFactory(); - SpellAbility sa = af.getAbility(abilty, affectedCard); + final AbilityFactory af = new AbilityFactory(); + final SpellAbility sa = af.getAbility(abilty, affectedCard); sa.setType("Temporary"); affectedCard.addSpellAbility(sa); } @@ -247,47 +247,47 @@ public class StaticAbility_Continuous { // add SVars if (addSVars != null) { - for (String sVar : addSVars) { + for (final String sVar : addSVars) { affectedCard.setSVar(sVar, hostCard.getSVar(sVar)); } } // add Types - if (addTypes != null || removeTypes != null) { + if ((addTypes != null) || (removeTypes != null)) { affectedCard.addChangedCardTypes(addTypes, removeTypes, removeSuperTypes, removeCardTypes, removeSubTypes, removeCreatureTypes, hostCard.getTimestamp()); } // add colors if (addColors != null) { - long t = affectedCard.addColor(addColors, affectedCard, !se.isOverwriteColors(), true); + final long t = affectedCard.addColor(addColors, affectedCard, !se.isOverwriteColors(), true); se.addTimestamp(affectedCard, t); } // add triggers if (addTriggers != null) { - for (String trigger : addTriggers) { - Trigger actualTrigger = TriggerHandler.parseTrigger(trigger, affectedCard, false); + for (final String trigger : addTriggers) { + final Trigger actualTrigger = TriggerHandler.parseTrigger(trigger, affectedCard, false); affectedCard.addTrigger(actualTrigger).setTemporary(true); } } // remove triggers if (params.containsKey("RemoveTriggers") || removeAllAbilities) { - ArrayList triggers = affectedCard.getTriggers(); - for (Trigger trigger : triggers) { + final ArrayList triggers = affectedCard.getTriggers(); + for (final Trigger trigger : triggers) { trigger.setTemporarilySuppressed(true); } } // remove activated and static abilities if (removeAllAbilities) { - ArrayList abilities = affectedCard.getSpellAbilities(); - for (SpellAbility ab : abilities) { + final ArrayList abilities = affectedCard.getSpellAbilities(); + for (final SpellAbility ab : abilities) { ab.setTemporarilySuppressed(true); } - ArrayList staticAbilities = affectedCard.getStaticAbilities(); - for (StaticAbility stA : staticAbilities) { + final ArrayList staticAbilities = affectedCard.getStaticAbilities(); + for (final StaticAbility stA : staticAbilities) { stA.setTemporarilySuppressed(true); } } @@ -295,19 +295,19 @@ public class StaticAbility_Continuous { } private static ArrayList getAffectedPlayers(final StaticAbility stAb) { - HashMap params = stAb.getMapParams(); - Card hostCard = stAb.getHostCard(); - Player controller = hostCard.getController(); + final HashMap params = stAb.getMapParams(); + final Card hostCard = stAb.getHostCard(); + final Player controller = hostCard.getController(); - ArrayList players = new ArrayList(); + final ArrayList players = new ArrayList(); if (!params.containsKey("Affected")) { return players; } - String[] strngs = params.get("Affected").split(","); + final String[] strngs = params.get("Affected").split(","); - for (String str : strngs) { + for (final String str : strngs) { if (str.equals("Player") || str.equals("You")) { players.add(controller); } @@ -321,9 +321,9 @@ public class StaticAbility_Continuous { } private static CardList getAffectedCards(final StaticAbility stAb) { - HashMap params = stAb.getMapParams(); - Card hostCard = stAb.getHostCard(); - Player controller = hostCard.getController(); + final HashMap params = stAb.getMapParams(); + final Card hostCard = stAb.getHostCard(); + final Player controller = hostCard.getController(); if (params.containsKey("CharacteristicDefining")) { return new CardList(hostCard); // will always be the card itself diff --git a/src/main/java/forge/card/staticAbility/StaticAbility_PreventDamage.java b/src/main/java/forge/card/staticAbility/StaticAbility_PreventDamage.java index a21f64b0735..66efac2dfcc 100644 --- a/src/main/java/forge/card/staticAbility/StaticAbility_PreventDamage.java +++ b/src/main/java/forge/card/staticAbility/StaticAbility_PreventDamage.java @@ -26,11 +26,10 @@ public class StaticAbility_PreventDamage { * the is combat * @return the int */ - public static int applyPreventDamageAbility(final StaticAbility stAb, - final Card source, final GameEntity target, final int damage, - final boolean isCombat) { - HashMap params = stAb.getMapParams(); - Card hostCard = stAb.getHostCard(); + public static int applyPreventDamageAbility(final StaticAbility stAb, final Card source, final GameEntity target, + final int damage, final boolean isCombat) { + final HashMap params = stAb.getMapParams(); + final Card hostCard = stAb.getHostCard(); int restDamage = damage; if (params.containsKey("Source") @@ -51,7 +50,7 @@ public class StaticAbility_PreventDamage { return restDamage; } - if (params.containsKey("MaxDamage") && Integer.parseInt(params.get("MaxDamage")) < damage) { + if (params.containsKey("MaxDamage") && (Integer.parseInt(params.get("MaxDamage")) < damage)) { return restDamage; } diff --git a/src/main/java/forge/deck/Deck.java b/src/main/java/forge/deck/Deck.java index f4f7bff0c41..a6aa4be1a95 100644 --- a/src/main/java/forge/deck/Deck.java +++ b/src/main/java/forge/deck/Deck.java @@ -47,8 +47,8 @@ public final class Deck implements Comparable, Serializable { *

*/ public Deck() { - main = new ItemPool(CardPrinted.class); - sideboard = new ItemPool(CardPrinted.class); + this.main = new ItemPool(CardPrinted.class); + this.sideboard = new ItemPool(CardPrinted.class); } /** @@ -61,7 +61,7 @@ public final class Deck implements Comparable, Serializable { */ public Deck(final GameType type) { this(); - setDeckType(type); + this.setDeckType(type); } /** @@ -72,7 +72,7 @@ public final class Deck implements Comparable, Serializable { * @return a {@link java.util.List} object. */ public ItemPoolView getMain() { - return main.getView(); + return this.main.getView(); } /** @@ -83,7 +83,7 @@ public final class Deck implements Comparable, Serializable { * @return a {@link java.util.List} object. */ public ItemPoolView getSideboard() { - return sideboard.getView(); + return this.sideboard.getView(); } /** @@ -94,7 +94,7 @@ public final class Deck implements Comparable, Serializable { * @return a {@link java.lang.String} object. */ public GameType getDeckType() { - return deckType; + return this.deckType; } // can only call this method ONCE @@ -123,7 +123,7 @@ public final class Deck implements Comparable, Serializable { * a {@link java.lang.String} object. */ public void setName(final String s) { - name = s; + this.name = s; } /** @@ -134,7 +134,7 @@ public final class Deck implements Comparable, Serializable { * @return a {@link java.lang.String} object. */ public String getName() { - return name; + return this.name; } /** @@ -157,7 +157,7 @@ public final class Deck implements Comparable, Serializable { * @return a {@link java.lang.String} object. */ public String getComment() { - return comment; + return this.comment; } /** @@ -169,7 +169,7 @@ public final class Deck implements Comparable, Serializable { * a {@link java.lang.String} object. */ public void addMain(final String cardName) { - addMain(CardDb.instance().getCard(cardName)); + this.addMain(CardDb.instance().getCard(cardName)); } /** @@ -179,7 +179,7 @@ public final class Deck implements Comparable, Serializable { * the card */ public void addMain(final CardPrinted card) { - main.add(card); + this.main.add(card); } /** @@ -191,7 +191,7 @@ public final class Deck implements Comparable, Serializable { * the amount */ public void addMain(final CardPrinted card, final int amount) { - main.add(card, amount); + this.main.add(card, amount); } /** @@ -201,7 +201,7 @@ public final class Deck implements Comparable, Serializable { * the list */ public void addMain(final ItemPoolView list) { - main.addAll(list); + this.main.addAll(list); } /** @@ -211,7 +211,7 @@ public final class Deck implements Comparable, Serializable { * the new main */ public void setMain(final Iterable cards) { - main = new ItemPool(cards, CardPrinted.class); + this.main = new ItemPool(cards, CardPrinted.class); } /** @@ -221,7 +221,7 @@ public final class Deck implements Comparable, Serializable { * the card */ public void removeMain(final CardPrinted card) { - main.remove(card); + this.main.remove(card); } /** @@ -233,7 +233,7 @@ public final class Deck implements Comparable, Serializable { * the amount */ public void removeMain(final CardPrinted card, final int amount) { - main.remove(card, amount); + this.main.remove(card, amount); } /** @@ -242,7 +242,7 @@ public final class Deck implements Comparable, Serializable { * @return the int */ public int countMain() { - return main.countAll(); + return this.main.countAll(); } /** @@ -254,7 +254,7 @@ public final class Deck implements Comparable, Serializable { * a {@link java.lang.String} object. */ public void addSideboard(final String cardName) { - addSideboard(CardDb.instance().getCard(cardName)); + this.addSideboard(CardDb.instance().getCard(cardName)); } /** @@ -264,7 +264,7 @@ public final class Deck implements Comparable, Serializable { * the card */ public void addSideboard(final CardPrinted card) { - sideboard.add(card); + this.sideboard.add(card); } /** @@ -276,7 +276,7 @@ public final class Deck implements Comparable, Serializable { * the amount */ public void addSideboard(final CardPrinted card, final int amount) { - sideboard.add(card, amount); + this.sideboard.add(card, amount); } /** @@ -286,7 +286,7 @@ public final class Deck implements Comparable, Serializable { * the cards */ public void addSideboard(final ItemPoolView cards) { - sideboard.addAll(cards); + this.sideboard.addAll(cards); } /** @@ -296,7 +296,7 @@ public final class Deck implements Comparable, Serializable { * the new sideboard */ public void setSideboard(final Iterable cards) { - sideboard = new ItemPool(cards, CardPrinted.class); + this.sideboard = new ItemPool(cards, CardPrinted.class); } /** @@ -307,7 +307,7 @@ public final class Deck implements Comparable, Serializable { * @return a int. */ public int countSideboard() { - return sideboard.countAll(); + return this.sideboard.countAll(); } /** @@ -317,10 +317,10 @@ public final class Deck implements Comparable, Serializable { * * @param card * the card - * + * */ public void removeFromSideboard(final CardPrinted card) { - sideboard.remove(card); + this.sideboard.remove(card); } /** @@ -331,7 +331,7 @@ public final class Deck implements Comparable, Serializable { * @return a boolean. */ public boolean isDraft() { - return getDeckType().equals(GameType.Draft); + return this.getDeckType().equals(GameType.Draft); } /** @@ -342,7 +342,7 @@ public final class Deck implements Comparable, Serializable { * @return a boolean. */ public boolean isSealed() { - return getDeckType().equals(GameType.Sealed); + return this.getDeckType().equals(GameType.Sealed); } /** @@ -353,7 +353,7 @@ public final class Deck implements Comparable, Serializable { * @return a boolean. */ public boolean isRegular() { - return getDeckType().equals(GameType.Constructed); + return this.getDeckType().equals(GameType.Constructed); } /** @@ -363,14 +363,15 @@ public final class Deck implements Comparable, Serializable { * * @return a int. */ + @Override public int hashCode() { - return getName().hashCode(); + return this.getName().hashCode(); } /** {@inheritDoc} */ @Override public String toString() { - return getName(); + return this.getName(); } /** @@ -382,15 +383,17 @@ public final class Deck implements Comparable, Serializable { * a {@link forge.deck.Deck} object. * @return a int. */ + @Override public int compareTo(final Deck d) { - return getName().compareTo(d.getName()); + return this.getName().compareTo(d.getName()); } /** {@inheritDoc} */ + @Override public boolean equals(final Object o) { if (o instanceof Deck) { - Deck d = (Deck) o; - return getName().equals(d.getName()); + final Deck d = (Deck) o; + return this.getName().equals(d.getName()); } return false; } @@ -399,14 +402,14 @@ public final class Deck implements Comparable, Serializable { * Clear sideboard. */ public void clearSideboard() { - sideboard.clear(); + this.sideboard.clear(); } /** * Clear main. */ public void clearMain() { - main.clear(); + this.main.clear(); } @@ -416,7 +419,7 @@ public final class Deck implements Comparable, Serializable { * @return the player type */ public PlayerType getPlayerType() { - return playerType; + return this.playerType; } /** @@ -435,7 +438,7 @@ public final class Deck implements Comparable, Serializable { * @return true, if is custom pool */ public boolean isCustomPool() { - return customPool; + return this.customPool; } /** @@ -445,6 +448,6 @@ public final class Deck implements Comparable, Serializable { * the new custom pool */ public void setCustomPool(final boolean cp) { - customPool = cp; + this.customPool = cp; } } diff --git a/src/main/java/forge/deck/DeckGeneration.java b/src/main/java/forge/deck/DeckGeneration.java index cd1cd65901b..2c3d4d688a3 100644 --- a/src/main/java/forge/deck/DeckGeneration.java +++ b/src/main/java/forge/deck/DeckGeneration.java @@ -35,7 +35,7 @@ public abstract class DeckGeneration { // TODO jendave to refactor deck generation Deck d = null; - ArrayList decks = new ArrayList(); + final ArrayList decks = new ArrayList(); decks.add("2-Color Deck"); decks.add("3-Color Deck"); decks.add("5-Color Deck"); @@ -44,25 +44,25 @@ public abstract class DeckGeneration { decks.add("5-Color Deck (original)"); decks.add("Semi-Random Theme Deck"); - String playerName = playerType.equals(PlayerType.HUMAN) ? "Human" : "Computer"; - String prompt = String.format("Generate %s Deck", playerName); + final String playerName = playerType.equals(PlayerType.HUMAN) ? "Human" : "Computer"; + final String prompt = String.format("Generate %s Deck", playerName); - Object o = GuiUtils.getChoice(prompt, decks.toArray()); + final Object o = GuiUtils.getChoice(prompt, decks.toArray()); if (o.toString().equals(decks.get(0))) { - d = generate2ColorDeck(playerType); + d = DeckGeneration.generate2ColorDeck(playerType); } else if (o.toString().equals(decks.get(1))) { - d = generate3ColorDeck(playerType); + d = DeckGeneration.generate3ColorDeck(playerType); } else if (o.toString().equals(decks.get(2))) { - d = generate5ColorDeck(playerType); + d = DeckGeneration.generate5ColorDeck(playerType); } else if (o.toString().equals(decks.get(3))) { - d = generateConstructedDeck(); + d = DeckGeneration.generateConstructedDeck(); } else if (o.toString().equals(decks.get(4))) { - d = generateConstructed3ColorDeck(); + d = DeckGeneration.generateConstructed3ColorDeck(); } else if (o.toString().equals(decks.get(5))) { - d = generateConstructed5ColorDeck(); + d = DeckGeneration.generateConstructed5ColorDeck(); } else if (o.toString().equals(decks.get(6))) { - d = generateConstructedThemeDeck(); + d = DeckGeneration.generateConstructedThemeDeck(); } if (playerType.equals(PlayerType.HUMAN)) { @@ -80,9 +80,9 @@ public abstract class DeckGeneration { * @return a {@link forge.deck.Deck} object. */ private static Deck generateConstructedDeck() { - GenerateConstructedDeck gen = new GenerateConstructedDeck(); - CardList name = gen.generateDeck(); - Deck deck = new Deck(GameType.Constructed); + final GenerateConstructedDeck gen = new GenerateConstructedDeck(); + final CardList name = gen.generateDeck(); + final Deck deck = new Deck(GameType.Constructed); for (int i = 0; i < 60; i++) { deck.addMain(name.get(i).getName()); @@ -98,9 +98,9 @@ public abstract class DeckGeneration { * @return a {@link forge.deck.Deck} object. */ private static Deck generateConstructed3ColorDeck() { - GenerateConstructedMultiColorDeck gen = new GenerateConstructedMultiColorDeck(); - CardList name = gen.generate3ColorDeck(); - Deck deck = new Deck(GameType.Constructed); + final GenerateConstructedMultiColorDeck gen = new GenerateConstructedMultiColorDeck(); + final CardList name = gen.generate3ColorDeck(); + final Deck deck = new Deck(GameType.Constructed); for (int i = 0; i < 60; i++) { deck.addMain(name.get(i).getName()); @@ -116,9 +116,9 @@ public abstract class DeckGeneration { * @return a {@link forge.deck.Deck} object. */ private static Deck generateConstructed5ColorDeck() { - GenerateConstructedMultiColorDeck gen = new GenerateConstructedMultiColorDeck(); - CardList name = gen.generate5ColorDeck(); - Deck deck = new Deck(GameType.Constructed); + final GenerateConstructedMultiColorDeck gen = new GenerateConstructedMultiColorDeck(); + final CardList name = gen.generate5ColorDeck(); + final Deck deck = new Deck(GameType.Constructed); for (int i = 0; i < 60; i++) { deck.addMain(name.get(i).getName()); @@ -134,21 +134,21 @@ public abstract class DeckGeneration { * @return a {@link forge.deck.Deck} object. */ private static Deck generateConstructedThemeDeck() { - GenerateThemeDeck gen = new GenerateThemeDeck(); - ArrayList tNames = gen.getThemeNames(); + final GenerateThemeDeck gen = new GenerateThemeDeck(); + final ArrayList tNames = gen.getThemeNames(); tNames.add(0, "Random"); - Object o = GuiUtils.getChoice("Select a theme.", tNames.toArray()); + final Object o = GuiUtils.getChoice("Select a theme.", tNames.toArray()); String stDeck; if (o.toString().equals("Random")) { - Random r = MyRandom.getRandom(); + final Random r = MyRandom.getRandom(); stDeck = tNames.get(r.nextInt(tNames.size() - 1) + 1); } else { stDeck = o.toString(); } - CardList td = gen.getThemeDeck(stDeck, 60); - Deck deck = new Deck(GameType.Constructed); + final CardList td = gen.getThemeDeck(stDeck, 60); + final Deck deck = new Deck(GameType.Constructed); for (int i = 0; i < td.size(); i++) { deck.addMain(td.get(i).getName()); @@ -167,9 +167,9 @@ public abstract class DeckGeneration { * @return a {@link forge.deck.Deck} object. */ private static Deck generate2ColorDeck(final PlayerType p) { - Random r = MyRandom.getRandom(); + final Random r = MyRandom.getRandom(); - ArrayList colors = new ArrayList(); + final ArrayList colors = new ArrayList(); colors.add("Random"); colors.add("white"); colors.add("blue"); @@ -199,10 +199,10 @@ public abstract class DeckGeneration { colors.remove(c1); c2 = colors.get(r.nextInt(colors.size() - 1) + 1); } - Generate2ColorDeck gen = new Generate2ColorDeck(c1, c2); - CardList d = gen.get2ColorDeck(60, p); + final Generate2ColorDeck gen = new Generate2ColorDeck(c1, c2); + final CardList d = gen.get2ColorDeck(60, p); - Deck deck = new Deck(GameType.Constructed); + final Deck deck = new Deck(GameType.Constructed); for (int i = 0; i < d.size(); i++) { deck.addMain(d.get(i).getName()); @@ -222,9 +222,9 @@ public abstract class DeckGeneration { * @return a {@link forge.deck.Deck} object. */ private static Deck generate3ColorDeck(final PlayerType p) { - Random r = MyRandom.getRandom(); + final Random r = MyRandom.getRandom(); - ArrayList colors = new ArrayList(); + final ArrayList colors = new ArrayList(); colors.add("Random"); colors.add("white"); colors.add("blue"); @@ -265,10 +265,10 @@ public abstract class DeckGeneration { colors.remove(c2); c3 = colors.get(r.nextInt(colors.size() - 1) + 1); } - Generate3ColorDeck gen = new Generate3ColorDeck(c1, c2, c3); - CardList d = gen.get3ColorDeck(60, p); + final Generate3ColorDeck gen = new Generate3ColorDeck(c1, c2, c3); + final CardList d = gen.get3ColorDeck(60, p); - Deck deck = new Deck(GameType.Constructed); + final Deck deck = new Deck(GameType.Constructed); for (int i = 0; i < d.size(); i++) { deck.addMain(d.get(i).getName()); @@ -298,10 +298,10 @@ public abstract class DeckGeneration { // colors.add("red"); // colors.add("green"); - Generate5ColorDeck gen = new Generate5ColorDeck("white", "blue", "black", "red", "green"); - CardList d = gen.get5ColorDeck(60, p); + final Generate5ColorDeck gen = new Generate5ColorDeck("white", "blue", "black", "red", "green"); + final CardList d = gen.get5ColorDeck(60, p); - Deck deck = new Deck(GameType.Constructed); + final Deck deck = new Deck(GameType.Constructed); for (int i = 0; i < d.size(); i++) { deck.addMain(d.get(i).getName()); diff --git a/src/main/java/forge/deck/DeckManager.java b/src/main/java/forge/deck/DeckManager.java index 68ab2f55694..02b8ed5f904 100644 --- a/src/main/java/forge/deck/DeckManager.java +++ b/src/main/java/forge/deck/DeckManager.java @@ -1,8 +1,5 @@ package forge.deck; -import static java.lang.Integer.parseInt; -import static java.lang.String.format; - import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; @@ -53,6 +50,7 @@ import freemarker.template.TemplateException; public class DeckManager { /** Constant BDKFileFilter. */ private static FilenameFilter bdkFileFilter = new FilenameFilter() { + @Override public boolean accept(final File dir, final String name) { return name.endsWith(".bdk"); } @@ -60,6 +58,7 @@ public class DeckManager { /** Constant DCKFileFilter. */ public static final FilenameFilter DCK_FILE_FILTER = new FilenameFilter() { + @Override public boolean accept(final File dir, final String name) { return name.endsWith(".dck"); } @@ -125,9 +124,9 @@ public class DeckManager { } this.deckMap = new HashMap(); this.draftMap = new HashMap(); - readAllDecks(); + this.readAllDecks(); } - } catch (IOException ex) { + } catch (final IOException ex) { ErrorViewer.showError(ex); throw new RuntimeException("DeckManager : writeDeck() error, " + ex.getMessage()); } @@ -143,7 +142,7 @@ public class DeckManager { * @return a boolean. */ public final boolean isUnique(final String deckName) { - return !deckMap.containsKey(deckName); + return !this.deckMap.containsKey(deckName); } /** @@ -156,7 +155,7 @@ public class DeckManager { * @return a boolean. */ public final boolean isUniqueDraft(final String deckName) { - return !draftMap.keySet().contains(deckName); + return !this.draftMap.keySet().contains(deckName); } /** @@ -169,7 +168,7 @@ public class DeckManager { * @return a {@link forge.deck.Deck} object. */ public final Deck getDeck(final String deckName) { - return deckMap.get(deckName); + return this.deckMap.get(deckName); } /** @@ -185,7 +184,7 @@ public class DeckManager { throw new RuntimeException("DeckManager : addDeck() error, deck type is Draft"); } - deckMap.put(deck.getName(), deck); + this.deckMap.put(deck.getName(), deck); } /** @@ -197,7 +196,7 @@ public class DeckManager { * a {@link java.lang.String} object. */ public final void deleteDeck(final String deckName) { - deckMap.remove(deckName); + this.deckMap.remove(deckName); } /** @@ -210,11 +209,11 @@ public class DeckManager { * @return an array of {@link forge.deck.Deck} objects. */ public final Deck[] getDraftDeck(final String deckName) { - if (!draftMap.containsKey(deckName)) { + if (!this.draftMap.containsKey(deckName)) { throw new RuntimeException("DeckManager : getDraftDeck() error, deck name not found - " + deckName); } - return draftMap.get(deckName); + return this.draftMap.get(deckName); } /** @@ -226,9 +225,9 @@ public class DeckManager { * an array of {@link forge.deck.Deck} objects. */ public final void addDraftDeck(final Deck[] deck) { - checkDraftDeck(deck); + this.checkDraftDeck(deck); - draftMap.put(deck[0].toString(), deck); + this.draftMap.put(deck[0].toString(), deck); } /** @@ -240,13 +239,13 @@ public class DeckManager { * a {@link java.lang.String} object. */ public final void deleteDraftDeck(final String deckName) { - if (!draftMap.containsKey(deckName)) { + if (!this.draftMap.containsKey(deckName)) { throw new RuntimeException("DeckManager : deleteDraftDeck() error, deck name not found - " + deckName); } - draftMap.remove(deckName); + this.draftMap.remove(deckName); // delete from disk as well - File f = makeFileName(deckName, GameType.Draft); + final File f = DeckManager.makeFileName(deckName, GameType.Draft); f.delete(); } @@ -259,7 +258,7 @@ public class DeckManager { * an array of {@link forge.deck.Deck} objects. */ private void checkDraftDeck(final Deck[] deck) { - if (deck == null || deck.length != 8 || deck[0].getName().equals("") + if ((deck == null) || (deck.length != 8) || deck[0].getName().equals("") || (!deck[0].getDeckType().equals(GameType.Draft))) { throw new RuntimeException("DeckManager : checkDraftDeck() error, invalid deck"); } @@ -272,7 +271,7 @@ public class DeckManager { * @return a Collection */ public final Collection getDecks() { - return deckMap.values(); + return this.deckMap.values(); } /** @@ -282,7 +281,7 @@ public class DeckManager { * @return a Map */ public final Map getDraftDecks() { - return new HashMap(draftMap); + return new HashMap(this.draftMap); } /** @@ -294,15 +293,15 @@ public class DeckManager { * @return a ArrayList */ public final ArrayList getDeckNames(final GameType deckType) { - ArrayList list = new ArrayList(); + final ArrayList list = new ArrayList(); // only get decks according to the OldGuiNewGame screen option if (deckType.equals(GameType.Draft)) { - for (String s : getDraftDecks().keySet()) { + for (final String s : this.getDraftDecks().keySet()) { list.add(s); } } else { - for (Deck deck : getDecks()) { + for (final Deck deck : this.getDecks()) { if (deckType.equals(deck.getDeckType())) { list.add(deck.toString()); } @@ -319,19 +318,20 @@ public class DeckManager { *

*/ public final void readAllDecks() { - deckMap.clear(); - draftMap.clear(); + this.deckMap.clear(); + this.draftMap.clear(); File[] files; - List decksThatFailedToLoad = new ArrayList(); - files = deckDir.listFiles(DCK_FILE_FILTER); - for (File file : files) { + final List decksThatFailedToLoad = new ArrayList(); + files = this.deckDir.listFiles(DeckManager.DCK_FILE_FILTER); + for (final File file : files) { try { - Deck newDeck = readDeck(file); - deckMap.put(newDeck.getName(), newDeck); - } catch (NoSuchElementException ex) { - String message = String.format("%s failed to load because ---- %s", file.getName(), ex.getMessage()); + final Deck newDeck = DeckManager.readDeck(file); + this.deckMap.put(newDeck.getName(), newDeck); + } catch (final NoSuchElementException ex) { + final String message = String.format("%s failed to load because ---- %s", file.getName(), + ex.getMessage()); decksThatFailedToLoad.add(message); } } @@ -342,13 +342,13 @@ public class DeckManager { "Some of your decks were not loaded.", JOptionPane.WARNING_MESSAGE); } - files = deckDir.listFiles(bdkFileFilter); - for (File file : files) { - Deck[] d = new Deck[8]; + files = this.deckDir.listFiles(DeckManager.bdkFileFilter); + for (final File file : files) { + final Deck[] d = new Deck[8]; boolean gotError = false; for (int i = 0; i < d.length; i++) { - d[i] = readDeck(new File(file, i + ".dck")); + d[i] = DeckManager.readDeck(new File(file, i + ".dck")); if (d[i] == null) { gotError = true; break; @@ -356,7 +356,7 @@ public class DeckManager { } if (!gotError) { - draftMap.put(d[0].getName(), d); + this.draftMap.put(d[0].getName(), d); } } } @@ -372,28 +372,28 @@ public class DeckManager { */ public static Deck readDeck(final File deckFile) { - List lines = FileUtil.readFile(deckFile); + final List lines = FileUtil.readFile(deckFile); if (lines.isEmpty()) { return null; } - Deck d = new Deck(); + final Deck d = new Deck(); - String firstLine = lines.get(0); + final String firstLine = lines.get(0); if (!firstLine.startsWith("[") || firstLine.equalsIgnoreCase("[general]")) { - readDeckOldMetadata(lines.iterator(), d); + DeckManager.readDeckOldMetadata(lines.iterator(), d); } else { - readDeckMetadata(findSection(lines, "metadata"), d); + DeckManager.readDeckMetadata(DeckManager.findSection(lines, "metadata"), d); } - d.setMain(readCardList(findSection(lines, "main"))); - d.setSideboard(readCardList(findSection(lines, "sideboard"))); + d.setMain(DeckManager.readCardList(DeckManager.findSection(lines, "main"))); + d.setSideboard(DeckManager.readCardList(DeckManager.findSection(lines, "sideboard"))); return d; } private static Iterator findSection(final Iterable lines, final String sectionName) { - Iterator lineIterator = lines.iterator(); - String toSearch = String.format("[%s]", sectionName); + final Iterator lineIterator = lines.iterator(); + final String toSearch = String.format("[%s]", sectionName); while (lineIterator.hasNext()) { if (toSearch.equalsIgnoreCase(lineIterator.next())) { break; @@ -405,32 +405,32 @@ public class DeckManager { private static void readDeckMetadata(final Iterator lineIterator, final Deck d) { while (lineIterator.hasNext()) { - String line = lineIterator.next(); + final String line = lineIterator.next(); if (line.startsWith("[")) { break; } - String[] linedata = line.split("=", 2); - String field = linedata[0].toLowerCase(); + final String[] linedata = line.split("=", 2); + final String field = linedata[0].toLowerCase(); String value = ""; if (linedata.length > 1) { value = linedata[1]; } - if (NAME.equalsIgnoreCase(field)) { + if (DeckManager.NAME.equalsIgnoreCase(field)) { d.setName(value); - } else if (COMMENT.equalsIgnoreCase(field)) { + } else if (DeckManager.COMMENT.equalsIgnoreCase(field)) { d.setComment(value); - } else if (DECK_TYPE.equalsIgnoreCase(field)) { + } else if (DeckManager.DECK_TYPE.equalsIgnoreCase(field)) { d.setDeckType(GameType.smartValueOf(value)); - } else if (CSTM_POOL.equalsIgnoreCase(field)) { + } else if (DeckManager.CSTM_POOL.equalsIgnoreCase(field)) { d.setCustomPool(value.equalsIgnoreCase("true")); - } else if (PLAYER.equalsIgnoreCase(field)) { + } else if (DeckManager.PLAYER.equalsIgnoreCase(field)) { if ("human".equalsIgnoreCase(value)) { d.setPlayerType(PlayerType.HUMAN); @@ -454,11 +454,11 @@ public class DeckManager { String line; // readDeck name - String name = iterator.next(); + final String name = iterator.next(); // readDeck comments String comment = null; - while (iterator.hasNext() && (line = iterator.next()) != null && !line.equals("[general]")) { + while (iterator.hasNext() && ((line = iterator.next()) != null) && !line.equals("[general]")) { if (comment == null) { comment = line; } else { @@ -468,7 +468,7 @@ public class DeckManager { // readDeck deck type - GameType deckType = iterator.hasNext() ? GameType.smartValueOf(iterator.next()) : GameType.Constructed; + final GameType deckType = iterator.hasNext() ? GameType.smartValueOf(iterator.next()) : GameType.Constructed; d.setName(name); d.setComment(comment); @@ -477,24 +477,24 @@ public class DeckManager { // Precondition: iterator should point at the first line of cards list private static List readCardList(final Iterator lineIterator) { - List result = new ArrayList(); - Pattern p = Pattern.compile("((\\d+)\\s+)?(.*?)"); + final List result = new ArrayList(); + final Pattern p = Pattern.compile("((\\d+)\\s+)?(.*?)"); while (lineIterator.hasNext()) { - String line = lineIterator.next(); + final String line = lineIterator.next(); if (line.startsWith("[")) { break; } // there comes another section - Matcher m = p.matcher(line.trim()); + final Matcher m = p.matcher(line.trim()); m.matches(); - String sCnt = m.group(2); - String cardName = m.group(3); + final String sCnt = m.group(2); + final String cardName = m.group(3); if (StringUtils.isBlank(cardName)) { continue; } - int count = sCnt == null ? 1 : parseInt(sCnt); + final int count = sCnt == null ? 1 : Integer.parseInt(sCnt); for (int i = 0; i < count; i++) { result.add(cardName); } @@ -517,10 +517,10 @@ public class DeckManager { * @return a String */ public static String cleanDeckName(final String in) { - char[] c = in.toCharArray(); - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < c.length && i < 20; i++) { - if (Character.isLetterOrDigit(c[i]) || c[i] == '-') { + final char[] c = in.toCharArray(); + final StringBuilder sb = new StringBuilder(); + for (int i = 0; (i < c.length) && (i < 20); i++) { + if (Character.isLetterOrDigit(c[i]) || (c[i] == '-')) { sb.append(c[i]); } } @@ -538,11 +538,11 @@ public class DeckManager { * @return a File */ public static File makeFileName(final String deckName, final GameType deckType) { - File path = ForgeProps.getFile(NewConstants.NEW_DECKS); + final File path = ForgeProps.getFile(NewConstants.NEW_DECKS); if (deckType == GameType.Draft) { - return new File(path, deriveFileName(deckName) + ".bdk"); + return new File(path, DeckManager.deriveFileName(deckName) + ".bdk"); } else { - return new File(path, deriveFileName(deckName) + ".dck"); + return new File(path, DeckManager.deriveFileName(deckName) + ".dck"); } } @@ -555,7 +555,7 @@ public class DeckManager { * @return a File */ public static File makeFileName(final Deck deck) { - return makeFileName(deck.getName(), deck.getDeckType()); + return DeckManager.makeFileName(deck.getName(), deck.getDeckType()); } /** @@ -567,15 +567,15 @@ public class DeckManager { */ public static void writeDraftDecks(final Deck[] drafts) { try { - File f = makeFileName(drafts[0]); + final File f = DeckManager.makeFileName(drafts[0]); f.mkdir(); for (int i = 0; i < drafts.length; i++) { - BufferedWriter out = new BufferedWriter(new FileWriter(new File(f, i + ".dck"))); - writeDeck(drafts[i], out); + final BufferedWriter out = new BufferedWriter(new FileWriter(new File(f, i + ".dck"))); + DeckManager.writeDeck(drafts[i], out); out.close(); } - } catch (IOException ex) { + } catch (final IOException ex) { ErrorViewer.showError(ex); throw new RuntimeException("DeckManager : writeDeck() error, " + ex.getMessage()); } @@ -594,27 +594,27 @@ public class DeckManager { * if any. */ private static void writeDeck(final Deck d, final BufferedWriter out) throws IOException { - out.write(format("[metadata]%n")); + out.write(String.format("[metadata]%n")); - out.write(format("%s=%s%n", NAME, d.getName().replaceAll("\n", ""))); - out.write(format("%s=%s%n", DECK_TYPE, d.getDeckType())); + out.write(String.format("%s=%s%n", DeckManager.NAME, d.getName().replaceAll("\n", ""))); + out.write(String.format("%s=%s%n", DeckManager.DECK_TYPE, d.getDeckType())); // these are optional if (d.getComment() != null) { - out.write(format("%s=%s%n", COMMENT, d.getComment().replaceAll("\n", ""))); + out.write(String.format("%s=%s%n", DeckManager.COMMENT, d.getComment().replaceAll("\n", ""))); } if (d.getPlayerType() != null) { - out.write(format("%s=%s%n", PLAYER, d.getPlayerType())); + out.write(String.format("%s=%s%n", DeckManager.PLAYER, d.getPlayerType())); } if (d.isCustomPool()) { - out.write(format("%s=%s%n", CSTM_POOL, "true")); + out.write(String.format("%s=%s%n", DeckManager.CSTM_POOL, "true")); } - out.write(format("%s%n", "[main]")); - writeCardPool(d.getMain(), out); + out.write(String.format("%s%n", "[main]")); + DeckManager.writeCardPool(d.getMain(), out); - out.write(format("%s%n", "[sideboard]")); - writeCardPool(d.getSideboard(), out); + out.write(String.format("%s%n", "[sideboard]")); + DeckManager.writeCardPool(d.getSideboard(), out); } /** @@ -631,12 +631,12 @@ public class DeckManager { */ private static void writeDeckHtml(final Deck d, final BufferedWriter out) throws IOException { Template temp = null; - int cardBorder = 0; - int height = 319; - int width = 222; + final int cardBorder = 0; + final int height = 319; + final int width = 222; /* Create and adjust the configuration */ - Configuration cfg = new Configuration(); + final Configuration cfg = new Configuration(); try { cfg.setClassForTemplateLoading(d.getClass(), "/"); cfg.setObjectWrapper(new DefaultObjectWrapper()); @@ -654,10 +654,10 @@ public class DeckManager { temp = cfg.getTemplate("proxy-template.ftl"); /* Create a data-model */ - Map root = new HashMap(); + final Map root = new HashMap(); root.put("title", d.getName()); - List list = new ArrayList(); - for (Card card : d.getMain().toForgeCardList().toArray()) { + final List list = new ArrayList(); + for (final Card card : d.getMain().toForgeCardList().toArray()) { // System.out.println(card.getSets().get(card.getSets().size() - // 1).URL); list.add(card.getSets().get(card.getSets().size() - 1).getUrl()); @@ -669,8 +669,8 @@ public class DeckManager { * 1).URL); nameList.add(card.getName()); } */ - TreeMap map = new TreeMap(); - for (Entry entry : d.getMain().getOrderedList()) { + final TreeMap map = new TreeMap(); + for (final Entry entry : d.getMain().getOrderedList()) { map.put(entry.getKey().getName(), entry.getValue()); // System.out.println(entry.getValue() + " " + // entry.getKey().getName()); @@ -688,24 +688,24 @@ public class DeckManager { // StringWriter sw = new StringWriter(); temp.process(root, out); out.flush(); - } catch (IOException e) { + } catch (final IOException e) { System.out.println(e.toString()); - } catch (TemplateException e) { + } catch (final TemplateException e) { System.out.println(e.toString()); } } private static void writeCardPool(final ItemPoolView pool, final BufferedWriter out) throws IOException { - List> main2sort = pool.getOrderedList(); + final List> main2sort = pool.getOrderedList(); Collections.sort(main2sort, TableSorter.byNameThenSet); - for (Entry e : main2sort) { - CardPrinted card = e.getKey(); - boolean hasBadSetInfo = "???".equals(card.getSet()) || StringUtils.isBlank(card.getSet()); + for (final Entry e : main2sort) { + final CardPrinted card = e.getKey(); + final boolean hasBadSetInfo = "???".equals(card.getSet()) || StringUtils.isBlank(card.getSet()); if (hasBadSetInfo) { - out.write(format("%d %s%n", e.getValue(), card.getName())); + out.write(String.format("%d %s%n", e.getValue(), card.getName())); } else { - out.write(format("%d %s|%s%n", e.getValue(), card.getName(), card.getSet())); + out.write(String.format("%d %s|%s%n", e.getValue(), card.getName(), card.getSet())); } } } @@ -722,10 +722,10 @@ public class DeckManager { */ public static void writeDeck(final Deck d, final File f) { try { - BufferedWriter writer = new BufferedWriter(new FileWriter(f)); - writeDeck(d, writer); + final BufferedWriter writer = new BufferedWriter(new FileWriter(f)); + DeckManager.writeDeck(d, writer); writer.close(); - } catch (IOException e) { + } catch (final IOException e) { throw new RuntimeException(e); } @@ -743,10 +743,10 @@ public class DeckManager { */ public static void writeDeckHtml(final Deck d, final File f) { try { - BufferedWriter writer = new BufferedWriter(new FileWriter(f)); - writeDeckHtml(d, writer); + final BufferedWriter writer = new BufferedWriter(new FileWriter(f)); + DeckManager.writeDeckHtml(d, writer); writer.close(); - } catch (IOException e) { + } catch (final IOException e) { throw new RuntimeException(e); } } diff --git a/src/main/java/forge/deck/DeckRecognizer.java b/src/main/java/forge/deck/DeckRecognizer.java index 4a2fa1a974b..4d9ed34f147 100644 --- a/src/main/java/forge/deck/DeckRecognizer.java +++ b/src/main/java/forge/deck/DeckRecognizer.java @@ -76,10 +76,10 @@ public class DeckRecognizer { } private Token(final CardPrinted knownCard, final TokenType type1, final int count, final String message) { - card = knownCard; - number = count; - type = type1; - text = message; + this.card = knownCard; + this.number = count; + this.type = type1; + this.text = message; } /** @@ -94,7 +94,7 @@ public class DeckRecognizer { */ public Token(final TokenType type1, final int count, final String message) { this(null, type1, count, message); - if (type1 == TokenType.KnownCard || type1 == TokenType.UnknownCard) { + if ((type1 == TokenType.KnownCard) || (type1 == TokenType.UnknownCard)) { throw new IllegalArgumentException("Use factory methods for recognized card lines"); } } @@ -105,7 +105,7 @@ public class DeckRecognizer { * @return the text */ public final String getText() { - return text; + return this.text; } /** @@ -114,7 +114,7 @@ public class DeckRecognizer { * @return the card */ public final CardPrinted getCard() { - return card; + return this.card; } /** @@ -123,7 +123,7 @@ public class DeckRecognizer { * @return the type */ public final TokenType getType() { - return type; + return this.type; } /** @@ -132,35 +132,35 @@ public class DeckRecognizer { * @return the number */ public final int getNumber() { - return number; + return this.number; } } // Let's think about it numbers in the back later // private static final Pattern searchNumbersInBack = // Pattern.compile("(.*)[^A-Za-wyz]*\\s+([\\d]{1,2})"); - private static final Pattern searchNumbersInFront = Pattern.compile("([\\d]{1,2})[^A-Za-wyz]*\\s+(.*)"); + private static final Pattern SEARCH_NUMBERS_IN_FRONT = Pattern.compile("([\\d]{1,2})[^A-Za-wyz]*\\s+(.*)"); /** * Recognize line. * - * @param raw_line + * @param rawLine * the raw_line * @return the token */ - public static Token recognizeLine(final String raw_line) { - if (StringUtils.isBlank(raw_line)) { - return new Token(TokenType.Comment, 0, raw_line); + public static Token recognizeLine(final String rawLine) { + if (StringUtils.isBlank(rawLine)) { + return new Token(TokenType.Comment, 0, rawLine); } - String line = raw_line.trim(); + final String line = rawLine.trim(); Token result = null; - Matcher foundNumbersInFront = searchNumbersInFront.matcher(line); + final Matcher foundNumbersInFront = DeckRecognizer.SEARCH_NUMBERS_IN_FRONT.matcher(line); // Matcher foundNumbersInBack = searchNumbersInBack.matcher(line); if (foundNumbersInFront.matches()) { - String cardName = foundNumbersInFront.group(2); - int amount = Integer.parseInt(foundNumbersInFront.group(1)); - result = recognizePossibleNameAndNumber(cardName, amount); + final String cardName = foundNumbersInFront.group(2); + final int amount = Integer.parseInt(foundNumbersInFront.group(1)); + result = DeckRecognizer.recognizePossibleNameAndNumber(cardName, amount); } /* * else if (foundNumbersInBack.matches()) { String cardName = * foundNumbersInBack.group(1); int amount = @@ -171,7 +171,7 @@ public class DeckRecognizer { if (CardDb.instance().isCardSupported(line)) { return Token.knownCard(CardDb.instance().getCard(line), 1); } - result = recognizeNonCard(line, 1); + result = DeckRecognizer.recognizeNonCard(line, 1); } return result != null ? result : new Token(TokenType.UnknownText, 0, line); } @@ -181,32 +181,32 @@ public class DeckRecognizer { return Token.knownCard(CardDb.instance().getCard(name), n); } - Token known = recognizeNonCard(name, n); + final Token known = DeckRecognizer.recognizeNonCard(name, n); return null == known ? Token.unknownCard(name, n) : known; } private static Token recognizeNonCard(final String text, final int n) { - if (isDecoration(text)) { + if (DeckRecognizer.isDecoration(text)) { return new Token(TokenType.Comment, n, text); } - if (isSectionName(text)) { + if (DeckRecognizer.isSectionName(text)) { return new Token(TokenType.SectionName, n, text); } return null; } - private static final String[] knownComments = new String[] { "land", "lands", "creatures", "creature", "spells", + private static final String[] KNOWN_COMMENTS = new String[] { "land", "lands", "creatures", "creature", "spells", "enchancements", "other spells", "artifacts" }; - private static final String[] knownCommentParts = new String[] { "card" }; + private static final String[] KNOWN_COMMENT_PARTS = new String[] { "card" }; private static boolean isDecoration(final String lineAsIs) { - String line = lineAsIs.toLowerCase(); - for (String s : knownCommentParts) { + final String line = lineAsIs.toLowerCase(); + for (final String s : DeckRecognizer.KNOWN_COMMENT_PARTS) { if (line.contains(s)) { return true; } } - for (String s : knownComments) { + for (final String s : DeckRecognizer.KNOWN_COMMENTS) { if (line.equalsIgnoreCase(s)) { return true; } diff --git a/src/main/java/forge/deck/generate/Generate2ColorDeck.java b/src/main/java/forge/deck/generate/Generate2ColorDeck.java index 0d6fe73b5c6..d8d5f0d6bd3 100644 --- a/src/main/java/forge/deck/generate/Generate2ColorDeck.java +++ b/src/main/java/forge/deck/generate/Generate2ColorDeck.java @@ -44,46 +44,46 @@ public class Generate2ColorDeck { * a {@link java.lang.String} object. */ public Generate2ColorDeck(final String Clr1, final String Clr2) { - r = MyRandom.getRandom(); + this.r = MyRandom.getRandom(); - cardCounts = new HashMap(); + this.cardCounts = new HashMap(); - clrMap = new HashMap(); - clrMap.put("white", "W"); - clrMap.put("blue", "U"); - clrMap.put("black", "B"); - clrMap.put("red", "R"); - clrMap.put("green", "G"); + this.clrMap = new HashMap(); + this.clrMap.put("white", "W"); + this.clrMap.put("blue", "U"); + this.clrMap.put("black", "B"); + this.clrMap.put("red", "R"); + this.clrMap.put("green", "G"); - notColors = new ArrayList(); - notColors.add("white"); - notColors.add("blue"); - notColors.add("black"); - notColors.add("red"); - notColors.add("green"); + this.notColors = new ArrayList(); + this.notColors.add("white"); + this.notColors.add("blue"); + this.notColors.add("black"); + this.notColors.add("red"); + this.notColors.add("green"); if (Clr1.equals("AI")) { // choose first color - color1 = notColors.get(r.nextInt(5)); + this.color1 = this.notColors.get(this.r.nextInt(5)); // choose second color - String c2 = notColors.get(r.nextInt(5)); - while (c2.equals(color1)) { - c2 = notColors.get(r.nextInt(5)); + String c2 = this.notColors.get(this.r.nextInt(5)); + while (c2.equals(this.color1)) { + c2 = this.notColors.get(this.r.nextInt(5)); } - color2 = c2; + this.color2 = c2; } else { - color1 = Clr1; - color2 = Clr2; + this.color1 = Clr1; + this.color2 = Clr2; } - notColors.remove(color1); - notColors.remove(color2); + this.notColors.remove(this.color1); + this.notColors.remove(this.color2); - dL = GenerateDeckUtil.getDualLandList(clrMap.get(color1) + clrMap.get(color2)); + this.dL = GenerateDeckUtil.getDualLandList(this.clrMap.get(this.color1) + this.clrMap.get(this.color2)); - for (int i = 0; i < dL.size(); i++) { - cardCounts.put(dL.get(i), 0); + for (int i = 0; i < this.dL.size(); i++) { + this.cardCounts.put(this.dL.get(i), 0); } } @@ -102,33 +102,36 @@ public class Generate2ColorDeck { public final CardList get2ColorDeck(final int Size, final PlayerType pt) { int lc = 0; // loop counter to prevent infinite card selection loops String tmpDeck = ""; - CardList tDeck = new CardList(); + final CardList tDeck = new CardList(); - int LandsPercentage = 42; - int CreatPercentage = 34; - int SpellPercentage = 24; + final int LandsPercentage = 42; + final int CreatPercentage = 34; + final int SpellPercentage = 24; // start with all cards // remove cards that generated decks don't like - CardList AllCards = CardFilter.filter(AllZone.getCardFactory(), new CardListFilter() { + final CardList AllCards = CardFilter.filter(AllZone.getCardFactory(), new CardListFilter() { + @Override public boolean addCard(final Card c) { if (c.getSVar("RemRandomDeck").equals("True")) { return false; } - return (!c.getSVar("RemAIDeck").equals("True") || (pt != null && pt.equals(PlayerType.HUMAN))); + return (!c.getSVar("RemAIDeck").equals("True") || ((pt != null) && pt.equals(PlayerType.HUMAN))); } }); // reduce to cards that match the colors - CardList CL1 = AllCards.getColor(color1); + CardList CL1 = AllCards.getColor(this.color1); CL1.addAll(AllCards.getColor(Constant.Color.COLORLESS)); - CardList CL2 = AllCards.getColor(color2); + CardList CL2 = AllCards.getColor(this.color2); // remove multicolor cards that don't match the colors - CardListFilter clrF = new CardListFilter() { + final CardListFilter clrF = new CardListFilter() { + @Override public boolean addCard(final Card c) { - for (int i = 0; i < notColors.size(); i++) { - if (c.getManaCost().contains(clrMap.get(notColors.get(i)))) { + for (int i = 0; i < Generate2ColorDeck.this.notColors.size(); i++) { + if (c.getManaCost().contains( + Generate2ColorDeck.this.clrMap.get(Generate2ColorDeck.this.notColors.get(i)))) { return false; } } @@ -139,49 +142,50 @@ public class Generate2ColorDeck { CL2 = CL2.filter(clrF); // build subsets based on type - CardList Cr1 = CL1.getType("Creature"); - CardList Cr2 = CL2.getType("Creature"); + final CardList Cr1 = CL1.getType("Creature"); + final CardList Cr2 = CL2.getType("Creature"); - String[] ISE = { "Instant", "Sorcery", "Enchantment", "Planeswalker", "Artifact.nonCreature" }; - CardList Sp1 = CL1.getValidCards(ISE, null, null); - CardList Sp2 = CL2.getValidCards(ISE, null, null); + final String[] ISE = { "Instant", "Sorcery", "Enchantment", "Planeswalker", "Artifact.nonCreature" }; + final CardList Sp1 = CL1.getValidCards(ISE, null, null); + final CardList Sp2 = CL2.getValidCards(ISE, null, null); // final card pools - CardList Cr12 = new CardList(); - CardList Sp12 = new CardList(); + final CardList Cr12 = new CardList(); + final CardList Sp12 = new CardList(); // used for mana curve in the card pool final int MinCMC[] = { 1 }, MaxCMC[] = { 2 }; - CardListFilter cmcF = new CardListFilter() { + final CardListFilter cmcF = new CardListFilter() { + @Override public boolean addCard(final Card c) { - int cCMC = c.getCMC(); + final int cCMC = c.getCMC(); return (cCMC >= MinCMC[0]) && (cCMC <= MaxCMC[0]); } }; // select cards to build card pools using a mana curve for (int i = 4; i > 0; i--) { - CardList Cr1CMC = Cr1.filter(cmcF); - CardList Cr2CMC = Cr2.filter(cmcF); - CardList Sp1CMC = Sp1.filter(cmcF); - CardList Sp2CMC = Sp2.filter(cmcF); + final CardList Cr1CMC = Cr1.filter(cmcF); + final CardList Cr2CMC = Cr2.filter(cmcF); + final CardList Sp1CMC = Sp1.filter(cmcF); + final CardList Sp2CMC = Sp2.filter(cmcF); for (int j = 0; j < i; j++) { - Card c = Cr1CMC.get(r.nextInt(Cr1CMC.size())); + Card c = Cr1CMC.get(this.r.nextInt(Cr1CMC.size())); Cr12.add(c); - cardCounts.put(c.getName(), 0); + this.cardCounts.put(c.getName(), 0); - c = Cr2CMC.get(r.nextInt(Cr2CMC.size())); + c = Cr2CMC.get(this.r.nextInt(Cr2CMC.size())); Cr12.add(c); - cardCounts.put(c.getName(), 0); + this.cardCounts.put(c.getName(), 0); - c = Sp1CMC.get(r.nextInt(Sp1CMC.size())); + c = Sp1CMC.get(this.r.nextInt(Sp1CMC.size())); Sp12.add(c); - cardCounts.put(c.getName(), 0); + this.cardCounts.put(c.getName(), 0); - c = Sp2CMC.get(r.nextInt(Sp2CMC.size())); + c = Sp2CMC.get(this.r.nextInt(Sp2CMC.size())); Sp12.add(c); - cardCounts.put(c.getName(), 0); + this.cardCounts.put(c.getName(), 0); } MinCMC[0] += 2; @@ -200,21 +204,21 @@ public class Generate2ColorDeck { Sp12.shuffle(); // calculate card counts - float p = (float) ((float) CreatPercentage * .01); - int CreatCnt = (int) (p * (float) Size); + float p = (float) (CreatPercentage * .01); + final int CreatCnt = (int) (p * Size); tmpDeck += "Creature Count:" + CreatCnt + "\n"; - p = (float) ((float) SpellPercentage * .01); - int SpellCnt = (int) (p * (float) Size); + p = (float) (SpellPercentage * .01); + final int SpellCnt = (int) (p * Size); tmpDeck += "Spell Count:" + SpellCnt + "\n"; // build deck from the card pools for (int i = 0; i < CreatCnt; i++) { - Card c = Cr12.get(r.nextInt(Cr12.size())); + Card c = Cr12.get(this.r.nextInt(Cr12.size())); lc = 0; - while (cardCounts.get(c.getName()) > 3 || lc > 100) { - c = Cr12.get(r.nextInt(Cr12.size())); + while ((this.cardCounts.get(c.getName()) > 3) || (lc > 100)) { + c = Cr12.get(this.r.nextInt(Cr12.size())); lc++; } if (lc > 100) { @@ -222,17 +226,17 @@ public class Generate2ColorDeck { } tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer())); - int n = cardCounts.get(c.getName()); - cardCounts.put(c.getName(), n + 1); + final int n = this.cardCounts.get(c.getName()); + this.cardCounts.put(c.getName(), n + 1); tmpDeck += c.getName() + " " + c.getManaCost() + "\n"; } for (int i = 0; i < SpellCnt; i++) { - Card c = Sp12.get(r.nextInt(Sp12.size())); + Card c = Sp12.get(this.r.nextInt(Sp12.size())); lc = 0; - while (cardCounts.get(c.getName()) > 3 || lc > 100) { - c = Sp12.get(r.nextInt(Sp12.size())); + while ((this.cardCounts.get(c.getName()) > 3) || (lc > 100)) { + c = Sp12.get(this.r.nextInt(Sp12.size())); lc++; } if (lc > 100) { @@ -240,16 +244,16 @@ public class Generate2ColorDeck { } tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer())); - int n = cardCounts.get(c.getName()); - cardCounts.put(c.getName(), n + 1); + final int n = this.cardCounts.get(c.getName()); + this.cardCounts.put(c.getName(), n + 1); tmpDeck += c.getName() + " " + c.getManaCost() + "\n"; } // Add lands int numLands = 0; if (LandsPercentage > 0) { - p = (float) ((float) LandsPercentage * .01); - numLands = (int) (p * (float) Size); + p = (float) (LandsPercentage * .01); + numLands = (int) (p * Size); } else { // otherwise, just fill in the rest of the deck with basic // lands numLands = Size - tDeck.size(); @@ -257,13 +261,13 @@ public class Generate2ColorDeck { tmpDeck += "numLands:" + numLands + "\n"; - int nDLands = (numLands / 6); + final int nDLands = (numLands / 6); for (int i = 0; i < nDLands; i++) { - String s = dL.get(r.nextInt(dL.size())); + String s = this.dL.get(this.r.nextInt(this.dL.size())); lc = 0; - while (cardCounts.get(s) > 3 || lc > 20) { - s = dL.get(r.nextInt(dL.size())); + while ((this.cardCounts.get(s) > 3) || (lc > 20)) { + s = this.dL.get(this.r.nextInt(this.dL.size())); lc++; } if (lc > 20) { @@ -271,27 +275,27 @@ public class Generate2ColorDeck { } tDeck.add(AllZone.getCardFactory().getCard(s, AllZone.getHumanPlayer())); - int n = cardCounts.get(s); - cardCounts.put(s, n + 1); + final int n = this.cardCounts.get(s); + this.cardCounts.put(s, n + 1); tmpDeck += s + "\n"; } numLands -= nDLands; - if (numLands > 0) // attempt to optimize basic land counts according to - // color representation - { - CCnt[] ClrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0), + if (numLands > 0) { + // attempt to optimize basic land counts according to + // color representation + final CCnt[] ClrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0), new CCnt("Mountain", 0), new CCnt("Forest", 0) }; // count each card color using mana costs // TODO count hybrid mana differently? for (int i = 0; i < tDeck.size(); i++) { - String mc = tDeck.get(i).getManaCost(); + final String mc = tDeck.get(i).getManaCost(); // count each mana symbol in the mana cost for (int j = 0; j < mc.length(); j++) { - char c = mc.charAt(j); + final char c = mc.charAt(j); if (c == 'W') { ClrCnts[0].Count++; @@ -320,12 +324,12 @@ public class Generate2ColorDeck { if (ClrCnts[i].Count > 0) { // calculate number of lands for // each color p = (float) ClrCnts[i].Count / (float) totalColor; - int nLand = (int) ((float) numLands * p); + final int nLand = (int) (numLands * p); tmpDeck += "nLand-" + ClrCnts[i].Color + ":" + nLand + "\n"; // just to prevent a null exception by the deck size fixing // code - cardCounts.put(ClrCnts[i].Color, nLand); + this.cardCounts.put(ClrCnts[i].Color, nLand); for (int j = 0; j <= nLand; j++) { tDeck.add(AllZone.getCardFactory().getCard(ClrCnts[i].Color, AllZone.getComputerPlayer())); @@ -337,33 +341,33 @@ public class Generate2ColorDeck { // fix under-sized or over-sized decks, due to integer arithmetic if (tDeck.size() < Size) { - int diff = Size - tDeck.size(); + final int diff = Size - tDeck.size(); for (int i = 0; i < diff; i++) { - Card c = tDeck.get(r.nextInt(tDeck.size())); + Card c = tDeck.get(this.r.nextInt(tDeck.size())); lc = 0; - while (cardCounts.get(c.getName()) > 3 || lc > Size) { - c = tDeck.get(r.nextInt(tDeck.size())); + while ((this.cardCounts.get(c.getName()) > 3) || (lc > Size)) { + c = tDeck.get(this.r.nextInt(tDeck.size())); lc++; } if (lc > Size) { throw new RuntimeException("Generate2ColorDeck : get2ColorDeck -- looped too much -- undersize"); } - int n = cardCounts.get(c.getName()); + final int n = this.cardCounts.get(c.getName()); tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer())); - cardCounts.put(c.getName(), n + 1); + this.cardCounts.put(c.getName(), n + 1); tmpDeck += "Added:" + c.getName() + "\n"; } } else if (tDeck.size() > Size) { - int diff = tDeck.size() - Size; + final int diff = tDeck.size() - Size; for (int i = 0; i < diff; i++) { - Card c = tDeck.get(r.nextInt(tDeck.size())); + Card c = tDeck.get(this.r.nextInt(tDeck.size())); while (c.isBasicLand()) { // don't remove basic lands - c = tDeck.get(r.nextInt(tDeck.size())); + c = tDeck.get(this.r.nextInt(tDeck.size())); } tDeck.remove(c); @@ -384,8 +388,8 @@ public class Generate2ColorDeck { public int Count; public CCnt(final String clr, final int cnt) { - Color = clr; - Count = cnt; + this.Color = clr; + this.Count = cnt; } } } diff --git a/src/main/java/forge/deck/generate/Generate3ColorDeck.java b/src/main/java/forge/deck/generate/Generate3ColorDeck.java index 30bde34718f..0255b87d844 100644 --- a/src/main/java/forge/deck/generate/Generate3ColorDeck.java +++ b/src/main/java/forge/deck/generate/Generate3ColorDeck.java @@ -47,54 +47,55 @@ public class Generate3ColorDeck { * a {@link java.lang.String} object. */ public Generate3ColorDeck(final String Clr1, final String Clr2, final String Clr3) { - r = MyRandom.getRandom(); + this.r = MyRandom.getRandom(); - cardCounts = new HashMap(); + this.cardCounts = new HashMap(); - crMap = new HashMap(); - crMap.put("white", "W"); - crMap.put("blue", "U"); - crMap.put("black", "B"); - crMap.put("red", "R"); - crMap.put("green", "G"); + this.crMap = new HashMap(); + this.crMap.put("white", "W"); + this.crMap.put("blue", "U"); + this.crMap.put("black", "B"); + this.crMap.put("red", "R"); + this.crMap.put("green", "G"); - notColors = new ArrayList(); - notColors.add("white"); - notColors.add("blue"); - notColors.add("black"); - notColors.add("red"); - notColors.add("green"); + this.notColors = new ArrayList(); + this.notColors.add("white"); + this.notColors.add("blue"); + this.notColors.add("black"); + this.notColors.add("red"); + this.notColors.add("green"); if (Clr1.equals("AI")) { // choose first color - color1 = notColors.get(r.nextInt(5)); + this.color1 = this.notColors.get(this.r.nextInt(5)); // choose second color - String c2 = notColors.get(r.nextInt(5)); - while (c2.equals(color1)) { - c2 = notColors.get(r.nextInt(5)); + String c2 = this.notColors.get(this.r.nextInt(5)); + while (c2.equals(this.color1)) { + c2 = this.notColors.get(this.r.nextInt(5)); } - color2 = c2; + this.color2 = c2; - String c3 = notColors.get(r.nextInt(5)); - while (c3.equals(color1) || c3.equals(color2)) { - c3 = notColors.get(r.nextInt(5)); + String c3 = this.notColors.get(this.r.nextInt(5)); + while (c3.equals(this.color1) || c3.equals(this.color2)) { + c3 = this.notColors.get(this.r.nextInt(5)); } - color3 = c3; + this.color3 = c3; } else { - color1 = Clr1; - color2 = Clr2; - color3 = Clr3; + this.color1 = Clr1; + this.color2 = Clr2; + this.color3 = Clr3; } - notColors.remove(color1); - notColors.remove(color2); - notColors.remove(color3); + this.notColors.remove(this.color1); + this.notColors.remove(this.color2); + this.notColors.remove(this.color3); - dL = GenerateDeckUtil.getDualLandList(crMap.get(color1) + crMap.get(color2) + crMap.get(color3)); + this.dL = GenerateDeckUtil.getDualLandList(this.crMap.get(this.color1) + this.crMap.get(this.color2) + + this.crMap.get(this.color3)); - for (int i = 0; i < dL.size(); i++) { - cardCounts.put(dL.get(i), 0); + for (int i = 0; i < this.dL.size(); i++) { + this.cardCounts.put(this.dL.get(i), 0); } } @@ -113,34 +114,37 @@ public class Generate3ColorDeck { public final CardList get3ColorDeck(final int Size, final PlayerType pt) { int lc = 0; // loop counter to prevent infinite card selection loops String tmpDeck = ""; - CardList tDeck = new CardList(); + final CardList tDeck = new CardList(); - int LandsPercentage = 44; - int CreatPercentage = 34; - int SpellPercentage = 22; + final int LandsPercentage = 44; + final int CreatPercentage = 34; + final int SpellPercentage = 22; // start with all cards // remove cards that generated decks don't like - CardList AllCards = CardFilter.filter(AllZone.getCardFactory(), new CardListFilter() { + final CardList AllCards = CardFilter.filter(AllZone.getCardFactory(), new CardListFilter() { + @Override public boolean addCard(final Card c) { if (c.getSVar("RemRandomDeck").equals("True")) { return false; } - return (!c.getSVar("RemAIDeck").equals("True") || (pt != null && pt.equals(PlayerType.HUMAN))); + return (!c.getSVar("RemAIDeck").equals("True") || ((pt != null) && pt.equals(PlayerType.HUMAN))); } }); // reduce to cards that match the colors - CardList CL1 = AllCards.getColor(color1); + CardList CL1 = AllCards.getColor(this.color1); CL1.addAll(AllCards.getColor(Constant.Color.COLORLESS)); - CardList CL2 = AllCards.getColor(color2); - CardList CL3 = AllCards.getColor(color3); + CardList CL2 = AllCards.getColor(this.color2); + CardList CL3 = AllCards.getColor(this.color3); // remove multicolor cards that don't match the colors - CardListFilter clrF = new CardListFilter() { + final CardListFilter clrF = new CardListFilter() { + @Override public boolean addCard(final Card c) { - for (int i = 0; i < notColors.size(); i++) { - if (c.getManaCost().contains(crMap.get(notColors.get(i)))) { + for (int i = 0; i < Generate3ColorDeck.this.notColors.size(); i++) { + if (c.getManaCost().contains( + Generate3ColorDeck.this.crMap.get(Generate3ColorDeck.this.notColors.get(i)))) { return false; } } @@ -152,62 +156,63 @@ public class Generate3ColorDeck { CL3 = CL3.filter(clrF); // build subsets based on type - CardList Cr1 = CL1.getType("Creature"); - CardList Cr2 = CL2.getType("Creature"); - CardList Cr3 = CL3.getType("Creature"); + final CardList Cr1 = CL1.getType("Creature"); + final CardList Cr2 = CL2.getType("Creature"); + final CardList Cr3 = CL3.getType("Creature"); - String[] ISE = { "Instant", "Sorcery", "Enchantment", "Planeswalker", "Artifact.nonCreature" }; - CardList Sp1 = CL1.getValidCards(ISE, null, null); - CardList Sp2 = CL2.getValidCards(ISE, null, null); - CardList Sp3 = CL3.getValidCards(ISE, null, null); + final String[] ISE = { "Instant", "Sorcery", "Enchantment", "Planeswalker", "Artifact.nonCreature" }; + final CardList Sp1 = CL1.getValidCards(ISE, null, null); + final CardList Sp2 = CL2.getValidCards(ISE, null, null); + final CardList Sp3 = CL3.getValidCards(ISE, null, null); // final card pools - CardList Cr123 = new CardList(); - CardList Sp123 = new CardList(); + final CardList Cr123 = new CardList(); + final CardList Sp123 = new CardList(); // used for mana curve in the card pool final int MinCMC[] = { 1 }, MaxCMC[] = { 3 }; - CardListFilter cmcF = new CardListFilter() { + final CardListFilter cmcF = new CardListFilter() { + @Override public boolean addCard(final Card c) { - int cCMC = c.getCMC(); + final int cCMC = c.getCMC(); return (cCMC >= MinCMC[0]) && (cCMC <= MaxCMC[0]); } }; // select cards to build card pools using a mana curve for (int i = 3; i > 0; i--) { - CardList Cr1CMC = Cr1.filter(cmcF); - CardList Cr2CMC = Cr2.filter(cmcF); - CardList Cr3CMC = Cr3.filter(cmcF); + final CardList Cr1CMC = Cr1.filter(cmcF); + final CardList Cr2CMC = Cr2.filter(cmcF); + final CardList Cr3CMC = Cr3.filter(cmcF); - CardList Sp1CMC = Sp1.filter(cmcF); - CardList Sp2CMC = Sp2.filter(cmcF); - CardList Sp3CMC = Sp3.filter(cmcF); + final CardList Sp1CMC = Sp1.filter(cmcF); + final CardList Sp2CMC = Sp2.filter(cmcF); + final CardList Sp3CMC = Sp3.filter(cmcF); for (int j = 0; j < i; j++) { - Card c = Cr1CMC.get(r.nextInt(Cr1CMC.size())); + Card c = Cr1CMC.get(this.r.nextInt(Cr1CMC.size())); Cr123.add(c); - cardCounts.put(c.getName(), 0); + this.cardCounts.put(c.getName(), 0); - c = Cr2CMC.get(r.nextInt(Cr2CMC.size())); + c = Cr2CMC.get(this.r.nextInt(Cr2CMC.size())); Cr123.add(c); - cardCounts.put(c.getName(), 0); + this.cardCounts.put(c.getName(), 0); - c = Cr3CMC.get(r.nextInt(Cr3CMC.size())); + c = Cr3CMC.get(this.r.nextInt(Cr3CMC.size())); Cr123.add(c); - cardCounts.put(c.getName(), 0); + this.cardCounts.put(c.getName(), 0); - c = Sp1CMC.get(r.nextInt(Sp1CMC.size())); + c = Sp1CMC.get(this.r.nextInt(Sp1CMC.size())); Sp123.add(c); - cardCounts.put(c.getName(), 0); + this.cardCounts.put(c.getName(), 0); - c = Sp2CMC.get(r.nextInt(Sp2CMC.size())); + c = Sp2CMC.get(this.r.nextInt(Sp2CMC.size())); Sp123.add(c); - cardCounts.put(c.getName(), 0); + this.cardCounts.put(c.getName(), 0); - c = Sp3CMC.get(r.nextInt(Sp3CMC.size())); + c = Sp3CMC.get(this.r.nextInt(Sp3CMC.size())); Sp123.add(c); - cardCounts.put(c.getName(), 0); + this.cardCounts.put(c.getName(), 0); } MinCMC[0] += 2; @@ -225,21 +230,21 @@ public class Generate3ColorDeck { Sp123.shuffle(); // calculate card counts - float p = (float) ((float) CreatPercentage * .01); - int CreatCnt = (int) (p * (float) Size); + float p = (float) (CreatPercentage * .01); + final int CreatCnt = (int) (p * Size); tmpDeck += "Creature Count:" + CreatCnt + "\n"; - p = (float) ((float) SpellPercentage * .01); - int SpellCnt = (int) (p * (float) Size); + p = (float) (SpellPercentage * .01); + final int SpellCnt = (int) (p * Size); tmpDeck += "Spell Count:" + SpellCnt + "\n"; // build deck from the card pools for (int i = 0; i < CreatCnt; i++) { - Card c = Cr123.get(r.nextInt(Cr123.size())); + Card c = Cr123.get(this.r.nextInt(Cr123.size())); lc = 0; - while (cardCounts.get(c.getName()) > 3 || lc > 100) { - c = Cr123.get(r.nextInt(Cr123.size())); + while ((this.cardCounts.get(c.getName()) > 3) || (lc > 100)) { + c = Cr123.get(this.r.nextInt(Cr123.size())); lc++; } if (lc > 100) { @@ -247,17 +252,17 @@ public class Generate3ColorDeck { } tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer())); - int n = cardCounts.get(c.getName()); - cardCounts.put(c.getName(), n + 1); + final int n = this.cardCounts.get(c.getName()); + this.cardCounts.put(c.getName(), n + 1); tmpDeck += c.getName() + " " + c.getManaCost() + "\n"; } for (int i = 0; i < SpellCnt; i++) { - Card c = Sp123.get(r.nextInt(Sp123.size())); + Card c = Sp123.get(this.r.nextInt(Sp123.size())); lc = 0; - while (cardCounts.get(c.getName()) > 3 || lc > 100) { - c = Sp123.get(r.nextInt(Sp123.size())); + while ((this.cardCounts.get(c.getName()) > 3) || (lc > 100)) { + c = Sp123.get(this.r.nextInt(Sp123.size())); lc++; } if (lc > 100) { @@ -265,16 +270,16 @@ public class Generate3ColorDeck { } tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer())); - int n = cardCounts.get(c.getName()); - cardCounts.put(c.getName(), n + 1); + final int n = this.cardCounts.get(c.getName()); + this.cardCounts.put(c.getName(), n + 1); tmpDeck += c.getName() + " " + c.getManaCost() + "\n"; } // Add lands int numLands = 0; if (LandsPercentage > 0) { - p = (float) ((float) LandsPercentage * .01); - numLands = (int) (p * (float) Size); + p = (float) (LandsPercentage * .01); + numLands = (int) (p * Size); } else { // otherwise, just fill in the rest of the deck with basic lands numLands = Size - tDeck.size(); @@ -282,13 +287,13 @@ public class Generate3ColorDeck { tmpDeck += "numLands:" + numLands + "\n"; - int ndLands = (numLands / 4); + final int ndLands = (numLands / 4); for (int i = 0; i < ndLands; i++) { - String s = dL.get(r.nextInt(dL.size())); + String s = this.dL.get(this.r.nextInt(this.dL.size())); lc = 0; - while (cardCounts.get(s) > 3 || lc > 20) { - s = dL.get(r.nextInt(dL.size())); + while ((this.cardCounts.get(s) > 3) || (lc > 20)) { + s = this.dL.get(this.r.nextInt(this.dL.size())); lc++; } if (lc > 20) { @@ -296,8 +301,8 @@ public class Generate3ColorDeck { } tDeck.add(AllZone.getCardFactory().getCard(s, AllZone.getHumanPlayer())); - int n = cardCounts.get(s); - cardCounts.put(s, n + 1); + final int n = this.cardCounts.get(s); + this.cardCounts.put(s, n + 1); tmpDeck += s + "\n"; } @@ -306,17 +311,17 @@ public class Generate3ColorDeck { if (numLands > 0) // attempt to optimize basic land counts according to // color representation { - CCnt[] ClrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0), + final CCnt[] ClrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0), new CCnt("Mountain", 0), new CCnt("Forest", 0) }; // count each card color using mana costs // TODO count hybrid mana differently? for (int i = 0; i < tDeck.size(); i++) { - String mc = tDeck.get(i).getManaCost(); + final String mc = tDeck.get(i).getManaCost(); // count each mana symbol in the mana cost for (int j = 0; j < mc.length(); j++) { - char c = mc.charAt(j); + final char c = mc.charAt(j); if (c == 'W') { ClrCnts[0].Count++; @@ -345,12 +350,12 @@ public class Generate3ColorDeck { if (ClrCnts[i].Count > 0) { // calculate number of lands for // each color p = (float) ClrCnts[i].Count / (float) totalColor; - int nLand = (int) ((float) numLands * p); + final int nLand = (int) (numLands * p); tmpDeck += "nLand-" + ClrCnts[i].Color + ":" + nLand + "\n"; // just to prevent a null exception by the deck size fixing // code - cardCounts.put(ClrCnts[i].Color, nLand); + this.cardCounts.put(ClrCnts[i].Color, nLand); for (int j = 0; j <= nLand; j++) { tDeck.add(AllZone.getCardFactory().getCard(ClrCnts[i].Color, AllZone.getComputerPlayer())); @@ -362,34 +367,34 @@ public class Generate3ColorDeck { // fix under-sized or over-sized decks, due to integer arithmetic if (tDeck.size() < Size) { - int diff = Size - tDeck.size(); + final int diff = Size - tDeck.size(); for (int i = 0; i < diff; i++) { - Card c = tDeck.get(r.nextInt(tDeck.size())); + Card c = tDeck.get(this.r.nextInt(tDeck.size())); lc = 0; - while (cardCounts.get(c.getName()) > 3 || lc > Size) { - c = tDeck.get(r.nextInt(tDeck.size())); + while ((this.cardCounts.get(c.getName()) > 3) || (lc > Size)) { + c = tDeck.get(this.r.nextInt(tDeck.size())); lc++; } if (lc > Size) { throw new RuntimeException("Generate3ColorDeck : get3ColorDeck -- looped too much -- undersize"); } - int n = cardCounts.get(c.getName()); + final int n = this.cardCounts.get(c.getName()); tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer())); - cardCounts.put(c.getName(), n + 1); + this.cardCounts.put(c.getName(), n + 1); tmpDeck += "Added:" + c.getName() + "\n"; } } else if (tDeck.size() > Size) { - int diff = tDeck.size() - Size; + final int diff = tDeck.size() - Size; for (int i = 0; i < diff; i++) { - Card c = tDeck.get(r.nextInt(tDeck.size())); + Card c = tDeck.get(this.r.nextInt(tDeck.size())); while (c.isBasicLand()) { // don't remove basic lands - c = tDeck.get(r.nextInt(tDeck.size())); + c = tDeck.get(this.r.nextInt(tDeck.size())); } tDeck.remove(c); @@ -410,8 +415,8 @@ public class Generate3ColorDeck { public int Count; public CCnt(final String clr, final int cnt) { - Color = clr; - Count = cnt; + this.Color = clr; + this.Count = cnt; } } } diff --git a/src/main/java/forge/deck/generate/Generate5ColorDeck.java b/src/main/java/forge/deck/generate/Generate5ColorDeck.java index 0fecb2c5a85..2f768f1126d 100644 --- a/src/main/java/forge/deck/generate/Generate5ColorDeck.java +++ b/src/main/java/forge/deck/generate/Generate5ColorDeck.java @@ -61,40 +61,40 @@ public class Generate5ColorDeck { */ public Generate5ColorDeck(final String clr1, final String clr2, final String clr3, final String clr4, final String clr5) { - r = MyRandom.getRandom(); + this.r = MyRandom.getRandom(); - cardCounts = new HashMap(); + this.cardCounts = new HashMap(); - clrMap = new HashMap(); - clrMap.put("white", "W"); - clrMap.put("blue", "U"); - clrMap.put("black", "B"); - clrMap.put("red", "R"); - clrMap.put("green", "G"); + this.clrMap = new HashMap(); + this.clrMap.put("white", "W"); + this.clrMap.put("blue", "U"); + this.clrMap.put("black", "B"); + this.clrMap.put("red", "R"); + this.clrMap.put("green", "G"); - notColors = new ArrayList(); - notColors.add("white"); - notColors.add("blue"); - notColors.add("black"); - notColors.add("red"); - notColors.add("green"); + this.notColors = new ArrayList(); + this.notColors.add("white"); + this.notColors.add("blue"); + this.notColors.add("black"); + this.notColors.add("red"); + this.notColors.add("green"); - color1 = clr1; - color2 = clr2; - color3 = clr3; - color4 = clr4; - color5 = clr5; + this.color1 = clr1; + this.color2 = clr2; + this.color3 = clr3; + this.color4 = clr4; + this.color5 = clr5; - notColors.remove(color1); - notColors.remove(color2); - notColors.remove(color3); - notColors.remove(color4); - notColors.remove(color5); + this.notColors.remove(this.color1); + this.notColors.remove(this.color2); + this.notColors.remove(this.color3); + this.notColors.remove(this.color4); + this.notColors.remove(this.color5); - dl = GenerateDeckUtil.getDualLandList("WUBRG"); + this.dl = GenerateDeckUtil.getDualLandList("WUBRG"); - for (int i = 0; i < dl.size(); i++) { - cardCounts.put(dl.get(i), 0); + for (int i = 0; i < this.dl.size(); i++) { + this.cardCounts.put(this.dl.get(i), 0); } } @@ -112,36 +112,39 @@ public class Generate5ColorDeck { public final CardList get5ColorDeck(final int size, final PlayerType pt) { int lc = 0; // loop counter to prevent infinite card selection loops String tmpDeck = ""; - CardList tDeck = new CardList(); + final CardList tDeck = new CardList(); - int landsPercentage = 44; - int creatPercentage = 34; - int spellPercentage = 22; + final int landsPercentage = 44; + final int creatPercentage = 34; + final int spellPercentage = 22; // start with all cards // remove cards that generated decks don't like - CardList allCards = CardFilter.filter(AllZone.getCardFactory(), new CardListFilter() { + final CardList allCards = CardFilter.filter(AllZone.getCardFactory(), new CardListFilter() { + @Override public boolean addCard(final Card c) { if (c.getSVar("RemRandomDeck").equals("True")) { return false; } - return (!c.getSVar("RemAIDeck").equals("True") || (pt != null && pt.equals(PlayerType.HUMAN))); + return (!c.getSVar("RemAIDeck").equals("True") || ((pt != null) && pt.equals(PlayerType.HUMAN))); } }); // reduce to cards that match the colors - CardList cL1 = allCards.getColor(color1); + CardList cL1 = allCards.getColor(this.color1); cL1.addAll(allCards.getColor(Constant.Color.COLORLESS)); - CardList cL2 = allCards.getColor(color2); - CardList cL3 = allCards.getColor(color3); - CardList cL4 = allCards.getColor(color4); - CardList cL5 = allCards.getColor(color5); + CardList cL2 = allCards.getColor(this.color2); + CardList cL3 = allCards.getColor(this.color3); + CardList cL4 = allCards.getColor(this.color4); + CardList cL5 = allCards.getColor(this.color5); // remove multicolor cards that don't match the colors - CardListFilter clrF = new CardListFilter() { + final CardListFilter clrF = new CardListFilter() { + @Override public boolean addCard(final Card c) { - for (int i = 0; i < notColors.size(); i++) { - if (c.getManaCost().contains(clrMap.get(notColors.get(i)))) { + for (int i = 0; i < Generate5ColorDeck.this.notColors.size(); i++) { + if (c.getManaCost().contains( + Generate5ColorDeck.this.clrMap.get(Generate5ColorDeck.this.notColors.get(i)))) { return false; } } @@ -155,87 +158,88 @@ public class Generate5ColorDeck { cL5 = cL5.filter(clrF); // build subsets based on type - CardList cr1 = cL1.getType("Creature"); - CardList cr2 = cL2.getType("Creature"); - CardList cr3 = cL3.getType("Creature"); - CardList cr4 = cL4.getType("Creature"); - CardList cr5 = cL5.getType("Creature"); + final CardList cr1 = cL1.getType("Creature"); + final CardList cr2 = cL2.getType("Creature"); + final CardList cr3 = cL3.getType("Creature"); + final CardList cr4 = cL4.getType("Creature"); + final CardList cr5 = cL5.getType("Creature"); - String[] ise = { "Instant", "Sorcery", "Enchantment", "Planeswalker", "Artifact.nonCreature" }; - CardList sp1 = cL1.getValidCards(ise, null, null); - CardList sp2 = cL2.getValidCards(ise, null, null); - CardList sp3 = cL3.getValidCards(ise, null, null); - CardList sp4 = cL4.getValidCards(ise, null, null); - CardList sp5 = cL5.getValidCards(ise, null, null); + final String[] ise = { "Instant", "Sorcery", "Enchantment", "Planeswalker", "Artifact.nonCreature" }; + final CardList sp1 = cL1.getValidCards(ise, null, null); + final CardList sp2 = cL2.getValidCards(ise, null, null); + final CardList sp3 = cL3.getValidCards(ise, null, null); + final CardList sp4 = cL4.getValidCards(ise, null, null); + final CardList sp5 = cL5.getValidCards(ise, null, null); // final card pools - CardList cr12345 = new CardList(); - CardList sp12345 = new CardList(); + final CardList cr12345 = new CardList(); + final CardList sp12345 = new CardList(); // used for mana curve in the card pool final int[] minCMC = { 1 }; final int[] maxCMC = { 3 }; - CardListFilter cmcF = new CardListFilter() { + final CardListFilter cmcF = new CardListFilter() { + @Override public boolean addCard(final Card c) { - int cCMC = c.getCMC(); + final int cCMC = c.getCMC(); return (cCMC >= minCMC[0]) && (cCMC <= maxCMC[0]); } }; // select cards to build card pools using a mana curve for (int i = 3; i > 0; i--) { - CardList cr1CMC = cr1.filter(cmcF); - CardList cr2CMC = cr2.filter(cmcF); - CardList cr3CMC = cr3.filter(cmcF); - CardList cr4CMC = cr4.filter(cmcF); - CardList cr5CMC = cr5.filter(cmcF); + final CardList cr1CMC = cr1.filter(cmcF); + final CardList cr2CMC = cr2.filter(cmcF); + final CardList cr3CMC = cr3.filter(cmcF); + final CardList cr4CMC = cr4.filter(cmcF); + final CardList cr5CMC = cr5.filter(cmcF); - CardList sp1CMC = sp1.filter(cmcF); - CardList sp2CMC = sp2.filter(cmcF); - CardList sp3CMC = sp3.filter(cmcF); - CardList sp4CMC = sp4.filter(cmcF); - CardList sp5CMC = sp5.filter(cmcF); + final CardList sp1CMC = sp1.filter(cmcF); + final CardList sp2CMC = sp2.filter(cmcF); + final CardList sp3CMC = sp3.filter(cmcF); + final CardList sp4CMC = sp4.filter(cmcF); + final CardList sp5CMC = sp5.filter(cmcF); for (int j = 0; j < i; j++) { - Card c = cr1CMC.get(r.nextInt(cr1CMC.size())); + Card c = cr1CMC.get(this.r.nextInt(cr1CMC.size())); cr12345.add(c); - cardCounts.put(c.getName(), 0); + this.cardCounts.put(c.getName(), 0); - c = cr2CMC.get(r.nextInt(cr2CMC.size())); + c = cr2CMC.get(this.r.nextInt(cr2CMC.size())); cr12345.add(c); - cardCounts.put(c.getName(), 0); + this.cardCounts.put(c.getName(), 0); - c = cr3CMC.get(r.nextInt(cr3CMC.size())); + c = cr3CMC.get(this.r.nextInt(cr3CMC.size())); cr12345.add(c); - cardCounts.put(c.getName(), 0); + this.cardCounts.put(c.getName(), 0); - c = cr4CMC.get(r.nextInt(cr4CMC.size())); + c = cr4CMC.get(this.r.nextInt(cr4CMC.size())); cr12345.add(c); - cardCounts.put(c.getName(), 0); + this.cardCounts.put(c.getName(), 0); - c = cr5CMC.get(r.nextInt(cr5CMC.size())); + c = cr5CMC.get(this.r.nextInt(cr5CMC.size())); cr12345.add(c); - cardCounts.put(c.getName(), 0); + this.cardCounts.put(c.getName(), 0); - c = sp1CMC.get(r.nextInt(sp1CMC.size())); + c = sp1CMC.get(this.r.nextInt(sp1CMC.size())); sp12345.add(c); - cardCounts.put(c.getName(), 0); + this.cardCounts.put(c.getName(), 0); - c = sp2CMC.get(r.nextInt(sp2CMC.size())); + c = sp2CMC.get(this.r.nextInt(sp2CMC.size())); sp12345.add(c); - cardCounts.put(c.getName(), 0); + this.cardCounts.put(c.getName(), 0); - c = sp3CMC.get(r.nextInt(sp3CMC.size())); + c = sp3CMC.get(this.r.nextInt(sp3CMC.size())); sp12345.add(c); - cardCounts.put(c.getName(), 0); + this.cardCounts.put(c.getName(), 0); - c = sp4CMC.get(r.nextInt(sp4CMC.size())); + c = sp4CMC.get(this.r.nextInt(sp4CMC.size())); sp12345.add(c); - cardCounts.put(c.getName(), 0); + this.cardCounts.put(c.getName(), 0); - c = sp5CMC.get(r.nextInt(sp5CMC.size())); + c = sp5CMC.get(this.r.nextInt(sp5CMC.size())); sp12345.add(c); - cardCounts.put(c.getName(), 0); + this.cardCounts.put(c.getName(), 0); } minCMC[0] += 2; @@ -253,21 +257,21 @@ public class Generate5ColorDeck { sp12345.shuffle(); // calculate card counts - float p = (float) ((float) creatPercentage * .01); - int creatCnt = (int) (p * (float) size); + float p = (float) (creatPercentage * .01); + final int creatCnt = (int) (p * size); tmpDeck += "Creature Count:" + creatCnt + "\n"; - p = (float) ((float) spellPercentage * .01); - int spellCnt = (int) (p * (float) size); + p = (float) (spellPercentage * .01); + final int spellCnt = (int) (p * size); tmpDeck += "Spell Count:" + spellCnt + "\n"; // build deck from the card pools for (int i = 0; i < creatCnt; i++) { - Card c = cr12345.get(r.nextInt(cr12345.size())); + Card c = cr12345.get(this.r.nextInt(cr12345.size())); lc = 0; - while (cardCounts.get(c.getName()) > 3 || lc > 100) { - c = cr12345.get(r.nextInt(cr12345.size())); + while ((this.cardCounts.get(c.getName()) > 3) || (lc > 100)) { + c = cr12345.get(this.r.nextInt(cr12345.size())); lc++; } if (lc > 100) { @@ -275,17 +279,17 @@ public class Generate5ColorDeck { } tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer())); - int n = cardCounts.get(c.getName()); - cardCounts.put(c.getName(), n + 1); + final int n = this.cardCounts.get(c.getName()); + this.cardCounts.put(c.getName(), n + 1); tmpDeck += c.getName() + " " + c.getManaCost() + "\n"; } for (int i = 0; i < spellCnt; i++) { - Card c = sp12345.get(r.nextInt(sp12345.size())); + Card c = sp12345.get(this.r.nextInt(sp12345.size())); lc = 0; - while (cardCounts.get(c.getName()) > 3 || lc > 100) { - c = sp12345.get(r.nextInt(sp12345.size())); + while ((this.cardCounts.get(c.getName()) > 3) || (lc > 100)) { + c = sp12345.get(this.r.nextInt(sp12345.size())); lc++; } if (lc > 100) { @@ -293,16 +297,16 @@ public class Generate5ColorDeck { } tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer())); - int n = cardCounts.get(c.getName()); - cardCounts.put(c.getName(), n + 1); + final int n = this.cardCounts.get(c.getName()); + this.cardCounts.put(c.getName(), n + 1); tmpDeck += c.getName() + " " + c.getManaCost() + "\n"; } // Add lands int numLands = 0; if (landsPercentage > 0) { - p = (float) ((float) landsPercentage * .01); - numLands = (int) (p * (float) size); + p = (float) (landsPercentage * .01); + numLands = (int) (p * size); } else { // otherwise, just fill in the rest of the deck with basic // lands numLands = size - tDeck.size(); @@ -310,13 +314,13 @@ public class Generate5ColorDeck { tmpDeck += "numLands:" + numLands + "\n"; - int nDLands = (numLands / 4); + final int nDLands = (numLands / 4); for (int i = 0; i < nDLands; i++) { - String s = dl.get(r.nextInt(dl.size())); + String s = this.dl.get(this.r.nextInt(this.dl.size())); lc = 0; - while (cardCounts.get(s) > 3 || lc > 20) { - s = dl.get(r.nextInt(dl.size())); + while ((this.cardCounts.get(s) > 3) || (lc > 20)) { + s = this.dl.get(this.r.nextInt(this.dl.size())); lc++; } if (lc > 20) { @@ -324,8 +328,8 @@ public class Generate5ColorDeck { } tDeck.add(AllZone.getCardFactory().getCard(s, AllZone.getHumanPlayer())); - int n = cardCounts.get(s); - cardCounts.put(s, n + 1); + final int n = this.cardCounts.get(s); + this.cardCounts.put(s, n + 1); tmpDeck += s + "\n"; } @@ -334,17 +338,17 @@ public class Generate5ColorDeck { if (numLands > 0) // attempt to optimize basic land counts according to // color representation { - CCnt[] clrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0), + final CCnt[] clrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0), new CCnt("Mountain", 0), new CCnt("Forest", 0) }; // count each card color using mana costs // TODO: count hybrid mana differently? for (int i = 0; i < tDeck.size(); i++) { - String mc = tDeck.get(i).getManaCost(); + final String mc = tDeck.get(i).getManaCost(); // count each mana symbol in the mana cost for (int j = 0; j < mc.length(); j++) { - char c = mc.charAt(j); + final char c = mc.charAt(j); if (c == 'W') { clrCnts[0].setCount(clrCnts[0].getCount() + 1); @@ -373,12 +377,12 @@ public class Generate5ColorDeck { if (clrCnts[i].getCount() > 0) { // calculate number of lands // for each color p = (float) clrCnts[i].getCount() / (float) totalColor; - int nLand = (int) ((float) numLands * p); + final int nLand = (int) (numLands * p); tmpDeck += "nLand-" + clrCnts[i].getColor() + ":" + nLand + "\n"; // just to prevent a null exception by the deck size fixing // code - cardCounts.put(clrCnts[i].getColor(), nLand); + this.cardCounts.put(clrCnts[i].getColor(), nLand); for (int j = 0; j <= nLand; j++) { tDeck.add(AllZone.getCardFactory().getCard(clrCnts[i].getColor(), AllZone.getComputerPlayer())); @@ -390,33 +394,33 @@ public class Generate5ColorDeck { // fix under-sized or over-sized decks, due to integer arithmetic if (tDeck.size() < size) { - int diff = size - tDeck.size(); + final int diff = size - tDeck.size(); for (int i = 0; i < diff; i++) { - Card c = tDeck.get(r.nextInt(tDeck.size())); + Card c = tDeck.get(this.r.nextInt(tDeck.size())); lc = 0; - while (cardCounts.get(c.getName()) > 3 || lc > size) { - c = tDeck.get(r.nextInt(tDeck.size())); + while ((this.cardCounts.get(c.getName()) > 3) || (lc > size)) { + c = tDeck.get(this.r.nextInt(tDeck.size())); lc++; } if (lc > size) { throw new RuntimeException("Generate5ColorDeck : get5ColorDeck -- looped too much -- undersize"); } - int n = cardCounts.get(c.getName()); + final int n = this.cardCounts.get(c.getName()); tDeck.add(AllZone.getCardFactory().getCard(c.getName(), AllZone.getComputerPlayer())); - cardCounts.put(c.getName(), n + 1); + this.cardCounts.put(c.getName(), n + 1); tmpDeck += "Added:" + c.getName() + "\n"; } } else if (tDeck.size() > size) { - int diff = tDeck.size() - size; + final int diff = tDeck.size() - size; for (int i = 0; i < diff; i++) { - Card c = tDeck.get(r.nextInt(tDeck.size())); + Card c = tDeck.get(this.r.nextInt(tDeck.size())); while (c.isBasicLand()) { // don't remove basic lands - c = tDeck.get(r.nextInt(tDeck.size())); + c = tDeck.get(this.r.nextInt(tDeck.size())); } tDeck.remove(c); @@ -433,7 +437,7 @@ public class Generate5ColorDeck { } private class CCnt { - private String color; + private final String color; private int count; public CCnt(final String clr, final int cnt) { diff --git a/src/main/java/forge/deck/generate/GenerateConstructedDeck.java b/src/main/java/forge/deck/generate/GenerateConstructedDeck.java index f05e9431f6b..45c7744a710 100644 --- a/src/main/java/forge/deck/generate/GenerateConstructedDeck.java +++ b/src/main/java/forge/deck/generate/GenerateConstructedDeck.java @@ -26,7 +26,7 @@ public class GenerateConstructedDeck { private String color1; private String color2; - private Map map = new HashMap(); + private final Map map = new HashMap(); /** *

@@ -34,7 +34,7 @@ public class GenerateConstructedDeck { *

*/ public GenerateConstructedDeck() { - setupMap(); + this.setupMap(); } /** @@ -43,11 +43,11 @@ public class GenerateConstructedDeck { *

*/ private void setupMap() { - map.put(Constant.Color.BLACK, "Swamp"); - map.put(Constant.Color.BLUE, "Island"); - map.put(Constant.Color.GREEN, "Forest"); - map.put(Constant.Color.RED, "Mountain"); - map.put(Constant.Color.WHITE, "Plains"); + this.map.put(Constant.Color.BLACK, "Swamp"); + this.map.put(Constant.Color.BLUE, "Island"); + this.map.put(Constant.Color.GREEN, "Forest"); + this.map.put(Constant.Color.RED, "Mountain"); + this.map.put(Constant.Color.WHITE, "Plains"); } /** @@ -63,12 +63,12 @@ public class GenerateConstructedDeck { int check; do { - deck = get2ColorDeck(); + deck = this.get2ColorDeck(); check = deck.getType("Creature").size(); - } while (check < 16 || 24 < check); + } while ((check < 16) || (24 < check)); - addLand(deck); + this.addLand(deck); if (deck.size() != 60) { throw new RuntimeException( @@ -90,10 +90,10 @@ public class GenerateConstructedDeck { private void addLand(final CardList list) { Card land; for (int i = 0; i < 13; i++) { - land = AllZone.getCardFactory().getCard(map.get(color1).toString(), AllZone.getComputerPlayer()); + land = AllZone.getCardFactory().getCard(this.map.get(this.color1).toString(), AllZone.getComputerPlayer()); list.add(land); - land = AllZone.getCardFactory().getCard(map.get(color2).toString(), AllZone.getComputerPlayer()); + land = AllZone.getCardFactory().getCard(this.map.get(this.color2).toString(), AllZone.getComputerPlayer()); list.add(land); } } // addLand() @@ -109,7 +109,7 @@ public class GenerateConstructedDeck { * never null */ private CardList getCards() { - return filterBadCards(AllZone.getCardFactory()); + return this.filterBadCards(AllZone.getCardFactory()); } // getCards() /** @@ -120,14 +120,14 @@ public class GenerateConstructedDeck { * @return a {@link forge.CardList} object. */ private CardList get2ColorDeck() { - CardList deck = get2Colors(getCards()); + final CardList deck = this.get2Colors(this.getCards()); - CardList out = new CardList(); + final CardList out = new CardList(); deck.shuffle(); // trim deck size down to 34 cards, presumes 26 land, for a total of 60 // cards - for (int i = 0; i < 34 && i < deck.size(); i++) { + for (int i = 0; (i < 34) && (i < deck.size()); i++) { out.add(deck.get(i)); } return out; @@ -151,15 +151,16 @@ public class GenerateConstructedDeck { b = CardUtil.getRandomIndex(Constant.Color.ONLY_COLORS); } while (a == b); // do not want to get the same color twice - color1 = Constant.Color.ONLY_COLORS[a]; - color2 = Constant.Color.ONLY_COLORS[b]; + this.color1 = Constant.Color.ONLY_COLORS[a]; + this.color2 = Constant.Color.ONLY_COLORS[b]; CardList out = new CardList(); - out.addAll(CardListUtil.getColor(in, color1)); - out.addAll(CardListUtil.getColor(in, color2)); + out.addAll(CardListUtil.getColor(in, this.color1)); + out.addAll(CardListUtil.getColor(in, this.color2)); out.shuffle(); - CardList artifact = in.filter(new CardListFilter() { + final CardList artifact = in.filter(new CardListFilter() { + @Override public boolean addCard(final Card c) { // is this really a colorless artifact and not something // weird like Sarcomite Myr which is a colored artifact @@ -170,8 +171,9 @@ public class GenerateConstructedDeck { out.addAll(artifact); out = out.filter(new CardListFilter() { + @Override public boolean addCard(final Card c) { - if (c.isCreature() && c.getNetAttack() <= 1 && Singletons.getModel().getPreferences().deckGenRmvSmall) { + if (c.isCreature() && (c.getNetAttack() <= 1) && Singletons.getModel().getPreferences().deckGenRmvSmall) { return false; } @@ -179,7 +181,7 @@ public class GenerateConstructedDeck { } }); - out = filterBadCards(out); + out = this.filterBadCards(out); return out; } @@ -197,19 +199,22 @@ public class GenerateConstructedDeck { final ArrayList goodLand = new ArrayList(); - CardList out = CardFilter.filter(sequence, new CardListFilter() { + final CardList out = CardFilter.filter(sequence, new CardListFilter() { + @Override public boolean addCard(final Card c) { - ArrayList list = CardUtil.getColors(c); + final ArrayList list = CardUtil.getColors(c); if (list.size() == 2) { - if (!(list.contains(color1) && list.contains(color2))) { + if (!(list.contains(GenerateConstructedDeck.this.color1) && list + .contains(GenerateConstructedDeck.this.color2))) { return false; } } - return CardUtil.getColors(c).size() <= 2 // only dual colored - // gold cards + return ((CardUtil.getColors(c).size() <= 2 // only dual colored + ) + // gold cards && !c.isLand() // no land - && !c.getSVar("RemRandomDeck").equals("True") && !c.getSVar("RemAIDeck").equals("True") - // OR very important + && !c.getSVar("RemRandomDeck").equals("True") && !c.getSVar("RemAIDeck").equals("True")) + // OR very important || goodLand.contains(c.getName()); } }); diff --git a/src/main/java/forge/deck/generate/GenerateConstructedMultiColorDeck.java b/src/main/java/forge/deck/generate/GenerateConstructedMultiColorDeck.java index 8ac9de415cc..772b6bfcc11 100644 --- a/src/main/java/forge/deck/generate/GenerateConstructedMultiColorDeck.java +++ b/src/main/java/forge/deck/generate/GenerateConstructedMultiColorDeck.java @@ -29,8 +29,8 @@ public class GenerateConstructedMultiColorDeck { private String color4; private String color5; - private Map map = new HashMap(); - private Map multiMap = new HashMap(); + private final Map map = new HashMap(); + private final Map multiMap = new HashMap(); /** *

@@ -38,8 +38,8 @@ public class GenerateConstructedMultiColorDeck { *

*/ public GenerateConstructedMultiColorDeck() { - setupBasicLandMap(); - setupMultiMap(); + this.setupBasicLandMap(); + this.setupMultiMap(); } /** @@ -48,11 +48,11 @@ public class GenerateConstructedMultiColorDeck { *

*/ private void setupBasicLandMap() { - map.put(Constant.Color.BLACK, "Swamp"); - map.put(Constant.Color.BLUE, "Island"); - map.put(Constant.Color.GREEN, "Forest"); - map.put(Constant.Color.RED, "Mountain"); - map.put(Constant.Color.WHITE, "Plains"); + this.map.put(Constant.Color.BLACK, "Swamp"); + this.map.put(Constant.Color.BLUE, "Island"); + this.map.put(Constant.Color.GREEN, "Forest"); + this.map.put(Constant.Color.RED, "Mountain"); + this.map.put(Constant.Color.WHITE, "Plains"); } /** @@ -61,26 +61,30 @@ public class GenerateConstructedMultiColorDeck { *

*/ private void setupMultiMap() { - multiMap.put(Constant.Color.BLACK + Constant.Color.BLUE, new String[] { "Underground Sea", "Watery Grave" }); - multiMap.put(Constant.Color.BLACK + Constant.Color.GREEN, new String[] { "Bayou", "Overgrown Tomb" }); - multiMap.put(Constant.Color.BLACK + Constant.Color.RED, new String[] { "Badlands", "Blood Crypt" }); - multiMap.put(Constant.Color.BLACK + Constant.Color.WHITE, new String[] { "Scrubland", "Godless Shrine" }); - multiMap.put(Constant.Color.BLUE + Constant.Color.BLACK, new String[] { "Underground Sea", "Watery Grave" }); - multiMap.put(Constant.Color.BLUE + Constant.Color.GREEN, new String[] { "Tropical Island", "Breeding Pool" }); - multiMap.put(Constant.Color.BLUE + Constant.Color.RED, new String[] { "Volcanic Island", "Steam Vents" }); - multiMap.put(Constant.Color.BLUE + Constant.Color.WHITE, new String[] { "Tundra", "Hallowed Fountain" }); - multiMap.put(Constant.Color.GREEN + Constant.Color.BLACK, new String[] { "Bayou", "Overgrown Tomb" }); - multiMap.put(Constant.Color.GREEN + Constant.Color.BLUE, new String[] { "Tropical Island", "Breeding Pool" }); - multiMap.put(Constant.Color.GREEN + Constant.Color.RED, new String[] { "Taiga", "Stomping Ground" }); - multiMap.put(Constant.Color.GREEN + Constant.Color.WHITE, new String[] { "Savannah", "Temple Garden" }); - multiMap.put(Constant.Color.RED + Constant.Color.BLACK, new String[] { "Badlands", "Blood Crypt" }); - multiMap.put(Constant.Color.RED + Constant.Color.BLUE, new String[] { "Volcanic Island", "Steam Vents" }); - multiMap.put(Constant.Color.RED + Constant.Color.GREEN, new String[] { "Taiga", "Stomping Ground" }); - multiMap.put(Constant.Color.RED + Constant.Color.WHITE, new String[] { "Plateau", "Sacred Foundry" }); - multiMap.put(Constant.Color.WHITE + Constant.Color.BLACK, new String[] { "Scrubland", "Godless Shrine" }); - multiMap.put(Constant.Color.WHITE + Constant.Color.BLUE, new String[] { "Tundra", "Hallowed Fountain" }); - multiMap.put(Constant.Color.WHITE + Constant.Color.GREEN, new String[] { "Savannah", "Temple Garden" }); - multiMap.put(Constant.Color.WHITE + Constant.Color.RED, new String[] { "Plateau", "Sacred Foundry" }); + this.multiMap.put(Constant.Color.BLACK + Constant.Color.BLUE, + new String[] { "Underground Sea", "Watery Grave" }); + this.multiMap.put(Constant.Color.BLACK + Constant.Color.GREEN, new String[] { "Bayou", "Overgrown Tomb" }); + this.multiMap.put(Constant.Color.BLACK + Constant.Color.RED, new String[] { "Badlands", "Blood Crypt" }); + this.multiMap.put(Constant.Color.BLACK + Constant.Color.WHITE, new String[] { "Scrubland", "Godless Shrine" }); + this.multiMap.put(Constant.Color.BLUE + Constant.Color.BLACK, + new String[] { "Underground Sea", "Watery Grave" }); + this.multiMap.put(Constant.Color.BLUE + Constant.Color.GREEN, + new String[] { "Tropical Island", "Breeding Pool" }); + this.multiMap.put(Constant.Color.BLUE + Constant.Color.RED, new String[] { "Volcanic Island", "Steam Vents" }); + this.multiMap.put(Constant.Color.BLUE + Constant.Color.WHITE, new String[] { "Tundra", "Hallowed Fountain" }); + this.multiMap.put(Constant.Color.GREEN + Constant.Color.BLACK, new String[] { "Bayou", "Overgrown Tomb" }); + this.multiMap.put(Constant.Color.GREEN + Constant.Color.BLUE, + new String[] { "Tropical Island", "Breeding Pool" }); + this.multiMap.put(Constant.Color.GREEN + Constant.Color.RED, new String[] { "Taiga", "Stomping Ground" }); + this.multiMap.put(Constant.Color.GREEN + Constant.Color.WHITE, new String[] { "Savannah", "Temple Garden" }); + this.multiMap.put(Constant.Color.RED + Constant.Color.BLACK, new String[] { "Badlands", "Blood Crypt" }); + this.multiMap.put(Constant.Color.RED + Constant.Color.BLUE, new String[] { "Volcanic Island", "Steam Vents" }); + this.multiMap.put(Constant.Color.RED + Constant.Color.GREEN, new String[] { "Taiga", "Stomping Ground" }); + this.multiMap.put(Constant.Color.RED + Constant.Color.WHITE, new String[] { "Plateau", "Sacred Foundry" }); + this.multiMap.put(Constant.Color.WHITE + Constant.Color.BLACK, new String[] { "Scrubland", "Godless Shrine" }); + this.multiMap.put(Constant.Color.WHITE + Constant.Color.BLUE, new String[] { "Tundra", "Hallowed Fountain" }); + this.multiMap.put(Constant.Color.WHITE + Constant.Color.GREEN, new String[] { "Savannah", "Temple Garden" }); + this.multiMap.put(Constant.Color.WHITE + Constant.Color.RED, new String[] { "Plateau", "Sacred Foundry" }); } /** @@ -96,12 +100,12 @@ public class GenerateConstructedMultiColorDeck { int check; do { - deck = get3ColorDeck(); + deck = this.get3ColorDeck(); check = deck.getType("Creature").size(); - } while (check < 16 || 24 < check); + } while ((check < 16) || (24 < check)); - addLand(deck, 3); + this.addLand(deck, 3); if (deck.size() != 60) { throw new RuntimeException( @@ -122,9 +126,9 @@ public class GenerateConstructedMultiColorDeck { public final CardList generate5ColorDeck() { CardList deck; - deck = get5ColorDeck(); + deck = this.get5ColorDeck(); - addLand(deck, 5); + this.addLand(deck, 5); if (deck.size() != 60) { throw new RuntimeException( @@ -147,92 +151,116 @@ public class GenerateConstructedMultiColorDeck { */ private void addLand(final CardList list, final int colors) { if (colors == 3) { - int numberBasic = 2; + final int numberBasic = 2; Card land; for (int i = 0; i < numberBasic; i++) { - land = AllZone.getCardFactory().getCard(map.get(color1).toString(), AllZone.getComputerPlayer()); + land = AllZone.getCardFactory().getCard(this.map.get(this.color1).toString(), + AllZone.getComputerPlayer()); list.add(land); - land = AllZone.getCardFactory().getCard(map.get(color2).toString(), AllZone.getComputerPlayer()); + land = AllZone.getCardFactory().getCard(this.map.get(this.color2).toString(), + AllZone.getComputerPlayer()); list.add(land); - land = AllZone.getCardFactory().getCard(map.get(color3).toString(), AllZone.getComputerPlayer()); + land = AllZone.getCardFactory().getCard(this.map.get(this.color3).toString(), + AllZone.getComputerPlayer()); list.add(land); } - int numberDual = 4; + final int numberDual = 4; for (int i = 0; i < numberDual; i++) { - land = AllZone.getCardFactory().getCard(multiMap.get(color1 + color2)[0], AllZone.getComputerPlayer()); + land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color1 + this.color2)[0], + AllZone.getComputerPlayer()); list.add(land); - land = AllZone.getCardFactory().getCard(multiMap.get(color1 + color3)[0], AllZone.getComputerPlayer()); + land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color1 + this.color3)[0], + AllZone.getComputerPlayer()); list.add(land); - land = AllZone.getCardFactory().getCard(multiMap.get(color2 + color3)[0], AllZone.getComputerPlayer()); + land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color2 + this.color3)[0], + AllZone.getComputerPlayer()); list.add(land); } for (int i = 0; i < 2; i++) { - land = AllZone.getCardFactory().getCard(multiMap.get(color1 + color2)[1], AllZone.getComputerPlayer()); + land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color1 + this.color2)[1], + AllZone.getComputerPlayer()); list.add(land); - land = AllZone.getCardFactory().getCard(multiMap.get(color1 + color3)[1], AllZone.getComputerPlayer()); + land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color1 + this.color3)[1], + AllZone.getComputerPlayer()); list.add(land); - land = AllZone.getCardFactory().getCard(multiMap.get(color2 + color3)[1], AllZone.getComputerPlayer()); + land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color2 + this.color3)[1], + AllZone.getComputerPlayer()); list.add(land); } } else if (colors == 5) { - int numberBasic = 1; + final int numberBasic = 1; Card land; for (int i = 0; i < numberBasic; i++) { - land = AllZone.getCardFactory().getCard(map.get(color1).toString(), AllZone.getComputerPlayer()); + land = AllZone.getCardFactory().getCard(this.map.get(this.color1).toString(), + AllZone.getComputerPlayer()); list.add(land); - land = AllZone.getCardFactory().getCard(map.get(color2).toString(), AllZone.getComputerPlayer()); + land = AllZone.getCardFactory().getCard(this.map.get(this.color2).toString(), + AllZone.getComputerPlayer()); list.add(land); - land = AllZone.getCardFactory().getCard(map.get(color3).toString(), AllZone.getComputerPlayer()); + land = AllZone.getCardFactory().getCard(this.map.get(this.color3).toString(), + AllZone.getComputerPlayer()); list.add(land); - land = AllZone.getCardFactory().getCard(map.get(color4).toString(), AllZone.getComputerPlayer()); + land = AllZone.getCardFactory().getCard(this.map.get(this.color4).toString(), + AllZone.getComputerPlayer()); list.add(land); - land = AllZone.getCardFactory().getCard(map.get(color5).toString(), AllZone.getComputerPlayer()); + land = AllZone.getCardFactory().getCard(this.map.get(this.color5).toString(), + AllZone.getComputerPlayer()); list.add(land); } - int numberDual = 2; + final int numberDual = 2; for (int i = 0; i < numberDual; i++) { - land = AllZone.getCardFactory().getCard(multiMap.get(color1 + color2)[0], AllZone.getComputerPlayer()); + land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color1 + this.color2)[0], + AllZone.getComputerPlayer()); list.add(land); - land = AllZone.getCardFactory().getCard(multiMap.get(color1 + color3)[0], AllZone.getComputerPlayer()); + land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color1 + this.color3)[0], + AllZone.getComputerPlayer()); list.add(land); - land = AllZone.getCardFactory().getCard(multiMap.get(color1 + color4)[0], AllZone.getComputerPlayer()); + land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color1 + this.color4)[0], + AllZone.getComputerPlayer()); list.add(land); - land = AllZone.getCardFactory().getCard(multiMap.get(color1 + color5)[0], AllZone.getComputerPlayer()); + land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color1 + this.color5)[0], + AllZone.getComputerPlayer()); list.add(land); - land = AllZone.getCardFactory().getCard(multiMap.get(color2 + color3)[0], AllZone.getComputerPlayer()); + land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color2 + this.color3)[0], + AllZone.getComputerPlayer()); list.add(land); - land = AllZone.getCardFactory().getCard(multiMap.get(color2 + color4)[0], AllZone.getComputerPlayer()); + land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color2 + this.color4)[0], + AllZone.getComputerPlayer()); list.add(land); - land = AllZone.getCardFactory().getCard(multiMap.get(color2 + color5)[0], AllZone.getComputerPlayer()); + land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color2 + this.color5)[0], + AllZone.getComputerPlayer()); list.add(land); - land = AllZone.getCardFactory().getCard(multiMap.get(color3 + color4)[0], AllZone.getComputerPlayer()); + land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color3 + this.color4)[0], + AllZone.getComputerPlayer()); list.add(land); - land = AllZone.getCardFactory().getCard(multiMap.get(color3 + color5)[0], AllZone.getComputerPlayer()); + land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color3 + this.color5)[0], + AllZone.getComputerPlayer()); list.add(land); - land = AllZone.getCardFactory().getCard(multiMap.get(color4 + color5)[0], AllZone.getComputerPlayer()); + land = AllZone.getCardFactory().getCard(this.multiMap.get(this.color4 + this.color5)[0], + AllZone.getComputerPlayer()); list.add(land); } @@ -251,7 +279,7 @@ public class GenerateConstructedMultiColorDeck { * empty, but never null */ private CardList getCards(final int colors) { - return filterBadCards(AllZone.getCardFactory(), colors); + return this.filterBadCards(AllZone.getCardFactory(), colors); } // getCards() /** @@ -262,14 +290,14 @@ public class GenerateConstructedMultiColorDeck { * @return a {@link forge.CardList} object. */ private CardList get3ColorDeck() { - CardList deck = get3Colors(getCards(3)); + final CardList deck = this.get3Colors(this.getCards(3)); - CardList out = new CardList(); + final CardList out = new CardList(); deck.shuffle(); // trim deck size down to 36 cards, presumes 24 land, for a total of 60 // cards - for (int i = 0; i < 36 && i < deck.size(); i++) { + for (int i = 0; (i < 36) && (i < deck.size()); i++) { out.add(deck.get(i)); } @@ -284,14 +312,14 @@ public class GenerateConstructedMultiColorDeck { * @return a {@link forge.CardList} object. */ private CardList get5ColorDeck() { - CardList deck = get5Colors(getCards(5)); + final CardList deck = this.get5Colors(this.getCards(5)); - CardList out = new CardList(); + final CardList out = new CardList(); deck.shuffle(); // trim deck size down to 36 cards, presumes 24 land, for a total of 60 // cards - for (int i = 0; i < 36 && i < deck.size(); i++) { + for (int i = 0; (i < 36) && (i < deck.size()); i++) { out.add(deck.get(i)); } @@ -316,20 +344,22 @@ public class GenerateConstructedMultiColorDeck { do { b = CardUtil.getRandomIndex(Constant.Color.ONLY_COLORS); c = CardUtil.getRandomIndex(Constant.Color.ONLY_COLORS); - } while (a == b || a == c || b == c); // do not want to get the same - // color thrice + } while ((a == b) || (a == c) || (b == c)); // do not want to get the + // same + // color thrice - color1 = Constant.Color.ONLY_COLORS[a]; - color2 = Constant.Color.ONLY_COLORS[b]; - color3 = Constant.Color.ONLY_COLORS[c]; + this.color1 = Constant.Color.ONLY_COLORS[a]; + this.color2 = Constant.Color.ONLY_COLORS[b]; + this.color3 = Constant.Color.ONLY_COLORS[c]; CardList out = new CardList(); - out.addAll(CardListUtil.getColor(in, color1)); - out.addAll(CardListUtil.getColor(in, color2)); - out.addAll(CardListUtil.getColor(in, color3)); + out.addAll(CardListUtil.getColor(in, this.color1)); + out.addAll(CardListUtil.getColor(in, this.color2)); + out.addAll(CardListUtil.getColor(in, this.color3)); out.shuffle(); - CardList artifact = in.filter(new CardListFilter() { + final CardList artifact = in.filter(new CardListFilter() { + @Override public boolean addCard(final Card c) { // is this really a colorless artifact and not something // wierd like Sarcomite Myr which is a colored artifact @@ -340,8 +370,9 @@ public class GenerateConstructedMultiColorDeck { out.addAll(artifact); out = out.filter(new CardListFilter() { + @Override public boolean addCard(final Card c) { - if (c.isCreature() && c.getNetAttack() <= 1 && Singletons.getModel().getPreferences().deckGenRmvSmall) { + if (c.isCreature() && (c.getNetAttack() <= 1) && Singletons.getModel().getPreferences().deckGenRmvSmall) { return false; } @@ -349,7 +380,7 @@ public class GenerateConstructedMultiColorDeck { } }); - out = filterBadCards(out, 3); + out = this.filterBadCards(out, 3); return out; } @@ -364,11 +395,11 @@ public class GenerateConstructedMultiColorDeck { */ private CardList get5Colors(final CardList in) { - color1 = Constant.Color.BLACK; - color2 = Constant.Color.BLUE; - color3 = Constant.Color.GREEN; - color4 = Constant.Color.RED; - color5 = Constant.Color.WHITE; + this.color1 = Constant.Color.BLACK; + this.color2 = Constant.Color.BLUE; + this.color3 = Constant.Color.GREEN; + this.color4 = Constant.Color.RED; + this.color5 = Constant.Color.WHITE; CardList out = new CardList(); /* @@ -381,7 +412,8 @@ public class GenerateConstructedMultiColorDeck { out.addAll(CardListUtil.getGoldCards(in)); out.shuffle(); - CardList artifact = in.filter(new CardListFilter() { + final CardList artifact = in.filter(new CardListFilter() { + @Override public boolean addCard(final Card c) { // is this really a colorless artifact and not something // wierd like Sarcomite Myr which is a colored artifact @@ -392,8 +424,9 @@ public class GenerateConstructedMultiColorDeck { out.addAll(artifact); out = out.filter(new CardListFilter() { + @Override public boolean addCard(final Card c) { - if (c.isCreature() && c.getNetAttack() <= 1 && Singletons.getModel().getPreferences().deckGenRmvSmall) { + if (c.isCreature() && (c.getNetAttack() <= 1) && Singletons.getModel().getPreferences().deckGenRmvSmall) { return false; } @@ -401,7 +434,7 @@ public class GenerateConstructedMultiColorDeck { } }); - out = filterBadCards(out, 3); + out = this.filterBadCards(out, 3); return out; } @@ -429,37 +462,44 @@ public class GenerateConstructedMultiColorDeck { if (colors == 3) { out = CardFilter.filter(sequence, new CardListFilter() { + @Override public boolean addCard(final Card c) { - ArrayList list = CardUtil.getColors(c); + final ArrayList list = CardUtil.getColors(c); if (list.size() == 3) { - if (!list.contains(color1) || !list.contains(color2) || !list.contains(color3)) { + if (!list.contains(GenerateConstructedMultiColorDeck.this.color1) + || !list.contains(GenerateConstructedMultiColorDeck.this.color2) + || !list.contains(GenerateConstructedMultiColorDeck.this.color3)) { return false; } } else if (list.size() == 2) { - if (!(list.contains(color1) && list.contains(color2)) - && !(list.contains(color1) && list.contains(color3)) - && !(list.contains(color2) && list.contains(color3))) { + if (!(list.contains(GenerateConstructedMultiColorDeck.this.color1) && list + .contains(GenerateConstructedMultiColorDeck.this.color2)) + && !(list.contains(GenerateConstructedMultiColorDeck.this.color1) && list + .contains(GenerateConstructedMultiColorDeck.this.color3)) + && !(list.contains(GenerateConstructedMultiColorDeck.this.color2) && list + .contains(GenerateConstructedMultiColorDeck.this.color3))) { return false; } } - return CardUtil.getColors(c).size() <= 3 && !c.isLand() && // no - // land - !c.getSVar("RemRandomDeck").equals("True") && !c.getSVar("RemAIDeck").equals("True") || - // OR very important + return ((CardUtil.getColors(c).size() <= 3) && !c.isLand() && // no + // land + !c.getSVar("RemRandomDeck").equals("True") && !c.getSVar("RemAIDeck").equals("True")) || + // OR very important goodLand.contains(c.getName()); } }); } else if (colors == 5) { out = CardFilter.filter(sequence, new CardListFilter() { + @Override public boolean addCard(final Card c) { - return CardUtil.getColors(c).size() >= 2 && // only get - // multicolored - // cards + return ((CardUtil.getColors(c).size() >= 2) && // only get + // multicolored + // cards !c.isLand() && // no land - !c.getSVar("RemRandomDeck").equals("True") && !c.getSVar("RemAIDeck").equals("True") || - // OR very important + !c.getSVar("RemRandomDeck").equals("True") && !c.getSVar("RemAIDeck").equals("True")) || + // OR very important goodLand.contains(c.getName()); } }); diff --git a/src/main/java/forge/deck/generate/GenerateDeckUtil.java b/src/main/java/forge/deck/generate/GenerateDeckUtil.java index 82d99743fa8..9b5fb280d4b 100644 --- a/src/main/java/forge/deck/generate/GenerateDeckUtil.java +++ b/src/main/java/forge/deck/generate/GenerateDeckUtil.java @@ -22,7 +22,7 @@ public class GenerateDeckUtil { */ public static ArrayList getDualLandList(final String colors) { - ArrayList dLands = new ArrayList(); + final ArrayList dLands = new ArrayList(); if (colors.length() > 3) { dLands.add("Rupture Spire"); diff --git a/src/main/java/forge/deck/generate/GenerateThemeDeck.java b/src/main/java/forge/deck/generate/GenerateThemeDeck.java index e5187a22934..e8b43c623fa 100644 --- a/src/main/java/forge/deck/generate/GenerateThemeDeck.java +++ b/src/main/java/forge/deck/generate/GenerateThemeDeck.java @@ -43,9 +43,9 @@ public class GenerateThemeDeck { * @return a {@link java.util.ArrayList} object. */ public final ArrayList getThemeNames() { - ArrayList ltNames = new ArrayList(); + final ArrayList ltNames = new ArrayList(); - File file = new File("res/quest/themes/"); + final File file = new File("res/quest/themes/"); if (!file.exists()) { throw new RuntimeException("GenerateThemeDeck : getThemeNames error -- file not found -- filename is " @@ -57,10 +57,10 @@ public class GenerateThemeDeck { + file.getAbsolutePath()); } - String[] fileList = file.list(); - for (int i = 0; i < fileList.length; i++) { - if (fileList[i].endsWith(".thm")) { - ltNames.add(fileList[i].substring(0, fileList[i].indexOf(".thm"))); + final String[] fileList = file.list(); + for (final String element : fileList) { + if (element.endsWith(".thm")) { + ltNames.add(element.substring(0, element.indexOf(".thm"))); } } @@ -79,55 +79,55 @@ public class GenerateThemeDeck { * @return a {@link forge.CardList} object. */ public final CardList getThemeDeck(final String themeName, final int size) { - CardList tDeck = new CardList(); + final CardList tDeck = new CardList(); - ArrayList groups = new ArrayList(); + final ArrayList groups = new ArrayList(); - Map cardCounts = new HashMap(); + final Map cardCounts = new HashMap(); String s = ""; int bLandPercentage = 0; boolean testing = false; // read theme file - String tFileName = "res/quest/themes/" + themeName + ".thm"; - File tFile = new File(tFileName); + final String tFileName = "res/quest/themes/" + themeName + ".thm"; + final File tFile = new File(tFileName); if (!tFile.exists()) { throw new RuntimeException("GenerateThemeDeck : getThemeDeck -- file not found -- filename is " + tFile.getAbsolutePath()); } try { - in = new BufferedReader(new FileReader(tFile)); - } catch (Exception ex) { + this.in = new BufferedReader(new FileReader(tFile)); + } catch (final Exception ex) { ErrorViewer.showError(ex, "File \"%s\" exception", tFile.getAbsolutePath()); throw new RuntimeException("GenerateThemeDeck : getThemeDeck -- file exception -- filename is " + tFile.getPath()); } - s = readLine(); + s = this.readLine(); while (!s.equals("End")) { if (s.startsWith("[Group")) { - Grp g = new Grp(); + final Grp g = new Grp(); - String[] ss = s.replaceAll("[\\[\\]]", "").split(" "); - for (int i = 0; i < ss.length; i++) { - if (ss[i].startsWith("Percentage")) { - String p = ss[i].substring("Percentage".length() + 1); + final String[] ss = s.replaceAll("[\\[\\]]", "").split(" "); + for (final String element : ss) { + if (element.startsWith("Percentage")) { + final String p = element.substring("Percentage".length() + 1); g.Percentage = Integer.parseInt(p); } - if (ss[i].startsWith("MaxCnt")) { - String m = ss[i].substring("MaxCnt".length() + 1); + if (element.startsWith("MaxCnt")) { + final String m = element.substring("MaxCnt".length() + 1); g.MaxCnt = Integer.parseInt(m); } } - s = readLine(); + s = this.readLine(); while (!s.equals("[/Group]")) { g.Cardnames.add(s); cardCounts.put(s, 0); - s = readLine(); + s = this.readLine(); } groups.add(g); @@ -141,12 +141,12 @@ public class GenerateThemeDeck { testing = true; } - s = readLine(); + s = this.readLine(); } try { - in.close(); - } catch (IOException ex) { + this.in.close(); + } catch (final IOException ex) { ErrorViewer.showError(ex, "File \"%s\" exception", tFile.getAbsolutePath()); throw new RuntimeException("GenerateThemeDeck : getThemeDeck -- file exception -- filename is " + tFile.getPath()); @@ -155,22 +155,23 @@ public class GenerateThemeDeck { String tmpDeck = ""; // begin assigning cards to the deck - Random r = MyRandom.getRandom(); + final Random r = MyRandom.getRandom(); for (int i = 0; i < groups.size(); i++) { - Grp g = groups.get(i); - float p = (float) ((float) g.Percentage * .01); - int grpCnt = (int) (p * (float) size); - int cnSize = g.Cardnames.size(); + final Grp g = groups.get(i); + final float p = (float) (g.Percentage * .01); + final int grpCnt = (int) (p * size); + final int cnSize = g.Cardnames.size(); tmpDeck += "Group" + i + ":" + grpCnt + "\n"; for (int j = 0; j < grpCnt; j++) { s = g.Cardnames.get(r.nextInt(cnSize)); int lc = 0; - while (cardCounts.get(s) >= g.MaxCnt || lc > size) // don't keep - // looping - // forever + while ((cardCounts.get(s) >= g.MaxCnt) || (lc > size)) // don't + // keep + // looping + // forever { s = g.Cardnames.get(r.nextInt(cnSize)); lc++; @@ -180,7 +181,7 @@ public class GenerateThemeDeck { + tFile.getAbsolutePath()); } - int n = cardCounts.get(s); + final int n = cardCounts.get(s); tDeck.add(AllZone.getCardFactory().getCard(s, AllZone.getComputerPlayer())); cardCounts.put(s, n + 1); tmpDeck += s + "\n"; @@ -190,8 +191,8 @@ public class GenerateThemeDeck { int numBLands = 0; if (bLandPercentage > 0) { // if theme explicitly defines this - float p = (float) ((float) bLandPercentage * .01); - numBLands = (int) (p * (float) size); + final float p = (float) (bLandPercentage * .01); + numBLands = (int) (p * size); } else { // otherwise, just fill in the rest of the deck with basic // lands numBLands = size - tDeck.size(); @@ -202,16 +203,16 @@ public class GenerateThemeDeck { if (numBLands > 0) // attempt to optimize basic land counts according to // color representation { - CCnt[] clrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0), + final CCnt[] clrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0), new CCnt("Mountain", 0), new CCnt("Forest", 0) }; // count each instance of a color in mana costs // TODO count hybrid mana differently? for (int i = 0; i < tDeck.size(); i++) { - String mc = tDeck.get(i).getManaCost(); + final String mc = tDeck.get(i).getManaCost(); for (int j = 0; j < mc.length(); j++) { - char c = mc.charAt(j); + final char c = mc.charAt(j); if (c == 'W') { clrCnts[0].Count++; @@ -238,8 +239,8 @@ public class GenerateThemeDeck { for (int i = 0; i < 5; i++) { if (clrCnts[i].Count > 0) { // calculate number of lands for // each color - float p = (float) clrCnts[i].Count / (float) totalColor; - int nLand = (int) ((float) numBLands * p); + final float p = (float) clrCnts[i].Count / (float) totalColor; + final int nLand = (int) (numBLands * p); tmpDeck += "numLand-" + clrCnts[i].Color + ":" + nLand + "\n"; cardCounts.put(clrCnts[i].Color, 2); @@ -252,7 +253,7 @@ public class GenerateThemeDeck { tmpDeck += "DeckSize:" + tDeck.size() + "\n"; if (tDeck.size() < size) { - int diff = size - tDeck.size(); + final int diff = size - tDeck.size(); for (int i = 0; i < diff; i++) { s = tDeck.get(r.nextInt(tDeck.size())).getName(); @@ -261,13 +262,13 @@ public class GenerateThemeDeck { s = tDeck.get(r.nextInt(tDeck.size())).getName(); } - int n = cardCounts.get(s); + final int n = cardCounts.get(s); tDeck.add(AllZone.getCardFactory().getCard(s, AllZone.getComputerPlayer())); cardCounts.put(s, n + 1); tmpDeck += "Added:" + s + "\n"; } } else if (tDeck.size() > size) { - int diff = tDeck.size() - size; + final int diff = tDeck.size() - size; for (int i = 0; i < diff; i++) { Card c = tDeck.get(r.nextInt(tDeck.size())); @@ -299,12 +300,12 @@ public class GenerateThemeDeck { private String readLine() { // makes the checked exception, into an unchecked runtime exception try { - String s = in.readLine(); + String s = this.in.readLine(); if (s != null) { s = s.trim(); } return s; - } catch (Exception ex) { + } catch (final Exception ex) { ErrorViewer.showError(ex); throw new RuntimeException("GenerateThemeDeck : readLine error"); } @@ -332,8 +333,8 @@ public class GenerateThemeDeck { * the cnt */ public CCnt(final String clr, final int cnt) { - Color = clr; - Count = cnt; + this.Color = clr; + this.Count = cnt; } } diff --git a/src/main/java/forge/deck/generate/package-info.java b/src/main/java/forge/deck/generate/package-info.java index b4ac3202953..36bf2c15f35 100644 --- a/src/main/java/forge/deck/generate/package-info.java +++ b/src/main/java/forge/deck/generate/package-info.java @@ -1,2 +1,3 @@ /** Forge Card Game. */ package forge.deck.generate; + diff --git a/src/main/java/forge/deck/package-info.java b/src/main/java/forge/deck/package-info.java index 0480e436cbd..bf76ced9d48 100644 --- a/src/main/java/forge/deck/package-info.java +++ b/src/main/java/forge/deck/package-info.java @@ -1,2 +1,3 @@ /** Forge Card Game. */ package forge.deck; +