Checkstyle fixes in SA_Condition and SA_Requirements

This commit is contained in:
slapshot5
2011-09-13 06:27:06 +00:00
parent 3a45c6ad23
commit 9645e948fb
2 changed files with 91 additions and 56 deletions

View File

@@ -1,7 +1,11 @@
package forge.card.spellability; 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.abilityFactory.AbilityFactory;
import forge.card.cardFactory.CardFactoryUtil; import forge.card.cardFactory.CardFactoryUtil;
@@ -32,25 +36,35 @@ public class SpellAbility_Condition extends SpellAbility_Variables {
* *
* @param params a {@link java.util.HashMap} object. * @param params a {@link java.util.HashMap} object.
*/ */
public void setConditions(HashMap<String, String> params) { public final void setConditions(final HashMap<String, String> params) {
if (params.containsKey("Condition")) { if (params.containsKey("Condition")) {
String value = params.get("Condition"); String value = params.get("Condition");
if (value.equals("Threshold")) setThreshold(true); if (value.equals("Threshold")) {
if (value.equals("Metalcraft")) setMetalcraft(true); setThreshold(true);
if (value.equals("Hellbent")) setHellbent(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")); setZone(params.get("ContitionZone"));
}
if (params.containsKey("ConditionSorcerySpeed")) if (params.containsKey("ConditionSorcerySpeed")) {
setSorcerySpeed(true); setSorcerySpeed(true);
}
if (params.containsKey("ConditionPlayerTurn")) if (params.containsKey("ConditionPlayerTurn")) {
setPlayerTurn(true); setPlayerTurn(true);
}
if (params.containsKey("ConditionOpponentTurn")) if (params.containsKey("ConditionOpponentTurn")) {
setOpponentTurn(true); setOpponentTurn(true);
}
if (params.containsKey("ConditionPhases")) { if (params.containsKey("ConditionPhases")) {
String phases = params.get("ConditionPhases"); String phases = params.get("ConditionPhases");
@@ -68,14 +82,16 @@ public class SpellAbility_Condition extends SpellAbility_Variables {
setPhases(phases); setPhases(phases);
} }
if (params.containsKey("ConditionCardsInHand")) if (params.containsKey("ConditionCardsInHand")) {
setActivateCardsInHand(Integer.parseInt(params.get("ConditionCardsInHand"))); setActivateCardsInHand(Integer.parseInt(params.get("ConditionCardsInHand")));
}
//Condition version of IsPresent stuff //Condition version of IsPresent stuff
if (params.containsKey("ConditionPresent")) { if (params.containsKey("ConditionPresent")) {
setIsPresent(params.get("ConditionPresent")); setIsPresent(params.get("ConditionPresent"));
if (params.containsKey("ConditionCompare")) if (params.containsKey("ConditionCompare")) {
setPresentCompare(params.get("ConditionCompare")); setPresentCompare(params.get("ConditionCompare"));
}
} }
if (params.containsKey("ConditionDefined")) { if (params.containsKey("ConditionDefined")) {
@@ -95,8 +111,8 @@ public class SpellAbility_Condition extends SpellAbility_Variables {
} }
} }
if(params.containsKey("ConditionManaSpent")) { if (params.containsKey("ConditionManaSpent")) {
setManaSpent(params.get("ConditionManaSpent")); setManaSpent(params.get("ConditionManaSpent"));
} }
if (params.containsKey("CheckSVar")) { if (params.containsKey("CheckSVar")) {
@@ -107,7 +123,7 @@ public class SpellAbility_Condition extends SpellAbility_Variables {
setSvarOperand(params.get("SVarCompare").substring(2)); setSvarOperand(params.get("SVarCompare").substring(2));
} }
}//setConditions } //setConditions
/** /**
* <p>checkConditions.</p> * <p>checkConditions.</p>
@@ -115,38 +131,46 @@ public class SpellAbility_Condition extends SpellAbility_Variables {
* @param sa a {@link forge.card.spellability.SpellAbility} object. * @param sa a {@link forge.card.spellability.SpellAbility} object.
* @return a boolean. * @return a boolean.
*/ */
public boolean checkConditions(SpellAbility sa) { public final boolean checkConditions(final SpellAbility sa) {
Player activator = sa.getActivatingPlayer(); Player activator = sa.getActivatingPlayer();
if (activator == null) { if (activator == null) {
activator = sa.getSourceCard().getController(); 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 (hellbent) {
if (!activator.hasHellbent()) if (!activator.hasHellbent()) {
return false; return false;
}
} }
if (threshold) { if (threshold) {
if (!activator.hasThreshold()) if (!activator.hasThreshold()) {
return false; return false;
}
} }
if (metalcraft) { if (metalcraft) {
if (!activator.hasMetalcraft()) if (!activator.hasMetalcraft()) {
return false; return false;
}
} }
if (bSorcerySpeed && !Phase.canCastSorcery(activator)) if (bSorcerySpeed && !Phase.canCastSorcery(activator)) {
return false; return false;
}
if (bPlayerTurn && !AllZone.getPhase().isPlayerTurn(activator)) if (bPlayerTurn && !AllZone.getPhase().isPlayerTurn(activator)) {
return false; return false;
}
if (bOpponentTurn && AllZone.getPhase().isPlayerTurn(activator)) if (bOpponentTurn && AllZone.getPhase().isPlayerTurn(activator)) {
return false; return false;
}
if (activationLimit != -1 && numberTurnActivations >= activationLimit) if (activationLimit != -1 && numberTurnActivations >= activationLimit) {
return false; return false;
}
if (phases.size() > 0) { if (phases.size() > 0) {
boolean isPhase = false; boolean isPhase = false;
@@ -158,14 +182,16 @@ public class SpellAbility_Condition extends SpellAbility_Variables {
} }
} }
if (!isPhase) if (!isPhase) {
return false; return false;
}
} }
if (nCardsInHand != -1) { if (nCardsInHand != -1) {
// Can handle Library of Alexandria, or Hellbent // Can handle Library of Alexandria, or Hellbent
if (AllZoneUtil.getPlayerHand(activator).size() != nCardsInHand) if (AllZoneUtil.getPlayerHand(activator).size() != nCardsInHand) {
return false; return false;
}
} }
if (sIsPresent != null) { if (sIsPresent != null) {
@@ -188,8 +214,9 @@ public class SpellAbility_Condition extends SpellAbility_Variables {
int left = list.size(); int left = list.size();
if (!AllZoneUtil.compare(left, presentCompare, right)) if (!AllZoneUtil.compare(left, presentCompare, right)) {
return false; return false;
}
} }
if (lifeTotal != null) { if (lifeTotal != null) {
@@ -214,22 +241,23 @@ public class SpellAbility_Condition extends SpellAbility_Variables {
} }
} }
if(null != manaSpent) { if (null != manaSpent) {
if(!sa.getSourceCard().getColorsPaid().contains(manaSpent)) { if (!sa.getSourceCard().getColorsPaid().contains(manaSpent)) {
return false; return false;
} }
} }
if (svarToCheck != null) { if (svarToCheck != null) {
int svarValue = AbilityFactory.calculateAmount(sa.getSourceCard(), svarToCheck, sa); int svarValue = AbilityFactory.calculateAmount(sa.getSourceCard(), svarToCheck, sa);
int operandValue = AbilityFactory.calculateAmount(sa.getSourceCard(), svarOperand, sa); int operandValue = AbilityFactory.calculateAmount(sa.getSourceCard(), svarOperand, sa);
if (!AllZoneUtil.compare(svarValue, svarOperator, operandValue)) if (!AllZoneUtil.compare(svarValue, svarOperator, operandValue)) {
return false; return false;
}
} }
return true; return true;
} }
}//end class SpellAbility_Condition } //end class SpellAbility_Condition

View File

@@ -26,7 +26,7 @@ public class SpellAbility_Requirements {
* *
* @param bSkip a boolean. * @param bSkip a boolean.
*/ */
public void setSkipStack(boolean bSkip) { public final void setSkipStack(final boolean bSkip) {
skipStack = bSkip; skipStack = bSkip;
} }
@@ -35,7 +35,7 @@ public class SpellAbility_Requirements {
* *
* @param bFree a boolean. * @param bFree a boolean.
*/ */
public void setFree(boolean bFree) { public final void setFree(final boolean bFree) {
isFree = bFree; isFree = bFree;
} }
@@ -49,7 +49,7 @@ public class SpellAbility_Requirements {
* @param ts a {@link forge.card.spellability.Target_Selection} object. * @param ts a {@link forge.card.spellability.Target_Selection} object.
* @param cp a {@link forge.card.cost.Cost_Payment} 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; ability = sa;
select = ts; select = ts;
payment = cp; payment = cp;
@@ -58,7 +58,7 @@ public class SpellAbility_Requirements {
/** /**
* <p>fillRequirements.</p> * <p>fillRequirements.</p>
*/ */
public void fillRequirements() { public final void fillRequirements() {
fillRequirements(false); fillRequirements(false);
} }
@@ -67,7 +67,7 @@ public class SpellAbility_Requirements {
* *
* @param skipTargeting a boolean. * @param skipTargeting a boolean.
*/ */
public void fillRequirements(boolean skipTargeting) { public final void fillRequirements(final boolean skipTargeting) {
if (ability instanceof Spell && !bCasting) { if (ability instanceof Spell && !bCasting) {
// remove from hand // remove from hand
bCasting = true; bCasting = true;
@@ -82,19 +82,21 @@ public class SpellAbility_Requirements {
// freeze Stack. No abilities should go onto the stack while I'm filling requirements. // freeze Stack. No abilities should go onto the stack while I'm filling requirements.
AllZone.getStack().freezeStack(); 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)) { if (!skipTargeting && (select.doesTarget() || ability.getSubAbility() != null)) {
select.setRequirements(this); select.setRequirements(this);
select.resetTargets(); select.resetTargets();
select.chooseTargets(); select.chooseTargets();
} else } else {
needPayment(); needPayment();
}
} }
/** /**
* <p>finishedTargeting.</p> * <p>finishedTargeting.</p>
*/ */
public void finishedTargeting() { public final void finishedTargeting() {
if (select.isCanceled()) { if (select.isCanceled()) {
// cancel ability during target choosing // cancel ability during target choosing
Card c = ability.getSourceCard(); Card c = ability.getSourceCard();
@@ -106,24 +108,26 @@ public class SpellAbility_Requirements {
select.resetTargets(); select.resetTargets();
AllZone.getStack().clearFrozen(); AllZone.getStack().clearFrozen();
return; return;
} else } else {
needPayment(); needPayment();
}
} }
/** /**
* <p>needPayment.</p> * <p>needPayment.</p>
*/ */
public void needPayment() { public final void needPayment() {
if (!isFree) if (!isFree) {
startPaying(); startPaying();
else } else {
finishPaying(); finishPaying();
}
} }
/** /**
* <p>startPaying.</p> * <p>startPaying.</p>
*/ */
public void startPaying() { public final void startPaying() {
payment.setRequirements(this); payment.setRequirements(this);
payment.payCost(); payment.payCost();
} }
@@ -131,12 +135,13 @@ public class SpellAbility_Requirements {
/** /**
* <p>finishPaying.</p> * <p>finishPaying.</p>
*/ */
public void finishPaying() { public final void finishPaying() {
if (isFree || payment.isAllPaid()) { if (isFree || payment.isAllPaid()) {
if (skipStack) if (skipStack) {
AbilityFactory.resolve(ability, false); AbilityFactory.resolve(ability, false);
else } else {
addAbilityToStack(); addAbilityToStack();
}
select.resetTargets(); select.resetTargets();
AllZone.getGameAction().checkStateEffects(); AllZone.getGameAction().checkStateEffects();
@@ -147,8 +152,9 @@ public class SpellAbility_Requirements {
AllZone.getGameAction().moveTo(fromZone, c); AllZone.getGameAction().moveTo(fromZone, c);
} }
if (select != null) if (select != null) {
select.resetTargets(); select.resetTargets();
}
ability.resetOnceResolved(); ability.resetOnceResolved();
payment.cancelPayment(); payment.cancelPayment();
@@ -159,7 +165,7 @@ public class SpellAbility_Requirements {
/** /**
* <p>addAbilityToStack.</p> * <p>addAbilityToStack.</p>
*/ */
public void addAbilityToStack() { public final void addAbilityToStack() {
// For older abilities that don't setStackDescription set it here // For older abilities that don't setStackDescription set it here
if (ability.getStackDescription().equals("")) { if (ability.getStackDescription().equals("")) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@@ -168,8 +174,9 @@ public class SpellAbility_Requirements {
ArrayList<Object> targets = ability.getTarget().getTargets(); ArrayList<Object> targets = ability.getTarget().getTargets();
if (targets.size() > 0) { if (targets.size() > 0) {
sb.append(" - Targeting "); sb.append(" - Targeting ");
for (Object o : targets) for (Object o : targets) {
sb.append(o.toString()).append(" "); sb.append(o.toString()).append(" ");
}
} }
} }