From ea8947dda54b53fb863819df548f5dd6cd37e73f Mon Sep 17 00:00:00 2001 From: Evan Kranzler <theelk801@gmail.com> Date: Wed, 2 Jan 2019 13:09:45 -0500 Subject: [PATCH] Implemented Deputy of Detention --- .../src/mage/cards/d/DeputyOfDetention.java | 110 ++++++++++++++++++ .../src/mage/sets/RavnicaAllegiance.java | 1 + 2 files changed, 111 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/d/DeputyOfDetention.java diff --git a/Mage.Sets/src/mage/cards/d/DeputyOfDetention.java b/Mage.Sets/src/mage/cards/d/DeputyOfDetention.java new file mode 100644 index 0000000000..cb6b207c94 --- /dev/null +++ b/Mage.Sets/src/mage/cards/d/DeputyOfDetention.java @@ -0,0 +1,110 @@ +package mage.cards.d; + +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.EntersBattlefieldTriggeredAbility; +import mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.SubType; +import mage.constants.TargetController; +import mage.filter.FilterPermanent; +import mage.filter.common.FilterNonlandPermanent; +import mage.filter.predicate.mageobject.NamePredicate; +import mage.filter.predicate.permanent.ControllerIdPredicate; +import mage.filter.predicate.permanent.ControllerPredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.TargetPermanent; +import mage.util.CardUtil; + +import java.util.LinkedHashSet; +import java.util.Set; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class DeputyOfDetention extends CardImpl { + + private static final FilterPermanent filter = new FilterNonlandPermanent("nonland permanent an opponent controls"); + + static { + filter.add(new ControllerPredicate(TargetController.OPPONENT)); + } + + public DeputyOfDetention(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{W}{U}"); + + this.subtype.add(SubType.VEDALKEN); + this.subtype.add(SubType.WIZARD); + this.power = new MageInt(1); + this.toughness = new MageInt(3); + + // When Deputy of Detention enters the battlefield, exile target nonland permanent an opponent controls and all other nonland permanents that player controls with the same name as that permanent until Deputy of Detention leaves the battlefield. + Ability ability = new EntersBattlefieldTriggeredAbility(new DeputyOfDetentionExileEffect(), false); + ability.addTarget(new TargetPermanent(filter)); + this.addAbility(ability); + } + + private DeputyOfDetention(final DeputyOfDetention card) { + super(card); + } + + @Override + public DeputyOfDetention copy() { + return new DeputyOfDetention(this); + } +} + +class DeputyOfDetentionExileEffect extends OneShotEffect { + + DeputyOfDetentionExileEffect() { + super(Outcome.Benefit); + this.staticText = "exile target nonland permanent an opponent controls " + + "and all other nonland permanents that player controls " + + "with the same name as that permanent until {this} leaves the battlefield"; + } + + private DeputyOfDetentionExileEffect(final DeputyOfDetentionExileEffect effect) { + super(effect); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + Permanent permanent = game.getPermanent(source.getSourceId()); + Permanent targeted = game.getPermanent(source.getFirstTarget()); + + if (permanent == null || controller == null || targeted == null) { + return false; + } + + FilterPermanent filter = new FilterPermanent(); + filter.add(new ControllerIdPredicate(targeted.getControllerId())); + filter.add(new NamePredicate(targeted.getName())); + + Set<Card> toExile = new LinkedHashSet<>(); + for (Permanent creature : game.getBattlefield().getActivePermanents(filter, controller.getId(), game)) { + toExile.add(creature); + } + + if (!toExile.isEmpty()) { + controller.moveCardsToExile(toExile, source, game, true, CardUtil.getCardExileZoneId(game, source), permanent.getIdName()); + new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility()).apply(game, source); + } + return true; + } + + @Override + public DeputyOfDetentionExileEffect copy() { + return new DeputyOfDetentionExileEffect(this); + } + +} diff --git a/Mage.Sets/src/mage/sets/RavnicaAllegiance.java b/Mage.Sets/src/mage/sets/RavnicaAllegiance.java index 2cf218a99e..d30da1dcf7 100644 --- a/Mage.Sets/src/mage/sets/RavnicaAllegiance.java +++ b/Mage.Sets/src/mage/sets/RavnicaAllegiance.java @@ -40,6 +40,7 @@ public final class RavnicaAllegiance extends ExpansionSet { cards.add(new SetCardInfo("Bedevil", 157, Rarity.RARE, mage.cards.b.Bedevil.class)); cards.add(new SetCardInfo("Blood Crypt", 245, Rarity.RARE, mage.cards.b.BloodCrypt.class)); cards.add(new SetCardInfo("Breeding Pool", 246, Rarity.RARE, mage.cards.b.BreedingPool.class)); + cards.add(new SetCardInfo("Deputy of Detention", 165, Rarity.RARE, mage.cards.d.DeputyOfDetention.class)); cards.add(new SetCardInfo("Emergency Powers", 169, Rarity.MYTHIC, mage.cards.e.EmergencyPowers.class)); cards.add(new SetCardInfo("Frenzied Arynx", 173, Rarity.COMMON, mage.cards.f.FrenziedArynx.class)); cards.add(new SetCardInfo("Gate Colossus", 232, Rarity.UNCOMMON, mage.cards.g.GateColossus.class));