diff --git a/Mage.Sets/src/mage/cards/y/YedoraGraveGardener.java b/Mage.Sets/src/mage/cards/y/YedoraGraveGardener.java index 9644ca3c4f..bce2caa7e2 100644 --- a/Mage.Sets/src/mage/cards/y/YedoraGraveGardener.java +++ b/Mage.Sets/src/mage/cards/y/YedoraGraveGardener.java @@ -1,7 +1,6 @@ package mage.cards.y; import mage.MageInt; -import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.common.DiesCreatureTriggeredAbility; import mage.abilities.effects.ContinuousEffectImpl; @@ -17,11 +16,14 @@ import mage.filter.predicate.Predicates; import mage.filter.predicate.mageobject.AnotherPredicate; import mage.filter.predicate.permanent.TokenPredicate; import mage.game.Game; -import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.targetpointer.FixedTarget; 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 @@ -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. 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() { - super(Outcome.Benefit); - staticText = "you may return it to the battlefield face down under its owner's control. " + - "It's a Forest land. (It has no other types or abilities.)"; + public YedoraEffect() { + super(Outcome.PutCreatureInPlay); + staticText = " return it to the battlefield face down under its owner's control. It's a Forest land"; } - private YedoraGraveGardenerEffect(final YedoraGraveGardenerEffect effect) { + public YedoraEffect(final YedoraEffect effect) { super(effect); } @Override - public YedoraGraveGardenerEffect copy() { - return new YedoraGraveGardenerEffect(this); + public YedoraEffect copy() { + return new YedoraEffect(this); } @Override public boolean apply(Game game, Ability source) { - Player player = game.getPlayer(source.getControllerId()); - Card card = game.getCard(getTargetPointer().getFirst(game, source)); - if (player == null || card == null) { - return false; + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + Card card = game.getCard(targetPointer.getFirst(game, source)); + 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( - new FixedTarget(new MageObjectReference(card, game, 1)) - ), source); - player.moveCards( - card, Zone.BATTLEFIELD, source, game, - false, true, true, null - ); - return true; + return false; + } + +} + +class YedoraReplacementEffect extends ReplacementEffectImpl { + + 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 { - public YedoraGraveGardenerContinuousEffect() { - super(Duration.Custom, Layer.CopyEffects_1, SubLayer.FaceDownEffects_1b, Outcome.Neutral); + YedoraGraveGardenerContinuousEffect() { + 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); } + @Override + public boolean apply(Game game, Ability source) { + return false; + } + @Override public YedoraGraveGardenerContinuousEffect copy() { return new YedoraGraveGardenerContinuousEffect(this); } @Override - public boolean apply(Game game, Ability source) { - Permanent target = game.getPermanent(targetPointer.getFirst(game, source)); - if (target == null || !target.isFaceDown(game)) { - discard(); - return false; + public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { + Permanent deadCreature; + if (source.getTargets().getFirstTarget() == null) { + deadCreature = game.getPermanent(getTargetPointer().getFirst(game, source)); + } 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; } + + @Override + public boolean hasLayer(Layer layer) { + return layer == Layer.TypeChangingEffects_4 + || layer == Layer.ColorChangingEffects_5; + } }