Merge branch 'angel' into 'master'

Fix paying negative life

See merge request core-developers/forge!4716
This commit is contained in:
Michael Kamensky
2021-05-20 04:45:40 +00:00
4 changed files with 7 additions and 5 deletions

View File

@@ -1551,7 +1551,7 @@ public class AbilityUtils {
boolean alreadyPaid = false;
for (Player payer : allPayers) {
if (unlessCost.equals("LifeTotalHalfUp")) {
String halfup = Integer.toString((int) Math.ceil(payer.getLife() / 2.0));
String halfup = Integer.toString(Math.max(0,(int) Math.ceil(payer.getLife() / 2.0)));
cost = new Cost("PayLife<" + halfup + ">", true);
}
alreadyPaid |= payer.getController().payCostToPreventEffect(cost, sa, alreadyPaid, allPayers);

View File

@@ -76,9 +76,13 @@ public class CostPayLife extends CostPart {
Integer amount = this.convertAmount();
if (amount == null) { // try to calculate when it's defined.
amount = AbilityUtils.calculateAmount(ability.getHostCard(), getAmount(), ability);
// CR 107.1b
if (getAmount().contains("/Half")) {
amount = Math.max(amount, 0);
}
}
if ((amount != null) && !payer.canPayLife(amount)) {
if (amount != null && !payer.canPayLife(amount)) {
return false;
}

View File

@@ -589,7 +589,7 @@ public class Player extends GameEntity implements Comparable<Player> {
}
public final boolean canPayLife(final int lifePayment) {
if (life < lifePayment) {
if (lifePayment > 0 && life < lifePayment) {
return false;
}
return (lifePayment <= 0) || !hasKeyword("Your life total can't change.");

View File

@@ -198,8 +198,6 @@ public class HumanPlay {
req.playAbility(!useOldTargets, false, true);
}
// ------------------------------------------------------------------------
private static int getAmountFromPart(CostPart part, Card source, SpellAbility sourceAbility) {
String amountString = part.getAmount();
return StringUtils.isNumeric(amountString) ? Integer.parseInt(amountString) : AbilityUtils.calculateAmount(source, amountString, sourceAbility);