Code cleanup

This commit is contained in:
drdev
2013-12-01 03:21:51 +00:00
parent 9b2f3f3108
commit 5009ebe0ab

View File

@@ -29,7 +29,6 @@ import forge.view.ButtonUtil;
* *
*/ */
public abstract class InputPayMana extends InputSyncronizedBase { public abstract class InputPayMana extends InputSyncronizedBase {
private static final long serialVersionUID = -9133423708688480255L; private static final long serialVersionUID = -9133423708688480255L;
protected int phyLifeToLose = 0; protected int phyLifeToLose = 0;
@@ -47,8 +46,6 @@ public abstract class InputPayMana extends InputSyncronizedBase {
this.saPaidFor = saToPayFor; this.saPaidFor = saToPayFor;
} }
@Override @Override
protected void onCardSelected(final Card card, final MouseEvent triggerEvent) { protected void onCardSelected(final Card card, final MouseEvent triggerEvent) {
if (card.getManaAbility().isEmpty()) { if (card.getManaAbility().isEmpty()) {
@@ -76,7 +73,8 @@ public abstract class InputPayMana extends InputSyncronizedBase {
protected void useManaFromPool(byte colorCode) { useManaFromPool(colorCode, manaCost); } protected void useManaFromPool(byte colorCode) { useManaFromPool(colorCode, manaCost); }
protected void useManaFromPool(byte colorCode, ManaCostBeingPaid manaCost) { protected void useManaFromPool(byte colorCode, ManaCostBeingPaid manaCost) {
// Convert Color to short String // Convert Color to short String
player.getManaPool().payManaFromPool(saPaidFor, manaCost, ManaCostShard.parseNonGeneric(MagicColor.toShortString(colorCode))); player.getManaPool().payManaFromPool(saPaidFor, manaCost,
ManaCostShard.parseNonGeneric(MagicColor.toShortString(colorCode)));
onManaAbilityPlayed(null); onManaAbilityPlayed(null);
showMessage(); showMessage();
@@ -105,8 +103,8 @@ public abstract class InputPayMana extends InputSyncronizedBase {
byte colorNeeded = 0; byte colorNeeded = 0;
for (final byte color : MagicColor.WUBRG) { for (final byte color : MagicColor.WUBRG) {
if (manaCost.isAnyPartPayableWith(color)) colorCanUse |= color; if (manaCost.isAnyPartPayableWith(color)) { colorCanUse |= color; }
if (manaCost.needsColor(color)) colorNeeded |= color; if (manaCost.needsColor(color)) { colorNeeded |= color; }
} }
boolean canUseColorless = manaCost.isAnyPartPayableWith((byte)0); boolean canUseColorless = manaCost.isAnyPartPayableWith((byte)0);
@@ -114,25 +112,27 @@ public abstract class InputPayMana extends InputSyncronizedBase {
// you can't remove unneeded abilities inside a for(am:abilities) loop :( // you can't remove unneeded abilities inside a for(am:abilities) loop :(
final String typeRes = manaCost.getSourceRestriction(); final String typeRes = manaCost.getSourceRestriction();
if( StringUtils.isNotBlank(typeRes) && !card.isType(typeRes)) if (StringUtils.isNotBlank(typeRes) && !card.isType(typeRes)) {
return; return;
}
boolean guessAbilityWithRequiredColors = true; boolean guessAbilityWithRequiredColors = true;
for (SpellAbility ma : card.getManaAbility()) { for (SpellAbility ma : card.getManaAbility()) {
ma.setActivatingPlayer(player); ma.setActivatingPlayer(player);
AbilityManaPart m = ma.getManaPartRecursive(); AbilityManaPart m = ma.getManaPartRecursive();
if (m == null || !ma.canPlay()) continue; if (m == null || !ma.canPlay()) { continue; }
if (!canUseColorless && !abilityProducesManaColor(ma, m, colorCanUse)) continue; if (!canUseColorless && !abilityProducesManaColor(ma, m, colorCanUse)) { continue; }
if (ma.isAbility() && ma.getRestrictions().isInstantSpeed()) continue; if (ma.isAbility() && ma.getRestrictions().isInstantSpeed()) { continue; }
if (!m.meetsManaRestrictions(saPaidFor)) continue; if (!m.meetsManaRestrictions(saPaidFor)) { continue; }
abilities.add(ma); abilities.add(ma);
// skip express mana if the ability is not undoable or reusable // skip express mana if the ability is not undoable or reusable
if (!ma.isUndoable() || !ma.getPayCosts().isRenewableResource() || ma.getSubAbility() != null) if (!ma.isUndoable() || !ma.getPayCosts().isRenewableResource() || ma.getSubAbility() != null) {
guessAbilityWithRequiredColors = false; guessAbilityWithRequiredColors = false;
} }
}
if (abilities.isEmpty()) { if (abilities.isEmpty()) {
return; return;
@@ -149,8 +149,6 @@ public abstract class InputPayMana extends InputSyncronizedBase {
} }
} }
// If the card has sunburst or any other ability that tracks mana spent, // If the card has sunburst or any other ability that tracks mana spent,
// skip express Mana choice // skip express Mana choice
if (saPaidFor.getSourceCard() != null && saPaidFor.getSourceCard().hasKeyword("Sunburst") && saPaidFor.isSpell()) { if (saPaidFor.getSourceCard() != null && saPaidFor.getSourceCard().hasKeyword("Sunburst") && saPaidFor.isSpell()) {
@@ -163,16 +161,17 @@ public abstract class InputPayMana extends InputSyncronizedBase {
// express Mana Choice // express Mana Choice
final ArrayList<SpellAbility> colorMatches = new ArrayList<SpellAbility>(); final ArrayList<SpellAbility> colorMatches = new ArrayList<SpellAbility>();
for (SpellAbility sa : abilities) { for (SpellAbility sa : abilities) {
if (colorNeeded != 0 && abilityProducesManaColor(sa, sa.getManaPartRecursive(), colorNeeded)) if (colorNeeded != 0 && abilityProducesManaColor(sa, sa.getManaPartRecursive(), colorNeeded)) {
colorMatches.add(sa); colorMatches.add(sa);
} }
}
if (colorMatches.isEmpty()) { if (colorMatches.isEmpty()) {
// can only match colorless just grab the first and move on. // can only match colorless just grab the first and move on.
// This is wrong. Sometimes all abilities aren't created equal // This is wrong. Sometimes all abilities aren't created equal
choice = false; choice = false;
} else if (colorMatches.size() < abilities.size()) { }
else if (colorMatches.size() < abilities.size()) {
// leave behind only color matches // leave behind only color matches
abilities = colorMatches; abilities = colorMatches;
} }
@@ -246,7 +245,8 @@ public abstract class InputPayMana extends InputSyncronizedBase {
return true; return true;
} }
} }
} else { }
else {
String colorsProduced = m.isComboMana() ? m.getComboColors() : m.getOrigProduced(); String colorsProduced = m.isComboMana() ? m.getComboColors() : m.getOrigProduced();
for (final String color : colorsProduced.split(" ")) { for (final String color : colorsProduced.split(" ")) {
if (0 != (neededColor & MagicColor.fromName(color))) { if (0 != (neededColor & MagicColor.fromName(color))) {
@@ -258,8 +258,9 @@ public abstract class InputPayMana extends InputSyncronizedBase {
} }
public void onManaAbilityPlayed(final SpellAbility saPaymentSrc) { public void onManaAbilityPlayed(final SpellAbility saPaymentSrc) {
if ( saPaymentSrc != null) // null comes when they've paid from pool if (saPaymentSrc != null) { // null comes when they've paid from pool
player.getManaPool().payManaFromAbility(saPaidFor, manaCost, saPaymentSrc); player.getManaPool().payManaFromAbility(saPaidFor, manaCost, saPaymentSrc);
}
onManaAbilityPaid(); onManaAbilityPaid();
} }
@@ -271,21 +272,27 @@ public abstract class InputPayMana extends InputSyncronizedBase {
return bPaid; return bPaid;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void showMessage() { public void showMessage() {
if ( isFinished() ) return; if (isFinished()) { return; }
ButtonUtil.enableOnlyCancel(); ButtonUtil.enableOnlyCancel();
onStateChanged(); onStateChanged();
} }
protected void onStateChanged() { protected void onStateChanged() {
if( isAlreadyPaid() ) { if(isAlreadyPaid()) {
done(); done();
stop(); stop();
} else }
FThreads.invokeInEdtNowOrLater(new Runnable() { @Override public void run(){ updateMessage(); }}); else {
FThreads.invokeInEdtNowOrLater(new Runnable() {
@Override
public void run() {
updateMessage();
}
});
}
} }
protected void onManaAbilityPaid() {} // some inputs overload it protected void onManaAbilityPaid() {} // some inputs overload it