mirror of
https://github.com/correl/mage.git
synced 2024-11-15 19:19:33 +00:00
Some changes to BuybackAbility.
This commit is contained in:
parent
e11fed3d03
commit
4a498fa256
1 changed files with 42 additions and 83 deletions
|
@ -28,8 +28,6 @@
|
||||||
package mage.abilities.keyword;
|
package mage.abilities.keyword;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import mage.Constants;
|
import mage.Constants;
|
||||||
import mage.Constants.Zone;
|
import mage.Constants.Zone;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
|
@ -49,35 +47,40 @@ import mage.game.events.ZoneChangeEvent;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 702.25. Buyback
|
||||||
|
*
|
||||||
|
* 702.25a Buyback appears on some instants and sorceries. It represents two static
|
||||||
|
* abilities that function while the spell is on the stack. "Buyback [cost]" means
|
||||||
|
* "You may pay an additional [cost] as you cast this spell" and "If the buyback
|
||||||
|
* cost was paid, put this spell into its owner's hand instead of into that player's
|
||||||
|
* graveyard as it resolves." Paying a spell's buyback cost follows the rules for
|
||||||
|
* paying additional costs in rules 601.2b and 601.2e-g.
|
||||||
*
|
*
|
||||||
* @author LevelX2
|
* @author LevelX2
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class BuybackAbility extends StaticAbility<BuybackAbility> implements OptionalAdditionalSourceCosts {
|
public class BuybackAbility extends StaticAbility<BuybackAbility> implements OptionalAdditionalSourceCosts {
|
||||||
|
|
||||||
private static final String keywordTextMana = "Buyback ";
|
private static final String keywordText = "Buyback";
|
||||||
private static final String keywordTextCost = "Buyback-";
|
|
||||||
private static final String reminderTextCost = "<i>(You may {cost} in addition to any other costs as you cast this spell. If you do, put this card into your hand as it resolves.)</i>";
|
private static final String reminderTextCost = "<i>(You may {cost} in addition to any other costs as you cast this spell. If you do, put this card into your hand as it resolves.)</i>";
|
||||||
private static final String reminderTextMana = "<i>(You may pay an additional {cost} as you cast this spell. If you do, put this card into your hand as it resolves.)</i>";
|
private static final String reminderTextMana = "<i>(You may pay an additional {cost} as you cast this spell. If you do, put this card into your hand as it resolves.)</i>";
|
||||||
protected List<OptionalAdditionalCost> buybackCosts = new LinkedList<OptionalAdditionalCost>();
|
protected OptionalAdditionalCost buybackCost;
|
||||||
|
|
||||||
public BuybackAbility(String manaString) {
|
public BuybackAbility(String manaString) {
|
||||||
super(Zone.STACK, new BuybackEffect());
|
super(Zone.STACK, new BuybackEffect());
|
||||||
OptionalAdditionalCostImpl buybackCost = new OptionalAdditionalCostImpl(keywordTextMana, reminderTextMana, new ManaCostsImpl(manaString));
|
this.buybackCost = new OptionalAdditionalCostImpl(keywordText, reminderTextMana, new ManaCostsImpl(manaString));
|
||||||
buybackCosts.add(buybackCost);
|
|
||||||
setRuleAtTheTop(true);
|
setRuleAtTheTop(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BuybackAbility(Cost cost) {
|
public BuybackAbility(Cost cost) {
|
||||||
super(Zone.STACK, new BuybackEffect());
|
super(Zone.STACK, new BuybackEffect());
|
||||||
OptionalAdditionalCostImpl buybackCost = new OptionalAdditionalCostImpl(keywordTextCost, reminderTextCost, cost);
|
this.buybackCost = new OptionalAdditionalCostImpl(keywordText, "-", reminderTextCost, cost);
|
||||||
buybackCosts.add(buybackCost);
|
|
||||||
setRuleAtTheTop(true);
|
setRuleAtTheTop(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BuybackAbility(final BuybackAbility ability) {
|
public BuybackAbility(final BuybackAbility ability) {
|
||||||
super(ability);
|
super(ability);
|
||||||
buybackCosts = ability.buybackCosts;
|
buybackCost = ability.buybackCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -87,65 +90,40 @@ public class BuybackAbility extends StaticAbility<BuybackAbility> implements Opt
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addCost(Cost cost) {
|
public void addCost(Cost cost) {
|
||||||
if (buybackCosts.size() > 0) {
|
if (buybackCost != null) {
|
||||||
((Costs) buybackCosts.get(0)).add(cost);
|
((Costs) buybackCost).add(cost);
|
||||||
} else {
|
|
||||||
OptionalAdditionalCostImpl buybackCost = new OptionalAdditionalCostImpl(keywordTextCost, reminderTextCost, cost);
|
|
||||||
buybackCosts.add(buybackCost);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isActivated() {
|
public boolean isActivated() {
|
||||||
for (OptionalAdditionalCost cost: buybackCosts) {
|
if (buybackCost != null) {
|
||||||
if(cost.isActivated()) {
|
return buybackCost.isActivated();
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetBuyback() {
|
public void resetBuyback() {
|
||||||
for (OptionalAdditionalCost cost: buybackCosts) {
|
if (buybackCost != null) {
|
||||||
cost.reset();
|
buybackCost.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OptionalAdditionalCost> getBuybackCosts () {
|
|
||||||
return buybackCosts;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addKickerManaCost(OptionalAdditionalCost kickerCost) {
|
|
||||||
buybackCosts.add(kickerCost);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addOptionalAdditionalCosts(Ability ability, Game game) {
|
public void addOptionalAdditionalCosts(Ability ability, Game game) {
|
||||||
if (ability instanceof SpellAbility) {
|
if (ability instanceof SpellAbility) {
|
||||||
Player player = game.getPlayer(controllerId);
|
Player player = game.getPlayer(controllerId);
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
this.resetBuyback();
|
this.resetBuyback();
|
||||||
for (OptionalAdditionalCost buybackCost: buybackCosts) {
|
if (buybackCost != null) {
|
||||||
boolean again = true;
|
if (player.chooseUse(Constants.Outcome.Benefit,new StringBuilder("Pay ").append(buybackCost.getText(false)).append(" ?").toString(), game)) {
|
||||||
while (again) {
|
buybackCost.activate();
|
||||||
String times = "";
|
for (Iterator it = ((Costs) buybackCost).iterator(); it.hasNext();) {
|
||||||
if (buybackCost.isRepeatable()) {
|
Cost cost = (Cost) it.next();
|
||||||
int activated = buybackCost.getActivateCount();
|
if (cost instanceof ManaCostsImpl) {
|
||||||
times = Integer.toString(activated + 1) + (activated == 0 ? " time ":" times ");
|
ability.getManaCostsToPay().add((ManaCostsImpl) cost.copy());
|
||||||
}
|
} else {
|
||||||
if (player.chooseUse(Constants.Outcome.Benefit, "Pay " + times + buybackCost.getText(false) + " ?", game)) {
|
ability.getCosts().add(cost.copy());
|
||||||
buybackCost.activate();
|
|
||||||
for (Iterator it = ((Costs) buybackCost).iterator(); it.hasNext();) {
|
|
||||||
Cost cost = (Cost) it.next();
|
|
||||||
if (cost instanceof ManaCostsImpl) {
|
|
||||||
ability.getManaCostsToPay().add((ManaCostsImpl) cost.copy());
|
|
||||||
} else {
|
|
||||||
ability.getCosts().add(cost.copy());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
again = buybackCost.isRepeatable();
|
|
||||||
} else {
|
|
||||||
again = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -156,48 +134,29 @@ public class BuybackAbility extends StaticAbility<BuybackAbility> implements Opt
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getRule() {
|
public String getRule() {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
String reminderText = "";
|
if (buybackCost != null) {
|
||||||
int numberBuyback = 0;
|
sb.append(buybackCost.getText(false));
|
||||||
for (OptionalAdditionalCost buybackCost: buybackCosts) {
|
sb.append(" ").append(buybackCost.getReminderText());
|
||||||
if (numberBuyback == 0) {
|
}
|
||||||
sb.append(buybackCost.getText(false));
|
return sb.toString();
|
||||||
reminderText = buybackCost.getReminderText();
|
|
||||||
} else {
|
|
||||||
sb.append(", ").append(buybackCost.getText(true));
|
|
||||||
}
|
|
||||||
++numberBuyback;
|
|
||||||
}
|
|
||||||
sb.append(" ").append(reminderText);
|
|
||||||
|
|
||||||
return sb.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCastMessageSuffix() {
|
public String getCastMessageSuffix() {
|
||||||
String message = "";
|
if (buybackCost != null) {
|
||||||
if (isActivated()) {
|
return buybackCost.getCastSuffixMessage(0);
|
||||||
message = " with " + keywordTextMana;
|
} else {
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
return message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getReminderText() {
|
public String getReminderText() {
|
||||||
String costsReminderText = reminderTextCost;
|
if (buybackCost != null) {
|
||||||
StringBuilder costsText = new StringBuilder();
|
return buybackCost.getReminderText();
|
||||||
int costCounter = 0;
|
} else {
|
||||||
for (OptionalAdditionalCost cost : buybackCosts) {
|
return "";
|
||||||
if (costCounter > 0) {
|
|
||||||
costsText.append(" and ");
|
|
||||||
} else {
|
|
||||||
if (((Costs)cost).get(0) instanceof ManaCostsImpl) {
|
|
||||||
costsReminderText = reminderTextMana;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
costsText.append(cost.getText(true));
|
|
||||||
++costCounter;
|
|
||||||
}
|
}
|
||||||
return costsReminderText.replace("{cost}", costsText);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue