Implemented Doom Foretold

This commit is contained in:
Evan Kranzler 2019-09-11 13:27:18 -04:00
parent 370de750f4
commit d9a934ac4f
3 changed files with 110 additions and 2 deletions

View file

@ -0,0 +1,104 @@
package mage.cards.d;
import mage.abilities.Ability;
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.effects.common.SacrificeSourceEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.TargetController;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterNonlandPermanent;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.permanent.ControllerIdPredicate;
import mage.filter.predicate.permanent.TokenPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.permanent.token.KnightToken;
import mage.players.Player;
import mage.target.TargetPermanent;
import java.util.UUID;
/**
* @author TheElk801
*/
public final class DoomForetold extends CardImpl {
public DoomForetold(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{2}{W}{B}");
// At the beginning of each player's upkeep, that player sacrifices a nonland, nontoken permanent. If that player can't, they discard a card, they lose 2 life, you draw a card, you gain 2 life, you create a 2/2 white Knight creature token with vigilance, then you sacrifice Doom Foretold.
this.addAbility(new BeginningOfUpkeepTriggeredAbility(
new DoomForetoldEffect(), TargetController.ACTIVE, false
));
}
private DoomForetold(final DoomForetold card) {
super(card);
}
@Override
public DoomForetold copy() {
return new DoomForetold(this);
}
}
class DoomForetoldEffect extends OneShotEffect {
private static final FilterPermanent filter = new FilterNonlandPermanent("nonland, nontoken permanent");
static {
filter.add(Predicates.not(TokenPredicate.instance));
}
private static final Effect effect1 = new CreateTokenEffect(new KnightToken());
private static final Effect effect2 = new SacrificeSourceEffect();
DoomForetoldEffect() {
super(Outcome.Benefit);
staticText = "that player sacrifices a nonland, nontoken permanent. " +
"If that player can't, they discard a card, they lose 2 life, you draw a card, you gain 2 life, " +
"you create a 2/2 white Knight creature token with vigilance, then you sacrifice {this}";
}
private DoomForetoldEffect(final DoomForetoldEffect effect) {
super(effect);
}
@Override
public DoomForetoldEffect copy() {
return new DoomForetoldEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player player = game.getPlayer(game.getActivePlayerId());
if (controller == null || player == null) {
return false;
}
FilterPermanent filter2 = filter.copy();
filter2.add(new ControllerIdPredicate(player.getId()));
if (game.getBattlefield().contains(filter2, 1, game)) {
TargetPermanent target = new TargetPermanent(filter2);
target.setNotTarget(true);
if (player.choose(outcome, target, source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null && permanent.sacrifice(source.getSourceId(), game)) {
return true;
}
}
}
player.discard(1, false, source, game);
player.loseLife(2, game, false);
controller.drawCards(1, game);
controller.gainLife(2, game, source);
effect1.apply(game, source);
return effect2.apply(game, source);
}
}

View file

@ -47,6 +47,7 @@ public final class ThroneOfEldraine extends ExpansionSet {
cards.add(new SetCardInfo("Command Tower", 333, Rarity.COMMON, mage.cards.c.CommandTower.class));
cards.add(new SetCardInfo("Corridor Monitor", 41, Rarity.COMMON, mage.cards.c.CorridorMonitor.class));
cards.add(new SetCardInfo("Crystal Slipper", 119, Rarity.COMMON, mage.cards.c.CrystalSlipper.class));
cards.add(new SetCardInfo("Doom Foretold", 187, Rarity.RARE, mage.cards.d.DoomForetold.class));
cards.add(new SetCardInfo("Embercleave", 120, Rarity.MYTHIC, mage.cards.e.Embercleave.class));
cards.add(new SetCardInfo("Embereth Paladin", 121, Rarity.COMMON, mage.cards.e.EmberethPaladin.class));
cards.add(new SetCardInfo("Embereth Shieldbreaker", 122, Rarity.UNCOMMON, mage.cards.e.EmberethShieldbreaker.class));

View file

@ -1,7 +1,6 @@
package mage.abilities.common;
import java.util.Locale;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.constants.TargetController;
@ -11,8 +10,9 @@ import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.target.targetpointer.FixedTarget;
import java.util.Locale;
/**
*
* @author Loki
*/
public class BeginningOfUpkeepTriggeredAbility extends TriggeredAbilityImpl {
@ -91,6 +91,7 @@ public class BeginningOfUpkeepTriggeredAbility extends TriggeredAbilityImpl {
}
break;
case ANY:
case ACTIVE:
if (setTargetPointer && getTargets().isEmpty()) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getPlayerId()));
@ -137,6 +138,8 @@ public class BeginningOfUpkeepTriggeredAbility extends TriggeredAbilityImpl {
return sb.insert(0, generateZoneString()).insert(0, "At the beginning of each opponent's upkeep, ").toString();
case ANY:
return sb.insert(0, generateZoneString()).insert(0, "At the beginning of each upkeep, ").toString();
case ACTIVE:
return sb.insert(0, generateZoneString()).insert(0, "At the beginning of each player's upkeep, ").toString();
case CONTROLLER_ATTACHED_TO:
return sb.insert(0, generateZoneString()).insert(0, "At the beginning of the upkeep of enchanted creature's controller, ").toString();
}