diff --git a/Mage.Sets/src/mage/cards/s/SanctuaryBlade.java b/Mage.Sets/src/mage/cards/s/SanctuaryBlade.java new file mode 100644 index 00000000000..0e3077f74d1 --- /dev/null +++ b/Mage.Sets/src/mage/cards/s/SanctuaryBlade.java @@ -0,0 +1,49 @@ +package mage.cards.s; + +import mage.abilities.common.AttachedToCreatureTriggeredAbility; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.costs.mana.GenericManaCost; +import mage.abilities.effects.Effect; +import mage.abilities.effects.common.continuous.BoostEquippedEffect; +import mage.abilities.effects.common.continuous.GainProtectionFromColorAttachedEffect; +import mage.abilities.keyword.EquipAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; + +import java.util.UUID; + +/** + * + * @author htrajan + */ +public final class SanctuaryBlade extends CardImpl { + + public SanctuaryBlade(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{2}"); + + this.subtype.add(SubType.EQUIPMENT); + + // As Sanctuary Blade becomes attached to a creature, choose a color. + GainProtectionFromColorAttachedEffect protectionEffect = new GainProtectionFromColorAttachedEffect(Duration.WhileOnBattlefield); + protectionEffect.setText("choose a color."); + this.addAbility(new AttachedToCreatureTriggeredAbility(protectionEffect, false)); + + // Equipped creature gets +2/+0 and has protection from the last chosen color. + Effect boostEffect = new BoostEquippedEffect(2, 0); + boostEffect.setText("Equipped creature gets +2/+0 and has protection from the last chosen color."); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, boostEffect)); + + // Equip {3} + this.addAbility(new EquipAbility(Outcome.BoostCreature, new GenericManaCost(3))); + } + + private SanctuaryBlade(final SanctuaryBlade card) { + super(card); + } + + @Override + public SanctuaryBlade copy() { + return new SanctuaryBlade(this); + } +} diff --git a/Mage.Sets/src/mage/cards/v/VergeRangers.java b/Mage.Sets/src/mage/cards/v/VergeRangers.java new file mode 100644 index 00000000000..78f0e166b51 --- /dev/null +++ b/Mage.Sets/src/mage/cards/v/VergeRangers.java @@ -0,0 +1,84 @@ +package mage.cards.v; + +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.common.continuous.LookAtTopCardOfLibraryAnyTimeEffect; +import mage.abilities.effects.common.continuous.PlayTheTopCardEffect; +import mage.abilities.keyword.FirstStrikeAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.SubType; +import mage.constants.Zone; +import mage.game.Game; + +import java.util.Comparator; +import java.util.UUID; + +import static mage.filter.StaticFilters.FILTER_CARD_LAND; +import static mage.filter.StaticFilters.FILTER_LAND; + +/** + * + * @author htrajan + */ +public final class VergeRangers extends CardImpl { + + public VergeRangers(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{W}"); + + this.subtype.add(SubType.HUMAN); + this.subtype.add(SubType.SCOUT); + this.power = new MageInt(3); + this.toughness = new MageInt(3); + + // First strike + this.addAbility(FirstStrikeAbility.getInstance()); + + // You may look at the top card of your library any time. + this.addAbility(new SimpleStaticAbility(new LookAtTopCardOfLibraryAnyTimeEffect())); + + // As long as an opponent controls more lands than you, you may play lands from the top of your library. + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new VergeRangersEffect())); + } + + private VergeRangers(final VergeRangers card) { + super(card); + } + + @Override + public VergeRangers copy() { + return new VergeRangers(this); + } +} + +class VergeRangersEffect extends PlayTheTopCardEffect { + + public VergeRangersEffect() { + super(FILTER_CARD_LAND); + staticText = "As long as an opponent controls more lands than you, you may play lands from the top of your library."; + } + + public VergeRangersEffect(final VergeRangersEffect effect) { + super(effect); + } + + @Override + public VergeRangersEffect copy() { + return new VergeRangersEffect(this); + } + + @Override + public boolean applies(UUID objectId, Ability affectedAbility, Ability source, Game game, UUID playerId) { + if (super.applies(objectId, affectedAbility, source, game, playerId)) { + int myLandCount = game.getBattlefield().countAll(FILTER_LAND, playerId, game); + int maxOpponentLandCount = game.getOpponents(playerId).stream() + .map(opponentId -> game.getBattlefield().countAll(FILTER_LAND, opponentId, game)) + .max(Comparator.naturalOrder()) + .orElse(0); + return maxOpponentLandCount > myLandCount; + } + return false; + } +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/Commander2020Edition.java b/Mage.Sets/src/mage/sets/Commander2020Edition.java index f16285a9687..e1aaff783af 100644 --- a/Mage.Sets/src/mage/sets/Commander2020Edition.java +++ b/Mage.Sets/src/mage/sets/Commander2020Edition.java @@ -244,6 +244,7 @@ public final class Commander2020Edition extends ExpansionSet { cards.add(new SetCardInfo("Rogue's Passage", 303, Rarity.UNCOMMON, mage.cards.r.RoguesPassage.class)); cards.add(new SetCardInfo("Rupture Spire", 304, Rarity.COMMON, mage.cards.r.RuptureSpire.class)); cards.add(new SetCardInfo("Sakura-Tribe Elder", 187, Rarity.COMMON, mage.cards.s.SakuraTribeElder.class)); + cards.add(new SetCardInfo("Sanctuary Blade", 69, Rarity.RARE, mage.cards.s.SanctuaryBlade.class)); cards.add(new SetCardInfo("Sandsteppe Citadel", 305, Rarity.UNCOMMON, mage.cards.s.SandsteppeCitadel.class)); cards.add(new SetCardInfo("Satyr Wayfinder", 188, Rarity.COMMON, mage.cards.s.SatyrWayfinder.class)); cards.add(new SetCardInfo("Sawtusk Demolisher", 64, Rarity.RARE, mage.cards.s.SawtuskDemolisher.class)); @@ -309,6 +310,7 @@ public final class Commander2020Edition extends ExpansionSet { cards.add(new SetCardInfo("Unexpectedly Absent", 106, Rarity.RARE, mage.cards.u.UnexpectedlyAbsent.class)); cards.add(new SetCardInfo("Vampire Nighthawk", 140, Rarity.UNCOMMON, mage.cards.v.VampireNighthawk.class)); cards.add(new SetCardInfo("Vastwood Hydra", 194, Rarity.RARE, mage.cards.v.VastwoodHydra.class)); + cards.add(new SetCardInfo("Verge Rangers", 29, Rarity.RARE, mage.cards.v.VergeRangers.class)); cards.add(new SetCardInfo("Vigilante Justice", 164, Rarity.UNCOMMON, mage.cards.v.VigilanteJustice.class)); cards.add(new SetCardInfo("Villainous Wealth", 233, Rarity.RARE, mage.cards.v.VillainousWealth.class)); cards.add(new SetCardInfo("Vitality Hunter", 30, Rarity.RARE, mage.cards.v.VitalityHunter.class)); diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/c20/SanctuaryBladeTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/c20/SanctuaryBladeTest.java new file mode 100644 index 00000000000..f13b7907a63 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/c20/SanctuaryBladeTest.java @@ -0,0 +1,30 @@ +package org.mage.test.cards.single.c20; + +import mage.abilities.keyword.ProtectionAbility; +import mage.constants.PhaseStep; +import mage.constants.Zone; +import mage.filter.FilterCard; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +public class SanctuaryBladeTest extends CardTestPlayerBase { + + @Test + public void testEquipped() { + addCard(Zone.BATTLEFIELD, playerA, "Sanctuary Blade"); + addCard(Zone.BATTLEFIELD, playerA, "Savai Sabertooth"); + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3); + + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Equip", "Savai Sabertooth"); + setChoice(playerA, "Black"); + + setStrictChooseMode(true); + setStopAt(1, PhaseStep.END_COMBAT); + execute(); + assertAllCommandsUsed(); + + assertPowerToughness(playerA, "Savai Sabertooth", 5, 1); + assertAbility(playerA, "Savai Sabertooth", new ProtectionAbility(new FilterCard("Black")), true); + } + +} diff --git a/Mage/src/main/java/mage/abilities/common/AttachedToCreatureTriggeredAbility.java b/Mage/src/main/java/mage/abilities/common/AttachedToCreatureTriggeredAbility.java new file mode 100644 index 00000000000..71868e2e3dd --- /dev/null +++ b/Mage/src/main/java/mage/abilities/common/AttachedToCreatureTriggeredAbility.java @@ -0,0 +1,42 @@ +package mage.abilities.common; + +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.effects.Effect; +import mage.constants.Zone; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; + +import static mage.constants.CardType.CREATURE; + +public class AttachedToCreatureTriggeredAbility extends TriggeredAbilityImpl { + + public AttachedToCreatureTriggeredAbility(Effect effect, boolean optional) { + super(Zone.BATTLEFIELD, effect, optional); + } + + public AttachedToCreatureTriggeredAbility(final AttachedToCreatureTriggeredAbility ability) { + super(ability); + } + + @Override + public boolean checkEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.ATTACHED && event.getSourceId().equals(this.getSourceId()); + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + Permanent attachedPermanent = game.getPermanent(event.getTargetId()); + return attachedPermanent != null && attachedPermanent.getCardType().contains(CREATURE); + } + + @Override + public String getRule() { + return "As {this} becomes attached to a creature, " + super.getRule(); + } + + @Override + public AttachedToCreatureTriggeredAbility copy() { + return new AttachedToCreatureTriggeredAbility(this); + } +} diff --git a/Mage/src/main/java/mage/abilities/effects/common/continuous/GainProtectionFromColorAttachedEffect.java b/Mage/src/main/java/mage/abilities/effects/common/continuous/GainProtectionFromColorAttachedEffect.java new file mode 100644 index 00000000000..cfd0db7f35b --- /dev/null +++ b/Mage/src/main/java/mage/abilities/effects/common/continuous/GainProtectionFromColorAttachedEffect.java @@ -0,0 +1,67 @@ + +package mage.abilities.effects.common.continuous; + +import mage.abilities.Ability; +import mage.abilities.keyword.ProtectionAbility; +import mage.choices.ChoiceColor; +import mage.constants.Duration; +import mage.filter.FilterCard; +import mage.filter.predicate.mageobject.ColorPredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; + +/** + * + * @author LevelX2 + */ +public class GainProtectionFromColorAttachedEffect extends GainAbilitySourceEffect { + + FilterCard protectionFilter; + + public GainProtectionFromColorAttachedEffect(Duration duration) { + super(new ProtectionAbility(new FilterCard()), duration); + protectionFilter = (FilterCard) ((ProtectionAbility) ability).getFilter(); + } + + public GainProtectionFromColorAttachedEffect(final GainProtectionFromColorAttachedEffect effect) { + super(effect); + this.protectionFilter = effect.protectionFilter.copy(); + } + + @Override + public GainProtectionFromColorAttachedEffect copy() { + return new GainProtectionFromColorAttachedEffect(this); + } + + @Override + public void init(Ability source, Game game) { + super.init(source, game); + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + ChoiceColor colorChoice = new ChoiceColor(true); + colorChoice.setMessage("Choose color for protection ability"); + if (controller.choose(outcome, colorChoice, game)) { + game.informPlayers("Choosen color: " + colorChoice.getColor()); + protectionFilter.add(new ColorPredicate(colorChoice.getColor())); + protectionFilter.setMessage(colorChoice.getChoice()); + ((ProtectionAbility) ability).setFilter(protectionFilter); + return; + } + } + discard(); + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent permanent = game.getPermanent(source.getSourceId()); + if (permanent != null && permanent.getAttachedTo() != null) { + Permanent attachedPermanent = game.getPermanent(permanent.getAttachedTo()); + attachedPermanent.addAbility(ability, source.getSourceId(), game); + } else { + // the source permanent is no longer on the battlefield, or it is not attached -- effect can be discarded + discard(); + } + return true; + } +}