diff --git a/Mage.Sets/src/mage/cards/g/GhostOfRamirezDePietro.java b/Mage.Sets/src/mage/cards/g/GhostOfRamirezDePietro.java new file mode 100644 index 0000000000..1eb1c68a26 --- /dev/null +++ b/Mage.Sets/src/mage/cards/g/GhostOfRamirezDePietro.java @@ -0,0 +1,117 @@ +package mage.cards.g; + +import mage.MageInt; +import mage.MageObjectReference; +import mage.abilities.Ability; +import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility; +import mage.abilities.common.SimpleEvasionAbility; +import mage.abilities.effects.common.ReturnFromGraveyardToHandTargetEffect; +import mage.abilities.effects.common.combat.CantBeBlockedByCreaturesSourceEffect; +import mage.abilities.keyword.PartnerAbility; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.filter.FilterCard; +import mage.filter.common.FilterCreaturePermanent; +import mage.filter.predicate.Predicate; +import mage.filter.predicate.mageobject.ToughnessPredicate; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.target.common.TargetCardInGraveyard; +import mage.watchers.Watcher; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class GhostOfRamirezDePietro extends CardImpl { + + private static final FilterCreaturePermanent filter + = new FilterCreaturePermanent("creatures with toughness 3 or greater"); + private static final FilterCard filter2 + = new FilterCard("card in any graveyard that has been discarded or milled this turn"); + + static { + filter.add(new ToughnessPredicate(ComparisonType.MORE_THAN, 2)); + filter2.add(GhostOfRamirezDePietroPredicate.instance); + } + + public GhostOfRamirezDePietro(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{U}"); + + this.addSuperType(SuperType.LEGENDARY); + this.subtype.add(SubType.PIRATE); + this.subtype.add(SubType.SPIRIT); + this.power = new MageInt(2); + this.toughness = new MageInt(3); + + // Ghost of Ramirez DePietro can't be blocked by creatures with toughness 3 or greater. + this.addAbility(new SimpleEvasionAbility( + new CantBeBlockedByCreaturesSourceEffect(filter, Duration.WhileOnBattlefield) + )); + + // Whenever Ghost of Ramirez DePietro deals combat damage to a player, choose up to one target card in any graveyard that has been discarded or milled this turn. Put that card into its owner's hand. + Ability ability = new DealsCombatDamageToAPlayerTriggeredAbility( + new ReturnFromGraveyardToHandTargetEffect() + .setText("choose up to one target card in any graveyard that has been discarded " + + "or milled this turn. Put that card into its owner's hand"), + false + ); + ability.addTarget(new TargetCardInGraveyard(filter2)); + this.addAbility(ability); + + // Partner + this.addAbility(PartnerAbility.getInstance()); + } + + private GhostOfRamirezDePietro(final GhostOfRamirezDePietro card) { + super(card); + } + + @Override + public GhostOfRamirezDePietro copy() { + return new GhostOfRamirezDePietro(this); + } +} + +enum GhostOfRamirezDePietroPredicate implements Predicate { + instance; + + @Override + public boolean apply(Card input, Game game) { + GhostOfRamirezDePietroWatcher watcher = game.getState().getWatcher(GhostOfRamirezDePietroWatcher.class); + return watcher != null && watcher.checkCard(input, game); + } +} + +class GhostOfRamirezDePietroWatcher extends Watcher { + + private final Set morSet = new HashSet<>(); + + GhostOfRamirezDePietroWatcher() { + super(WatcherScope.GAME); + } + + @Override + public void watch(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.DISCARDED_CARD + || event.getType() == GameEvent.EventType.MILLED_CARD) { + morSet.add(new MageObjectReference(event.getTargetId(), game)); + } + return; + } + + @Override + public void reset() { + super.reset(); + morSet.clear(); + } + + boolean checkCard(Card card, Game game) { + return morSet.stream().anyMatch(mor -> mor.refersTo(card, game)); + } +} diff --git a/Mage.Sets/src/mage/sets/CommanderLegends.java b/Mage.Sets/src/mage/sets/CommanderLegends.java index 0ba09d1a1a..c02e628d0e 100644 --- a/Mage.Sets/src/mage/sets/CommanderLegends.java +++ b/Mage.Sets/src/mage/sets/CommanderLegends.java @@ -50,6 +50,7 @@ public final class CommanderLegends extends ExpansionSet { cards.add(new SetCardInfo("Farhaven Elf", 225, Rarity.COMMON, mage.cards.f.FarhavenElf.class)); cards.add(new SetCardInfo("Forceful Denial", 69, Rarity.COMMON, mage.cards.f.ForcefulDenial.class)); cards.add(new SetCardInfo("Fyndhorn Elves", 228, Rarity.COMMON, mage.cards.f.FyndhornElves.class)); + cards.add(new SetCardInfo("Ghost of Ramirez DePietro", 71, Rarity.UNCOMMON, mage.cards.g.GhostOfRamirezDePietro.class)); cards.add(new SetCardInfo("Halana, Kessig Ranger", 231, Rarity.UNCOMMON, mage.cards.h.HalanaKessigRanger.class)); cards.add(new SetCardInfo("Horizon Scholar", 73, Rarity.UNCOMMON, mage.cards.h.HorizonScholar.class)); cards.add(new SetCardInfo("Ikra Shidiqi, the Usurper", 519, Rarity.MYTHIC, mage.cards.i.IkraShidiqiTheUsurper.class)); diff --git a/Mage/src/main/java/mage/game/events/GameEvent.java b/Mage/src/main/java/mage/game/events/GameEvent.java index 642f299686..eb1d8d01e9 100644 --- a/Mage/src/main/java/mage/game/events/GameEvent.java +++ b/Mage/src/main/java/mage/game/events/GameEvent.java @@ -91,6 +91,7 @@ public class GameEvent implements Serializable { CLASH, CLASHED, DAMAGE_PLAYER, MILL_CARDS, + MILLED_CARD, /* DAMAGED_PLAYER targetId the id of the damaged player sourceId sourceId of the ability which caused the damage diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index c1faf4b7f9..7dfb63bb83 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -4414,6 +4414,9 @@ public abstract class PlayerImpl implements Player, Serializable { } Cards cards = new CardsImpl(this.getLibrary().getTopCards(game, event.getAmount())); this.moveCards(cards, Zone.GRAVEYARD, source, game); + for (Card card : cards.getCards(game)) { + game.fireEvent(GameEvent.getEvent(EventType.MILLED_CARD, card.getId(), source.getSourceId(), getId())); + } return cards; }