From 32ff6ada7b67aa76c29a36da6dc9ee02bc78aa79 Mon Sep 17 00:00:00 2001 From: Daniel Eberhard Date: Tue, 13 Dec 2022 19:45:24 +0100 Subject: [PATCH] Added card "A Jedi's Fervor" and its abilities and effects --- Mage.Sets/src/mage/cards/a/AJedisFervor.java | 96 ++++++++++++++++++- .../main/java/mage/filter/StaticFilters.java | 6 ++ ...rolledCreatureOrPlaneswalkerPermanent.java | 46 +++++++++ 3 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 Mage/src/main/java/mage/filter/common/FilterControlledCreatureOrPlaneswalkerPermanent.java diff --git a/Mage.Sets/src/mage/cards/a/AJedisFervor.java b/Mage.Sets/src/mage/cards/a/AJedisFervor.java index c8727edcf5..46d34e97b0 100644 --- a/Mage.Sets/src/mage/cards/a/AJedisFervor.java +++ b/Mage.Sets/src/mage/cards/a/AJedisFervor.java @@ -1,4 +1,98 @@ package mage.cards.a; -public class AJedisFervor { +import mage.abilities.Ability; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.continuous.GainAbilityControlledEffect; +import mage.abilities.keyword.IndestructibleAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.filter.StaticFilters; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.game.stack.Spell; +import mage.target.TargetPermanent; +import mage.watchers.common.SpellsCastWatcher; + +import java.util.*; + +/** + * @author: Merlingilb + */ +public final class AJedisFervor extends CardImpl { + public AJedisFervor(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{1}{W}"); + + // Creatures you control gain indestructible until end of turn. + this.getSpellAbility().addEffect(new GainAbilityControlledEffect( + IndestructibleAbility.getInstance(), Duration.EndOfTurn, + StaticFilters.FILTER_PERMANENT_CREATURES) + ); + + // If an opponent cast a black spell this turn, that player sacrifices a creature or planeswalker. + this.getSpellAbility().addEffect(new AJedisFervorEffect()); + this.getSpellAbility().addWatcher(new SpellsCastWatcher()); + } + + private AJedisFervor(final AJedisFervor card) { + super(card); + } + + @Override + public AJedisFervor copy() { + return new AJedisFervor(this); + } } + +class AJedisFervorEffect extends OneShotEffect { + public AJedisFervorEffect() { + super(Outcome.Sacrifice); + } + + public AJedisFervorEffect(final AJedisFervorEffect effect) { + super(effect); + } + + @Override + public boolean apply(Game game, Ability source) { + SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class); + Set opponents = game.getOpponents(source.getControllerId()); + Set opponentsBlack = new HashSet<>(); + List perms = new ArrayList<>(); + //get opponents that cast a black spell this turn + if (watcher != null) { + for (UUID opponentId : opponents) { + List spells = watcher.getSpellsCastThisTurn(opponentId); + if (spells != null) { + for (Spell spell : spells) { + if (spell.getColor(game).isBlack()) { + opponentsBlack.add(opponentId); + } + } + } + } + } + //get that opponents to pick a creature or planeswalker + for (UUID opponentId : opponentsBlack) { + TargetPermanent target = new TargetPermanent(1, 1, + StaticFilters.FILTER_CONTROLLED_PERMANENT_CREATURE_OR_PLANESWALKER, false); + game.getPlayer(opponentId).chooseTarget(Outcome.Sacrifice, target, source, game); + perms.addAll(target.getTargets()); + } + //sacrifices the picked cards + for (UUID permID : perms) { + Permanent permanent = game.getPermanent(permID); + if (permanent != null) { + permanent.sacrifice(source, game); + } + } + return true; + } + + @Override + public AJedisFervorEffect copy() { + return new AJedisFervorEffect(this); + } +} \ No newline at end of file diff --git a/Mage/src/main/java/mage/filter/StaticFilters.java b/Mage/src/main/java/mage/filter/StaticFilters.java index 7780850f00..0379138ba8 100644 --- a/Mage/src/main/java/mage/filter/StaticFilters.java +++ b/Mage/src/main/java/mage/filter/StaticFilters.java @@ -442,6 +442,12 @@ public final class StaticFilters { FILTER_CONTROLLED_PERMANENT_LANDS.setLockedFilter(true); } + public static final FilterPermanent FILTER_CONTROLLED_PERMANENT_CREATURE_OR_PLANESWALKER = new FilterControlledCreatureOrPlaneswalkerPermanent("creature or planeswalker you control"); + + static { + FILTER_CONTROLLED_PERMANENT_CREATURE_OR_PLANESWALKER.setLockedFilter(true); + } + public static final FilterControlledPermanent FILTER_CONTROLLED_PERMANENT_PLANESWALKER = new FilterControlledPlaneswalkerPermanent("planeswalker you control"); static { diff --git a/Mage/src/main/java/mage/filter/common/FilterControlledCreatureOrPlaneswalkerPermanent.java b/Mage/src/main/java/mage/filter/common/FilterControlledCreatureOrPlaneswalkerPermanent.java new file mode 100644 index 0000000000..e82d6b4491 --- /dev/null +++ b/Mage/src/main/java/mage/filter/common/FilterControlledCreatureOrPlaneswalkerPermanent.java @@ -0,0 +1,46 @@ +package mage.filter.common; + +import mage.constants.CardType; +import mage.constants.SubType; +import mage.filter.predicate.Predicates; + +/** + * @author LevelX2 + */ +public class FilterControlledCreatureOrPlaneswalkerPermanent extends FilterControlledPermanent { + + public FilterControlledCreatureOrPlaneswalkerPermanent() { + this("creature or planeswalker you control"); + } + + public FilterControlledCreatureOrPlaneswalkerPermanent(SubType subType) { + this(subType, "a " + subType + " creature or a " + subType + " planeswalker"); + } + + public FilterControlledCreatureOrPlaneswalkerPermanent(SubType subType, String name) { + super(name); + this.add(Predicates.or( + CardType.CREATURE.getPredicate(), + CardType.PLANESWALKER.getPredicate() + )); + this.add(subType.getPredicate()); + } + + public FilterControlledCreatureOrPlaneswalkerPermanent(String name) { + super(name); + this.add(Predicates.or( + CardType.CREATURE.getPredicate(), + CardType.PLANESWALKER.getPredicate() + )); + } + + public FilterControlledCreatureOrPlaneswalkerPermanent(final FilterControlledCreatureOrPlaneswalkerPermanent filter) { + super(filter); + } + + @Override + public FilterControlledCreatureOrPlaneswalkerPermanent copy() { + return new FilterControlledCreatureOrPlaneswalkerPermanent(this); + } + +}