diff --git a/src/main/java/forge/card/spellability/SpellAbility_Condition.java b/src/main/java/forge/card/spellability/SpellAbility_Condition.java index 22d3fc537ea..2bf9cbf27cf 100644 --- a/src/main/java/forge/card/spellability/SpellAbility_Condition.java +++ b/src/main/java/forge/card/spellability/SpellAbility_Condition.java @@ -1,7 +1,11 @@ package forge.card.spellability; -import forge.*; +import forge.AllZone; +import forge.AllZoneUtil; +import forge.CardList; +import forge.Phase; +import forge.Player; import forge.card.abilityFactory.AbilityFactory; import forge.card.cardFactory.CardFactoryUtil; @@ -32,25 +36,35 @@ public class SpellAbility_Condition extends SpellAbility_Variables { * * @param params a {@link java.util.HashMap} object. */ - public void setConditions(HashMap params) { + public final void setConditions(final HashMap params) { if (params.containsKey("Condition")) { String value = params.get("Condition"); - if (value.equals("Threshold")) setThreshold(true); - if (value.equals("Metalcraft")) setMetalcraft(true); - if (value.equals("Hellbent")) setHellbent(true); + if (value.equals("Threshold")) { + setThreshold(true); + } + if (value.equals("Metalcraft")) { + setMetalcraft(true); + } + if (value.equals("Hellbent")) { + setHellbent(true); + } } - if (params.containsKey("ConditionZone")) + if (params.containsKey("ConditionZone")) { setZone(params.get("ContitionZone")); + } - if (params.containsKey("ConditionSorcerySpeed")) + if (params.containsKey("ConditionSorcerySpeed")) { setSorcerySpeed(true); + } - if (params.containsKey("ConditionPlayerTurn")) + if (params.containsKey("ConditionPlayerTurn")) { setPlayerTurn(true); + } - if (params.containsKey("ConditionOpponentTurn")) + if (params.containsKey("ConditionOpponentTurn")) { setOpponentTurn(true); + } if (params.containsKey("ConditionPhases")) { String phases = params.get("ConditionPhases"); @@ -68,14 +82,16 @@ public class SpellAbility_Condition extends SpellAbility_Variables { setPhases(phases); } - if (params.containsKey("ConditionCardsInHand")) + if (params.containsKey("ConditionCardsInHand")) { setActivateCardsInHand(Integer.parseInt(params.get("ConditionCardsInHand"))); + } //Condition version of IsPresent stuff if (params.containsKey("ConditionPresent")) { setIsPresent(params.get("ConditionPresent")); - if (params.containsKey("ConditionCompare")) + if (params.containsKey("ConditionCompare")) { setPresentCompare(params.get("ConditionCompare")); + } } if (params.containsKey("ConditionDefined")) { @@ -94,11 +110,11 @@ public class SpellAbility_Condition extends SpellAbility_Variables { lifeAmount = params.get("ConditionLifeAmount"); } } - - if(params.containsKey("ConditionManaSpent")) { - setManaSpent(params.get("ConditionManaSpent")); + + if (params.containsKey("ConditionManaSpent")) { + setManaSpent(params.get("ConditionManaSpent")); } - + if (params.containsKey("CheckSVar")) { setSvarToCheck(params.get("CheckSVar")); } @@ -106,8 +122,8 @@ public class SpellAbility_Condition extends SpellAbility_Variables { setSvarOperator(params.get("SVarCompare").substring(0, 2)); setSvarOperand(params.get("SVarCompare").substring(2)); } - - }//setConditions + + } //setConditions /** *

checkConditions.

@@ -115,38 +131,46 @@ public class SpellAbility_Condition extends SpellAbility_Variables { * @param sa a {@link forge.card.spellability.SpellAbility} object. * @return a boolean. */ - public boolean checkConditions(SpellAbility sa) { + public final boolean checkConditions(final SpellAbility sa) { Player activator = sa.getActivatingPlayer(); if (activator == null) { activator = sa.getSourceCard().getController(); - System.out.println(sa.getSourceCard().getName() + " Did not have activator set in SpellAbility_Condition.checkConditions()"); + System.out.println(sa.getSourceCard().getName() + + " Did not have activator set in SpellAbility_Condition.checkConditions()"); } if (hellbent) { - if (!activator.hasHellbent()) + if (!activator.hasHellbent()) { return false; + } } if (threshold) { - if (!activator.hasThreshold()) + if (!activator.hasThreshold()) { return false; + } } if (metalcraft) { - if (!activator.hasMetalcraft()) + if (!activator.hasMetalcraft()) { return false; + } } - if (bSorcerySpeed && !Phase.canCastSorcery(activator)) + if (bSorcerySpeed && !Phase.canCastSorcery(activator)) { return false; + } - if (bPlayerTurn && !AllZone.getPhase().isPlayerTurn(activator)) + if (bPlayerTurn && !AllZone.getPhase().isPlayerTurn(activator)) { return false; + } - if (bOpponentTurn && AllZone.getPhase().isPlayerTurn(activator)) + if (bOpponentTurn && AllZone.getPhase().isPlayerTurn(activator)) { return false; + } - if (activationLimit != -1 && numberTurnActivations >= activationLimit) + if (activationLimit != -1 && numberTurnActivations >= activationLimit) { return false; + } if (phases.size() > 0) { boolean isPhase = false; @@ -158,14 +182,16 @@ public class SpellAbility_Condition extends SpellAbility_Variables { } } - if (!isPhase) + if (!isPhase) { return false; + } } if (nCardsInHand != -1) { // Can handle Library of Alexandria, or Hellbent - if (AllZoneUtil.getPlayerHand(activator).size() != nCardsInHand) + if (AllZoneUtil.getPlayerHand(activator).size() != nCardsInHand) { return false; + } } if (sIsPresent != null) { @@ -188,8 +214,9 @@ public class SpellAbility_Condition extends SpellAbility_Variables { int left = list.size(); - if (!AllZoneUtil.compare(left, presentCompare, right)) + if (!AllZoneUtil.compare(left, presentCompare, right)) { return false; + } } if (lifeTotal != null) { @@ -213,23 +240,24 @@ public class SpellAbility_Condition extends SpellAbility_Variables { return false; } } - - if(null != manaSpent) { - if(!sa.getSourceCard().getColorsPaid().contains(manaSpent)) { - return false; - } + + if (null != manaSpent) { + if (!sa.getSourceCard().getColorsPaid().contains(manaSpent)) { + return false; + } } - + if (svarToCheck != null) { int svarValue = AbilityFactory.calculateAmount(sa.getSourceCard(), svarToCheck, sa); int operandValue = AbilityFactory.calculateAmount(sa.getSourceCard(), svarOperand, sa); - if (!AllZoneUtil.compare(svarValue, svarOperator, operandValue)) + if (!AllZoneUtil.compare(svarValue, svarOperator, operandValue)) { return false; + } } return true; } -}//end class SpellAbility_Condition +} //end class SpellAbility_Condition diff --git a/src/main/java/forge/card/spellability/SpellAbility_Requirements.java b/src/main/java/forge/card/spellability/SpellAbility_Requirements.java index a0e63699f57..c59f66827f4 100644 --- a/src/main/java/forge/card/spellability/SpellAbility_Requirements.java +++ b/src/main/java/forge/card/spellability/SpellAbility_Requirements.java @@ -26,7 +26,7 @@ public class SpellAbility_Requirements { * * @param bSkip a boolean. */ - public void setSkipStack(boolean bSkip) { + public final void setSkipStack(final boolean bSkip) { skipStack = bSkip; } @@ -35,7 +35,7 @@ public class SpellAbility_Requirements { * * @param bFree a boolean. */ - public void setFree(boolean bFree) { + public final void setFree(final boolean bFree) { isFree = bFree; } @@ -49,7 +49,7 @@ public class SpellAbility_Requirements { * @param ts a {@link forge.card.spellability.Target_Selection} object. * @param cp a {@link forge.card.cost.Cost_Payment} object. */ - public SpellAbility_Requirements(SpellAbility sa, Target_Selection ts, Cost_Payment cp) { + public SpellAbility_Requirements(final SpellAbility sa, final Target_Selection ts, final Cost_Payment cp) { ability = sa; select = ts; payment = cp; @@ -58,7 +58,7 @@ public class SpellAbility_Requirements { /** *

fillRequirements.

*/ - public void fillRequirements() { + public final void fillRequirements() { fillRequirements(false); } @@ -67,7 +67,7 @@ public class SpellAbility_Requirements { * * @param skipTargeting a boolean. */ - public void fillRequirements(boolean skipTargeting) { + public final void fillRequirements(final boolean skipTargeting) { if (ability instanceof Spell && !bCasting) { // remove from hand bCasting = true; @@ -82,19 +82,21 @@ public class SpellAbility_Requirements { // freeze Stack. No abilities should go onto the stack while I'm filling requirements. AllZone.getStack().freezeStack(); - // Skip to paying if parent ability doesn't target and has no subAbilities. (or trigger case where its already targeted) + // Skip to paying if parent ability doesn't target and has no subAbilities. + // (or trigger case where its already targeted) if (!skipTargeting && (select.doesTarget() || ability.getSubAbility() != null)) { select.setRequirements(this); select.resetTargets(); select.chooseTargets(); - } else + } else { needPayment(); + } } /** *

finishedTargeting.

*/ - public void finishedTargeting() { + public final void finishedTargeting() { if (select.isCanceled()) { // cancel ability during target choosing Card c = ability.getSourceCard(); @@ -106,24 +108,26 @@ public class SpellAbility_Requirements { select.resetTargets(); AllZone.getStack().clearFrozen(); return; - } else + } else { needPayment(); + } } /** *

needPayment.

*/ - public void needPayment() { - if (!isFree) + public final void needPayment() { + if (!isFree) { startPaying(); - else + } else { finishPaying(); + } } /** *

startPaying.

*/ - public void startPaying() { + public final void startPaying() { payment.setRequirements(this); payment.payCost(); } @@ -131,12 +135,13 @@ public class SpellAbility_Requirements { /** *

finishPaying.

*/ - public void finishPaying() { + public final void finishPaying() { if (isFree || payment.isAllPaid()) { - if (skipStack) + if (skipStack) { AbilityFactory.resolve(ability, false); - else + } else { addAbilityToStack(); + } select.resetTargets(); AllZone.getGameAction().checkStateEffects(); @@ -147,8 +152,9 @@ public class SpellAbility_Requirements { AllZone.getGameAction().moveTo(fromZone, c); } - if (select != null) + if (select != null) { select.resetTargets(); + } ability.resetOnceResolved(); payment.cancelPayment(); @@ -159,7 +165,7 @@ public class SpellAbility_Requirements { /** *

addAbilityToStack.

*/ - public void addAbilityToStack() { + public final void addAbilityToStack() { // For older abilities that don't setStackDescription set it here if (ability.getStackDescription().equals("")) { StringBuilder sb = new StringBuilder(); @@ -168,8 +174,9 @@ public class SpellAbility_Requirements { ArrayList targets = ability.getTarget().getTargets(); if (targets.size() > 0) { sb.append(" - Targeting "); - for (Object o : targets) + for (Object o : targets) { sb.append(o.toString()).append(" "); + } } }