add ReplacePayLife

This commit is contained in:
Hans Mackowiak
2023-09-15 07:24:35 +02:00
committed by Chris H
parent 11ae9ed6ce
commit a424c7892c
3 changed files with 57 additions and 5 deletions

View File

@@ -625,11 +625,21 @@ public class Player extends GameEntity implements Comparable<Player> {
return false;
}
// Ashiok Exile instead of paying life
if (hasKeyword("Exile library instead of pay life") && lifePayment <= getZone(ZoneType.Library).size()) {
// TODO is cause always set or not? if not then the ChangeZoneTable needs to trigger differently?
getGame().getAction().exile(getTopXCardsFromLibrary(lifePayment), cause, null);
return true;
// Replacement only matters when life payment is greater than 0
if (lifePayment > 0) {
Map<AbilityKey, Object> replaceParams = AbilityKey.mapFromAffected(this);
replaceParams.put(AbilityKey.Amount, lifePayment);
replaceParams.put(AbilityKey.Cause, cause);
replaceParams.put(AbilityKey.EffectOnly, effect);
switch (getGame().getReplacementHandler().run(ReplacementType.PayLife, replaceParams)) {
case Replaced:
return true;
case Prevented:
case Skipped:
return false;
default:
break;
};
}
final int lost = loseLife(lifePayment, false, false);

View File

@@ -0,0 +1,41 @@
package forge.game.replacement;
import java.util.Map;
import forge.game.ability.AbilityKey;
import forge.game.card.Card;
import forge.game.spellability.SpellAbility;
import forge.util.Expressions;
public class ReplacePayLife extends ReplacementEffect {
public ReplacePayLife(Map<String, String> map, Card host, boolean intrinsic) {
super(map, host, intrinsic);
}
@Override
public boolean canReplace(Map<AbilityKey, Object> runParams) {
// TODO Auto-generated method stub
if (!matchesValidParam("ValidPlayer", runParams.get(AbilityKey.Affected))) {
return false;
}
if (hasParam("Amount")) {
final int n = (Integer)runParams.get(AbilityKey.Amount);
String comparator = getParam("Amount");
final String operator = comparator.substring(0, 2);
final int operandValue = Integer.parseInt(comparator.substring(2));
if (!Expressions.compare(n, operator, operandValue)) {
return false;
}
}
return true;
}
@Override
public void setReplacingObjects(Map<AbilityKey, Object> runParams, SpellAbility sa) {
sa.setReplacingObject(AbilityKey.Player, runParams.get(AbilityKey.Affected));
sa.setReplacingObjectsFrom(runParams, AbilityKey.Amount);
}
}

View File

@@ -33,6 +33,7 @@ public enum ReplacementType {
LoseMana(ReplaceLoseMana.class),
Mill(ReplaceMill.class),
Moved(ReplaceMoved.class),
PayLife(ReplacePayLife.class),
PlanarDiceResult(ReplacePlanarDiceResult.class),
ProduceMana(ReplaceProduceMana.class),
Proliferate(ReplaceProliferate.class),