Commit af76c37c authored by Hans Mackowiak's avatar Hans Mackowiak

ReplaceDying moved to SpellAbilityEffect

parent e3b3db74
......@@ -10,6 +10,7 @@ import org.apache.commons.lang3.StringUtils;
import com.google.common.collect.Lists;
import forge.GameCommand;
import forge.card.CardType;
import forge.game.Game;
import forge.game.GameObject;
......@@ -385,4 +386,83 @@ public abstract class SpellAbilityEffect {
return eff;
}
protected static void replaceDying(final SpellAbility sa) {
if (sa.hasParam("ReplaceDyingDefined") || sa.hasParam("ReplaceDyingValid")) {
if (sa.hasParam("ReplaceDyingCondition")) {
// currently there is only one with Kicker
final String condition = sa.getParam("ReplaceDyingCondition");
if ("Kicked".equals(condition)) {
if (!sa.isKicked()) {
return;
}
}
}
final Card host = sa.getHostCard();
final Player controller = sa.getActivatingPlayer();
final Game game = host.getGame();
String zone = sa.getParamOrDefault("ReplaceDyingZone", "Exile");
CardCollection cards = null;
if (sa.hasParam("ReplaceDyingDefined")) {
cards = AbilityUtils.getDefinedCards(host, sa.getParam("ReplaceDyingDefined"), sa);
// no cards, no need for Effect
if (cards.isEmpty()) {
return;
}
}
// build an Effect with that infomation
String name = host.getName() + "'s Effect";
final Card eff = createEffect(host, controller, name, host.getImageKey());
if (cards != null) {
eff.addRemembered(cards);
}
String valid = sa.getParamOrDefault("ReplaceDyingValid", "Card.IsRemembered");
String repeffstr = "Event$ Moved | ValidCard$ " + valid +
"| Origin$ Battlefield | Destination$ Graveyard " +
"| Description$ If the creature would die this turn, exile it instead.";
String effect = "DB$ ChangeZone | Defined$ ReplacedCard | Origin$ Battlefield | Destination$ " + zone;
ReplacementEffect re = ReplacementHandler.parseReplacement(repeffstr, eff, true);
re.setLayer(ReplacementLayer.Other);
re.setOverridingAbility(AbilityFactory.getAbility(effect, eff));
eff.addReplacementEffect(re);
if (cards != null) {
// Add forgot trigger
addForgetOnMovedTrigger(eff, "Battlefield");
}
// Copy text changes
if (sa.isIntrinsic()) {
eff.copyChangedTextFrom(host);
}
final GameCommand endEffect = new GameCommand() {
private static final long serialVersionUID = -5861759814760561373L;
@Override
public void run() {
game.getAction().exile(eff, null);
}
};
game.getEndOfTurn().addUntil(endEffect);
eff.updateStateForView();
// TODO: Add targeting to the effect so it knows who it's dealing with
game.getTriggerHandler().suppressMode(TriggerType.ChangesZone);
game.getAction().moveTo(ZoneType.Command, eff, sa);
game.getTriggerHandler().clearSuppression(TriggerType.ChangesZone);
}
}
}
package forge.game.ability.effects;
import forge.GameCommand;
import forge.game.Game;
import forge.game.ability.AbilityFactory;
import forge.game.ability.AbilityUtils;
import forge.game.ability.SpellAbilityEffect;
import forge.game.card.Card;
import forge.game.card.CardCollection;
import forge.game.player.Player;
import forge.game.replacement.ReplacementEffect;
import forge.game.replacement.ReplacementHandler;
import forge.game.replacement.ReplacementLayer;
import forge.game.spellability.SpellAbility;
import forge.game.trigger.TriggerType;
import forge.game.zone.ZoneType;
abstract public class DamageBaseEffect extends SpellAbilityEffect {
static void replaceDying(final SpellAbility sa) {
if (sa.hasParam("ReplaceDyingDefined")) {
if (sa.hasParam("ReplaceDyingCondition")) {
// currently there is only one with Kicker
final String condition = sa.getParam("ReplaceDyingCondition");
if ("Kicked".equals(condition)) {
if (!sa.isKicked()) {
return;
}
}
}
final Card host = sa.getHostCard();
final Player controller = sa.getActivatingPlayer();
final Game game = host.getGame();
String zone = sa.getParamOrDefault("ReplaceDyingZone", "Exile");
CardCollection cards = AbilityUtils.getDefinedCards(host, sa.getParam("ReplaceDyingDefined"), sa);
// no cards, no need for Effect
if (cards.isEmpty()) {
return;
}
// build an Effect with that infomation
String name = host.getName() + "'s Effect";
final Card eff = createEffect(host, controller, name, host.getImageKey());
eff.addRemembered(cards);
String repeffstr = "Event$ Moved | ValidCard$ Card.IsRemembered " +
"| Origin$ Battlefield | Destination$ Graveyard " +
"| Description$ If the creature would die this turn, exile it instead.";
String effect = "DB$ ChangeZone | Defined$ ReplacedCard | Origin$ Battlefield | Destination$ " + zone;
ReplacementEffect re = ReplacementHandler.parseReplacement(repeffstr, eff, true);
re.setLayer(ReplacementLayer.Other);
re.setOverridingAbility(AbilityFactory.getAbility(effect, eff));
eff.addReplacementEffect(re);
// Add forgot trigger
addForgetOnMovedTrigger(eff, "Battlefield");
// Copy text changes
if (sa.isIntrinsic()) {
eff.copyChangedTextFrom(host);
}
final GameCommand endEffect = new GameCommand() {
private static final long serialVersionUID = -5861759814760561373L;
@Override
public void run() {
game.getAction().exile(eff, null);
}
};
game.getEndOfTurn().addUntil(endEffect);
eff.updateStateForView();
// TODO: Add targeting to the effect so it knows who it's dealing with
game.getTriggerHandler().suppressMode(TriggerType.ChangesZone);
game.getAction().moveTo(ZoneType.Command, eff, sa);
game.getTriggerHandler().clearSuppression(TriggerType.ChangesZone);
}
}
}
......@@ -158,6 +158,8 @@ public class PumpAllEffect extends SpellAbilityEffect {
keywords = CardFactoryUtil.sharedKeywords(keywords, restrictions, zones, sa.getHostCard());
}
applyPumpAll(sa, list, a, d, keywords, affectedZones);
replaceDying(sa);
} // pumpAllResolve()
}
......@@ -383,5 +383,7 @@ public class PumpEffect extends SpellAbilityEffect {
applyPump(sa, p, keywords, timestamp);
}
replaceDying(sa);
} // pumpResolve()
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment