diff --git a/Mage.Sets/src/mage/cards/p/PippinGuardOfTheCitadel.java b/Mage.Sets/src/mage/cards/p/PippinGuardOfTheCitadel.java new file mode 100644 index 00000000000..71733f5c184 --- /dev/null +++ b/Mage.Sets/src/mage/cards/p/PippinGuardOfTheCitadel.java @@ -0,0 +1,101 @@ +package mage.cards.p; + +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.SimpleActivatedAbility; +import mage.abilities.costs.common.TapSourceCost; +import mage.abilities.costs.mana.ManaCostsImpl; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.continuous.GainAbilityTargetEffect; +import mage.abilities.keyword.ProtectionAbility; +import mage.abilities.keyword.VigilanceAbility; +import mage.abilities.keyword.WardAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.choices.Choice; +import mage.choices.ChoiceCardType; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.SubType; +import mage.constants.SuperType; +import mage.filter.FilterCard; +import mage.filter.StaticFilters; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.TargetPermanent; +import mage.target.targetpointer.FixedTarget; + +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class PippinGuardOfTheCitadel extends CardImpl { + + public PippinGuardOfTheCitadel(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{W}{U}"); + + this.supertype.add(SuperType.LEGENDARY); + this.subtype.add(SubType.HALFLING); + this.subtype.add(SubType.SOLDIER); + this.power = new MageInt(2); + this.toughness = new MageInt(2); + + // Vigilance + this.addAbility(VigilanceAbility.getInstance()); + + // Ward {1} + this.addAbility(new WardAbility(new ManaCostsImpl<>("{1}"))); + + // {T}: Another target creature you control gains protection from the card type of your choice until end of turn. + Ability ability = new SimpleActivatedAbility(new PippinGuardOfTheCitadelEffect(), new TapSourceCost()); + ability.addTarget(new TargetPermanent(StaticFilters.FILTER_CONTROLLED_ANOTHER_CREATURE)); + this.addAbility(ability); + } + + private PippinGuardOfTheCitadel(final PippinGuardOfTheCitadel card) { + super(card); + } + + @Override + public PippinGuardOfTheCitadel copy() { + return new PippinGuardOfTheCitadel(this); + } +} + +class PippinGuardOfTheCitadelEffect extends OneShotEffect { + + PippinGuardOfTheCitadelEffect() { + super(Outcome.Benefit); + staticText = "another target creature you control gains protection " + + "from the card type of your choice until end of turn"; + } + + private PippinGuardOfTheCitadelEffect(final PippinGuardOfTheCitadelEffect effect) { + super(effect); + } + + @Override + public PippinGuardOfTheCitadelEffect copy() { + return new PippinGuardOfTheCitadelEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source)); + if (player == null || permanent == null) { + return false; + } + Choice choice = new ChoiceCardType(); + player.choose(outcome, choice, game); + CardType cardType = CardType.fromString(choice.getChoice()); + String typeName = cardType.toString(); + FilterCard filter = new FilterCard(cardType.getPluralName().toLowerCase()); + filter.add(cardType.getPredicate()); + game.addEffect(new GainAbilityTargetEffect(new ProtectionAbility(filter)) + .setTargetPointer(new FixedTarget(permanent, game)), source); + return true; + } +} diff --git a/Mage.Sets/src/mage/sets/TheLordOfTheRingsTalesOfMiddleEarth.java b/Mage.Sets/src/mage/sets/TheLordOfTheRingsTalesOfMiddleEarth.java index 85fd10af227..7e5e1872b78 100644 --- a/Mage.Sets/src/mage/sets/TheLordOfTheRingsTalesOfMiddleEarth.java +++ b/Mage.Sets/src/mage/sets/TheLordOfTheRingsTalesOfMiddleEarth.java @@ -148,6 +148,7 @@ public final class TheLordOfTheRingsTalesOfMiddleEarth extends ExpansionSet { cards.add(new SetCardInfo("Pelargir Survivor", 64, Rarity.COMMON, mage.cards.p.PelargirSurvivor.class)); cards.add(new SetCardInfo("Peregrin Took", 181, Rarity.UNCOMMON, mage.cards.p.PeregrinTook.class)); cards.add(new SetCardInfo("Pippin's Bravery", 182, Rarity.COMMON, mage.cards.p.PippinsBravery.class)); + cards.add(new SetCardInfo("Pippin, Guard of the Citadel", 218, Rarity.RARE, mage.cards.p.PippinGuardOfTheCitadel.class)); cards.add(new SetCardInfo("Plains", 262, Rarity.LAND, mage.cards.basiclands.Plains.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("Prince Imrahil the Fair", 219, Rarity.UNCOMMON, mage.cards.p.PrinceImrahilTheFair.class)); cards.add(new SetCardInfo("Protector of Gondor", 25, Rarity.COMMON, mage.cards.p.ProtectorOfGondor.class)); diff --git a/Mage/src/main/java/mage/constants/CardType.java b/Mage/src/main/java/mage/constants/CardType.java index 575528ae498..1259b1c4764 100644 --- a/Mage/src/main/java/mage/constants/CardType.java +++ b/Mage/src/main/java/mage/constants/CardType.java @@ -45,6 +45,10 @@ public enum CardType { return text; } + public String getPluralName() { + return text.endsWith("y") ? text.substring(0, text.length() - 1) + "ies" : text + 's'; + } + public static CardType fromString(String value) { for (CardType ct : CardType.values()) { if (ct.toString().equals(value)) {