[ICE] Implement Snowfall (#11467)

* [ICE] Implement Snowfall

* Change filter text, declare Island subtype in constructor

* Make choice optional

* Inherit outcome from superclass; add check in HumanPlayer.java to prevent auto-selecting non-ChoiceColor choices
This commit is contained in:
Cameron Merkel 2023-11-27 22:41:40 -06:00 committed by GitHub
parent 2abe61643c
commit 1132cc27ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 173 additions and 1 deletions

View file

@ -16,6 +16,7 @@ import mage.abilities.mana.ManaAbility;
import mage.cards.*;
import mage.cards.decks.Deck;
import mage.choices.Choice;
import mage.choices.ChoiceColor;
import mage.choices.ChoiceImpl;
import mage.constants.*;
import mage.filter.StaticFilters;
@ -582,7 +583,7 @@ public class HumanPlayer extends PlayerImpl {
}
// Try to autopay for mana
if (Outcome.PutManaInPool == outcome && currentlyUnpaidMana != null) {
if (Outcome.PutManaInPool == outcome && choice instanceof ChoiceColor && currentlyUnpaidMana != null) {
// Check check if the spell being paid for cares about the color of mana being paid
// See: https://github.com/magefree/mage/issues/9070
boolean caresAboutManaColor = false;

View file

@ -0,0 +1,170 @@
package mage.cards.s;
import java.util.*;
import mage.ConditionalMana;
import mage.Mana;
import mage.abilities.Ability;
import mage.abilities.common.TapForManaAllTriggeredManaAbility;
import mage.abilities.condition.Condition;
import mage.abilities.costs.Cost;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.mana.ManaEffect;
import mage.abilities.keyword.CumulativeUpkeepAbility;
import mage.abilities.mana.conditional.ManaCondition;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.choices.Choice;
import mage.choices.ChoiceImpl;
import mage.constants.*;
import mage.filter.common.FilterLandPermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
/**
* @author Cguy7777
*/
public final class Snowfall extends CardImpl {
private static final FilterLandPermanent filter = new FilterLandPermanent(SubType.ISLAND, "an Island is tapped");
public Snowfall(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{2}{U}");
// Cumulative upkeep {U}
this.addAbility(new CumulativeUpkeepAbility(new ManaCostsImpl<>("{U}")));
// Whenever an Island is tapped for mana, its controller may add an additional {U}.
// If that Island is snow, its controller may add an additional {U}{U} instead.
// Spend this mana only to pay cumulative upkeep costs.
this.addAbility(new TapForManaAllTriggeredManaAbility(new SnowfallManaEffect(), filter, SetTargetPointer.PERMANENT));
}
private Snowfall(final Snowfall card) {
super(card);
}
@Override
public Snowfall copy() {
return new Snowfall(this);
}
}
class SnowfallManaEffect extends ManaEffect {
private static final Set<String> choice = new HashSet<>();
static {
choice.add("Add one additional blue mana.");
choice.add("Add two additional blue mana.");
choice.add("Don't add additional mana.");
}
SnowfallManaEffect() {
super();
this.staticText = "its controller may add an additional {U}. " +
"If that Island is snow, its controller may add an additional {U}{U} instead. " +
"Spend this mana only to pay cumulative upkeep costs.";
}
private SnowfallManaEffect(final SnowfallManaEffect effect) {
super(effect);
}
@Override
public Player getPlayer(Game game, Ability source) {
Permanent land = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
if (land != null) {
return game.getPlayer(land.getControllerId());
}
return null;
}
@Override
public List<Mana> getNetMana(Game game, Ability source) {
List<Mana> netMana = new ArrayList<>();
if (game == null) {
return netMana;
}
Permanent land = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
if (land == null) {
return netMana;
}
Mana mana = Mana.BlueMana(land.isSnow(game) ? 2 : 1);
netMana.add(mana);
return netMana;
}
@Override
public Mana produceMana(Game game, Ability source) {
if (game == null) {
return new Mana();
}
Permanent land = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
if (land == null) {
return new Mana();
}
Player player = game.getPlayer(land.getControllerId());
if (player == null) {
return new Mana();
}
if (land.isSnow(game)) {
Choice choiceImpl = new ChoiceImpl();
choiceImpl.setMessage("Add additional blue mana? This mana can only be spent to pay cumulative upkeep costs.");
choiceImpl.setChoices(choice);
if (player.choose(outcome, choiceImpl, game)) {
switch (choiceImpl.getChoice()) {
case "Add one additional blue mana.":
return new SnowfallConditionalMana(Mana.BlueMana(1));
case "Add two additional blue mana.":
return new SnowfallConditionalMana(Mana.BlueMana(2));
default:
break;
}
}
} else {
String message = "Add an additional {U}? This mana can only be spent to pay cumulative upkeep costs.";
if (player.chooseUse(outcome, message, source, game)) {
return new SnowfallConditionalMana(Mana.BlueMana(1));
}
}
return new Mana();
}
@Override
public SnowfallManaEffect copy() {
return new SnowfallManaEffect(this);
}
}
class SnowfallConditionalMana extends ConditionalMana {
public SnowfallConditionalMana(Mana mana) {
super(mana);
staticText = "Spend this mana only to pay cumulative upkeep costs";
addCondition(new SnowfallManaCondition());
}
}
class SnowfallManaCondition extends ManaCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
if (source != null) {
return source instanceof CumulativeUpkeepAbility;
}
return false;
}
@Override
public boolean apply(Game game, Ability source, UUID originalId, Cost costToPay) {
return apply(game, source);
}
}

View file

@ -319,6 +319,7 @@ public final class IceAge extends ExpansionSet {
cards.add(new SetCardInfo("Snow-Covered Plains", 367, Rarity.LAND, mage.cards.s.SnowCoveredPlains.class));
cards.add(new SetCardInfo("Snow-Covered Swamp", 372, Rarity.LAND, mage.cards.s.SnowCoveredSwamp.class));
cards.add(new SetCardInfo("Snowblind", 264, Rarity.RARE, mage.cards.s.Snowblind.class));
cards.add(new SetCardInfo("Snowfall", 101, Rarity.COMMON, mage.cards.s.Snowfall.class));
cards.add(new SetCardInfo("Soldevi Golem", 338, Rarity.RARE, mage.cards.s.SoldeviGolem.class));
cards.add(new SetCardInfo("Soldevi Machinist", 102, Rarity.UNCOMMON, mage.cards.s.SoldeviMachinist.class));
cards.add(new SetCardInfo("Soldevi Simulacrum", 339, Rarity.UNCOMMON, mage.cards.s.SoldeviSimulacrum.class));