Refactor how human pays for FlipCoin part

This commit is contained in:
Hans Mackowiak
2020-07-31 14:35:03 +00:00
parent 2d5c94aac8
commit 45b6a0b0a6
9 changed files with 37 additions and 48 deletions

View File

@@ -18,14 +18,13 @@
package forge.game.cost;
import forge.game.ability.effects.FlipCoinEffect;
import forge.game.card.Card;
import forge.game.player.Player;
import forge.game.spellability.SpellAbility;
/**
* This is for the "FlipCoin" Cost
*/
public class CostFlipCoin extends CostPartWithList {
public class CostFlipCoin extends CostPart {
/**
* Serializables need a version ID.
@@ -42,18 +41,6 @@ public class CostFlipCoin extends CostPartWithList {
this.setAmount(amount);
}
/* (non-Javadoc)
* @see forge.card.cost.CostPartWithList#getHashForList()
*/
@Override
public String getHashForLKIList() {
return "Flipped";
}
@Override
public String getHashForCardList() {
return "FlippedCards";
}
/*
* (non-Javadoc)
*
@@ -71,15 +58,13 @@ public class CostFlipCoin extends CostPartWithList {
return Cost.convertAmountTypeToWords(this.convertAmount(), this.getAmount(), "Coin");
}
/* (non-Javadoc)
* @see forge.card.cost.CostPartWithList#executePayment(forge.card.spellability.SpellAbility, forge.Card)
*/
@Override
protected Card doPayment(SpellAbility ability, Card targetCard) {
final Player activator = ability.getActivatingPlayer();
int i = FlipCoinEffect.getFilpMultiplier(activator);
FlipCoinEffect.flipCoinCall(activator, ability, i);
return targetCard;
public boolean payAsDecided(Player payer, PaymentDecision pd, SpellAbility sa) {
int m = FlipCoinEffect.getFilpMultiplier(payer);
for (int i = 0; i < pd.c; i++) {
FlipCoinEffect.flipCoinCall(payer, sa, m);
}
return true;
}
public <T> T accept(ICostVisitor<T> visitor) {

View File

@@ -132,12 +132,8 @@ public abstract class CostPartWithList extends CostPart {
}
cardList.addAll(doListPayment(ability, targetCards));
} else {
if (targetCards.isEmpty() && this instanceof CostFlipCoin) {
doPayment(ability, null); // TODO: generalize for other cost types if necessary
} else {
for (Card c : targetCards) {
executePayment(ability, c);
}
for (Card c : targetCards) {
executePayment(ability, c);
}
}
handleChangeZoneTrigger(payer, ability, targetCards);

View File

@@ -1658,8 +1658,8 @@ lblOr=oder
lblDoYouWantPay=Möchtest du bezahlen:
lblDoYouWantPayNLife=Möchtest du {0} Leben bezahlen?
lblDoyouWantTo=Möchtest du
lblDoYouWantMillNCardsOrDoAction=Möchtest du {0} Karte(n) von der Bibliothek auf den Friedhof legen?
lblDoYouWantFlipNCoinOrDoAction=Möchtest du {0} Münze(n) werfen? {1}
lblDoYouWantMillNCardsOrDoAction=Möchtest du {0} Karte(n) von der Bibliothek auf den Friedhof legen? {1}
lblDoYouWantFlipNCoinAction=Möchtest du {0} Münze(n) werfen?
lblDoYouWantRemoveNTargetTypeCounterFromCard=Möchtest du {0} {1}-Marken von {2} entfernen?
lblDoYouWantRemoveCountersFromCard=Möchtest du Marken von {0} entfernen?
lblDoYouWantExileNCardsFromYourLibrary=Möchtest du {0} Karte(n) von deiner Bibliothek ins Exil schicken?

View File

@@ -1659,7 +1659,7 @@ lblDoYouWantPay=Do you want to pay
lblDoYouWantPayNLife=Do you want to pay {0} life?
lblDoyouWantTo=Do you want to
lblDoYouWantMillNCardsOrDoAction=Do you want to mill {0} card(s)? {1}
lblDoYouWantFlipNCoinOrDoAction=Do you want to flip {0} coin(s)? {1}
lblDoYouWantFlipNCoinAction=Do you want to flip {0} coin(s)?
lblDoYouWantRemoveNTargetTypeCounterFromCard=Do you want to remove {0} {1} counter from {2}?
lblDoYouWantRemoveCountersFromCard=Do you want to remove counters from {0}?
lblDoYouWantExileNCardsFromYourLibrary=Do you want to exile {0} card(s) from your library?

View File

@@ -1659,7 +1659,7 @@ lblDoYouWantPay=¿Quieres pagar
lblDoYouWantPayNLife=¿Quieres pagar {0} de vida?
lblDoyouWantTo=¿Quieres
lblDoYouWantMillNCardsOrDoAction=¿Quieres moler {0} carta(s)? {1}
lblDoYouWantFlipNCoinOrDoAction=¿Quieres lanzar {0} moneda(s)? {1}
lblDoYouWantFlipNCoinAction=¿Quieres lanzar {0} moneda(s)?
lblDoYouWantRemoveNTargetTypeCounterFromCard=¿Quieres quitar el contador {0} {1} de {2}?
lblDoYouWantRemoveCountersFromCard=¿Quieres quitar los contadores de {0}?
lblDoYouWantExileNCardsFromYourLibrary=¿Quieres exiliar {0} carta(s) de tu biblioteca?

View File

@@ -1659,7 +1659,7 @@ lblDoYouWantPay=Do you want to pay
lblDoYouWantPayNLife=Do you want to pay {0} life?
lblDoyouWantTo=Do you want to
lblDoYouWantMillNCardsOrDoAction=Do you want to mill {0} card(s)? {1}
lblDoYouWantFlipNCoinOrDoAction=Do you want to flip {0} coin(s)? {1}
lblDoYouWantFlipNCoinAction=Do you want to flip {0} coin(s)?
lblDoYouWantRemoveNTargetTypeCounterFromCard=Do you want to remove {0} {1} counter from {2}?
lblDoYouWantRemoveCountersFromCard=Do you want to remove counters from {0}?
lblDoYouWantExileNCardsFromYourLibrary=Do you want to exile {0} card(s) from your library?

View File

@@ -1659,7 +1659,7 @@ lblDoYouWantPay=你想要支付
lblDoYouWantPayNLife=你想要支付{0}点生命吗?
lblDoyouWantTo=你想要
lblDoYouWantMillNCardsOrDoAction=你想要磨{0}张牌吗? {1}
lblDoYouWantFlipNCoinOrDoAction=你想要抛{0}个硬币吗? {1}
lblDoYouWantFlipNCoinAction=你想要抛{0}个硬币吗?
lblDoYouWantRemoveNTargetTypeCounterFromCard=你想要从{2}移除{0}个{1}指示物吗?
lblDoYouWantRemoveCountersFromCard=你想要从{0}删除指示物吗?
lblDoYouWantExileNCardsFromYourLibrary=你想要从你的牌库放逐{0}张牌吗?

View File

@@ -525,14 +525,13 @@ public class HumanCostDecision extends CostDecisionMakerBase {
Integer c = cost.convertAmount();
if (c == null) {
final String sVar = ability.getSVar(amount);
// Generalize this
if (sVar.equals("XChoice")) {
c = chooseXValue(cost.getLKIList().size());
} else {
c = AbilityUtils.calculateAmount(source, amount, ability);
}
c = AbilityUtils.calculateAmount(source, amount, ability);
}
if (!player.getController().confirmPayment(cost, Localizer.getInstance().getMessage("lblDoYouWantFlipNCoinAction", String.valueOf(c)), ability)) {
return null;
}
return PaymentDecision.number(c);
}

View File

@@ -11,7 +11,6 @@ import forge.game.GameEntityViewMap;
import forge.game.ability.AbilityUtils;
import forge.game.ability.ApiType;
import forge.game.ability.effects.CharmEffect;
import forge.game.ability.effects.FlipCoinEffect;
import forge.game.card.*;
import forge.game.card.CardPredicates.Presets;
import forge.game.cost.*;
@@ -322,16 +321,22 @@ public class HumanPlay {
((CostMill) part).payAsDecided(p, PaymentDecision.card(listmill), sourceAbility);
}
else if (part instanceof CostFlipCoin) {
final int amount = getAmountFromPart(part, source, sourceAbility);
if (!p.getController().confirmPayment(part, Localizer.getInstance().getMessage("lblDoYouWantFlipNCoinOrDoAction", String.valueOf(amount), orString), sourceAbility)) {
if (!part.canPay(sourceAbility, p)) {
return false;
}
final int n = FlipCoinEffect.getFilpMultiplier(p);
for (int i = 0; i < amount; i++) {
FlipCoinEffect.flipCoinCall(p, sourceAbility, n);
}
PaymentDecision pd = part.accept(hcd);
if (pd == null)
return false;
else
part.payAsDecided(p, pd, sourceAbility);
}
else if (part instanceof CostDamage) {
if (!part.canPay(sourceAbility, p)) {
return false;
}
// not a pay life but damage!
PaymentDecision pd = part.accept(hcd);
@@ -341,6 +346,10 @@ public class HumanPlay {
part.payAsDecided(p, pd, sourceAbility);
}
else if (part instanceof CostPutCounter) {
if (!part.canPay(sourceAbility, p)) {
return false;
}
PaymentDecision pd = part.accept(hcd);
if (pd == null)