diff --git a/Mage.Sets/src/mage/cards/n/NoWitnesses.java b/Mage.Sets/src/mage/cards/n/NoWitnesses.java new file mode 100644 index 00000000000..35da3f0aba7 --- /dev/null +++ b/Mage.Sets/src/mage/cards/n/NoWitnesses.java @@ -0,0 +1,88 @@ +package mage.cards.n; + +import mage.abilities.Ability; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.DestroyAllEffect; +import mage.abilities.effects.keyword.InvestigateEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.filter.StaticFilters; +import mage.game.Controllable; +import mage.game.Game; + +import java.util.Map; +import java.util.Objects; +import java.util.UUID; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * @author TheElk801 + */ +public final class NoWitnesses extends CardImpl { + + public NoWitnesses(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{2}{W}{W}"); + + // Each player who controls the most creatures investigates. Then destroy all creatures. + this.getSpellAbility().addEffect(new NoWitnessesEffect()); + this.getSpellAbility().addEffect(new DestroyAllEffect(StaticFilters.FILTER_PERMANENT_CREATURES).concatBy("Then")); + } + + private NoWitnesses(final NoWitnesses card) { + super(card); + } + + @Override + public NoWitnesses copy() { + return new NoWitnesses(this); + } +} + +class NoWitnessesEffect extends OneShotEffect { + + NoWitnessesEffect() { + super(Outcome.Benefit); + staticText = "each player who controls the most creatures investigates"; + } + + private NoWitnessesEffect(final NoWitnessesEffect effect) { + super(effect); + } + + @Override + public NoWitnessesEffect copy() { + return new NoWitnessesEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Map map = game + .getBattlefield() + .getActivePermanents( + StaticFilters.FILTER_PERMANENT_CREATURE, + source.getControllerId(), source, game + ) + .stream() + .filter(Objects::nonNull) + .map(Controllable::getControllerId) + .collect(Collectors.toMap(Function.identity(), x -> 1, Integer::sum)); + if (map.isEmpty()) { + return false; + } + int maxValue = map + .values() + .stream() + .mapToInt(x -> x) + .max() + .orElse(0); + for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) { + if (map.getOrDefault(playerId, -1) >= maxValue) { + InvestigateEffect.doInvestigate(playerId, 1, game, source); + } + } + return true; + } +} diff --git a/Mage.Sets/src/mage/sets/MurdersAtKarlovManor.java b/Mage.Sets/src/mage/sets/MurdersAtKarlovManor.java index 81f65a4ee75..2d01ac473d6 100644 --- a/Mage.Sets/src/mage/sets/MurdersAtKarlovManor.java +++ b/Mage.Sets/src/mage/sets/MurdersAtKarlovManor.java @@ -65,6 +65,7 @@ public final class MurdersAtKarlovManor extends ExpansionSet { cards.add(new SetCardInfo("Mountain", 275, Rarity.LAND, mage.cards.basiclands.Mountain.class, FULL_ART_BFZ_VARIOUS)); cards.add(new SetCardInfo("Nightdrinker Moroii", 96, Rarity.UNCOMMON, mage.cards.n.NightdrinkerMoroii.class)); cards.add(new SetCardInfo("No More Lies", 221, Rarity.UNCOMMON, mage.cards.n.NoMoreLies.class)); + cards.add(new SetCardInfo("No Witnesses", 27, Rarity.RARE, mage.cards.n.NoWitnesses.class)); cards.add(new SetCardInfo("Not on My Watch", 28, Rarity.UNCOMMON, mage.cards.n.NotOnMyWatch.class)); cards.add(new SetCardInfo("Novice Inspector", 29, Rarity.COMMON, mage.cards.n.NoviceInspector.class)); cards.add(new SetCardInfo("Out Cold", 66, Rarity.COMMON, mage.cards.o.OutCold.class)); diff --git a/Mage/src/main/java/mage/abilities/effects/keyword/InvestigateEffect.java b/Mage/src/main/java/mage/abilities/effects/keyword/InvestigateEffect.java index c1025776cba..9d54181fc11 100644 --- a/Mage/src/main/java/mage/abilities/effects/keyword/InvestigateEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/keyword/InvestigateEffect.java @@ -10,6 +10,8 @@ import mage.game.events.GameEvent; import mage.game.permanent.token.ClueArtifactToken; import mage.util.CardUtil; +import java.util.UUID; + /** * @author LevelX2 */ @@ -39,14 +41,21 @@ public class InvestigateEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { int value = this.amount.calculate(game, source, this); - if (value < 1) { - return false; + if (value > 0) { + doInvestigate(source.getControllerId(), value, game, source); + return true; } - new ClueArtifactToken().putOntoBattlefield(value, game, source, source.getControllerId()); + return false; + } + + public static void doInvestigate(UUID playerId, int value, Game game, Ability source) { + new ClueArtifactToken().putOntoBattlefield(value, game, source, playerId); for (int i = 0; i < value; i++) { - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.INVESTIGATED, source.getSourceId(), source, source.getControllerId())); + game.fireEvent(GameEvent.getEvent( + GameEvent.EventType.INVESTIGATED, + source.getSourceId(), source, playerId + )); } - return true; } @Override diff --git a/Mage/src/main/java/mage/abilities/effects/keyword/InvestigateTargetEffect.java b/Mage/src/main/java/mage/abilities/effects/keyword/InvestigateTargetEffect.java index f9ac666d3f2..e21522e7fe7 100644 --- a/Mage/src/main/java/mage/abilities/effects/keyword/InvestigateTargetEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/keyword/InvestigateTargetEffect.java @@ -7,8 +7,6 @@ import mage.abilities.dynamicvalue.common.StaticValue; import mage.abilities.effects.OneShotEffect; import mage.constants.Outcome; import mage.game.Game; -import mage.game.events.GameEvent; -import mage.game.permanent.token.ClueArtifactToken; import mage.players.Player; /** @@ -43,14 +41,11 @@ public class InvestigateTargetEffect extends OneShotEffect { return false; } int value = this.amount.calculate(game, source, this); - if (value < 1) { - return false; + if (value > 0) { + InvestigateEffect.doInvestigate(targetPlayer.getId(), value, game, source); + return true; } - new ClueArtifactToken().putOntoBattlefield(value, game, source, targetPlayer.getId()); - for (int i = 0; i < value; i++) { - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.INVESTIGATED, source.getSourceId(), source, targetPlayer.getId())); - } - return true; + return false; } @Override