Skip to content

Commit

Permalink
Implemented Mandate of Peace
Browse files Browse the repository at this point in the history
  • Loading branch information
goesta committed Nov 14, 2019
1 parent 22fbe57 commit 5bdce2f
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 0 deletions.
129 changes: 129 additions & 0 deletions Mage.Sets/src/mage/cards/m/MandateOfPeace.java
Original file line number Diff line number Diff line change
@@ -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. <i>(Remove all attackers and blockers from combat. Exile all spells and abilities from the stack, including this spell.)</i>";
}

public MandateOfPeaceEndCombatEffect(OneShotEffect effect) {
super(effect);
}

@Override
public boolean apply(Game game, Ability source) {
Combat combat = game.getCombat();
List<UUID> attackerIds = combat.getAttackers();
List<UUID> 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);
}
}
1 change: 1 addition & 0 deletions Mage.Sets/src/mage/sets/Commander2019Edition.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 5bdce2f

Please sign in to comment.