ReplaceLifeReduced: update for Bloodletter (#4197)

* ReplaceLifeReduced: update for Bloodletter

* add Bloodletter of aclazotz
This commit is contained in:
Hans Mackowiak
2023-11-25 20:41:07 +01:00
committed by GitHub
parent e67f71aa66
commit 1bfa22e5b5
11 changed files with 61 additions and 38 deletions

View File

@@ -556,7 +556,7 @@ public class Player extends GameEntity implements Comparable<Player> {
int oldLife = life;
// Run applicable replacement effects
final Map<AbilityKey, Object> repParams = AbilityKey.mapFromAffected(this);
repParams.put(AbilityKey.Result, oldLife-toLose);
repParams.put(AbilityKey.Amount, toLose);
repParams.put(AbilityKey.IsDamage, damage);
switch (getGame().getReplacementHandler().run(ReplacementType.LifeReduced, repParams)) {
@@ -565,8 +565,7 @@ public class Player extends GameEntity implements Comparable<Player> {
case Updated:
// check if this is still the affected player
if (this.equals(repParams.get(AbilityKey.Affected))) {
int result = (int) repParams.get(AbilityKey.Result);
toLose = oldLife - result;
toLose = (int) repParams.get(AbilityKey.Amount);
// there is nothing that changes lifegain into lifeloss this way
if (toLose <= 0) {
return 0;

View File

@@ -4,6 +4,8 @@ import java.util.Map;
import forge.game.ability.AbilityKey;
import forge.game.card.Card;
import forge.game.player.Player;
import forge.game.spellability.SpellAbility;
import forge.util.Expressions;
/**
@@ -27,7 +29,13 @@ public class ReplaceLifeReduced extends ReplacementEffect {
*/
@Override
public boolean canReplace(Map<AbilityKey, Object> runParams) {
if (!matchesValidParam("ValidPlayer", runParams.get(AbilityKey.Affected))) {
int amount = (int)runParams.get(AbilityKey.Amount);
Player affected = (Player) runParams.get(AbilityKey.Affected);
if (amount <= 0) {
return false;
}
if (!matchesValidParam("ValidPlayer", affected)) {
return false;
}
@@ -36,8 +44,9 @@ public class ReplaceLifeReduced extends ReplacementEffect {
return false;
}
}
if (hasParam("Result")) {
final int n = (Integer)runParams.get(AbilityKey.Result);
final int n = affected.getLife() - amount;
String comparator = getParam("Result");
final String operator = comparator.substring(0, 2);
final int operandValue = Integer.parseInt(comparator.substring(2));
@@ -47,4 +56,10 @@ public class ReplaceLifeReduced extends ReplacementEffect {
}
return true;
}
@Override
public void setReplacingObjects(Map<AbilityKey, Object> runParams, SpellAbility sa) {
sa.setReplacingObjectsFrom(runParams, AbilityKey.Amount);
sa.setReplacingObject(AbilityKey.Player, runParams.get(AbilityKey.Affected));
}
}