mirror of
https://github.com/correl/mage.git
synced 2024-11-15 19:19:33 +00:00
Changes to buyback, added random discard to DiscardCost.
This commit is contained in:
parent
a8d45df9bb
commit
48f7eace00
4 changed files with 81 additions and 29 deletions
|
@ -28,6 +28,8 @@
|
|||
|
||||
package mage.abilities.costs;
|
||||
|
||||
import mage.abilities.costs.mana.ManaCostsImpl;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
|
@ -103,7 +105,7 @@ public class OptionalAdditionalCostImpl <T extends OptionalAdditionalCostImpl<T>
|
|||
*/
|
||||
@Override
|
||||
public String getCastSuffixMessage(int position) {
|
||||
return "";
|
||||
return " with " + name;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
*/
|
||||
package mage.abilities.costs.common;
|
||||
|
||||
import mage.filter.FilterCard;
|
||||
import mage.target.common.TargetCardInHand;
|
||||
|
||||
/**
|
||||
|
@ -36,7 +37,11 @@ import mage.target.common.TargetCardInHand;
|
|||
public class DiscardCardCost extends DiscardTargetCost {
|
||||
|
||||
public DiscardCardCost() {
|
||||
super(new TargetCardInHand());
|
||||
this(false);
|
||||
}
|
||||
|
||||
public DiscardCardCost(boolean randomDiscard) {
|
||||
super(new TargetCardInHand(new FilterCard("a Card at random")), randomDiscard);
|
||||
}
|
||||
|
||||
public DiscardCardCost(DiscardCardCost cost) {
|
||||
|
|
|
@ -46,9 +46,15 @@ import mage.target.common.TargetCardInHand;
|
|||
public class DiscardTargetCost extends CostImpl<DiscardTargetCost> {
|
||||
|
||||
List<Card> cards = new ArrayList<Card>();
|
||||
protected boolean randomDiscard;
|
||||
|
||||
public DiscardTargetCost(TargetCardInHand target) {
|
||||
this(target, false);
|
||||
}
|
||||
|
||||
public DiscardTargetCost(TargetCardInHand target, boolean randomDiscard) {
|
||||
this.addTarget(target);
|
||||
this.randomDiscard = randomDiscard;
|
||||
this.text = "Discard " + target.getTargetName();
|
||||
}
|
||||
|
||||
|
@ -57,19 +63,32 @@ public class DiscardTargetCost extends CostImpl<DiscardTargetCost> {
|
|||
for (Card card: cost.cards) {
|
||||
this.cards.add(card.copy());
|
||||
}
|
||||
this.randomDiscard = cost.randomDiscard;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana) {
|
||||
if (targets.choose(Outcome.Discard, controllerId, sourceId, game)) {
|
||||
Player player = game.getPlayer(controllerId);
|
||||
for (UUID targetId: targets.get(0).getTargets()) {
|
||||
Card card = player.getHand().get(targetId, game);
|
||||
if (card == null) {
|
||||
return false;
|
||||
Player player = game.getPlayer(controllerId);
|
||||
if (randomDiscard) {
|
||||
int amount = this.getTargets().get(0).getMaxNumberOfTargets();
|
||||
int maxAmount = Math.min(amount, player.getHand().size());
|
||||
for (int i = 0; i < maxAmount; i++) {
|
||||
Card card = player.getHand().getRandom(game);
|
||||
if (card != null) {
|
||||
paid |= player.discard(card, null, game);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (targets.choose(Outcome.Discard, controllerId, sourceId, game)) {
|
||||
|
||||
for (UUID targetId: targets.get(0).getTargets()) {
|
||||
Card card = player.getHand().get(targetId, game);
|
||||
if (card == null) {
|
||||
return false;
|
||||
}
|
||||
this.cards.add(card.copy());
|
||||
paid |= player.discard(card, null, game);
|
||||
}
|
||||
this.cards.add(card.copy());
|
||||
paid |= player.discard(card, null, game);
|
||||
}
|
||||
}
|
||||
return paid;
|
||||
|
|
|
@ -40,7 +40,6 @@ import mage.abilities.costs.Costs;
|
|||
import mage.abilities.costs.OptionalAdditionalCost;
|
||||
import mage.abilities.costs.OptionalAdditionalCostImpl;
|
||||
import mage.abilities.costs.OptionalAdditionalSourceCosts;
|
||||
import mage.abilities.costs.mana.BuybackManaCost;
|
||||
import mage.abilities.costs.mana.ManaCostsImpl;
|
||||
import mage.abilities.effects.ReplacementEffectImpl;
|
||||
import mage.cards.Card;
|
||||
|
@ -56,24 +55,29 @@ import mage.players.Player;
|
|||
|
||||
public class BuybackAbility extends StaticAbility<BuybackAbility> implements OptionalAdditionalSourceCosts {
|
||||
|
||||
private static final String keywordTextMana = "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 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>();
|
||||
|
||||
public BuybackAbility(String manaString) {
|
||||
super(Zone.STACK, new BuybackEffect());
|
||||
this.buybackCosts.add(new BuybackManaCost(manaString));
|
||||
OptionalAdditionalCostImpl buybackCost = new OptionalAdditionalCostImpl(keywordTextMana, reminderTextMana, new ManaCostsImpl(manaString));
|
||||
buybackCosts.add(buybackCost);
|
||||
setRuleAtTheTop(true);
|
||||
}
|
||||
|
||||
public BuybackAbility(Cost cost) {
|
||||
super(Zone.STACK, new BuybackEffect());
|
||||
OptionalAdditionalCostImpl buybackCost = new OptionalAdditionalCostImpl("Buyback", "(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.)", cost);
|
||||
this.buybackCosts.add(buybackCost);
|
||||
OptionalAdditionalCostImpl buybackCost = new OptionalAdditionalCostImpl(keywordTextCost, reminderTextCost, cost);
|
||||
buybackCosts.add(buybackCost);
|
||||
setRuleAtTheTop(true);
|
||||
}
|
||||
|
||||
public BuybackAbility(final BuybackAbility ability) {
|
||||
super(ability);
|
||||
this.buybackCosts = ability.buybackCosts;
|
||||
buybackCosts = ability.buybackCosts;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -81,6 +85,16 @@ public class BuybackAbility extends StaticAbility<BuybackAbility> implements Opt
|
|||
return new BuybackAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCost(Cost cost) {
|
||||
if (buybackCosts.size() > 0) {
|
||||
((Costs) buybackCosts.get(0)).add(cost);
|
||||
} else {
|
||||
OptionalAdditionalCostImpl buybackCost = new OptionalAdditionalCostImpl(keywordTextCost, reminderTextCost, cost);
|
||||
buybackCosts.add(buybackCost);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isActivated() {
|
||||
for (OptionalAdditionalCost cost: buybackCosts) {
|
||||
if(cost.isActivated()) {
|
||||
|
@ -143,35 +157,47 @@ public class BuybackAbility extends StaticAbility<BuybackAbility> implements Opt
|
|||
@Override
|
||||
public String getRule() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String reminderText = "";
|
||||
int numberBuyback = 0;
|
||||
String remarkText = "";
|
||||
for (OptionalAdditionalCost buybackCost: buybackCosts) {
|
||||
if (numberBuyback == 0) {
|
||||
sb.append(buybackCost.getText(false));
|
||||
remarkText = buybackCost.getReminderText();
|
||||
reminderText = buybackCost.getReminderText();
|
||||
} else {
|
||||
sb.append(" and/or ").append(buybackCost.getText(true));
|
||||
sb.append(", ").append(buybackCost.getText(true));
|
||||
}
|
||||
++numberBuyback;
|
||||
}
|
||||
if (numberBuyback == 1) {
|
||||
sb.append(" ").append(remarkText);
|
||||
}
|
||||
sb.append(" ").append(reminderText);
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCastMessageSuffix() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int position = 0;
|
||||
for (OptionalAdditionalCost cost : buybackCosts) {
|
||||
if (cost.isActivated()) {
|
||||
sb.append(cost.getCastSuffixMessage(position));
|
||||
++position;
|
||||
}
|
||||
String message = "";
|
||||
if (isActivated()) {
|
||||
message = " with " + keywordTextMana;
|
||||
}
|
||||
return sb.toString();
|
||||
return message;
|
||||
}
|
||||
|
||||
public String getReminderText() {
|
||||
String costsReminderText = reminderTextCost;
|
||||
StringBuilder costsText = new StringBuilder();
|
||||
int costCounter = 0;
|
||||
for (OptionalAdditionalCost cost : buybackCosts) {
|
||||
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