- Yedora, Grave Gardener now uses layer 4 (type-changing). Note: if you alter the code below, please verify that the effect actually works. The "remove" and "add" cardType and subType were not working in some continuousEffect layers. It works fine with this. Test suite tomorrow.

This commit is contained in:
jeffwadsworth 2021-08-10 17:43:35 -05:00
parent 9b98565e8a
commit b8ac3c0809

View file

@ -1,7 +1,6 @@
package mage.cards.y; package mage.cards.y;
import mage.MageInt; import mage.MageInt;
import mage.MageObjectReference;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.DiesCreatureTriggeredAbility; import mage.abilities.common.DiesCreatureTriggeredAbility;
import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.ContinuousEffectImpl;
@ -17,11 +16,14 @@ import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.AnotherPredicate; import mage.filter.predicate.mageobject.AnotherPredicate;
import mage.filter.predicate.permanent.TokenPredicate; import mage.filter.predicate.permanent.TokenPredicate;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import mage.target.targetpointer.FixedTarget; import mage.target.targetpointer.FixedTarget;
import java.util.UUID; import java.util.UUID;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.game.events.EntersTheBattlefieldEvent;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
/** /**
* @author TheElk801 * @author TheElk801
@ -46,7 +48,7 @@ public final class YedoraGraveGardener extends CardImpl {
// Whenever another nontoken creature you control dies, you may return it to the battlefield face down under its owner's control. It's a Forest land. // Whenever another nontoken creature you control dies, you may return it to the battlefield face down under its owner's control. It's a Forest land.
this.addAbility(new DiesCreatureTriggeredAbility( this.addAbility(new DiesCreatureTriggeredAbility(
new YedoraGraveGardenerEffect(), true, filter, true new YedoraEffect(), true, filter, true
)); ));
} }
@ -60,70 +62,148 @@ public final class YedoraGraveGardener extends CardImpl {
} }
} }
class YedoraGraveGardenerEffect extends OneShotEffect { class YedoraEffect extends OneShotEffect {
YedoraGraveGardenerEffect() { public YedoraEffect() {
super(Outcome.Benefit); super(Outcome.PutCreatureInPlay);
staticText = "you may return it to the battlefield face down under its owner's control. " + staticText = " return it to the battlefield face down under its owner's control. It's a Forest land";
"It's a Forest land. <i>(It has no other types or abilities.)</i>";
} }
private YedoraGraveGardenerEffect(final YedoraGraveGardenerEffect effect) { public YedoraEffect(final YedoraEffect effect) {
super(effect); super(effect);
} }
@Override @Override
public YedoraGraveGardenerEffect copy() { public YedoraEffect copy() {
return new YedoraGraveGardenerEffect(this); return new YedoraEffect(this);
} }
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
Card card = game.getCard(getTargetPointer().getFirst(game, source)); if (controller != null) {
if (player == null || card == null) { Card card = game.getCard(targetPointer.getFirst(game, source));
return false; if (card != null) {
YedoraReplacementEffect effect = new YedoraReplacementEffect();
effect.setTargetPointer(new FixedTarget(card.getId()));
game.addEffect(effect, source);
controller.moveCards(card, Zone.BATTLEFIELD, source, game, false, true, true, null);
}
return true;
} }
game.addEffect(new YedoraGraveGardenerContinuousEffect().setTargetPointer( return false;
new FixedTarget(new MageObjectReference(card, game, 1)) }
), source);
player.moveCards( }
card, Zone.BATTLEFIELD, source, game,
false, true, true, null class YedoraReplacementEffect extends ReplacementEffectImpl {
);
return true; YedoraReplacementEffect() {
super(Duration.WhileOnBattlefield, Outcome.Neutral);
}
YedoraReplacementEffect(YedoraReplacementEffect effect) {
super(effect);
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
return event.getTargetId().equals(getTargetPointer().getFirst(game, source));
}
@Override
public boolean apply(Game game, Ability source) {
return false;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent creature = ((EntersTheBattlefieldEvent) event).getTarget();
if (creature != null) {
YedoraGraveGardenerContinuousEffect effect = new YedoraGraveGardenerContinuousEffect();
effect.setTargetPointer(new FixedTarget(creature.getId(), creature.getZoneChangeCounter(game) + 1));
game.addEffect(effect, source);
}
return false;
}
@Override
public YedoraReplacementEffect copy() {
return new YedoraReplacementEffect(this);
} }
} }
class YedoraGraveGardenerContinuousEffect extends ContinuousEffectImpl { class YedoraGraveGardenerContinuousEffect extends ContinuousEffectImpl {
public YedoraGraveGardenerContinuousEffect() { YedoraGraveGardenerContinuousEffect() {
super(Duration.Custom, Layer.CopyEffects_1, SubLayer.FaceDownEffects_1b, Outcome.Neutral); super(Duration.WhileOnBattlefield, Outcome.Neutral);
this.staticText = "It is a forest";
this.dependencyTypes.add(DependencyType.BecomeForest);
} }
public YedoraGraveGardenerContinuousEffect(final YedoraGraveGardenerContinuousEffect effect) { YedoraGraveGardenerContinuousEffect(final YedoraGraveGardenerContinuousEffect effect) {
super(effect); super(effect);
} }
@Override
public boolean apply(Game game, Ability source) {
return false;
}
@Override @Override
public YedoraGraveGardenerContinuousEffect copy() { public YedoraGraveGardenerContinuousEffect copy() {
return new YedoraGraveGardenerContinuousEffect(this); return new YedoraGraveGardenerContinuousEffect(this);
} }
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
Permanent target = game.getPermanent(targetPointer.getFirst(game, source)); Permanent deadCreature;
if (target == null || !target.isFaceDown(game)) { if (source.getTargets().getFirstTarget() == null) {
discard(); deadCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
return false; } else {
deadCreature = game.getPermanent(source.getTargets().getFirstTarget());
if (deadCreature == null) {
deadCreature = game.getPermanentEntering(source.getTargets().getFirstTarget());
}
}
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
// Lands have their mana ability intrinsically, so that is added in layer 4
// If someone wants to clear up the un-needed code below, please do, but test it to verify it still works!! Some *removeAll* code simply didn't work.
deadCreature.getSuperType().clear();
deadCreature.removeAllSubTypes(game);
deadCreature.removeAllSubTypes(game, SubTypeSet.CreatureType);
deadCreature.removeAllCardTypes();
deadCreature.removeAllCardTypes(game);
deadCreature.removeAllAbilities(source.getSourceId(), game);
deadCreature.addCardType(game, CardType.LAND);
deadCreature.addCardType(CardType.LAND);
deadCreature.addSubType(game, SubType.FOREST);
deadCreature.addSuperType(SuperType.BASIC);
deadCreature.addSubType(SubType.FOREST);
deadCreature.addAbility(new GreenManaAbility(), source.getSourceId(), game);
break;
case ColorChangingEffects_5:
deadCreature.getColor(game).setWhite(false);
deadCreature.getColor(game).setGreen(false);
deadCreature.getColor(game).setBlack(false);
deadCreature.getColor(game).setBlue(false);
deadCreature.getColor(game).setRed(false);
break;
} }
target.getSuperType().clear();
target.removeAllCardTypes(game);
target.removeAllSubTypes(game);
target.addCardType(game, CardType.LAND);
target.addSubType(game, SubType.FOREST);
target.removeAllAbilities(source.getSourceId(), game);
target.addAbility(new GreenManaAbility(), source.getSourceId(), game);
return true; return true;
} }
@Override
public boolean hasLayer(Layer layer) {
return layer == Layer.TypeChangingEffects_4
|| layer == Layer.ColorChangingEffects_5;
}
} }