diff --git a/src/main/java/forge/StaticEffect.java b/src/main/java/forge/StaticEffect.java index a8be7452e80..2f55ff15c01 100644 --- a/src/main/java/forge/StaticEffect.java +++ b/src/main/java/forge/StaticEffect.java @@ -19,7 +19,7 @@ public class StaticEffect { private int xValue = 0; private int yValue = 0; private long timestamp = -1; - + private String chosenType; private HashMap mapParams = new HashMap(); @@ -45,13 +45,23 @@ public class StaticEffect { private String colorDesc = ""; private boolean overwriteColors = false; private HashMap timestamps = new HashMap(); - - public void setTimestamp(long t) { - timestamp = t; + + /** + * setTimestamp + * TODO Write javadoc for this method. + * @param t a long + */ + public final void setTimestamp(final long t) { + timestamp = t; } - - public long getTimestamp() { - return timestamp; + + /** + * getTimestamp. + * TODO Write javadoc for this method. + * @return a long + */ + public final long getTimestamp() { + return timestamp; } @@ -61,17 +71,17 @@ public class StaticEffect { * * @return a boolean. */ - public boolean isOverwriteAbilities() { + public final boolean isOverwriteAbilities() { return overwriteAbilities; } /** *

Setter for the field overwriteAbilities.

* - * @param overwriteAbilities a boolean. + * @param overwriteAbilitiesIn a boolean. */ - public void setOverwriteAbilities(boolean overwriteAbilities) { - this.overwriteAbilities = overwriteAbilities; + public final void setOverwriteAbilities(final boolean overwriteAbilitiesIn) { + this.overwriteAbilities = overwriteAbilitiesIn; } //original SAs @@ -81,12 +91,14 @@ public class StaticEffect { * @param c a {@link forge.Card} object. * @param sa a {@link forge.card.spellability.SpellAbility} object. */ - public void addOriginalAbilities(Card c, SpellAbility sa) { + public final void addOriginalAbilities(final Card c, final SpellAbility sa) { if (!originalAbilities.containsKey(c)) { ArrayList list = new ArrayList(); list.add(sa); originalAbilities.put(c, list); - } else originalAbilities.get(c).add(sa); + } else { + originalAbilities.get(c).add(sa); + } } /** @@ -95,7 +107,7 @@ public class StaticEffect { * @param c a {@link forge.Card} object. * @param s a {@link java.util.ArrayList} object. */ - public void addOriginalAbilities(Card c, ArrayList s) { + public final void addOriginalAbilities(final Card c, final ArrayList s) { ArrayList list = new ArrayList(s); if (!originalAbilities.containsKey(c)) { originalAbilities.put(c, list); @@ -111,7 +123,7 @@ public class StaticEffect { * @param c a {@link forge.Card} object. * @return a {@link java.util.ArrayList} object. */ - public ArrayList getOriginalAbilities(Card c) { + public final ArrayList getOriginalAbilities(final Card c) { ArrayList returnList = new ArrayList(); if (originalAbilities.containsKey(c)) { returnList.addAll(originalAbilities.get(c)); @@ -124,7 +136,7 @@ public class StaticEffect { * * @param c a {@link forge.Card} object. */ - public void clearOriginalAbilities(Card c) { + public final void clearOriginalAbilities(final Card c) { if (originalAbilities.containsKey(c)) { originalAbilities.get(c).clear(); } @@ -133,7 +145,7 @@ public class StaticEffect { /** *

clearAllOriginalAbilities.

*/ - public void clearAllOriginalAbilities() { + public final void clearAllOriginalAbilities() { originalAbilities.clear(); } @@ -143,17 +155,17 @@ public class StaticEffect { * * @return a boolean. */ - public boolean isOverwriteKeywords() { + public final boolean isOverwriteKeywords() { return overwriteKeywords; } /** *

Setter for the field overwriteKeywords.

* - * @param overwriteKeywords a boolean. + * @param overwriteKeywordsIn a boolean. */ - public void setOverwriteKeywords(boolean overwriteKeywords) { - this.overwriteKeywords = overwriteKeywords; + public final void setOverwriteKeywords(final boolean overwriteKeywordsIn) { + this.overwriteKeywords = overwriteKeywordsIn; } //original keywords @@ -163,12 +175,14 @@ public class StaticEffect { * @param c a {@link forge.Card} object. * @param s a {@link java.lang.String} object. */ - public void addOriginalKeyword(Card c, String s) { + public final void addOriginalKeyword(final Card c, final String s) { if (!originalKeywords.containsKey(c)) { ArrayList list = new ArrayList(); list.add(s); originalKeywords.put(c, list); - } else originalKeywords.get(c).add(s); + } else { + originalKeywords.get(c).add(s); + } } /** @@ -177,7 +191,7 @@ public class StaticEffect { * @param c a {@link forge.Card} object. * @param s a {@link java.util.ArrayList} object. */ - public void addOriginalKeywords(Card c, ArrayList s) { + public final void addOriginalKeywords(final Card c, final ArrayList s) { ArrayList list = new ArrayList(s); if (!originalKeywords.containsKey(c)) { originalKeywords.put(c, list); @@ -193,7 +207,7 @@ public class StaticEffect { * @param c a {@link forge.Card} object. * @return a {@link java.util.ArrayList} object. */ - public ArrayList getOriginalKeywords(Card c) { + public final ArrayList getOriginalKeywords(final Card c) { ArrayList returnList = new ArrayList(); if (originalKeywords.containsKey(c)) { returnList.addAll(originalKeywords.get(c)); @@ -206,7 +220,7 @@ public class StaticEffect { * * @param c a {@link forge.Card} object. */ - public void clearOriginalKeywords(Card c) { + public final void clearOriginalKeywords(final Card c) { if (originalKeywords.containsKey(c)) { originalKeywords.get(c).clear(); } @@ -215,7 +229,7 @@ public class StaticEffect { /** *

clearAllOriginalKeywords.

*/ - public void clearAllOriginalKeywords() { + public final void clearAllOriginalKeywords() { originalKeywords.clear(); } @@ -227,7 +241,7 @@ public class StaticEffect { * @param power a int. * @param toughness a int. */ - public void addOriginalPT(Card c, int power, int toughness) { + public final void addOriginalPT(final Card c, final int power, final int toughness) { String pt = power + "/" + toughness; if (!originalPT.containsKey(c)) { originalPT.put(c, pt); @@ -240,7 +254,7 @@ public class StaticEffect { * @param c a {@link forge.Card} object. * @return a int. */ - public int getOriginalPower(Card c) { + public final int getOriginalPower(final Card c) { int power = -1; if (originalPT.containsKey(c)) { power = Integer.parseInt(originalPT.get(c).split("/")[0]); @@ -254,7 +268,7 @@ public class StaticEffect { * @param c a {@link forge.Card} object. * @return a int. */ - public int getOriginalToughness(Card c) { + public final int getOriginalToughness(final Card c) { int tough = -1; if (originalPT.containsKey(c)) { tough = Integer.parseInt(originalPT.get(c).split("/")[1]); @@ -265,7 +279,7 @@ public class StaticEffect { /** *

clearAllOriginalPTs.

*/ - public void clearAllOriginalPTs() { + public final void clearAllOriginalPTs() { originalPT.clear(); } @@ -275,17 +289,17 @@ public class StaticEffect { * * @return a boolean. */ - public boolean isOverwriteTypes() { + public final boolean isOverwriteTypes() { return overwriteTypes; } /** *

Setter for the field overwriteTypes.

* - * @param overwriteTypes a boolean. + * @param overwriteTypesIn a boolean. */ - public void setOverwriteTypes(boolean overwriteTypes) { - this.overwriteTypes = overwriteTypes; + public final void setOverwriteTypes(final boolean overwriteTypesIn) { + this.overwriteTypes = overwriteTypesIn; } /** @@ -293,17 +307,17 @@ public class StaticEffect { * * @return a boolean. */ - public boolean isKeepSupertype() { + public final boolean isKeepSupertype() { return keepSupertype; } /** *

Setter for the field keepSupertype.

* - * @param keepSupertype a boolean. + * @param keepSupertypeIn a boolean. */ - public void setKeepSupertype(boolean keepSupertype) { - this.keepSupertype = keepSupertype; + public final void setKeepSupertype(boolean keepSupertypeIn) { + this.keepSupertype = keepSupertypeIn; } //should we overwrite land types? @@ -312,17 +326,17 @@ public class StaticEffect { * * @return a boolean. */ - public boolean isRemoveSubTypes() { + public final boolean isRemoveSubTypes() { return removeSubTypes; } /** *

Setter for the field removeSubTypes.

* - * @param removeSubTypes a boolean. + * @param removeSubTypesIn a boolean. */ - public void setRemoveSubTypes(boolean removeSubTypes) { - this.removeSubTypes = removeSubTypes; + public final void setRemoveSubTypes(final boolean removeSubTypesIn) { + this.removeSubTypes = removeSubTypesIn; } //original types @@ -332,12 +346,14 @@ public class StaticEffect { * @param c a {@link forge.Card} object. * @param s a {@link java.lang.String} object. */ - public void addOriginalType(Card c, String s) { + public final void addOriginalType(final Card c, final String s) { if (!originalTypes.containsKey(c)) { ArrayList list = new ArrayList(); list.add(s); originalTypes.put(c, list); - } else originalTypes.get(c).add(s); + } else { + originalTypes.get(c).add(s); + } } /** @@ -346,7 +362,7 @@ public class StaticEffect { * @param c a {@link forge.Card} object. * @param s a {@link java.util.ArrayList} object. */ - public void addOriginalTypes(Card c, ArrayList s) { + public final void addOriginalTypes(final Card c, final ArrayList s) { ArrayList list = new ArrayList(s); if (!originalTypes.containsKey(c)) { originalTypes.put(c, list); @@ -362,7 +378,7 @@ public class StaticEffect { * @param c a {@link forge.Card} object. * @return a {@link java.util.ArrayList} object. */ - public ArrayList getOriginalTypes(Card c) { + public final ArrayList getOriginalTypes(final Card c) { ArrayList returnList = new ArrayList(); if (originalTypes.containsKey(c)) { returnList.addAll(originalTypes.get(c)); @@ -375,7 +391,7 @@ public class StaticEffect { * * @param c a {@link forge.Card} object. */ - public void clearOriginalTypes(Card c) { + public final void clearOriginalTypes(final Card c) { if (originalTypes.containsKey(c)) { originalTypes.get(c).clear(); } @@ -384,7 +400,7 @@ public class StaticEffect { /** *

clearAllOriginalTypes.

*/ - public void clearAllOriginalTypes() { + public final void clearAllOriginalTypes() { originalTypes.clear(); } @@ -395,12 +411,14 @@ public class StaticEffect { * @param c a {@link forge.Card} object. * @param s a {@link java.lang.String} object. */ - public void addType(Card c, String s) { + public final void addType(final Card c, final String s) { if (!types.containsKey(c)) { ArrayList list = new ArrayList(); list.add(s); types.put(c, list); - } else types.get(c).add(s); + } else { + types.get(c).add(s); + } } /** @@ -409,7 +427,7 @@ public class StaticEffect { * @param c a {@link forge.Card} object. * @return a {@link java.util.ArrayList} object. */ - public ArrayList getTypes(Card c) { + public final ArrayList getTypes(final Card c) { ArrayList returnList = new ArrayList(); if (types.containsKey(c)) { returnList.addAll(types.get(c)); @@ -423,7 +441,7 @@ public class StaticEffect { * @param c a {@link forge.Card} object. * @param type a {@link java.lang.String} object. */ - public void removeType(Card c, String type) { + public final void removeType(final Card c, final String type) { if (types.containsKey(c)) { types.get(c).remove(type); } @@ -602,7 +620,7 @@ public class StaticEffect { * * @param y a int. */ - public void setYValue(int y) { + public final void setYValue(final int y) { yValue = y; } @@ -611,25 +629,34 @@ public class StaticEffect { * * @return a int. */ - public int getYValue() { + public final int getYValue() { return yValue; } - - public void setParams(HashMap params) { - mapParams = params; - } - - public HashMap getParams() { - return mapParams; - } - - public void setChosenType(String type) { - chosenType = type; - } - - public String getChosenType() { - return chosenType; - } - -}//end class StaticEffect + /** + * setParams. + * TODO Write javadoc for this method. + * @param params a HashMap + */ + public final void setParams(HashMap params) { + mapParams = params; + } + + public HashMap getParams() { + return mapParams; + } + + public void setChosenType(String type) { + chosenType = type; + } + + /** + * getChosenType. + * TODO Write javadoc for this method. + * @return + */ + public String getChosenType() { + return chosenType; + } + +} //end class StaticEffect diff --git a/src/main/java/forge/StaticEffects.java b/src/main/java/forge/StaticEffects.java index 893f883f748..b992879fb35 100644 --- a/src/main/java/forge/StaticEffects.java +++ b/src/main/java/forge/StaticEffects.java @@ -16,107 +16,141 @@ import java.util.HashMap; * @version $Id$ */ public class StaticEffects { - - //**************** StaticAbility system ************************** - public ArrayList staticEffects; - - public void clearStaticEffects() { + + //**************** StaticAbility system ************************** + /** + * staticEffects. + */ + public ArrayList staticEffects; + + /** + * clearStaticEffect. + * TODO Write javadoc for this method. + */ + public final void clearStaticEffects() { // remove all static effects for (int i = 0; i < staticEffects.size(); i++) { removeStaticEffect(staticEffects.get(i)); } - staticEffects = new ArrayList(); - - AllZone.getTriggerHandler().removeTemporaryTriggers(); - } - - public void addStaticEffect(StaticEffect staticEffect) { - staticEffects.add(staticEffect); - } - - void removeStaticEffect(StaticEffect se) { + staticEffects = new ArrayList(); + + AllZone.getTriggerHandler().removeTemporaryTriggers(); + } + + /** + * addStaticEffect. + * TODO Write javadoc for this method. + * @param staticEffect a StaticEffect + */ + public final void addStaticEffect(final StaticEffect staticEffect) { + staticEffects.add(staticEffect); + } + + /** + * removeStaticEffect + * TODO Write javadoc for this method. + * @param se a StaticEffect + */ + final void removeStaticEffect(final StaticEffect se) { CardList affectedCards = se.getAffectedCards(); HashMap params = se.getParams(); int powerBonus = 0; int toughnessBonus = 0; - boolean setPT = false; - String addKeywords[] = null; - String addColors = null; - - if (params.containsKey("SetPower") || params.containsKey("SetToughness")) { - setPT = true; - } - - if (params.containsKey("AddPower")) { - if (params.get("AddPower").equals("X")) { - powerBonus = se.getXValue(); - } else if (params.get("AddPower").equals("Y")) { - powerBonus = se.getYValue(); - } else - powerBonus = Integer.valueOf(params.get("AddPower")); - } - - if (params.containsKey("AddToughness")) { - if (params.get("AddToughness").equals("X")) - toughnessBonus = se.getXValue(); - else if (params.get("AddToughness").equals("Y")) - toughnessBonus = se.getYValue(); - else toughnessBonus = Integer.valueOf(params.get("AddToughness")); - } - - if (params.containsKey("AddKeyword")) - addKeywords = params.get("AddKeyword").split(" & "); - - if (params.containsKey("AddColor")) - addColors = CardUtil.getShortColorsString(new ArrayList(Arrays.asList(params.get("AddColor").split(" & ")))); - - if (params.containsKey("SetColor")) - addColors = CardUtil.getShortColorsString(new ArrayList(Arrays.asList(params.get("SetColor").split(" & ")))); - - //modify the affected card - for (int i = 0; i < affectedCards.size(); i++) { + boolean setPT = false; + String[] addKeywords = null; + String addColors = null; + + if (params.containsKey("SetPower") || params.containsKey("SetToughness")) { + setPT = true; + } + + if (params.containsKey("AddPower")) { + if (params.get("AddPower").equals("X")) { + powerBonus = se.getXValue(); + } else if (params.get("AddPower").equals("Y")) { + powerBonus = se.getYValue(); + } else { + powerBonus = Integer.valueOf(params.get("AddPower")); + } + } + + if (params.containsKey("AddToughness")) { + if (params.get("AddToughness").equals("X")) { + toughnessBonus = se.getXValue(); + } else if (params.get("AddToughness").equals("Y")) { + toughnessBonus = se.getYValue(); + } else { + toughnessBonus = Integer.valueOf(params.get("AddToughness")); + } + } + + if (params.containsKey("AddKeyword")) { + addKeywords = params.get("AddKeyword").split(" & "); + } + + if (params.containsKey("AddColor")) { + addColors = CardUtil.getShortColorsString( + new ArrayList(Arrays.asList(params.get("AddColor").split(" & ")))); + } + + if (params.containsKey("SetColor")) { + addColors = CardUtil.getShortColorsString( + new ArrayList(Arrays.asList(params.get("SetColor").split(" & ")))); + } + + //modify the affected card + for (int i = 0; i < affectedCards.size(); i++) { Card affectedCard = affectedCards.get(i); - + //remove set P/T - if(!params.containsKey("CharacteristicDefining") && setPT) - affectedCard.removeNewPT(se.getTimestamp()); - + if (!params.containsKey("CharacteristicDefining") && setPT) { + affectedCard.removeNewPT(se.getTimestamp()); + } + //remove P/T bonus affectedCard.addSemiPermanentAttackBoost(powerBonus * -1); affectedCard.addSemiPermanentDefenseBoost(toughnessBonus * -1); - + //remove keywords - if (addKeywords != null) - for (String keyword : addKeywords) - affectedCard.removeExtrinsicKeyword(keyword); - + if (addKeywords != null) { + for (String keyword : addKeywords) { + affectedCard.removeExtrinsicKeyword(keyword); + } + } + //remove abilities if (params.containsKey("AddAbility")) { - SpellAbility[] spellAbility = affectedCard.getSpellAbility(); - for (SpellAbility s : spellAbility) - if (s.getType().equals("Temporary")) + SpellAbility[] spellAbility = affectedCard.getSpellAbility(); + for (SpellAbility s : spellAbility) { + if (s.getType().equals("Temporary")) { affectedCard.removeSpellAbility(s); + } + } } - + //remove Types - if (params.containsKey("AddType")) - affectedCard.removeChangedCardTypes(se.getTimestamp()); - + if (params.containsKey("AddType")) { + affectedCard.removeChangedCardTypes(se.getTimestamp()); + } + //remove colors - if (addColors != null) - affectedCard.removeColor(addColors, affectedCard, !se.isOverwriteColors(), se.getTimestamp(affectedCard)); - } - se.clearTimestamps(); + if (addColors != null) { + affectedCard.removeColor(addColors, affectedCard, + !se.isOverwriteColors(), se.getTimestamp(affectedCard)); + } + } + se.clearTimestamps(); } - - //**************** End StaticAbility system ************************** - + + //**************** End StaticAbility system ************************** + //this is used to keep track of all state-based effects in play: private HashMap stateBasedMap = new HashMap(); - //this is used to define all cards that are state-based effects, and map the corresponding commands to their cardnames - /** Constant cardToEffectsList */ + //this is used to define all cards that are state-based effects, and map the + //corresponding commands to their cardnames + /** Constant cardToEffectsList. */ private static HashMap cardToEffectsList = new HashMap(); /** @@ -130,7 +164,7 @@ public class StaticEffects { /** *

initStateBasedEffectsList.

*/ - public void initStateBasedEffectsList() { + public final void initStateBasedEffectsList() { //value has to be an array, since certain cards have multiple commands associated with them cardToEffectsList.put("Avatar", new String[]{"Ajani_Avatar_Token"}); @@ -157,7 +191,7 @@ public class StaticEffects { * * @return a {@link java.util.HashMap} object. */ - public HashMap getCardToEffectsList() { + public final HashMap getCardToEffectsList() { return cardToEffectsList; } @@ -166,11 +200,12 @@ public class StaticEffects { * * @param s a {@link java.lang.String} object. */ - public void addStateBasedEffect(String s) { - if (stateBasedMap.containsKey(s)) + public final void addStateBasedEffect(final String s) { + if (stateBasedMap.containsKey(s)) { stateBasedMap.put(s, stateBasedMap.get(s) + 1); - else + } else { stateBasedMap.put(s, 1); + } } /** @@ -178,11 +213,12 @@ public class StaticEffects { * * @param s a {@link java.lang.String} object. */ - public void removeStateBasedEffect(String s) { + public final void removeStateBasedEffect(final String s) { if (stateBasedMap.containsKey(s)) { stateBasedMap.put(s, stateBasedMap.get(s) - 1); - if (stateBasedMap.get(s) == 0) + if (stateBasedMap.get(s) == 0) { stateBasedMap.remove(s); + } } } @@ -191,21 +227,21 @@ public class StaticEffects { * * @return a {@link java.util.HashMap} object. */ - public HashMap getStateBasedMap() { + public final HashMap getStateBasedMap() { return stateBasedMap; } /** *

reset.

*/ - public void reset() { + public final void reset() { stateBasedMap.clear(); } /** *

rePopulateStateBasedList.

*/ - public void rePopulateStateBasedList() { + public final void rePopulateStateBasedList() { reset(); CardList cards = AllZoneUtil.getCardsInPlay(); @@ -229,4 +265,5 @@ public class StaticEffects { Log.debug("== End add state effects =="); } -} + +} //end class StaticEffects