mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
Merge branch 'healinggrace' into 'master'
ReplaceDamage: new Effect for reducing Damage inside ReplacementEffect Closes #268 See merge request core-developers/forge!427
This commit is contained in:
@@ -126,6 +126,7 @@ public enum SpellApiToAi {
|
|||||||
.put(ApiType.Repeat, RepeatAi.class)
|
.put(ApiType.Repeat, RepeatAi.class)
|
||||||
.put(ApiType.RepeatEach, RepeatEachAi.class)
|
.put(ApiType.RepeatEach, RepeatEachAi.class)
|
||||||
.put(ApiType.ReplaceEffect, AlwaysPlayAi.class)
|
.put(ApiType.ReplaceEffect, AlwaysPlayAi.class)
|
||||||
|
.put(ApiType.ReplaceDamage, AlwaysPlayAi.class)
|
||||||
.put(ApiType.ReplaceSplitDamage, AlwaysPlayAi.class)
|
.put(ApiType.ReplaceSplitDamage, AlwaysPlayAi.class)
|
||||||
.put(ApiType.RestartGame, RestartGameAi.class)
|
.put(ApiType.RestartGame, RestartGameAi.class)
|
||||||
.put(ApiType.Reveal, RevealAi.class)
|
.put(ApiType.Reveal, RevealAi.class)
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ public enum ApiType {
|
|||||||
Repeat (RepeatEffect.class),
|
Repeat (RepeatEffect.class),
|
||||||
RepeatEach (RepeatEachEffect.class),
|
RepeatEach (RepeatEachEffect.class),
|
||||||
ReplaceEffect (ReplaceEffect.class),
|
ReplaceEffect (ReplaceEffect.class),
|
||||||
|
ReplaceDamage (ReplaceDamageEffect.class),
|
||||||
ReplaceSplitDamage (ReplaceSplitDamageEffect.class),
|
ReplaceSplitDamage (ReplaceSplitDamageEffect.class),
|
||||||
RestartGame (RestartGameEffect.class),
|
RestartGame (RestartGameEffect.class),
|
||||||
Reveal (RevealEffect.class),
|
Reveal (RevealEffect.class),
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package forge.game.ability.effects;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
|
import forge.game.Game;
|
||||||
|
import forge.game.ability.AbilityUtils;
|
||||||
|
import forge.game.ability.SpellAbilityEffect;
|
||||||
|
import forge.game.card.Card;
|
||||||
|
import forge.game.replacement.ReplacementResult;
|
||||||
|
import forge.game.spellability.SpellAbility;
|
||||||
|
|
||||||
|
public class ReplaceDamageEffect extends SpellAbilityEffect {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resolve(SpellAbility sa) {
|
||||||
|
final Card card = sa.getHostCard();
|
||||||
|
final Game game = card.getGame();
|
||||||
|
|
||||||
|
// outside of Replacement Effect, unwanted result
|
||||||
|
if (!sa.getRootAbility().isReplacementAbility()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String varValue = sa.getParamOrDefault("VarName", "1");
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Map<String, Object> originalParams = (Map<String, Object>) sa.getReplacingObject("OriginalParams");
|
||||||
|
Map<String, Object> params = Maps.newHashMap(originalParams);
|
||||||
|
|
||||||
|
Integer dmg = (Integer) sa.getReplacingObject("DamageAmount");
|
||||||
|
|
||||||
|
int prevent = AbilityUtils.calculateAmount(card, varValue, sa);
|
||||||
|
|
||||||
|
// Currently it does reduce damage by amount, need second mode for Setting Damage
|
||||||
|
|
||||||
|
if (prevent > 0) {
|
||||||
|
int n = Math.min(dmg, prevent);
|
||||||
|
dmg -= n;
|
||||||
|
prevent -= n;
|
||||||
|
|
||||||
|
if (card.getType().hasStringType("Effect") && prevent <= 0) {
|
||||||
|
game.getAction().exile(card, null);
|
||||||
|
} else if (!StringUtils.isNumeric(varValue)) {
|
||||||
|
card.setSVar(varValue, "Number$" + prevent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// no damage for original target anymore
|
||||||
|
if (dmg <= 0) {
|
||||||
|
originalParams.put("ReplacementResult", ReplacementResult.Replaced);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
params.put("DamageAmount", dmg);
|
||||||
|
|
||||||
|
|
||||||
|
//try to call replacementHandler with new Params
|
||||||
|
ReplacementResult result = game.getReplacementHandler().run(params);
|
||||||
|
switch (result) {
|
||||||
|
case NotReplaced:
|
||||||
|
case Updated: {
|
||||||
|
for (Map.Entry<String, Object> e : params.entrySet()) {
|
||||||
|
originalParams.put(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
// effect was updated
|
||||||
|
originalParams.put("ReplacementResult", ReplacementResult.Updated);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
// effect was replaced with something else
|
||||||
|
originalParams.put("ReplacementResult", result);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
12
forge-gui/res/cardsfolder/h/healing_grace.txt
Normal file
12
forge-gui/res/cardsfolder/h/healing_grace.txt
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
Name:Healing Grace
|
||||||
|
ManaCost:W
|
||||||
|
Types:Instant
|
||||||
|
A:SP$ ChooseSource | Cost$ W | Choices$ Card,Emblem | SubAbility$ DBEffect | StackDescription$ SpellDescription | SpellDescription$ Prevent the next 3 damage that would be dealt to any target this turn by a source of your choice. You gain 3 life.
|
||||||
|
SVar:DBEffect:DB$ Effect | ValidTgts$ Creature,Player | TgtPrompt$ Select target to prevent damage to | ReplacementEffects$ GraceDamage | SVars$ GraceDmg,X | References$ GraceDamage,GraceDmg,X | ForgetOnMoved$ Battlefield | RememberObjects$ Targeted | SubAbility$ DBGainLife
|
||||||
|
SVar:GraceDamage:Event$ DamageDone | ValidTarget$ Creature.IsRemembered,Player.IsRemembered | ValidSource$ Card.ChosenCard,Emblem.ChosenCard | ReplaceWith$ GraceDmg | PreventionEffect$ True | Description$ Prevent the next 3 damage that would be dealt to any target this turn by a source of your choice.
|
||||||
|
SVar:GraceDmg:DB$ ReplaceDamage | VarName$ X | References$ X
|
||||||
|
SVar:DBGainLife:DB$ GainLife | LifeAmount$ 3 | SubAbility$ DBCleanup
|
||||||
|
SVar:DBCleanup:DB$ Cleanup | ClearChosenCard$ True
|
||||||
|
SVar:X:Number$3
|
||||||
|
SVar:RemAIDeck:True
|
||||||
|
Oracle:Prevent the next 3 damage that would be dealt to any target this turn by a source of your choice. You gain 3 life.
|
||||||
Reference in New Issue
Block a user