diff --git a/Mage.Sets/src/mage/cards/f/FaramirPrinceOfIthilien.java b/Mage.Sets/src/mage/cards/f/FaramirPrinceOfIthilien.java new file mode 100644 index 00000000000..9ab6cb9254b --- /dev/null +++ b/Mage.Sets/src/mage/cards/f/FaramirPrinceOfIthilien.java @@ -0,0 +1,144 @@ +package mage.cards.f; + +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.BeginningOfYourEndStepTriggeredAbility; +import mage.abilities.common.delayed.AtTheBeginOfPlayersNextEndStepDelayedTriggeredAbility; +import mage.abilities.effects.Effect; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.CreateTokenEffect; +import mage.abilities.effects.common.DrawCardSourceControllerEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.SubType; +import mage.constants.SuperType; +import mage.game.Game; +import mage.game.permanent.token.HumanSoldierToken; +import mage.players.Player; +import mage.target.Target; +import mage.target.common.TargetOpponent; +import mage.target.targetpointer.FixedTarget; +import mage.watchers.common.PlayersAttackedThisTurnWatcher; + +import java.util.UUID; + +/** + * + * @author Susucr + */ +public final class FaramirPrinceOfIthilien extends CardImpl { + + public FaramirPrinceOfIthilien(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{W}{U}"); + + this.supertype.add(SuperType.LEGENDARY); + this.subtype.add(SubType.HUMAN); + this.subtype.add(SubType.NOBLE); + this.power = new MageInt(3); + this.toughness = new MageInt(3); + + // At the beginning of your end step, choose an opponent. + // At the beginning of that player's next end step, + // you draw a card if they didn't attack you that turn. + // Otherwise, create three 1/1 white Human Soldier creature tokens. + this.addAbility(new BeginningOfYourEndStepTriggeredAbility(new FaramirPrinceOfIthilienEffect(), false)); + } + + private FaramirPrinceOfIthilien(final FaramirPrinceOfIthilien card) { + super(card); + } + + @Override + public FaramirPrinceOfIthilien copy() { + return new FaramirPrinceOfIthilien(this); + } + +} + +class FaramirPrinceOfIthilienEffect extends OneShotEffect { + + FaramirPrinceOfIthilienEffect() { + super(Outcome.Neutral); + staticText = "choose an opponent. " + + "At the beginning of that player's next end step, " + + "you draw a card if they didn't attack you that turn. " + + "Otherwise, create three 1/1 white Human Soldier creature tokens."; + } + + FaramirPrinceOfIthilienEffect(final FaramirPrinceOfIthilienEffect effect) { + super(effect); + } + + @Override + public FaramirPrinceOfIthilienEffect copy() { + return new FaramirPrinceOfIthilienEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller == null) { + return false; + } + + Target target = new TargetOpponent(true); + target.choose(Outcome.Neutral, source.getControllerId(), source.getSourceId(), source, game); + Player opponent = game.getPlayer(target.getFirstTarget()); + if (opponent == null) { + return false; + } + + Effect effect = new FaramirPrinceOfIthilienDelayedEffect(); + effect.setTargetPointer(new FixedTarget(opponent.getId(), game)); + game.addDelayedTriggeredAbility( + new AtTheBeginOfPlayersNextEndStepDelayedTriggeredAbility( + effect, + opponent.getId() + ), source); + + return true; + } +} + + +class FaramirPrinceOfIthilienDelayedEffect extends OneShotEffect { + + FaramirPrinceOfIthilienDelayedEffect() { + super(Outcome.Benefit); + staticText = "you draw a card if the chosen player didn't attack you that turn. " + + "Otherwise, create three 1/1 white Human Soldier creature tokens."; + } + + FaramirPrinceOfIthilienDelayedEffect(final FaramirPrinceOfIthilienDelayedEffect effect) { + super(effect); + } + + @Override + public FaramirPrinceOfIthilienDelayedEffect copy() { + return new FaramirPrinceOfIthilienDelayedEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + PlayersAttackedThisTurnWatcher watcher = game.getState().getWatcher(PlayersAttackedThisTurnWatcher.class); + if(watcher == null){ + return false; + } + + UUID controllerId = source.getControllerId(); + UUID targetId = getTargetPointer().getFirst(game, source); + + Player controller = game.getPlayer(controllerId); + if(controller == null){ + return false; + } + + if(watcher.hasPlayerAttackedPlayer(targetId, controllerId)){ + return new CreateTokenEffect(new HumanSoldierToken(), 3).apply(game, source); + } else { + return new DrawCardSourceControllerEffect(1).apply(game, source); + } + } +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/TheLordOfTheRingsTalesOfMiddleEarth.java b/Mage.Sets/src/mage/sets/TheLordOfTheRingsTalesOfMiddleEarth.java index 39242da3ca9..cdc0fa6be31 100644 --- a/Mage.Sets/src/mage/sets/TheLordOfTheRingsTalesOfMiddleEarth.java +++ b/Mage.Sets/src/mage/sets/TheLordOfTheRingsTalesOfMiddleEarth.java @@ -86,6 +86,7 @@ public final class TheLordOfTheRingsTalesOfMiddleEarth extends ExpansionSet { cards.add(new SetCardInfo("Fall of Gil-galad", 165, Rarity.RARE, mage.cards.f.FallOfGilGalad.class)); cards.add(new SetCardInfo("Fangorn, Tree Shepherd", 166, Rarity.RARE, mage.cards.f.FangornTreeShepherd.class)); cards.add(new SetCardInfo("Faramir, Field Commander", 14, Rarity.UNCOMMON, mage.cards.f.FaramirFieldCommander.class)); + cards.add(new SetCardInfo("Faramir, Prince of Ithilien", 202, Rarity.RARE, mage.cards.f.FaramirPrinceOfIthilien.class)); cards.add(new SetCardInfo("Fear, Fire, Foes!", 125, Rarity.UNCOMMON, mage.cards.f.FearFireFoes.class)); cards.add(new SetCardInfo("Fiery Inscription", 126, Rarity.UNCOMMON, mage.cards.f.FieryInscription.class)); cards.add(new SetCardInfo("Fire of Orthanc", 127, Rarity.COMMON, mage.cards.f.FireOfOrthanc.class)); diff --git a/Mage/src/main/java/mage/watchers/common/PlayersAttackedThisTurnWatcher.java b/Mage/src/main/java/mage/watchers/common/PlayersAttackedThisTurnWatcher.java index fe39ea98e88..5314e684c74 100644 --- a/Mage/src/main/java/mage/watchers/common/PlayersAttackedThisTurnWatcher.java +++ b/Mage/src/main/java/mage/watchers/common/PlayersAttackedThisTurnWatcher.java @@ -59,6 +59,11 @@ public class PlayersAttackedThisTurnWatcher extends Watcher { } } + public boolean hasPlayerAttackedPlayer(UUID attacker, UUID defender){ + PlayerList defendersList = playersAttackedThisTurn.getOrDefault(attacker, null); + return defendersList != null && defendersList.contains(defender); + } + public int getAttackedPlayersCount(UUID playerID) { PlayerList defendersList = playersAttackedThisTurn.getOrDefault(playerID, null); if (defendersList != null) {