Renamed TargetChooser.java back into TargetSelection (for Sol)

CostSacrifice - removed input, using a common one
other list-related costs use getDescriptiveType method from base class
InputPayManaExecuteCommands won't reset manaCost because the class is not reusable anyway.
This commit is contained in:
Maxmtg
2013-04-01 15:27:02 +00:00
parent b532e7147e
commit e329fe22c5
8 changed files with 24 additions and 117 deletions

2
.gitattributes vendored
View File

@@ -13766,7 +13766,7 @@ src/main/java/forge/card/spellability/SpellAbilityVariables.java svneol=native#t
src/main/java/forge/card/spellability/SpellPermanent.java svneol=native#text/plain
src/main/java/forge/card/spellability/Target.java svneol=native#text/plain
src/main/java/forge/card/spellability/TargetChoices.java svneol=native#text/plain
src/main/java/forge/card/spellability/TargetChooser.java svneol=native#text/plain
src/main/java/forge/card/spellability/TargetSelection.java svneol=native#text/plain
src/main/java/forge/card/spellability/package-info.java svneol=native#text/plain
src/main/java/forge/card/staticability/StaticAbility.java svneol=native#text/plain
src/main/java/forge/card/staticability/StaticAbilityCantAttackBlock.java -text

View File

@@ -91,13 +91,9 @@ public abstract class CostPart {
return this.typeDescription;
}
/**
* Gets the descriptive type.
*
* @return the descriptive type
*/
public final String getDescriptiveType() {
return this.getTypeDescription() == null ? this.getType() : this.getTypeDescription();
String typeDesc = this.getTypeDescription();
return typeDesc == null ? this.getType() : typeDesc;
}
/**

View File

@@ -24,85 +24,20 @@ import forge.CardLists;
import forge.FThreads;
import forge.card.ability.AbilityUtils;
import forge.card.spellability.SpellAbility;
import forge.control.input.InputPayment;
import forge.control.input.InputSelectCards;
import forge.control.input.InputSelectCardsFromList;
import forge.game.GameState;
import forge.game.ai.ComputerUtil;
import forge.game.player.AIPlayer;
import forge.game.player.Player;
import forge.game.zone.ZoneType;
import forge.gui.GuiDialog;
import forge.gui.match.CMatchUI;
import forge.view.ButtonUtil;
/**
* The Class CostSacrifice.
*/
public class CostSacrifice extends CostPartWithList {
/**
* TODO: Write javadoc for this type.
*
*/
public static final class InputPayCostSacrificeFromList extends InputPayCostBase {
private final CostSacrifice part;
private final SpellAbility sa;
private final int nNeeded;
private final List<Card> typeList;
private static final long serialVersionUID = 2685832214519141903L;
private int nSacrifices = 0;
/**
* TODO: Write javadoc for Constructor.
* @param part
* @param sa
* @param nNeeded
* @param payment
* @param typeList
*/
public InputPayCostSacrificeFromList(CostSacrifice part, SpellAbility sa, int nNeeded, List<Card> typeList) {
this.part = part;
this.sa = sa;
this.nNeeded = nNeeded;
this.typeList = typeList;
}
@Override
public void showMessage() {
if (nNeeded == 0) {
this.done();
}
final StringBuilder msg = new StringBuilder("Sacrifice ");
final int nLeft = nNeeded - this.nSacrifices;
msg.append(nLeft).append(" ");
msg.append(part.getDescriptiveType());
if (nLeft > 1) {
msg.append("s");
}
CMatchUI.SINGLETON_INSTANCE.showMessage(msg.toString());
ButtonUtil.enableOnlyCancel();
}
@Override
public void selectCard(final Card card) {
if (typeList.contains(card)) {
this.nSacrifices++;
part.executePayment(sa, card);
typeList.remove(card);
// in case nothing else to sacrifice
if (this.nSacrifices == nNeeded) {
this.done();
} else if (typeList.isEmpty()) {
// happen
this.cancel();
} else {
this.showMessage();
}
}
}
}
/**
* Instantiates a new cost sacrifice.
*
@@ -226,9 +161,14 @@ public class CostSacrifice extends CostPartWithList {
if (0 == c.intValue()) {
return true;
}
InputPayment inp = new InputPayCostSacrificeFromList(this, ability, c, list);
InputSelectCards inp = new InputSelectCardsFromList(c, c, list);
inp.setMessage("Select a " + this.getDescriptiveType() + " to sacrifice (%d left)");
FThreads.setInputAndWait(inp);
return inp.isPaid();
if ( inp.hasCancelled() )
return false;
return executePayment(ability, inp.getSelected());
}
return false;
}

View File

@@ -62,15 +62,6 @@ public class CostTapType extends CostPartWithList {
public boolean isReusable() { return true; }
/**
* Gets the description.
*
* @return the description
*/
public final String getDescription() {
return this.getTypeDescription() == null ? this.getType() : this.getTypeDescription();
}
/*
* (non-Javadoc)
*
@@ -82,7 +73,7 @@ public class CostTapType extends CostPartWithList {
sb.append("Tap ");
final Integer i = this.convertAmount();
final String desc = this.getDescription();
final String desc = this.getDescriptiveType();
final String type = this.getType();
if (type.contains("sharesCreatureTypeWith")) {
@@ -206,7 +197,7 @@ public class CostTapType extends CostPartWithList {
InputSelectCards inp = new InputSelectCardsFromList(c, c, typeList);
inp.setMessage("Select a " + getDescription() + " to tap (%d left)");
inp.setMessage("Select a " + getDescriptiveType() + " to tap (%d left)");
FThreads.setInputAndWait(inp);
if ( inp.hasCancelled() )
return false;

View File

@@ -59,15 +59,6 @@ public class CostUntapType extends CostPartWithList {
public boolean isReusable() { return true; }
/**
* Gets the description.
*
* @return the description
*/
public final String getDescription() {
return this.getTypeDescription() == null ? this.getType() : this.getTypeDescription();
}
/*
* (non-Javadoc)
*
@@ -79,7 +70,7 @@ public class CostUntapType extends CostPartWithList {
sb.append("Untap ");
final Integer i = this.convertAmount();
final String desc = this.getDescription();
final String desc = this.getDescriptiveType();
sb.append(Cost.convertAmountTypeToWords(i, this.getAmount(), " tapped " + desc));
@@ -161,7 +152,7 @@ public class CostUntapType extends CostPartWithList {
}
}
InputSelectCards inp = new InputSelectCardsFromList(c, c, typeList);
inp.setMessage("Select a " + getDescription() + " to untap (%d left)");
inp.setMessage("Select a " + getDescriptiveType() + " to untap (%d left)");
FThreads.setInputAndWait(inp);
if( inp.hasCancelled() || inp.getSelected().size() != c )
return false;

View File

@@ -70,7 +70,7 @@ public class SpellAbilityRequirements {
return;
}
final TargetChooser select = new TargetChooser(ability);
final TargetSelection select = new TargetSelection(ability);
// Skip to paying if parent ability doesn't target and has no
// subAbilities.
// (or trigger case where its already targeted)
@@ -113,7 +113,7 @@ public class SpellAbilityRequirements {
}
}
private void rollbackAbility(Zone fromZone, int zonePosition, TargetChooser select) {
private void rollbackAbility(Zone fromZone, int zonePosition, TargetSelection select) {
// cancel ability during target choosing
final Card c = this.ability.getSourceCard();

View File

@@ -42,11 +42,11 @@ import forge.gui.GuiChoose;
* @author Forge
* @version $Id$
*/
public class TargetChooser {
public class TargetSelection {
private final SpellAbility ability;
public TargetChooser(final SpellAbility sa) {
public TargetSelection(final SpellAbility sa) {
this.ability = sa;
}
@@ -58,7 +58,7 @@ public class TargetChooser {
return this.ability.getSourceCard();
}
private TargetChooser subSelection = null;
private TargetSelection subSelection = null;
private boolean bCancel = false;
private boolean bTargetingDone = false;
@@ -125,7 +125,7 @@ public class TargetChooser {
return true;
// Has Sub Ability
this.subSelection = new TargetChooser(abSub);
this.subSelection = new TargetSelection(abSub);
this.subSelection.clearTargets();
return this.subSelection.chooseTargets();
}
@@ -171,7 +171,7 @@ public class TargetChooser {
* </p>
* @return
*/
public final List<Card> chooseValidInput() {
private final List<Card> chooseValidInput() {
final Target tgt = this.getTgt();
final GameState game = ability.getActivatingPlayer().getGame();
final List<ZoneType> zone = tgt.getZone();

View File

@@ -34,7 +34,7 @@ import forge.view.ButtonUtil;
* @author Forge
* @version $Id$
*/
public class InputPayManaExecuteCommands extends InputPayManaBase implements InputPayment {
public class InputPayManaExecuteCommands extends InputPayManaBase {
/**
* Constant <code>serialVersionUID=3836655722696348713L</code>.
*/
@@ -80,14 +80,6 @@ public class InputPayManaExecuteCommands extends InputPayManaBase implements Inp
}
/**
* <p>
* resetManaCost.
* </p>
*/
public final void resetManaCost() {
this.manaCost = new ManaCostBeingPaid(this.originalManaCost);
}
@Override
public void selectPlayer(final Player selectedPlayer) {
@@ -109,7 +101,6 @@ public class InputPayManaExecuteCommands extends InputPayManaBase implements Inp
if (this.phyLifeToLose > 0) {
Singletons.getControl().getPlayer().payLife(this.phyLifeToLose, null);
}
this.resetManaCost();
Singletons.getControl().getPlayer().getManaPool().clearManaPaid(this.saPaidFor, false);
bPaid = true;
this.stop();
@@ -118,8 +109,6 @@ public class InputPayManaExecuteCommands extends InputPayManaBase implements Inp
/** {@inheritDoc} */
@Override
public final void selectButtonCancel() {
this.resetManaCost();
Singletons.getControl().getPlayer().getManaPool().refundManaPaid(this.saPaidFor, true);
bPaid = false;
this.stop();