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; boolean alreadyPaid = false;
for (Player payer : allPayers) { for (Player payer : allPayers) {
if (unlessCost.equals("LifeTotalHalfUp")) { 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); cost = new Cost("PayLife<" + halfup + ">", true);
} }
alreadyPaid |= payer.getController().payCostToPreventEffect(cost, sa, alreadyPaid, allPayers); alreadyPaid |= payer.getController().payCostToPreventEffect(cost, sa, alreadyPaid, allPayers);

View File

@@ -76,9 +76,13 @@ public class CostPayLife extends CostPart {
Integer amount = this.convertAmount(); Integer amount = this.convertAmount();
if (amount == null) { // try to calculate when it's defined. if (amount == null) { // try to calculate when it's defined.
amount = AbilityUtils.calculateAmount(ability.getHostCard(), getAmount(), ability); 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; return false;
} }

View File

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

View File

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