From 9abb4d30919ef57c70ae3efce195c2b90cee06f6 Mon Sep 17 00:00:00 2001 From: Daniel Eberhard Date: Sat, 17 Dec 2022 21:56:35 +0100 Subject: [PATCH] Added card "Unpleasant Discovery" and its abilities and effects --- .../src/mage/cards/u/UnpleasantDiscovery.java | 33 ++++++- .../common/RevealHandEachPlayerEffect.java | 89 +++++++++++++++++++ 2 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 Mage/src/main/java/mage/abilities/effects/common/RevealHandEachPlayerEffect.java diff --git a/Mage.Sets/src/mage/cards/u/UnpleasantDiscovery.java b/Mage.Sets/src/mage/cards/u/UnpleasantDiscovery.java index 88a84c2c3a..87e2089947 100644 --- a/Mage.Sets/src/mage/cards/u/UnpleasantDiscovery.java +++ b/Mage.Sets/src/mage/cards/u/UnpleasantDiscovery.java @@ -1,4 +1,35 @@ package mage.cards.u; -public class UnpleasantDiscovery { +import mage.abilities.effects.common.LoseLifeOpponentsEffect; +import mage.abilities.effects.common.MillCardsEachPlayerEffect; +import mage.abilities.effects.common.RevealHandEachPlayerEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.TargetController; + +import java.util.UUID; + +/** + * @author Merlingilb + */ +public class UnpleasantDiscovery extends CardImpl { + public UnpleasantDiscovery(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{B}"); + + //Each opponent reveals their hand, loses 1 life, and mills two cards. + this.getSpellAbility().addEffect(new RevealHandEachPlayerEffect(TargetController.OPPONENT)); + this.getSpellAbility().addEffect(new LoseLifeOpponentsEffect(1).setText("and loses 1 life")); + this.getSpellAbility().addEffect(new MillCardsEachPlayerEffect(2, TargetController.OPPONENT) + .setText(" and mills two cards")); + } + + public UnpleasantDiscovery(final UnpleasantDiscovery card) { + super(card); + } + + @Override + public UnpleasantDiscovery copy() { + return new UnpleasantDiscovery(this); + } } diff --git a/Mage/src/main/java/mage/abilities/effects/common/RevealHandEachPlayerEffect.java b/Mage/src/main/java/mage/abilities/effects/common/RevealHandEachPlayerEffect.java new file mode 100644 index 0000000000..49f8aca74e --- /dev/null +++ b/Mage/src/main/java/mage/abilities/effects/common/RevealHandEachPlayerEffect.java @@ -0,0 +1,89 @@ +package mage.abilities.effects.common; + +import mage.MageObject; +import mage.abilities.Ability; +import mage.abilities.Mode; +import mage.abilities.effects.OneShotEffect; +import mage.constants.Outcome; +import mage.constants.TargetController; +import mage.game.Game; +import mage.players.Player; + +import java.util.UUID; + +/** + * @author Merlingilb + */ +public class RevealHandEachPlayerEffect extends OneShotEffect { + private final TargetController targetController; + + public RevealHandEachPlayerEffect() { + this(TargetController.ANY); + } + + public RevealHandEachPlayerEffect(TargetController targetController) { + super(Outcome.Benefit); + this.targetController = targetController; + } + + public RevealHandEachPlayerEffect(final RevealHandEachPlayerEffect effect) { + super(effect); + this.targetController = effect.targetController; + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + MageObject sourceObject = game.getObject(source); + if (controller == null) { + return true; + } + for (UUID playerId : game.getPlayers().keySet()) { + Player player = game.getPlayer(playerId); + if (player == null) { + continue; + } + switch (targetController) { + case NOT_YOU: + if (playerId.equals(source.getControllerId())) { + continue; + } + break; + case OPPONENT: + if (!game.getOpponents(source.getControllerId()).contains(playerId)) { + continue; + } + break; + } + player.revealCards(sourceObject.getIdName() + player.getName(), player.getHand(), game); + } + return true; + } + + @Override + public RevealHandEachPlayerEffect copy() { + return new RevealHandEachPlayerEffect(this); + } + + @Override + public String getText(Mode mode) { + if (staticText != null && !staticText.isEmpty()) { + return staticText; + } + StringBuilder sb = new StringBuilder(); + sb.append("each "); + switch (targetController) { + case NOT_YOU: + sb.append("other player"); + break; + case OPPONENT: + sb.append("opponent"); + break; + case ANY: + sb.append("player"); + break; + } + sb.append(" reveals their hand"); + return sb.toString(); + } +}