From 0af261aeb37b37eb7f2d53e9de310acf847b7e9e Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Mon, 15 Jun 2020 19:54:00 -0400 Subject: [PATCH] Implemented Barrin, Tolarian Archmage --- .../mage/cards/b/BarrinTolarianArchmage.java | 111 ++++++++++++++++++ Mage.Sets/src/mage/sets/CoreSet2021.java | 1 + 2 files changed, 112 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/b/BarrinTolarianArchmage.java diff --git a/Mage.Sets/src/mage/cards/b/BarrinTolarianArchmage.java b/Mage.Sets/src/mage/cards/b/BarrinTolarianArchmage.java new file mode 100644 index 0000000000..77dc1727ab --- /dev/null +++ b/Mage.Sets/src/mage/cards/b/BarrinTolarianArchmage.java @@ -0,0 +1,111 @@ +package mage.cards.b; + +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.BeginningOfEndStepTriggeredAbility; +import mage.abilities.common.EntersBattlefieldTriggeredAbility; +import mage.abilities.condition.Condition; +import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility; +import mage.abilities.effects.common.DrawCardSourceControllerEffect; +import mage.abilities.effects.common.ReturnToHandTargetEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.filter.FilterPermanent; +import mage.filter.common.FilterCreatureOrPlaneswalkerPermanent; +import mage.filter.predicate.permanent.AnotherPredicate; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.ZoneChangeEvent; +import mage.target.TargetPermanent; +import mage.watchers.Watcher; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class BarrinTolarianArchmage extends CardImpl { + + private static final FilterPermanent filter + = new FilterCreatureOrPlaneswalkerPermanent("other target creature or planeswalker"); + + static { + filter.add(AnotherPredicate.instance); + } + + public BarrinTolarianArchmage(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{U}{U}"); + + this.addSuperType(SuperType.LEGENDARY); + this.subtype.add(SubType.HUMAN); + this.subtype.add(SubType.WIZARD); + this.power = new MageInt(2); + this.toughness = new MageInt(2); + + // When Barrin, Tolarian Archmage enters the battlefield, return up to one other target creature or planeswalker to its owner's hand. + Ability ability = new EntersBattlefieldTriggeredAbility(new ReturnToHandTargetEffect()); + ability.addTarget(new TargetPermanent(0, 1, filter, false)); + this.addAbility(ability); + + // At the beginning of your end step, if a permanent was put into your hand from the battlefield this turn, draw a card. + this.addAbility(new ConditionalInterveningIfTriggeredAbility( + new BeginningOfEndStepTriggeredAbility( + new DrawCardSourceControllerEffect(1), TargetController.YOU, false + ), BarrinTolarianArchmageCondition.instance, "At the beginning of your end step, " + + "if a permanent was put into your hand from the battlefield this turn, draw a card." + ), new BarrinTolarianArchmageWatcher()); + } + + private BarrinTolarianArchmage(final BarrinTolarianArchmage card) { + super(card); + } + + @Override + public BarrinTolarianArchmage copy() { + return new BarrinTolarianArchmage(this); + } +} + +enum BarrinTolarianArchmageCondition implements Condition { + instance; + + @Override + public boolean apply(Game game, Ability source) { + BarrinTolarianArchmageWatcher watcher = game.getState().getWatcher(BarrinTolarianArchmageWatcher.class); + return watcher != null && watcher.checkPlayer(source.getControllerId()); + } +} + +class BarrinTolarianArchmageWatcher extends Watcher { + + private final Set playerSet = new HashSet<>(); + + BarrinTolarianArchmageWatcher() { + super(WatcherScope.GAME); + } + + @Override + public void watch(GameEvent event, Game game) { + if (event.getType() != GameEvent.EventType.ZONE_CHANGE) { + return; + } + ZoneChangeEvent zEvent = (ZoneChangeEvent) event; + if (zEvent.getFromZone() == Zone.BATTLEFIELD + && zEvent.getToZone() == Zone.HAND) { + playerSet.add(zEvent.getTarget().getOwnerId()); + } + } + + @Override + public void reset() { + playerSet.clear(); + super.reset(); + } + + boolean checkPlayer(UUID playerId) { + return playerSet.contains(playerId); + } +} diff --git a/Mage.Sets/src/mage/sets/CoreSet2021.java b/Mage.Sets/src/mage/sets/CoreSet2021.java index 5d8d3329b9..f7a714dd57 100644 --- a/Mage.Sets/src/mage/sets/CoreSet2021.java +++ b/Mage.Sets/src/mage/sets/CoreSet2021.java @@ -41,6 +41,7 @@ public final class CoreSet2021 extends ExpansionSet { cards.add(new SetCardInfo("Azusa, Lost but Seeking", 173, Rarity.RARE, mage.cards.a.AzusaLostButSeeking.class)); cards.add(new SetCardInfo("Bad Deal", 89, Rarity.UNCOMMON, mage.cards.b.BadDeal.class)); cards.add(new SetCardInfo("Baneslayer Angel", 6, Rarity.MYTHIC, mage.cards.b.BaneslayerAngel.class)); + cards.add(new SetCardInfo("Barrin, Tolarian Archmage", 45, Rarity.RARE, mage.cards.b.BarrinTolarianArchmage.class)); cards.add(new SetCardInfo("Basri Ket", 7, Rarity.MYTHIC, mage.cards.b.BasriKet.class)); cards.add(new SetCardInfo("Basri's Acolyte", 8, Rarity.COMMON, mage.cards.b.BasrisAcolyte.class)); cards.add(new SetCardInfo("Basri's Aegis", 322, Rarity.RARE, mage.cards.b.BasrisAegis.class));