diff --git a/Mage.Sets/src/mage/cards/g/GrievousWound.java b/Mage.Sets/src/mage/cards/g/GrievousWound.java new file mode 100644 index 00000000000..ec35432ee57 --- /dev/null +++ b/Mage.Sets/src/mage/cards/g/GrievousWound.java @@ -0,0 +1,88 @@ +package mage.cards.g; + +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.common.AttachEffect; +import mage.abilities.effects.common.LoseHalfLifeTargetEffect; +import mage.abilities.effects.common.continuous.CantGainLifeAllEffect; +import mage.abilities.keyword.EnchantAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; +import mage.target.TargetPlayer; +import mage.target.targetpointer.FixedTarget; + +import java.util.Optional; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class GrievousWound extends CardImpl { + + public GrievousWound(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{3}{B}{B}"); + + this.subtype.add(SubType.AURA); + + // Enchant player + TargetPlayer auraTarget = new TargetPlayer(); + this.getSpellAbility().addTarget(auraTarget); + this.getSpellAbility().addEffect(new AttachEffect(Outcome.BoostCreature)); + this.addAbility(new EnchantAbility(auraTarget)); + + // Enchanted player can't gain life. + this.addAbility(new SimpleStaticAbility( + new CantGainLifeAllEffect(Duration.WhileOnBattlefield, TargetController.ENCHANTED) + )); + + // Whenever enchanted player is dealt damage, they lose half their life, rounded up. + this.addAbility(new GrievousWoundTriggeredAbility()); + } + + private GrievousWound(final GrievousWound card) { + super(card); + } + + @Override + public GrievousWound copy() { + return new GrievousWound(this); + } +} + +class GrievousWoundTriggeredAbility extends TriggeredAbilityImpl { + + GrievousWoundTriggeredAbility() { + super(Zone.BATTLEFIELD, new LoseHalfLifeTargetEffect().setText("they lose half their life, rounded up")); + this.setTriggerPhrase("Whenever enchanted player is dealt damage, "); + } + + private GrievousWoundTriggeredAbility(final GrievousWoundTriggeredAbility ability) { + super(ability); + } + + @Override + public GrievousWoundTriggeredAbility copy() { + return new GrievousWoundTriggeredAbility(this); + } + + @Override + public boolean checkEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.DAMAGED_BATCH_FOR_ONE_PLAYER; + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + if (!Optional + .ofNullable(getSourcePermanentIfItStillExists(game)) + .map(Permanent::getAttachedTo) + .equals(event.getTargetId())) { + return false; + } + this.getEffects().setTargetPointer(new FixedTarget(event.getTargetId())); + return true; + } +} diff --git a/Mage.Sets/src/mage/sets/DuskmournHouseOfHorror.java b/Mage.Sets/src/mage/sets/DuskmournHouseOfHorror.java index 6936ee5b401..4062f1173a7 100644 --- a/Mage.Sets/src/mage/sets/DuskmournHouseOfHorror.java +++ b/Mage.Sets/src/mage/sets/DuskmournHouseOfHorror.java @@ -84,6 +84,7 @@ public final class DuskmournHouseOfHorror extends ExpansionSet { cards.add(new SetCardInfo("Gloomlake Verge", 260, Rarity.RARE, mage.cards.g.GloomlakeVerge.class)); cards.add(new SetCardInfo("Grasping Longneck", 180, Rarity.COMMON, mage.cards.g.GraspingLongneck.class)); cards.add(new SetCardInfo("Gremlin Tamer", 215, Rarity.UNCOMMON, mage.cards.g.GremlinTamer.class)); + cards.add(new SetCardInfo("Grievous Wound", 102, Rarity.RARE, mage.cards.g.GrievousWound.class)); cards.add(new SetCardInfo("Growing Dread", 216, Rarity.UNCOMMON, mage.cards.g.GrowingDread.class)); cards.add(new SetCardInfo("Hand That Feeds", 139, Rarity.COMMON, mage.cards.h.HandThatFeeds.class)); cards.add(new SetCardInfo("Hardened Escort", 16, Rarity.COMMON, mage.cards.h.HardenedEscort.class)); diff --git a/Mage/src/main/java/mage/abilities/effects/common/continuous/CantGainLifeAllEffect.java b/Mage/src/main/java/mage/abilities/effects/common/continuous/CantGainLifeAllEffect.java index 5a07edb97f8..0d363ea0da2 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/continuous/CantGainLifeAllEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/continuous/CantGainLifeAllEffect.java @@ -1,18 +1,15 @@ - package mage.abilities.effects.common.continuous; -import java.util.UUID; - import mage.abilities.Ability; import mage.abilities.effects.ContinuousEffectImpl; -import mage.constants.Duration; -import mage.constants.Layer; -import mage.constants.Outcome; -import mage.constants.SubLayer; -import mage.constants.TargetController; +import mage.constants.*; import mage.game.Game; +import mage.game.permanent.Permanent; import mage.players.Player; +import java.util.Optional; +import java.util.UUID; + /** * @author LevelX2 */ @@ -48,41 +45,47 @@ public class CantGainLifeAllEffect extends ContinuousEffectImpl { @Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - switch (targetController) { - case YOU: - controller.setCanGainLife(false); - break; - case NOT_YOU: - for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { - Player player = game.getPlayer(playerId); - if (player != null && !player.equals(controller)) { - player.setCanGainLife(false); - } + if (controller == null) { + return false; + } + switch (targetController) { + case YOU: + controller.setCanGainLife(false); + break; + case NOT_YOU: + for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { + Player player = game.getPlayer(playerId); + if (player != null && !player.equals(controller)) { + player.setCanGainLife(false); } - break; - case OPPONENT: - for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { - if (controller.hasOpponent(playerId, game)) { - Player player = game.getPlayer(playerId); - if (player != null) { - player.setCanGainLife(false); - } - } - } - break; - case ANY: - for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { + } + break; + case OPPONENT: + for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { + if (controller.hasOpponent(playerId, game)) { Player player = game.getPlayer(playerId); if (player != null) { player.setCanGainLife(false); } } - break; - } - return true; + } + break; + case ANY: + for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { + Player player = game.getPlayer(playerId); + if (player != null) { + player.setCanGainLife(false); + } + } + break; + case ENCHANTED: + Optional + .ofNullable(source.getSourcePermanentIfItStillExists(game)) + .map(Permanent::getAttachedTo) + .map(game::getPlayer) + .ifPresent(player -> player.setCanGainLife(false)); } - return false; + return true; } private String setText() { @@ -100,6 +103,8 @@ public class CantGainLifeAllEffect extends ContinuousEffectImpl { case ANY: sb.append("Players"); break; + case ENCHANTED: + sb.append("enchanted player"); } sb.append(" can't gain life"); if (!this.duration.toString().isEmpty()) {