diff --git a/Mage.Sets/src/mage/cards/i/ImprisonedInTheMoon.java b/Mage.Sets/src/mage/cards/i/ImprisonedInTheMoon.java index 2271a71ada..40abc9d361 100644 --- a/Mage.Sets/src/mage/cards/i/ImprisonedInTheMoon.java +++ b/Mage.Sets/src/mage/cards/i/ImprisonedInTheMoon.java @@ -1,6 +1,5 @@ package mage.cards.i; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.ContinuousEffectImpl; @@ -9,21 +8,16 @@ import mage.abilities.keyword.EnchantAbility; import mage.abilities.mana.ColorlessManaAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.CardType; -import mage.constants.SubType; -import mage.constants.Duration; -import mage.constants.Layer; -import mage.constants.Outcome; -import mage.constants.SubLayer; -import mage.constants.Zone; +import mage.constants.*; import mage.filter.FilterPermanent; import mage.filter.predicate.Predicates; import mage.game.Game; import mage.game.permanent.Permanent; import mage.target.TargetPermanent; +import java.util.UUID; + /** - * * @author fireshoes */ public final class ImprisonedInTheMoon extends CardImpl { @@ -31,9 +25,11 @@ public final class ImprisonedInTheMoon extends CardImpl { private static final FilterPermanent filter = new FilterPermanent("creature, land, or planeswalker"); static { - filter.add(Predicates.or(CardType.CREATURE.getPredicate(), + filter.add(Predicates.or( + CardType.CREATURE.getPredicate(), CardType.LAND.getPredicate(), - CardType.PLANESWALKER.getPredicate())); + CardType.PLANESWALKER.getPredicate() + )); } public ImprisonedInTheMoon(UUID ownerId, CardSetInfo setInfo) { @@ -48,7 +44,7 @@ public final class ImprisonedInTheMoon extends CardImpl { this.addAbility(ability); // Enchanted permanent is a colorless land with "{T}: Add {C}" and loses all other card types and abilities. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BecomesColorlessLandEffect())); + this.addAbility(new SimpleStaticAbility(new ImprisonedInTheMoonEffect())); } private ImprisonedInTheMoon(final ImprisonedInTheMoon card) { @@ -61,14 +57,15 @@ public final class ImprisonedInTheMoon extends CardImpl { } } -class BecomesColorlessLandEffect extends ContinuousEffectImpl { +class ImprisonedInTheMoonEffect extends ContinuousEffectImpl { - public BecomesColorlessLandEffect() { + ImprisonedInTheMoonEffect() { super(Duration.WhileOnBattlefield, Outcome.Detriment); - this.staticText = "Enchanted permanent is a colorless land with \"{T}: Add {C}\" and loses all other card types and abilities"; + this.staticText = "Enchanted permanent is a colorless land " + + "with \"{T}: Add {C}\" and loses all other card types and abilities"; } - public BecomesColorlessLandEffect(final BecomesColorlessLandEffect effect) { + private ImprisonedInTheMoonEffect(final ImprisonedInTheMoonEffect effect) { super(effect); } @@ -78,47 +75,49 @@ class BecomesColorlessLandEffect extends ContinuousEffectImpl { } @Override - public BecomesColorlessLandEffect copy() { - return new BecomesColorlessLandEffect(this); + public ImprisonedInTheMoonEffect copy() { + return new ImprisonedInTheMoonEffect(this); } @Override public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { - Permanent enchantment = game.getPermanent(source.getSourceId()); - if (enchantment != null - && enchantment.getAttachedTo() != null) { - Permanent permanent = game.getPermanent(enchantment.getAttachedTo()); - if (permanent != null) { - 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 - permanent.removeAllAbilities(source.getSourceId(), game); - permanent.getCardType().clear(); - permanent.addCardType(CardType.LAND); - break; - case ColorChangingEffects_5: - permanent.getColor(game).setWhite(false); - permanent.getColor(game).setGreen(false); - permanent.getColor(game).setBlack(false); - permanent.getColor(game).setBlue(false); - permanent.getColor(game).setRed(false); - break; - case AbilityAddingRemovingEffects_6: - permanent.removeAllAbilities(source.getSourceId(), game); - permanent.addAbility(new ColorlessManaAbility(), source.getSourceId(), game); - break; - } - return true; - } + Permanent enchantment = source.getSourcePermanentIfItStillExists(game); + if (enchantment == null + || enchantment.getAttachedTo() == null) { + return false; } - return false; + Permanent permanent = game.getPermanent(enchantment.getAttachedTo()); + if (permanent == null) { + return false; + } + 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 + permanent.removeAllAbilities(source.getSourceId(), game); + permanent.getCardType().clear(); + permanent.addCardType(CardType.LAND); + permanent.retainAllLandSubTypes(game); + break; + case ColorChangingEffects_5: + permanent.getColor(game).setWhite(false); + permanent.getColor(game).setBlue(false); + permanent.getColor(game).setBlack(false); + permanent.getColor(game).setRed(false); + permanent.getColor(game).setGreen(false); + break; + case AbilityAddingRemovingEffects_6: + permanent.removeAllAbilities(source.getSourceId(), game); + permanent.addAbility(new ColorlessManaAbility(), source.getSourceId(), game); + break; + } + return true; } @Override public boolean hasLayer(Layer layer) { - return layer == Layer.AbilityAddingRemovingEffects_6 - || layer == Layer.ColorChangingEffects_5 + return layer == Layer.AbilityAddingRemovingEffects_6 + || layer == Layer.ColorChangingEffects_5 || layer == Layer.TypeChangingEffects_4; } } diff --git a/Mage/src/main/java/mage/MageObject.java b/Mage/src/main/java/mage/MageObject.java index 7f882b0b1a..ea3c24dbfa 100644 --- a/Mage/src/main/java/mage/MageObject.java +++ b/Mage/src/main/java/mage/MageObject.java @@ -280,6 +280,11 @@ public interface MageObject extends MageItem, Serializable { game.getState().getCreateMageObjectAttribute(this, game).getSubtype().retainAll(SubType.getEnchantmentTypes()); } + default void retainAllLandSubTypes(Game game) { + setIsAllCreatureTypes(game, false); + game.getState().getCreateMageObjectAttribute(this, game).getSubtype().retainAll(SubType.getLandTypes()); + } + /** * Remove object's own creature types forever (for copy effects usage) */