[C21] Implemented Study Hall

This commit is contained in:
Evan Kranzler 2021-04-27 21:33:56 -04:00
parent 90e620452d
commit a69f6b38d9
3 changed files with 136 additions and 9 deletions

View file

@ -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

View file

@ -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.";
}
}

View file

@ -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));