diff --git a/Mage.Sets/src/mage/cards/a/AggressiveMining.java b/Mage.Sets/src/mage/cards/a/AggressiveMining.java index fa7abdcb086..08e8b0ca18a 100644 --- a/Mage.Sets/src/mage/cards/a/AggressiveMining.java +++ b/Mage.Sets/src/mage/cards/a/AggressiveMining.java @@ -1,7 +1,6 @@ package mage.cards.a; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.LimitedTimesPerTurnActivatedAbility; import mage.abilities.common.SimpleStaticAbility; @@ -20,6 +19,8 @@ import mage.game.Game; import mage.game.events.GameEvent; import mage.target.common.TargetControlledPermanent; +import java.util.UUID; + /** * * @author Quercitron @@ -34,7 +35,7 @@ public final class AggressiveMining extends CardImpl { this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new AggressiveMiningEffect())); // Sacrifice a land: Draw two cards. Activate this ability only once each turn. - Cost cost = new SacrificeTargetCost(new TargetControlledPermanent(new TargetControlledPermanent(new FilterControlledLandPermanent("a land")))); + Cost cost = new SacrificeTargetCost(new TargetControlledPermanent(new FilterControlledLandPermanent("a land"))); this.addAbility(new LimitedTimesPerTurnActivatedAbility(Zone.BATTLEFIELD, new DrawCardSourceControllerEffect(2), cost)); } diff --git a/Mage.Sets/src/mage/cards/d/DescendantsFury.java b/Mage.Sets/src/mage/cards/d/DescendantsFury.java new file mode 100644 index 00000000000..3ec8c6e2f33 --- /dev/null +++ b/Mage.Sets/src/mage/cards/d/DescendantsFury.java @@ -0,0 +1,179 @@ +package mage.cards.d; + +import mage.abilities.Ability; +import mage.abilities.common.DealCombatDamageControlledTriggeredAbility; +import mage.abilities.costs.Cost; +import mage.abilities.costs.CostImpl; +import mage.abilities.costs.SacrificeCost; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.DoIfCostPaid; +import mage.cards.*; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.Zone; +import mage.filter.common.FilterControlledPermanent; +import mage.filter.predicate.permanent.PermanentReferenceInCollectionPredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.common.TargetControlledPermanent; +import mage.target.targetpointer.TargetPointer; +import mage.watchers.common.DamagedPlayerThisCombatWatcher; + +import java.util.UUID; + +/** + * @author Susucr + */ +public final class DescendantsFury extends CardImpl { + + public DescendantsFury(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{3}{R}"); + + // Whenever one or more creatures you control deal combat damage to a player, you may sacrifice one of them. If you do, reveal cards from the top of your library until you reveal a creature card that shares a creature type with the sacrificed creature. Put that card onto the battlefield and the rest on the bottom of your library in a random order. + Ability ability = new DealCombatDamageControlledTriggeredAbility( + Zone.BATTLEFIELD, + new DoIfCostPaid( + new DescendantsFuryEffect(), + new DescendantsFurySacrificeCost() + ), + true + ); + + ability.addWatcher(new DamagedPlayerThisCombatWatcher()); + this.addAbility(ability); + } + + private DescendantsFury(final DescendantsFury card) { + super(card); + } + + @Override + public DescendantsFury copy() { + return new DescendantsFury(this); + } +} + +class DescendantsFurySacrificeCost extends CostImpl implements SacrificeCost { + DescendantsFurySacrificeCost() { + this.text = "sacrifice one of them"; + } + + private DescendantsFurySacrificeCost(final DescendantsFurySacrificeCost cost) { + super(cost); + } + + @Override + public DescendantsFurySacrificeCost copy() { + return new DescendantsFurySacrificeCost(this); + } + + @Override + public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) { + DamagedPlayerThisCombatWatcher watcher = game.getState().getWatcher(DamagedPlayerThisCombatWatcher.class); + if (watcher == null) { + return false; + } + TargetPointer targetPointer = source.getEffects().get(0).getTargetPointer(); + if (targetPointer == null) { + return false; + } + Player damagedPlayer = game.getPlayer(targetPointer.getFirst(game, source)); + Player controller = game.getPlayer(source.getControllerId()); + if (controller == null || damagedPlayer == null) { + return false; + } + + FilterControlledPermanent filter = new FilterControlledPermanent(); + filter.add(new PermanentReferenceInCollectionPredicate( + watcher.getPermanents(controller.getId(), damagedPlayer.getId()))); + + TargetControlledPermanent target = new TargetControlledPermanent(0, 1, filter, true); + + if (!controller.choose(Outcome.Sacrifice, target, source, game)) { + return false; + } + + Permanent permanent = game.getPermanent(target.getFirstTarget()); + if (permanent == null) { + return false; + } + + if (permanent.sacrifice(source, game)) { + source.getEffects().setValue("SACRIFICED_PERMANENT", permanent); + return true; + } + + return false; + } + + @Override + public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) { + DamagedPlayerThisCombatWatcher watcher = game.getState().getWatcher(DamagedPlayerThisCombatWatcher.class); + if (watcher == null) { + return false; + } + TargetPointer targetPointer = source.getEffects().get(0).getTargetPointer(); + if (targetPointer == null) { + return false; + } + Player damagedPlayer = game.getPlayer(targetPointer.getFirst(game, source)); + Player controller = game.getPlayer(source.getControllerId()); + if (controller == null || damagedPlayer == null) { + return false; + } + + return watcher.getPermanents(controller.getId(), damagedPlayer.getId()) + .stream() + .map(p -> p.getPermanent(game)) + .anyMatch(p -> p != null && controller.canPaySacrificeCost(p, source, controllerId, game)); + } +} + + +class DescendantsFuryEffect extends OneShotEffect { + + DescendantsFuryEffect() { + super(Outcome.PutCreatureInPlay); + this.staticText = "reveal cards from the top of your library until you reveal a creature card that " + + "shares a creature type with the sacrificed creature. Put that card onto the battlefield " + + "and the rest on the bottom of your library in a random order"; + } + + private DescendantsFuryEffect(final DescendantsFuryEffect effect) { + super(effect); + } + + @Override + public DescendantsFuryEffect copy() { + return new DescendantsFuryEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent permanent = (Permanent) getValue("SACRIFICED_PERMANENT"); + if (permanent == null) { + return false; + } + + Player controller = game.getPlayer(source.getControllerId()); + if (controller == null) { + return false; + } + + Cards revealed = new CardsImpl(); + Cards otherCards = new CardsImpl(); + for (Card card : controller.getLibrary().getCards(game)) { + revealed.add(card); + if (card != null && card.isCreature(game) && permanent.shareCreatureTypes(game, card)) { + controller.moveCards(card, Zone.BATTLEFIELD, source, game); + break; + } else { + otherCards.add(card); + } + } + controller.revealCards(source, revealed, game); + controller.putCardsOnBottomOfLibrary(otherCards, game, source, false); + return true; + } +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/k/KaitoDancingShadow.java b/Mage.Sets/src/mage/cards/k/KaitoDancingShadow.java index efc36f69373..96aa035fc3a 100644 --- a/Mage.Sets/src/mage/cards/k/KaitoDancingShadow.java +++ b/Mage.Sets/src/mage/cards/k/KaitoDancingShadow.java @@ -1,13 +1,5 @@ package mage.cards.k; -import mage.MageObjectReference; -import mage.constants.*; -import mage.filter.FilterPermanent; -import mage.filter.StaticFilters; -import mage.cards.Card; -import mage.cards.CardImpl; -import mage.cards.CardSetInfo; -import mage.constants.CardType; import mage.abilities.Ability; import mage.abilities.LoyaltyAbility; import mage.abilities.common.DealCombatDamageControlledTriggeredAbility; @@ -17,18 +9,21 @@ import mage.abilities.effects.common.CreateTokenEffect; import mage.abilities.effects.common.DrawCardSourceControllerEffect; import mage.abilities.effects.common.combat.CantAttackTargetEffect; import mage.abilities.effects.common.combat.CantBlockTargetEffect; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.filter.FilterPermanent; +import mage.filter.StaticFilters; import mage.filter.predicate.permanent.PermanentReferenceInCollectionPredicate; import mage.game.Game; -import mage.game.events.DamagedPlayerEvent; -import mage.game.events.GameEvent; import mage.game.permanent.Permanent; import mage.game.permanent.token.DroneToken; import mage.players.Player; import mage.target.TargetPermanent; -import mage.watchers.Watcher; +import mage.watchers.common.DamagedPlayerThisCombatWatcher; -import java.util.*; -import java.util.stream.Collectors; +import java.util.UUID; /** * @@ -45,7 +40,7 @@ public final class KaitoDancingShadow extends CardImpl { // Whenever one or more creatures you control deal combat damage to a player, you may return one of them to its owner's hand. If you do, you may activate loyalty abilities of Kaito twice this turn rather than only once. Ability ability = new DealCombatDamageControlledTriggeredAbility(Zone.BATTLEFIELD, new KaitoDancingShadowEffect(), true); - ability.addWatcher(new KaitoDancingShadowWatcher()); + ability.addWatcher(new DamagedPlayerThisCombatWatcher()); this.addAbility(ability); // +1: Up to one target creature can't attack or block until your next turn. @@ -89,7 +84,7 @@ class KaitoDancingShadowEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - KaitoDancingShadowWatcher watcher = game.getState().getWatcher(KaitoDancingShadowWatcher.class); + DamagedPlayerThisCombatWatcher watcher = game.getState().getWatcher(DamagedPlayerThisCombatWatcher.class); if (watcher == null) { return false; } @@ -117,49 +112,6 @@ class KaitoDancingShadowEffect extends OneShotEffect { } } -class KaitoDancingShadowWatcher extends Watcher { - //A creature you control that dealt damage to a player - does not apply across multiple combat steps - - //Player ID -> List of permanents they controlled that dealt damage - private final Map> permanents = new HashMap<>(); - //MOR -> Player they dealt damage to - private final Map damageTarget = new HashMap<>(); - - KaitoDancingShadowWatcher() { - super(WatcherScope.GAME); - } - - @Override - public void watch(GameEvent event, Game game) { - if (event.getType() == GameEvent.EventType.COMBAT_DAMAGE_STEP_POST) { - permanents.clear(); - damageTarget.clear(); - return; - } - if (event.getType() != GameEvent.EventType.DAMAGED_PLAYER - || !((DamagedPlayerEvent) event).isCombatDamage()) { - return; - } - Permanent creature = game.getPermanent(event.getSourceId()); - if (creature == null) { - return; - } - MageObjectReference mor = new MageObjectReference(creature, game); - damageTarget.put(mor, event.getPlayerId()); - - List list = permanents.computeIfAbsent(creature.getControllerId(), (key) -> new ArrayList<>()); - list.add(mor); - } - - //Return the set of permanents that the controller controlled which dealt combat damage to the player - //Returns empty set if there were none - public Set getPermanents(UUID controllerID, UUID damagedPlayerID) { - return permanents.getOrDefault(controllerID, Collections.emptyList()).stream() - .filter((mor) -> damagedPlayerID.equals(damageTarget.get(mor))) - .collect(Collectors.toSet()); - } -} - class KaitoDancingShadowIncreaseLoyaltyUseEffect extends ContinuousEffectImpl { public KaitoDancingShadowIncreaseLoyaltyUseEffect() { diff --git a/Mage.Sets/src/mage/sets/CommanderMasters.java b/Mage.Sets/src/mage/sets/CommanderMasters.java index 5719395e2a7..31f2cde14cc 100644 --- a/Mage.Sets/src/mage/sets/CommanderMasters.java +++ b/Mage.Sets/src/mage/sets/CommanderMasters.java @@ -163,6 +163,7 @@ public final class CommanderMasters extends ExpansionSet { cards.add(new SetCardInfo("Demonlord Belzenlok", 151, Rarity.RARE, mage.cards.d.DemonlordBelzenlok.class)); cards.add(new SetCardInfo("Deploy the Gatewatch", 819, Rarity.MYTHIC, mage.cards.d.DeployTheGatewatch.class)); cards.add(new SetCardInfo("Deranged Assistant", 87, Rarity.COMMON, mage.cards.d.DerangedAssistant.class)); + cards.add(new SetCardInfo("Descendants' Fury", 736, Rarity.RARE, mage.cards.d.DescendantsFury.class)); cards.add(new SetCardInfo("Desecrate Reality", 714, Rarity.RARE, mage.cards.d.DesecrateReality.class)); cards.add(new SetCardInfo("Destiny Spinner", 890, Rarity.UNCOMMON, mage.cards.d.DestinySpinner.class)); cards.add(new SetCardInfo("Diffusion Sliver", 845, Rarity.UNCOMMON, mage.cards.d.DiffusionSliver.class)); diff --git a/Mage/src/main/java/mage/target/common/TargetControlledPermanent.java b/Mage/src/main/java/mage/target/common/TargetControlledPermanent.java index 39a538b7821..11d89b08f1c 100644 --- a/Mage/src/main/java/mage/target/common/TargetControlledPermanent.java +++ b/Mage/src/main/java/mage/target/common/TargetControlledPermanent.java @@ -29,7 +29,7 @@ public class TargetControlledPermanent extends TargetPermanent { super(minNumTargets, maxNumTargets, filter, notTarget); } - public TargetControlledPermanent(final TargetControlledPermanent target) { + protected TargetControlledPermanent(final TargetControlledPermanent target) { super(target); } diff --git a/Mage/src/main/java/mage/watchers/common/DamagedPlayerThisCombatWatcher.java b/Mage/src/main/java/mage/watchers/common/DamagedPlayerThisCombatWatcher.java new file mode 100644 index 00000000000..1b3874e8cae --- /dev/null +++ b/Mage/src/main/java/mage/watchers/common/DamagedPlayerThisCombatWatcher.java @@ -0,0 +1,61 @@ +package mage.watchers.common; + +import mage.MageObjectReference; +import mage.constants.WatcherScope; +import mage.game.Game; +import mage.game.events.DamagedPlayerEvent; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; +import mage.watchers.Watcher; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * @author notgreat + */ +public class DamagedPlayerThisCombatWatcher extends Watcher { + // Watch over creatures that dealt combat damage to a player the last damage phase of current combat. + // Gets cleared post combat damage step. + + // Player ID -> List of permanents they controlled that dealt damage + private final Map> permanents = new HashMap<>(); + // MOR -> Player they dealt damage to + private final Map damageTarget = new HashMap<>(); + + public DamagedPlayerThisCombatWatcher() { + super(WatcherScope.GAME); + } + + @Override + public void watch(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.COMBAT_DAMAGE_STEP_POST + || event.getType() == GameEvent.EventType.CLEANUP_STEP_POST) { + permanents.clear(); + damageTarget.clear(); + return; + } + if (event.getType() != GameEvent.EventType.DAMAGED_PLAYER + || !((DamagedPlayerEvent) event).isCombatDamage()) { + return; + } + Permanent creature = game.getPermanent(event.getSourceId()); + if (creature == null) { + return; + } + MageObjectReference mor = new MageObjectReference(creature, game); + damageTarget.put(mor, event.getPlayerId()); + + List list = permanents.computeIfAbsent(creature.getControllerId(), (key) -> new ArrayList<>()); + list.add(mor); + } + + // Return the set of permanents that the controller controlled which dealt combat damage to the player, + // during the very last combat step. (so no first striker on normal combat damage) + // Returns empty set if there were none + public Set getPermanents(UUID controllerID, UUID damagedPlayerID) { + return permanents.getOrDefault(controllerID, Collections.emptyList()).stream() + .filter((mor) -> damagedPlayerID.equals(damageTarget.get(mor))) + .collect(Collectors.toSet()); + } +}