From a69f6b38d956e494b56c8fda4334aa158b3e3a5c Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Tue, 27 Apr 2021 21:33:56 -0400 Subject: [PATCH] [C21] Implemented Study Hall --- .../mage/cards/g/GilanraCallerOfWirewood.java | 19 +-- Mage.Sets/src/mage/cards/s/StudyHall.java | 125 ++++++++++++++++++ .../src/mage/sets/Commander2021Edition.java | 1 + 3 files changed, 136 insertions(+), 9 deletions(-) create mode 100644 Mage.Sets/src/mage/cards/s/StudyHall.java diff --git a/Mage.Sets/src/mage/cards/g/GilanraCallerOfWirewood.java b/Mage.Sets/src/mage/cards/g/GilanraCallerOfWirewood.java index 6e93b10abec..685cb7448f6 100644 --- a/Mage.Sets/src/mage/cards/g/GilanraCallerOfWirewood.java +++ b/Mage.Sets/src/mage/cards/g/GilanraCallerOfWirewood.java @@ -18,6 +18,7 @@ import mage.game.Game; import mage.game.events.GameEvent; import mage.game.permanent.Permanent; import mage.game.stack.Spell; +import mage.players.ManaPoolItem; import mage.players.Player; import java.util.UUID; @@ -81,12 +82,11 @@ class GilanraCallerOfWirewoodTriggeredAbility extends DelayedTriggeredAbility { if (!getSourceId().equals(event.getSourceId())) { return false; } - Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(getSourceId()); + Permanent sourcePermanent = getSourcePermanentOrLKI(game); if (sourcePermanent == null || sourcePermanent .getAbilities(game) .stream() - .filter(GreenManaAbility.class::isInstance) .map(Ability::getOriginalId) .map(UUID::toString) .noneMatch(event.getData()::equals)) { @@ -101,15 +101,16 @@ class GilanraCallerOfWirewoodTriggeredAbility extends DelayedTriggeredAbility { if (super.isInactive(game)) { return true; } - // must remove effect on empty mana pool to fix accumulate bug - Player player = game.getPlayer(this.getControllerId()); - if (player == null) { - return true; - } - // if no mana in pool then it can be discarded - return player.getManaPool().getManaItems().stream().noneMatch(m -> m.getSourceId().equals(getSourceId())); + Player player = game.getPlayer(this.getControllerId()); + return player == null + || player + .getManaPool() + .getManaItems() + .stream() + .map(ManaPoolItem::getSourceId) + .noneMatch(getSourceId()::equals); } @Override diff --git a/Mage.Sets/src/mage/cards/s/StudyHall.java b/Mage.Sets/src/mage/cards/s/StudyHall.java new file mode 100644 index 00000000000..01ad66aef5d --- /dev/null +++ b/Mage.Sets/src/mage/cards/s/StudyHall.java @@ -0,0 +1,125 @@ +package mage.cards.s; + +import mage.abilities.Ability; +import mage.abilities.DelayedTriggeredAbility; +import mage.abilities.costs.common.TapSourceCost; +import mage.abilities.costs.mana.GenericManaCost; +import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect; +import mage.abilities.effects.keyword.ScryEffect; +import mage.abilities.mana.AnyColorManaAbility; +import mage.abilities.mana.ColorlessManaAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; +import mage.game.stack.Spell; +import mage.players.ManaPoolItem; +import mage.players.Player; +import mage.watchers.common.CommanderPlaysCountWatcher; + +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class StudyHall extends CardImpl { + + public StudyHall(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.LAND}, ""); + + // {T}: Add {C}. + this.addAbility(new ColorlessManaAbility()); + + // {1}, {T}: Add one mana of any color. When you spend this mana to cast your commander, scry X, where X is the number of times it's been cast from the command zone this game. + AnyColorManaAbility ability = new AnyColorManaAbility(new GenericManaCost(1)); + ability.addCost(new TapSourceCost()); + ability.addEffect(new CreateDelayedTriggeredAbilityEffect(new StudyHallTriggeredAbility())); + ability.setUndoPossible(false); + this.addAbility(ability); + } + + private StudyHall(final StudyHall card) { + super(card); + } + + @Override + public StudyHall copy() { + return new StudyHall(this); + } +} + +class StudyHallTriggeredAbility extends DelayedTriggeredAbility { + + StudyHallTriggeredAbility() { + super(null, Duration.Custom, true, false); + } + + private StudyHallTriggeredAbility(final StudyHallTriggeredAbility ability) { + super(ability); + } + + @Override + public StudyHallTriggeredAbility copy() { + return new StudyHallTriggeredAbility(this); + } + + @Override + public boolean checkEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.MANA_PAID; + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + if (!getSourceId().equals(event.getSourceId())) { + return false; + } + Permanent sourcePermanent = getSourcePermanentOrLKI(game); + if (sourcePermanent == null + || sourcePermanent + .getAbilities(game) + .stream() + .map(Ability::getOriginalId) + .map(UUID::toString) + .noneMatch(event.getData()::equals)) { + return false; + } + Player player = game.getPlayer(getControllerId()); + Spell spell = game.getStack().getSpell(event.getTargetId()); + CommanderPlaysCountWatcher watcher = game.getState().getWatcher(CommanderPlaysCountWatcher.class); + if (player == null + || spell == null + || watcher == null + || !game.isCommanderObject(player, spell)) { + return false; + } + getEffects().clear(); + addEffect(new ScryEffect(watcher.getPlaysCount(spell.getMainCard().getId()))); + return true; + } + + @Override + public boolean isInactive(Game game) { + if (super.isInactive(game)) { + return true; + } + // must remove effect on empty mana pool to fix accumulate bug + // if no mana in pool then it can be discarded + Player player = game.getPlayer(this.getControllerId()); + return player == null + || player + .getManaPool() + .getManaItems() + .stream() + .map(ManaPoolItem::getSourceId) + .noneMatch(getSourceId()::equals); + } + + @Override + public String getRule() { + return "When you spend this mana to cast your commander, scry X, " + + "where X is the number of times it's been cast from the command zone this game."; + } +} diff --git a/Mage.Sets/src/mage/sets/Commander2021Edition.java b/Mage.Sets/src/mage/sets/Commander2021Edition.java index 928f3516dd2..fc344102691 100644 --- a/Mage.Sets/src/mage/sets/Commander2021Edition.java +++ b/Mage.Sets/src/mage/sets/Commander2021Edition.java @@ -292,6 +292,7 @@ public final class Commander2021Edition extends ExpansionSet { cards.add(new SetCardInfo("Steel Hellkite", 266, Rarity.RARE, mage.cards.s.SteelHellkite.class)); cards.add(new SetCardInfo("Steel Overseer", 267, Rarity.RARE, mage.cards.s.SteelOverseer.class)); cards.add(new SetCardInfo("Stinging Study", 44, Rarity.RARE, mage.cards.s.StingingStudy.class)); + cards.add(new SetCardInfo("Study Hall", 80, Rarity.COMMON, mage.cards.s.StudyHall.class)); cards.add(new SetCardInfo("Suffer the Past", 155, Rarity.UNCOMMON, mage.cards.s.SufferThePast.class)); cards.add(new SetCardInfo("Sun Droplet", 268, Rarity.UNCOMMON, mage.cards.s.SunDroplet.class)); cards.add(new SetCardInfo("Sun Titan", 106, Rarity.MYTHIC, mage.cards.s.SunTitan.class));