[VOW] Implemented Alchemist's Gambit

This commit is contained in:
Evan Kranzler 2021-11-12 09:11:00 -05:00
parent 5260d6d363
commit 783a818cb7
3 changed files with 135 additions and 20 deletions

View file

@ -0,0 +1,98 @@
package mage.cards.a;
import mage.abilities.Ability;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.common.ExileSpellEffect;
import mage.abilities.effects.common.turn.AddExtraTurnControllerEffect;
import mage.abilities.keyword.CleaveAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.game.Game;
import mage.game.events.GameEvent;
import java.util.UUID;
/**
* @author TheElk801
*/
public final class AlchemistsGambit extends CardImpl {
public AlchemistsGambit(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{1}{R}{R}");
// Cleave {4}{U}{U}{R}
Ability ability = new CleaveAbility(
this,
new AddExtraTurnControllerEffect(
false, AlchemistsGambitApplier.instance
), "{4}{U}{U}{R}"
);
ability.addEffect(new ExileSpellEffect());
this.addAbility(ability);
// Take an extra turn after this one. During that turn, damage can't be prevented. [At the beginning of that turn's end step, you lose the game.]
this.getSpellAbility().addEffect(new AddExtraTurnControllerEffect(
true, AlchemistsGambitApplier.instance
).setText("take an extra turn after this one. During that turn, damage can't be prevented. " +
"[At the beginning of that turn's end step, you lose the game.]"));
// Exile Alchemist's Gambit.
this.getSpellAbility().addEffect(new ExileSpellEffect().concatBy("<br>"));
}
private AlchemistsGambit(final AlchemistsGambit card) {
super(card);
}
@Override
public AlchemistsGambit copy() {
return new AlchemistsGambit(this);
}
}
enum AlchemistsGambitApplier implements AddExtraTurnControllerEffect.TurnModApplier {
instance;
@Override
public void apply(UUID turnId, Ability source, Game game) {
game.addEffect(new AlchemistsGambitEffect(turnId), source);
}
}
class AlchemistsGambitEffect extends ReplacementEffectImpl {
private final UUID turnId;
public AlchemistsGambitEffect(UUID turnId) {
super(Duration.Custom, Outcome.Benefit);
this.turnId = turnId;
}
public AlchemistsGambitEffect(final AlchemistsGambitEffect effect) {
super(effect);
this.turnId = effect.turnId;
}
@Override
public AlchemistsGambitEffect copy() {
return new AlchemistsGambitEffect(this);
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
return true;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.PREVENT_DAMAGE;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
return game.getState().getTurnId().equals(turnId);
}
}

View file

@ -36,6 +36,7 @@ public final class InnistradCrimsonVow extends ExpansionSet {
cards.add(new SetCardInfo("Abrade", 139, Rarity.COMMON, mage.cards.a.Abrade.class));
cards.add(new SetCardInfo("Adamant Will", 1, Rarity.COMMON, mage.cards.a.AdamantWill.class));
cards.add(new SetCardInfo("Aim for the Head", 92, Rarity.COMMON, mage.cards.a.AimForTheHead.class));
cards.add(new SetCardInfo("Alchemist's Gambit", 140, Rarity.RARE, mage.cards.a.AlchemistsGambit.class));
cards.add(new SetCardInfo("Alchemist's Retrieval", 47, Rarity.COMMON, mage.cards.a.AlchemistsRetrieval.class));
cards.add(new SetCardInfo("Alluring Suitor", 141, Rarity.UNCOMMON, mage.cards.a.AlluringSuitor.class));
cards.add(new SetCardInfo("Ancestor's Embrace", 22, Rarity.COMMON, mage.cards.a.AncestorsEmbrace.class));

View file

@ -1,42 +1,51 @@
package mage.abilities.effects.common.turn;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.DelayedTriggeredAbility;
import mage.abilities.Mode;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.LoseGameSourceControllerEffect;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.turn.TurnMod;
import mage.players.Player;
import java.util.UUID;
/**
* @author noxx
*/
public class AddExtraTurnControllerEffect extends OneShotEffect {
@FunctionalInterface
public static interface TurnModApplier {
void apply(UUID turnId, Ability source, Game game);
}
private final boolean loseGameAtEnd;
private final TurnModApplier turnModApplier;
public AddExtraTurnControllerEffect() {
this(false);
}
public AddExtraTurnControllerEffect(boolean loseGameAtEnd) {
this(loseGameAtEnd, null);
}
public AddExtraTurnControllerEffect(boolean loseGameAtEnd, TurnModApplier turnModApplier) {
super(loseGameAtEnd ? Outcome.AIDontUseIt : Outcome.ExtraTurn);
this.loseGameAtEnd = loseGameAtEnd;
staticText = "take an extra turn after this one";
if (loseGameAtEnd) {
staticText += ". At the beginning of that turn's end step, you lose the game";
}
this.turnModApplier = turnModApplier;
}
public AddExtraTurnControllerEffect(final AddExtraTurnControllerEffect effect) {
super(effect);
this.loseGameAtEnd = effect.loseGameAtEnd;
this.turnModApplier = effect.turnModApplier;
}
@Override
@ -47,26 +56,37 @@ public class AddExtraTurnControllerEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
TurnMod extraTurn = new TurnMod(player.getId(), false);
game.getState().getTurnMods().add(extraTurn);
if (loseGameAtEnd) {
LoseGameDelayedTriggeredAbility delayedTriggeredAbility = new LoseGameDelayedTriggeredAbility();
delayedTriggeredAbility.setConnectedTurnMod(extraTurn.getId());
game.addDelayedTriggeredAbility(delayedTriggeredAbility, source);
}
if (player == null) {
return true;
}
TurnMod extraTurn = new TurnMod(player.getId(), false);
game.getState().getTurnMods().add(extraTurn);
if (loseGameAtEnd) {
game.addDelayedTriggeredAbility(new LoseGameDelayedTriggeredAbility(extraTurn.getId()), source);
}
if (turnModApplier != null) {
turnModApplier.apply(extraTurn.getId(), source, game);
}
return true;
}
@Override
public String getText(Mode mode) {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
return "take an extra turn after this one"
+ (loseGameAtEnd ? ". At the beginning of that turn's end step, you lose the game" : "");
}
}
class LoseGameDelayedTriggeredAbility extends DelayedTriggeredAbility {
private UUID connectedTurnMod;
private final UUID connectedTurnMod;
public LoseGameDelayedTriggeredAbility() {
public LoseGameDelayedTriggeredAbility(UUID connectedTurnMod) {
super(new LoseGameSourceControllerEffect(), Duration.EndOfGame);
this.connectedTurnMod = connectedTurnMod;
}
public LoseGameDelayedTriggeredAbility(final LoseGameDelayedTriggeredAbility ability) {
@ -89,10 +109,6 @@ class LoseGameDelayedTriggeredAbility extends DelayedTriggeredAbility {
return connectedTurnMod != null && connectedTurnMod.equals(game.getState().getTurnId());
}
public void setConnectedTurnMod(UUID connectedTurnMod) {
this.connectedTurnMod = connectedTurnMod;
}
@Override
public String getRule() {
return "At the beginning of that turn's end step, you lose the game";