diff --git a/Mage.Sets/src/mage/cards/p/PromiseOfLoyalty.java b/Mage.Sets/src/mage/cards/p/PromiseOfLoyalty.java new file mode 100644 index 00000000000..1a0847bb96e --- /dev/null +++ b/Mage.Sets/src/mage/cards/p/PromiseOfLoyalty.java @@ -0,0 +1,137 @@ +package mage.cards.p; + +import mage.abilities.Ability; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.RestrictionEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.counters.CounterType; +import mage.filter.StaticFilters; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.TargetPermanent; +import mage.target.common.TargetControlledCreaturePermanent; +import mage.target.targetpointer.FixedTarget; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class PromiseOfLoyalty extends CardImpl { + + public PromiseOfLoyalty(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{4}{W}"); + + // Each player puts a vow counter on a creature they control and sacrifices the rest. Each of those creatures can't attack you or planeswalkers you control for as long as it has a vow counter on it. + this.getSpellAbility().addEffect(new PromiseOfLoyaltyEffect()); + } + + private PromiseOfLoyalty(final PromiseOfLoyalty card) { + super(card); + } + + @Override + public PromiseOfLoyalty copy() { + return new PromiseOfLoyalty(this); + } +} + +class PromiseOfLoyaltyEffect extends OneShotEffect { + + PromiseOfLoyaltyEffect() { + super(Outcome.Benefit); + staticText = "each player puts a vow counter on a creature they control and sacrifices the rest. " + + "Each of those creatures can't attack you or planeswalkers you control for as long as it has a vow counter on it"; + } + + private PromiseOfLoyaltyEffect(final PromiseOfLoyaltyEffect effect) { + super(effect); + } + + @Override + public PromiseOfLoyaltyEffect copy() { + return new PromiseOfLoyaltyEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + List permanents = new ArrayList<>(); + for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) { + Player player = game.getPlayer(playerId); + if (player == null || game.getBattlefield().count( + StaticFilters.FILTER_CONTROLLED_CREATURE, + source.getSourceId(), playerId, game + ) < 1) { + continue; + } + TargetPermanent target = new TargetControlledCreaturePermanent(); + target.setNotTarget(true); + player.choose(outcome, target, source.getSourceId(), game); + Permanent permanent = game.getPermanent(target.getFirstTarget()); + if (permanent == null) { + continue; + } + permanents.add(permanent); + permanent.addCounters(CounterType.VOW.createInstance(), playerId, source, game); + } + for (Permanent permanent : game.getBattlefield().getActivePermanents( + StaticFilters.FILTER_PERMANENT_CREATURE, source.getSourceId(), game + )) { + if (permanent == null) { + continue; + } + if (permanents.contains(permanent)) { + game.addEffect(new PromiseOfLoyaltyAttackEffect().setTargetPointer(new FixedTarget(permanent, game)), source); + } else { + permanent.sacrifice(source, game); + } + } + return true; + } +} + +class PromiseOfLoyaltyAttackEffect extends RestrictionEffect { + + public PromiseOfLoyaltyAttackEffect() { + super(Duration.Custom); + } + + public PromiseOfLoyaltyAttackEffect(final PromiseOfLoyaltyAttackEffect effect) { + super(effect); + } + + @Override + public boolean applies(Permanent permanent, Ability source, Game game) { + Permanent p = game.getPermanent(getTargetPointer().getFirst(game, source)); + if (p == null || p.getCounters(game).getCount(CounterType.VOW) < 1) { + discard(); + return false; + } + return permanent.getId().equals(p.getId()); + } + + @Override + public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game, boolean canUseChooseDialogs) { + if (defenderId == null) { + return true; + } + if (source.isControlledBy(defenderId)) { + return false; + } + Permanent planeswalker = game.getPermanent(defenderId); + return planeswalker == null || !planeswalker.isControlledBy(source.getControllerId()); + } + + + @Override + public PromiseOfLoyaltyAttackEffect copy() { + return new PromiseOfLoyaltyAttackEffect(this); + } +} diff --git a/Mage.Sets/src/mage/sets/Commander2021Edition.java b/Mage.Sets/src/mage/sets/Commander2021Edition.java index 702aace5186..b8475dd56ce 100644 --- a/Mage.Sets/src/mage/sets/Commander2021Edition.java +++ b/Mage.Sets/src/mage/sets/Commander2021Edition.java @@ -230,6 +230,7 @@ public final class Commander2021Edition extends ExpansionSet { cards.add(new SetCardInfo("Ponder", 125, Rarity.COMMON, mage.cards.p.Ponder.class)); cards.add(new SetCardInfo("Primal Empathy", 227, Rarity.UNCOMMON, mage.cards.p.PrimalEmpathy.class)); cards.add(new SetCardInfo("Pristine Talisman", 258, Rarity.COMMON, mage.cards.p.PristineTalisman.class)); + cards.add(new SetCardInfo("Promise of Loyalty", 21, Rarity.RARE, mage.cards.p.PromiseOfLoyalty.class)); cards.add(new SetCardInfo("Pulse of Murasa", 202, Rarity.UNCOMMON, mage.cards.p.PulseOfMurasa.class)); cards.add(new SetCardInfo("Pyromancer's Goggles", 259, Rarity.MYTHIC, mage.cards.p.PyromancersGoggles.class)); cards.add(new SetCardInfo("Quicksmith Genius", 178, Rarity.UNCOMMON, mage.cards.q.QuicksmithGenius.class));