diff --git a/Mage.Sets/src/mage/cards/t/ThePhasingOfZhalfir.java b/Mage.Sets/src/mage/cards/t/ThePhasingOfZhalfir.java new file mode 100644 index 0000000000..0aa4e011a9 --- /dev/null +++ b/Mage.Sets/src/mage/cards/t/ThePhasingOfZhalfir.java @@ -0,0 +1,138 @@ +package mage.cards.t; + +import mage.abilities.Ability; +import mage.abilities.common.SagaAbility; +import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; +import mage.abilities.effects.Effects; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.PhaseOutTargetEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.filter.FilterPermanent; +import mage.filter.StaticFilters; +import mage.filter.common.FilterNonlandPermanent; +import mage.filter.predicate.mageobject.AnotherPredicate; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; +import mage.game.permanent.token.PhyrexianToken; +import mage.game.permanent.token.Token; +import mage.target.TargetPermanent; +import mage.util.CardUtil; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class ThePhasingOfZhalfir extends CardImpl { + + private static final FilterPermanent filter = new FilterNonlandPermanent("another nonland permanent"); + + static { + filter.add(AnotherPredicate.instance); + } + + public ThePhasingOfZhalfir(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{2}{U}{U}"); + + this.subtype.add(SubType.SAGA); + + // Read ahead + SagaAbility sagaAbility = new SagaAbility(this, SagaChapter.CHAPTER_III, true); + + // I, II -- Another target nonland permanent phases out. It can't phase in for as long as you control The Phasing of Zhalfir. + sagaAbility.addChapterEffect( + this, SagaChapter.CHAPTER_I, SagaChapter.CHAPTER_II, + new Effects( + new PhaseOutTargetEffect("another target nonland permanent"), + new ThePhasingOfZhalfirPhaseEffect() + ), new TargetPermanent(filter) + ); + + // III -- Destroy all creatures. For each creature destroyed this way, its controller creates a 2/2 black Phyrexian creature token. + sagaAbility.addChapterEffect(this, SagaChapter.CHAPTER_III, new ThePhasingOfZhalfirDestroyEffect()); + this.addAbility(sagaAbility); + } + + private ThePhasingOfZhalfir(final ThePhasingOfZhalfir card) { + super(card); + } + + @Override + public ThePhasingOfZhalfir copy() { + return new ThePhasingOfZhalfir(this); + } +} + +class ThePhasingOfZhalfirPhaseEffect extends ContinuousRuleModifyingEffectImpl { + + ThePhasingOfZhalfirPhaseEffect() { + super(Duration.WhileControlled, Outcome.Neutral); + staticText = "It can't phase in for as long as you control {this}"; + } + + private ThePhasingOfZhalfirPhaseEffect(final ThePhasingOfZhalfirPhaseEffect effect) { + super(effect); + } + + @Override + public ThePhasingOfZhalfirPhaseEffect copy() { + return new ThePhasingOfZhalfirPhaseEffect(this); + } + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.PHASE_IN; + } + + @Override + public boolean apply(Game game, Ability source) { + return true; + } + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + return event.getTargetId().equals(this.getTargetPointer().getFirst(game, source)); + } +} + +class ThePhasingOfZhalfirDestroyEffect extends OneShotEffect { + + ThePhasingOfZhalfirDestroyEffect() { + super(Outcome.Benefit); + staticText = "destroy all creatures. For each creature destroyed this way, " + + "its controller creates a 2/2 black Phyrexian creature token"; + } + + private ThePhasingOfZhalfirDestroyEffect(final ThePhasingOfZhalfirDestroyEffect effect) { + super(effect); + } + + @Override + public ThePhasingOfZhalfirDestroyEffect copy() { + return new ThePhasingOfZhalfirDestroyEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Map playerMap = new HashMap<>(); + for (Permanent permanent : game.getBattlefield().getActivePermanents( + StaticFilters.FILTER_PERMANENT_CREATURES, + source.getControllerId(), source, game + )) { + UUID controllerId = permanent.getControllerId(); + if (permanent.destroy(source, game, false)) { + playerMap.compute(permanent.getControllerId(), CardUtil::setOrIncrementValue); + } + } + Token token = new PhyrexianToken(); + for (Map.Entry entry : playerMap.entrySet()) { + token.putOntoBattlefield(entry.getValue(), game, source, entry.getKey()); + } + return true; + } +} diff --git a/Mage.Sets/src/mage/sets/DominariaUnited.java b/Mage.Sets/src/mage/sets/DominariaUnited.java index b1334d4d19..660a7cd1c8 100644 --- a/Mage.Sets/src/mage/sets/DominariaUnited.java +++ b/Mage.Sets/src/mage/sets/DominariaUnited.java @@ -236,6 +236,7 @@ public final class DominariaUnited extends ExpansionSet { cards.add(new SetCardInfo("Territorial Maro", 184, Rarity.UNCOMMON, mage.cards.t.TerritorialMaro.class)); cards.add(new SetCardInfo("The Cruelty of Gix", 87, Rarity.RARE, mage.cards.t.TheCrueltyOfGix.class)); cards.add(new SetCardInfo("The Elder Dragon War", 121, Rarity.RARE, mage.cards.t.TheElderDragonWar.class)); + cards.add(new SetCardInfo("The Phasing of Zhalfir", 59, Rarity.RARE, mage.cards.t.ThePhasingOfZhalfir.class)); cards.add(new SetCardInfo("The Raven Man", 103, Rarity.RARE, mage.cards.t.TheRavenMan.class)); cards.add(new SetCardInfo("The Weatherseed Treaty", 188, Rarity.UNCOMMON, mage.cards.t.TheWeatherseedTreaty.class)); cards.add(new SetCardInfo("The World Spell", 189, Rarity.MYTHIC, mage.cards.t.TheWorldSpell.class)); diff --git a/Mage/src/main/java/mage/game/permanent/token/PhyrexianToken.java b/Mage/src/main/java/mage/game/permanent/token/PhyrexianToken.java new file mode 100644 index 0000000000..ae5b243c07 --- /dev/null +++ b/Mage/src/main/java/mage/game/permanent/token/PhyrexianToken.java @@ -0,0 +1,33 @@ +package mage.game.permanent.token; + +import mage.MageInt; +import mage.constants.CardType; +import mage.constants.SubType; + +import java.util.Arrays; + +/** + * @author TheElk801 + */ +public final class PhyrexianToken extends TokenImpl { + + public PhyrexianToken() { + super("Phyrexian Token", "2/2 black Phyrexian creature token"); + cardType.add(CardType.CREATURE); + color.setBlack(true); + subtype.add(SubType.PHYREXIAN); + power = new MageInt(2); + toughness = new MageInt(2); + + availableImageSetCodes = Arrays.asList("DMU"); + } + + public PhyrexianToken(final PhyrexianToken token) { + super(token); + } + + @Override + public PhyrexianToken copy() { + return new PhyrexianToken(this); + } +}