From 8116f1365edd803b95982c4b9231be7e22567a18 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Tue, 19 Jun 2018 13:32:15 -0400 Subject: [PATCH] Implemented Alpine Moon --- Mage.Sets/src/mage/cards/a/AlpineMoon.java | 114 ++++++++++++++++++ Mage.Sets/src/mage/sets/CoreSet2019.java | 1 + .../effects/common/ChooseACardNameEffect.java | 8 ++ .../mage/cards/repository/CardRepository.java | 24 ++++ 4 files changed, 147 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/a/AlpineMoon.java diff --git a/Mage.Sets/src/mage/cards/a/AlpineMoon.java b/Mage.Sets/src/mage/cards/a/AlpineMoon.java new file mode 100644 index 0000000000..a88fa999f8 --- /dev/null +++ b/Mage.Sets/src/mage/cards/a/AlpineMoon.java @@ -0,0 +1,114 @@ +package mage.cards.a; + +import java.util.UUID; +import mage.abilities.Ability; +import mage.abilities.common.AsEntersBattlefieldAbility; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.ContinuousEffectImpl; +import mage.abilities.effects.common.ChooseACardNameEffect; +import mage.abilities.mana.AnyColorManaAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Layer; +import mage.constants.Outcome; +import mage.constants.SubLayer; +import mage.constants.SubType; +import mage.constants.SuperType; +import mage.constants.TargetController; +import mage.constants.Zone; +import mage.filter.FilterPermanent; +import mage.filter.common.FilterLandPermanent; +import mage.filter.predicate.Predicates; +import mage.filter.predicate.mageobject.NamePredicate; +import mage.filter.predicate.mageobject.SupertypePredicate; +import mage.filter.predicate.permanent.ControllerPredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author TheElk801 + */ +public final class AlpineMoon extends CardImpl { + + public AlpineMoon(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{R}"); + + // As Alpine Moon enters the battlefield, choose a nonbasic land card name. + this.addAbility(new AsEntersBattlefieldAbility(new ChooseACardNameEffect(ChooseACardNameEffect.TypeOfName.NONBASIC_LAND_NAME))); + + // Lands your opponents control with the chosen name lose all land types and abilities, and they gain "{T}: Add one mana of any color." + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new AlpineMoonEffect())); + } + + public AlpineMoon(final AlpineMoon card) { + super(card); + } + + @Override + public AlpineMoon copy() { + return new AlpineMoon(this); + } +} + +class AlpineMoonEffect extends ContinuousEffectImpl { + + private static final FilterPermanent filter = new FilterLandPermanent(); + + static { + filter.add(new ControllerPredicate(TargetController.OPPONENT)); + filter.add(Predicates.not(new SupertypePredicate(SuperType.BASIC))); + } + + public AlpineMoonEffect() { + super(Duration.WhileOnBattlefield, Outcome.Benefit); + this.staticText = "lands your opponents control with the chosen name " + + "lose all land types and abilities, " + + "and they gain \"{T}: Add one mana of any color.\""; + } + + public AlpineMoonEffect(final AlpineMoonEffect effect) { + super(effect); + } + + @Override + public AlpineMoonEffect copy() { + return new AlpineMoonEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + return false; + } + + @Override + public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { + String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY); + if (cardName == null) { + return false; + } + FilterPermanent filter2 = filter.copy(); + filter2.add(new NamePredicate(cardName)); + for (Permanent land : game.getBattlefield().getActivePermanents(filter2, source.getControllerId(), game)) { + switch (layer) { + case TypeChangingEffects_4: + // 305.7 Note that this doesn't remove any abilities that were granted to the land by other effects + // So the ability removing has to be done before Layer 6 + land.removeAllAbilities(source.getSourceId(), game); + land.getSubtype(game).removeAll(SubType.getLandTypes(false)); + break; + case AbilityAddingRemovingEffects_6: + land.addAbility(new AnyColorManaAbility(), source.getSourceId(), game); + break; + } + } + return true; + } + + @Override + public boolean hasLayer(Layer layer) { + return layer == Layer.AbilityAddingRemovingEffects_6 || layer == Layer.TypeChangingEffects_4; + } +} diff --git a/Mage.Sets/src/mage/sets/CoreSet2019.java b/Mage.Sets/src/mage/sets/CoreSet2019.java index 2f0d218470..070c1618eb 100644 --- a/Mage.Sets/src/mage/sets/CoreSet2019.java +++ b/Mage.Sets/src/mage/sets/CoreSet2019.java @@ -37,6 +37,7 @@ public final class CoreSet2019 extends ExpansionSet { cards.add(new SetCardInfo("Ajani's Pridemate", 5, Rarity.UNCOMMON, mage.cards.a.AjanisPridemate.class)); cards.add(new SetCardInfo("Ajani, Adversary of Tyrants", 3, Rarity.MYTHIC, mage.cards.a.AjaniAdversaryOfTyrants.class)); cards.add(new SetCardInfo("Ajani, Wise Counselor", 281, Rarity.MYTHIC, mage.cards.a.AjaniWiseCounselor.class)); + cards.add(new SetCardInfo("Alpine Moon", 128, Rarity.RARE, mage.cards.a.AlpineMoon.class)); cards.add(new SetCardInfo("Anticipate", 44, Rarity.COMMON, mage.cards.a.Anticipate.class)); cards.add(new SetCardInfo("Apex of Power", 129, Rarity.MYTHIC, mage.cards.a.ApexOfPower.class)); cards.add(new SetCardInfo("Arisen Gorgon", 292, Rarity.UNCOMMON, mage.cards.a.ArisenGorgon.class)); diff --git a/Mage/src/main/java/mage/abilities/effects/common/ChooseACardNameEffect.java b/Mage/src/main/java/mage/abilities/effects/common/ChooseACardNameEffect.java index f0439a01cf..e8fc6ab108 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/ChooseACardNameEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/ChooseACardNameEffect.java @@ -24,6 +24,7 @@ public class ChooseACardNameEffect extends OneShotEffect { ALL, NOT_BASIC_LAND_NAME, + NONBASIC_LAND_NAME, NON_ARTIFACT_AND_NON_LAND_NAME, NON_LAND_NAME, NON_LAND_AND_NON_CREATURE_NAME, @@ -62,6 +63,10 @@ public class ChooseACardNameEffect extends OneShotEffect { cardChoice.setChoices(CardRepository.instance.getNotBasicLandNames()); cardChoice.setMessage("Choose a card name other than a basic land card name"); break; + case NONBASIC_LAND_NAME: + cardChoice.setChoices(CardRepository.instance.getNonbasicLandNames()); + cardChoice.setMessage("Choose a nonbasic land card name"); + break; case NON_ARTIFACT_AND_NON_LAND_NAME: cardChoice.setChoices(CardRepository.instance.getNonArtifactAndNonLandNames()); cardChoice.setMessage("Choose a nonartifact, nonland card name"); @@ -113,6 +118,9 @@ public class ChooseACardNameEffect extends OneShotEffect { case NOT_BASIC_LAND_NAME: sb.append("card name other than a basic land card"); break; + case NONBASIC_LAND_NAME: + sb.append("nonbasic land card name"); + break; case NON_ARTIFACT_AND_NON_LAND_NAME: sb.append("nonartifact, nonland card"); break; diff --git a/Mage/src/main/java/mage/cards/repository/CardRepository.java b/Mage/src/main/java/mage/cards/repository/CardRepository.java index d2215e2758..0fecf5e4fd 100644 --- a/Mage/src/main/java/mage/cards/repository/CardRepository.java +++ b/Mage/src/main/java/mage/cards/repository/CardRepository.java @@ -153,6 +153,30 @@ public enum CardRepository { return names; } + public Set getNonbasicLandNames() { + Set names = new TreeSet<>(); + try { + QueryBuilder qb = cardDao.queryBuilder(); + qb.distinct().selectColumns("name"); + Where where = qb.where(); + where.and(where.not().not().like("supertypes", '%' + SuperType.BASIC.name() + '%'), where.like("types", '%' + CardType.LAND.name() + '%')); + List results = cardDao.query(qb.prepare()); + for (CardInfo card : results) { + int result = card.getName().indexOf(" // "); + if (result > 0) { + names.add(card.getName().substring(0, result)); + names.add(card.getName().substring(result + 4)); + } else { + names.add(card.getName()); + } + } + } catch (SQLException ex) { + Logger.getLogger(CardRepository.class).error("Error getting non-land names from DB : " + ex); + + } + return names; + } + public Set getNotBasicLandNames() { Set names = new TreeSet<>(); try {