diff --git a/Mage.Sets/src/mage/cards/a/ArclightPhoenix.java b/Mage.Sets/src/mage/cards/a/ArclightPhoenix.java new file mode 100644 index 00000000000..d6a3d022772 --- /dev/null +++ b/Mage.Sets/src/mage/cards/a/ArclightPhoenix.java @@ -0,0 +1,114 @@ +package mage.cards.a; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.BeginningOfCombatTriggeredAbility; +import mage.abilities.condition.Condition; +import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility; +import mage.abilities.effects.common.ReturnSourceFromGraveyardToBattlefieldEffect; +import mage.constants.SubType; +import mage.abilities.keyword.FlyingAbility; +import mage.abilities.keyword.HasteAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.TargetController; +import mage.constants.WatcherScope; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.stack.Spell; +import mage.watchers.Watcher; + +/** + * + * @author TheElk801 + */ +public final class ArclightPhoenix extends CardImpl { + + public ArclightPhoenix(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{R}"); + + this.subtype.add(SubType.PHOENIX); + this.power = new MageInt(3); + this.toughness = new MageInt(2); + + // Flying + this.addAbility(FlyingAbility.getInstance()); + + // Haste + this.addAbility(HasteAbility.getInstance()); + + // At the beginning of combat on your turn, if you cast 3 or more instants and/or sorceries this turn, you may return Arclight Phoenix from your graveyard to the battlefield. + this.addAbility(new ConditionalInterveningIfTriggeredAbility( + new BeginningOfCombatTriggeredAbility( + new ReturnSourceFromGraveyardToBattlefieldEffect(), + TargetController.YOU, true + ), ArclightPhoenixCondition.instance, + "At the beginning of combat on your turn, " + + "if you cast 3 or more instants and/or sorceries this turn, " + + "you may return {this} from your graveyard to the battlefield." + )); + } + + public ArclightPhoenix(final ArclightPhoenix card) { + super(card); + } + + @Override + public ArclightPhoenix copy() { + return new ArclightPhoenix(this); + } +} + +enum ArclightPhoenixCondition implements Condition { + instance; + + @Override + public boolean apply(Game game, Ability source) { + ArclightPhoenixWatcher watcher + = (ArclightPhoenixWatcher) game.getState().getWatchers().get( + ArclightPhoenixWatcher.class.getSimpleName() + ); + return watcher.getInstantSorceryCount(source.getControllerId()) > 2; + } +} + +class ArclightPhoenixWatcher extends Watcher { + + private Map instantSorceryCount = new HashMap(); + + public ArclightPhoenixWatcher() { + super(ArclightPhoenixWatcher.class.getSimpleName(), WatcherScope.GAME); + } + + public ArclightPhoenixWatcher(final ArclightPhoenixWatcher watcher) { + super(watcher); + this.instantSorceryCount.putAll(watcher.instantSorceryCount); + } + + @Override + public ArclightPhoenixWatcher copy() { + return new ArclightPhoenixWatcher(this); + } + + @Override + public void watch(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.SPELL_CAST) { + Spell spell = game.getStack().getSpell(event.getTargetId()); + if (spell == null || !spell.isInstantOrSorcery()) { + return; + } + this.instantSorceryCount.putIfAbsent(spell.getControllerId(), 0); + this.instantSorceryCount.compute( + spell.getControllerId(), (k, a) -> a + 1 + ); + } + } + + public int getInstantSorceryCount(UUID playerId) { + return this.instantSorceryCount.getOrDefault(playerId, 0); + } +} diff --git a/Mage.Sets/src/mage/sets/GuildsOfRavnica.java b/Mage.Sets/src/mage/sets/GuildsOfRavnica.java index 5504342f41a..3b8ad4424ea 100644 --- a/Mage.Sets/src/mage/sets/GuildsOfRavnica.java +++ b/Mage.Sets/src/mage/sets/GuildsOfRavnica.java @@ -23,6 +23,7 @@ public final class GuildsOfRavnica extends ExpansionSet { this.ratioBoosterMythic = 8; cards.add(new SetCardInfo("Arboretum Elemental", 122, Rarity.UNCOMMON, mage.cards.a.ArboretumElemental.class)); + cards.add(new SetCardInfo("Arclight Phoenix", 91, Rarity.MYTHIC, mage.cards.a.ArclightPhoenix.class)); cards.add(new SetCardInfo("Artful Takedown", 151, Rarity.COMMON, mage.cards.a.ArtfulTakedown.class)); cards.add(new SetCardInfo("Assassin's Trophy", 152, Rarity.RARE, mage.cards.a.AssassinsTrophy.class)); cards.add(new SetCardInfo("Attendant of Vraska", 271, Rarity.UNCOMMON, mage.cards.a.AttendantOfVraska.class));