[EMN] fixed Imprisoned in the Moon not correctly removing subtypes

This commit is contained in:
Evan Kranzler 2021-03-25 08:25:00 -04:00
parent b74ff4a2f8
commit 83993500e0
2 changed files with 52 additions and 48 deletions

View file

@ -1,6 +1,5 @@
package mage.cards.i; package mage.cards.i;
import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility; import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.ContinuousEffectImpl;
@ -9,21 +8,16 @@ import mage.abilities.keyword.EnchantAbility;
import mage.abilities.mana.ColorlessManaAbility; import mage.abilities.mana.ColorlessManaAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.constants.CardType; import mage.constants.*;
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.filter.FilterPermanent; import mage.filter.FilterPermanent;
import mage.filter.predicate.Predicates; import mage.filter.predicate.Predicates;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.target.TargetPermanent; import mage.target.TargetPermanent;
import java.util.UUID;
/** /**
*
* @author fireshoes * @author fireshoes
*/ */
public final class ImprisonedInTheMoon extends CardImpl { 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"); private static final FilterPermanent filter = new FilterPermanent("creature, land, or planeswalker");
static { static {
filter.add(Predicates.or(CardType.CREATURE.getPredicate(), filter.add(Predicates.or(
CardType.CREATURE.getPredicate(),
CardType.LAND.getPredicate(), CardType.LAND.getPredicate(),
CardType.PLANESWALKER.getPredicate())); CardType.PLANESWALKER.getPredicate()
));
} }
public ImprisonedInTheMoon(UUID ownerId, CardSetInfo setInfo) { public ImprisonedInTheMoon(UUID ownerId, CardSetInfo setInfo) {
@ -48,7 +44,7 @@ public final class ImprisonedInTheMoon extends CardImpl {
this.addAbility(ability); this.addAbility(ability);
// Enchanted permanent is a colorless land with "{T}: Add {C}" and loses all other card types and abilities. // 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) { 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); 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); super(effect);
} }
@ -78,47 +75,49 @@ class BecomesColorlessLandEffect extends ContinuousEffectImpl {
} }
@Override @Override
public BecomesColorlessLandEffect copy() { public ImprisonedInTheMoonEffect copy() {
return new BecomesColorlessLandEffect(this); return new ImprisonedInTheMoonEffect(this);
} }
@Override @Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
Permanent enchantment = game.getPermanent(source.getSourceId()); Permanent enchantment = source.getSourcePermanentIfItStillExists(game);
if (enchantment != null if (enchantment == null
&& enchantment.getAttachedTo() != null) { || enchantment.getAttachedTo() == null) {
Permanent permanent = game.getPermanent(enchantment.getAttachedTo()); return false;
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;
}
} }
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 @Override
public boolean hasLayer(Layer layer) { public boolean hasLayer(Layer layer) {
return layer == Layer.AbilityAddingRemovingEffects_6 return layer == Layer.AbilityAddingRemovingEffects_6
|| layer == Layer.ColorChangingEffects_5 || layer == Layer.ColorChangingEffects_5
|| layer == Layer.TypeChangingEffects_4; || layer == Layer.TypeChangingEffects_4;
} }
} }

View file

@ -280,6 +280,11 @@ public interface MageObject extends MageItem, Serializable {
game.getState().getCreateMageObjectAttribute(this, game).getSubtype().retainAll(SubType.getEnchantmentTypes()); 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) * Remove object's own creature types forever (for copy effects usage)
*/ */