From 5bdce2f38d69ea04d4eaf0b9e3cfd0ca39d9cb2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Go=CC=88sta?= Date: Thu, 14 Nov 2019 13:26:52 +0100 Subject: [PATCH] Implemented Mandate of Peace --- .../src/mage/cards/m/MandateOfPeace.java | 129 ++++++++++++++++++ .../src/mage/sets/Commander2019Edition.java | 1 + 2 files changed, 130 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/m/MandateOfPeace.java diff --git a/Mage.Sets/src/mage/cards/m/MandateOfPeace.java b/Mage.Sets/src/mage/cards/m/MandateOfPeace.java new file mode 100644 index 000000000000..06c0f637341a --- /dev/null +++ b/Mage.Sets/src/mage/cards/m/MandateOfPeace.java @@ -0,0 +1,129 @@ +package mage.cards.m; + +import java.util.List; +import java.util.UUID; +import java.util.stream.Stream; + +import mage.MageObject; +import mage.abilities.Ability; +import mage.abilities.common.CastOnlyDuringPhaseStepSourceAbility; +import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; +import mage.abilities.effects.Effect; +import mage.abilities.effects.OneShotEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.constants.TurnPhase; +import mage.game.Game; +import mage.game.combat.Combat; +import mage.game.events.GameEvent; +import mage.game.stack.Spell; + +/** + * + * @author goesta + */ +public final class MandateOfPeace extends CardImpl { + + public MandateOfPeace(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{1}{W}"); + // Cast this spell only during combat. + this.addAbility(new CastOnlyDuringPhaseStepSourceAbility(TurnPhase.COMBAT)); + // Your opponents can't cast spells this turn. + this.getSpellAbility().addEffect(new MandateOfPeaceOpponentsCantCastSpellsEffect()); + // End the combat phase. + this.getSpellAbility().addEffect(new MandateOfPeaceEndCombatEffect()); + } + + private MandateOfPeace(final MandateOfPeace card) { + super(card); + } + + @Override + public MandateOfPeace copy() { + return new MandateOfPeace(this); + } +} + +class MandateOfPeaceOpponentsCantCastSpellsEffect extends ContinuousRuleModifyingEffectImpl { + + public MandateOfPeaceOpponentsCantCastSpellsEffect() { + super(Duration.EndOfTurn, Outcome.Benefit); + staticText = "Your opponents can't cast spells this turn."; + } + + public MandateOfPeaceOpponentsCantCastSpellsEffect(final MandateOfPeaceOpponentsCantCastSpellsEffect effect) { + super(effect); + } + + @Override + public MandateOfPeaceOpponentsCantCastSpellsEffect copy() { + return new MandateOfPeaceOpponentsCantCastSpellsEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + return true; + } + + @Override + public String getInfoMessage(Ability source, GameEvent event, Game game) { + MageObject mageObject = game.getObject(source.getSourceId()); + if (mageObject != null) { + return "You can't cast spells this turn (" + mageObject.getIdName() + ")."; + } + return null; + } + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.CAST_SPELL; + } + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + return game.getOpponents(source.getControllerId()).contains(event.getPlayerId()); + } + +} + +class MandateOfPeaceEndCombatEffect extends OneShotEffect { + + public MandateOfPeaceEndCombatEffect() { + super(Outcome.Benefit); + this.staticText = "End the combat phase. (Remove all attackers and blockers from combat. Exile all spells and abilities from the stack, including this spell.)"; + } + + public MandateOfPeaceEndCombatEffect(OneShotEffect effect) { + super(effect); + } + + @Override + public boolean apply(Game game, Ability source) { + Combat combat = game.getCombat(); + List attackerIds = combat.getAttackers(); + List blockerIds = combat.getBlockers(); + Stream.concat(blockerIds.stream(), attackerIds.stream()) + .map(id -> game.getPermanent(id)) + .filter(e -> e != null) + .forEach(permanent -> permanent.removeFromCombat(game)); + + game.getStack().stream() + .filter(stackObject -> stackObject instanceof Spell) + .forEach(stackObject -> ((Spell) stackObject).moveToExile(null, "", null, game)); + + game.getStack().stream() + .filter(stackObject -> stackObject instanceof Ability) + .forEach(stackObject -> game.getStack().counter(stackObject.getId(), source.getSourceId(), game)); + + combat.endCombat(game); + return true; + } + + @Override + public Effect copy() { + return new MandateOfPeaceEndCombatEffect(this); + } +} diff --git a/Mage.Sets/src/mage/sets/Commander2019Edition.java b/Mage.Sets/src/mage/sets/Commander2019Edition.java index 7fbfd03fb835..3b82f0ab895b 100644 --- a/Mage.Sets/src/mage/sets/Commander2019Edition.java +++ b/Mage.Sets/src/mage/sets/Commander2019Edition.java @@ -173,6 +173,7 @@ private Commander2019Edition() { cards.add(new SetCardInfo("Magmaquake", 148, Rarity.RARE, mage.cards.m.Magmaquake.class)); cards.add(new SetCardInfo("Magus of the Wheel", 149, Rarity.RARE, mage.cards.m.MagusOfTheWheel.class)); cards.add(new SetCardInfo("Malevolent Whispers", 150, Rarity.UNCOMMON, mage.cards.m.MalevolentWhispers.class)); + cards.add(new SetCardInfo("Mandate of Peace", 4, Rarity.RARE, mage.cards.m.MandateOfPeace.class)); cards.add(new SetCardInfo("Marisi, Breaker of the Coil", 46, Rarity.MYTHIC, mage.cards.m.MarisiBreakerOfTheCoil.class)); cards.add(new SetCardInfo("Mass Diminish", 10, Rarity.RARE, mage.cards.m.MassDiminish.class)); cards.add(new SetCardInfo("Memorial to Folly", 259, Rarity.UNCOMMON, mage.cards.m.MemorialToFolly.class));