diff --git a/Mage.Sets/src/mage/cards/a/AriaOfFlame.java b/Mage.Sets/src/mage/cards/a/AriaOfFlame.java index 2856347067a..ae2fbda0afd 100644 --- a/Mage.Sets/src/mage/cards/a/AriaOfFlame.java +++ b/Mage.Sets/src/mage/cards/a/AriaOfFlame.java @@ -5,17 +5,15 @@ import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.SpellCastControllerTriggeredAbility; import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.dynamicvalue.common.CountersSourceCount; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.DamageTargetEffect; +import mage.abilities.effects.common.GainLifeAllEffect; import mage.abilities.effects.common.counter.AddCountersSourceEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Outcome; +import mage.constants.TargetController; import mage.counters.CounterType; import mage.filter.StaticFilters; -import mage.game.Game; -import mage.players.Player; import mage.target.common.TargetPlayerOrPlaneswalker; import java.util.UUID; @@ -31,7 +29,7 @@ public final class AriaOfFlame extends CardImpl { super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{2}{R}"); // When Aria of Flame enters the battlefield, each opponent gains 10 life. - this.addAbility(new EntersBattlefieldTriggeredAbility(new AriaOfFlameEffect())); + this.addAbility(new EntersBattlefieldTriggeredAbility(new GainLifeAllEffect(10, TargetController.OPPONENT))); // Whenever you cast an instant or sorcery spell, put a verse counter on Aria of Flame, then it deals damage equal to the number of verse counters on it to target player or planeswalker. Ability ability = new SpellCastControllerTriggeredAbility( @@ -54,31 +52,3 @@ public final class AriaOfFlame extends CardImpl { return new AriaOfFlame(this); } } - -class AriaOfFlameEffect extends OneShotEffect { - - AriaOfFlameEffect() { - super(Outcome.Benefit); - staticText = "each opponent gains 10 life"; - } - - private AriaOfFlameEffect(AriaOfFlameEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - for (UUID playerId : game.getOpponents(source.getControllerId())) { - Player player = game.getPlayer(playerId); - if (player != null) { - player.gainLife(10, game, source); - } - } - return true; - } - - @Override - public AriaOfFlameEffect copy() { - return new AriaOfFlameEffect(this); - } -} diff --git a/Mage.Sets/src/mage/cards/c/CentaurPeacemaker.java b/Mage.Sets/src/mage/cards/c/CentaurPeacemaker.java index 45e10757f0b..d14039c1307 100644 --- a/Mage.Sets/src/mage/cards/c/CentaurPeacemaker.java +++ b/Mage.Sets/src/mage/cards/c/CentaurPeacemaker.java @@ -1,20 +1,16 @@ package mage.cards.c; -import java.util.Objects; -import java.util.UUID; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; -import mage.abilities.effects.OneShotEffect; -import mage.constants.SubType; +import mage.abilities.effects.common.GainLifeAllEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Outcome; -import mage.game.Game; +import mage.constants.SubType; + +import java.util.UUID; /** - * * @author TheElk801 */ public final class CentaurPeacemaker extends CardImpl { @@ -28,9 +24,7 @@ public final class CentaurPeacemaker extends CardImpl { this.toughness = new MageInt(3); // When Centaur Mediator enters the battlefield, each player gains 4 life. - this.addAbility(new EntersBattlefieldTriggeredAbility( - new CentaurMediatorEffect() - )); + this.addAbility(new EntersBattlefieldTriggeredAbility(new GainLifeAllEffect(4))); } private CentaurPeacemaker(final CentaurPeacemaker card) { @@ -42,32 +36,3 @@ public final class CentaurPeacemaker extends CardImpl { return new CentaurPeacemaker(this); } } - -class CentaurMediatorEffect extends OneShotEffect { - - CentaurMediatorEffect() { - super(Outcome.GainLife); - staticText = "each player gains 4 life."; - } - - private CentaurMediatorEffect(final CentaurMediatorEffect effect) { - super(effect); - } - - @Override - public CentaurMediatorEffect copy() { - return new CentaurMediatorEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - game.getState().getPlayersInRange( - source.getControllerId(), game) - .stream() - .map(game::getPlayer) - .filter(Objects::nonNull) - .forEachOrdered(player -> player.gainLife(4, game, source)); - return true; - } - -} diff --git a/Mage.Sets/src/mage/cards/g/GroveOfTheBurnwillows.java b/Mage.Sets/src/mage/cards/g/GroveOfTheBurnwillows.java index 616a8ec8b8a..88f33581be5 100644 --- a/Mage.Sets/src/mage/cards/g/GroveOfTheBurnwillows.java +++ b/Mage.Sets/src/mage/cards/g/GroveOfTheBurnwillows.java @@ -1,37 +1,35 @@ - package mage.cards.g; -import java.util.UUID; import mage.abilities.Ability; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.GainLifeAllEffect; import mage.abilities.mana.ColorlessManaAbility; import mage.abilities.mana.GreenManaAbility; import mage.abilities.mana.RedManaAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Outcome; -import mage.game.Game; -import mage.players.Player; +import mage.constants.TargetController; + +import java.util.UUID; /** - * * @author jonubuu */ public final class GroveOfTheBurnwillows extends CardImpl { public GroveOfTheBurnwillows(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.LAND},""); + super(ownerId, setInfo, new CardType[]{CardType.LAND}, ""); // {tap}: Add {C}. this.addAbility(new ColorlessManaAbility()); + // {tap}: Add {R} or {G}. Each opponent gains 1 life. - Ability RedManaAbility = new RedManaAbility(); - RedManaAbility.addEffect(new GroveOfTheBurnwillowsEffect()); - this.addAbility(RedManaAbility); - Ability GreenManaAbility = new GreenManaAbility(); - GreenManaAbility.addEffect(new GroveOfTheBurnwillowsEffect()); - this.addAbility(GreenManaAbility); + Ability ability = new RedManaAbility(); + ability.addEffect(new GainLifeAllEffect(1, TargetController.OPPONENT)); + this.addAbility(ability); + ability = new GreenManaAbility(); + ability.addEffect(new GainLifeAllEffect(1, TargetController.OPPONENT)); + this.addAbility(ability); } private GroveOfTheBurnwillows(final GroveOfTheBurnwillows card) { @@ -43,31 +41,3 @@ public final class GroveOfTheBurnwillows extends CardImpl { return new GroveOfTheBurnwillows(this); } } - -class GroveOfTheBurnwillowsEffect extends OneShotEffect { - - GroveOfTheBurnwillowsEffect() { - super(Outcome.Benefit); - staticText = "Each opponent gains 1 life"; - } - - private GroveOfTheBurnwillowsEffect(final GroveOfTheBurnwillowsEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - for (UUID playerId : game.getOpponents(source.getControllerId())) { - Player player = game.getPlayer(playerId); - if(player != null) { - player.gainLife(1, game, source); - } - } - return true; - } - - @Override - public GroveOfTheBurnwillowsEffect copy() { - return new GroveOfTheBurnwillowsEffect(this); - } -} diff --git a/Mage.Sets/src/mage/cards/h/HappilyEverAfter.java b/Mage.Sets/src/mage/cards/h/HappilyEverAfter.java index 15ea9944cf1..544db48f69c 100644 --- a/Mage.Sets/src/mage/cards/h/HappilyEverAfter.java +++ b/Mage.Sets/src/mage/cards/h/HappilyEverAfter.java @@ -4,7 +4,8 @@ import mage.ObjectColor; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.condition.Condition; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.DrawCardAllEffect; +import mage.abilities.effects.common.GainLifeAllEffect; import mage.abilities.effects.common.WinGameSourceControllerEffect; import mage.abilities.hint.Hint; import mage.abilities.hint.HintUtils; @@ -12,7 +13,6 @@ import mage.abilities.triggers.BeginningOfUpkeepTriggeredAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Outcome; import mage.game.Game; import mage.players.Player; @@ -27,7 +27,9 @@ public final class HappilyEverAfter extends CardImpl { super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{2}{W}"); // When Happily Ever After enters the battlefield, each player gains 5 life and draws a card. - this.addAbility(new EntersBattlefieldTriggeredAbility(new HappilyEverAfterEffect())); + Ability ability = new EntersBattlefieldTriggeredAbility(new GainLifeAllEffect(5)); + ability.addEffect(new DrawCardAllEffect(1).setText("and draws a card")); + this.addAbility(ability); // At the beginning of your upkeep, if there are five colors among permanents you control, there are six or more card types among permanents you control and/or cards in your graveyard, and your life total is greater than or equal to your starting life total, you win the game. this.addAbility(new BeginningOfUpkeepTriggeredAbility(new WinGameSourceControllerEffect()) @@ -47,37 +49,6 @@ public final class HappilyEverAfter extends CardImpl { } } -class HappilyEverAfterEffect extends OneShotEffect { - - HappilyEverAfterEffect() { - super(Outcome.GainLife); - staticText = "each player gains 5 life and draws a card"; - } - - private HappilyEverAfterEffect(final HappilyEverAfterEffect effect) { - super(effect); - } - - @Override - public HappilyEverAfterEffect copy() { - return new HappilyEverAfterEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - game.getState() - .getPlayersInRange(source.getControllerId(), game) - .stream() - .map(game::getPlayer) - .filter(Objects::nonNull) - .forEachOrdered(player -> { - player.gainLife(5, game, source); - player.drawCards(1, source, game); - }); - return true; - } -} - enum HappilyEverAfterCondition implements Condition { instance; diff --git a/Mage.Sets/src/mage/cards/m/MathasFiendSeeker.java b/Mage.Sets/src/mage/cards/m/MathasFiendSeeker.java index 044ed3e202f..3ff467d78a0 100644 --- a/Mage.Sets/src/mage/cards/m/MathasFiendSeeker.java +++ b/Mage.Sets/src/mage/cards/m/MathasFiendSeeker.java @@ -4,8 +4,8 @@ import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.DiesSourceTriggeredAbility; import mage.abilities.effects.ContinuousEffectImpl; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.DrawCardAllEffect; +import mage.abilities.effects.common.GainLifeAllEffect; import mage.abilities.effects.common.counter.AddCountersTargetEffect; import mage.abilities.keyword.MenaceAbility; import mage.abilities.triggers.BeginningOfEndStepTriggeredAbility; @@ -15,7 +15,6 @@ import mage.constants.*; import mage.counters.CounterType; import mage.game.Game; import mage.game.permanent.Permanent; -import mage.players.Player; import mage.target.common.TargetOpponentsCreaturePermanent; import java.util.UUID; @@ -40,7 +39,7 @@ public final class MathasFiendSeeker extends CardImpl { Ability ability = new BeginningOfEndStepTriggeredAbility( new AddCountersTargetEffect(CounterType.BOUNTY.createInstance()) ); - ability.addEffect(new MathasFiendSeekerGainAbilityEffect()); + ability.addEffect(new MathasFiendSeekerEffect()); ability.addTarget(new TargetOpponentsCreaturePermanent()); this.addAbility(ability); } @@ -55,26 +54,26 @@ public final class MathasFiendSeeker extends CardImpl { } } -class MathasFiendSeekerGainAbilityEffect extends ContinuousEffectImpl { +class MathasFiendSeekerEffect extends ContinuousEffectImpl { private final Ability ability; - MathasFiendSeekerGainAbilityEffect() { + MathasFiendSeekerEffect() { super(Duration.Custom, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility); staticText = "For as long as that creature has a bounty counter on it, " + "it has \"When this creature dies, each opponent draws a card and gains 2 life.\""; this.ability = new DiesSourceTriggeredAbility(new DrawCardAllEffect(1, TargetController.OPPONENT)); - this.ability.addEffect(new MathasFiendSeekerGainLifeEffect()); + this.ability.addEffect(new GainLifeAllEffect(2, TargetController.OPPONENT).setText("and gains 2 life")); } - private MathasFiendSeekerGainAbilityEffect(final MathasFiendSeekerGainAbilityEffect effect) { + private MathasFiendSeekerEffect(final MathasFiendSeekerEffect effect) { super(effect); this.ability = effect.ability.copy(); } @Override - public MathasFiendSeekerGainAbilityEffect copy() { - return new MathasFiendSeekerGainAbilityEffect(this); + public MathasFiendSeekerEffect copy() { + return new MathasFiendSeekerEffect(this); } @Override @@ -88,31 +87,3 @@ class MathasFiendSeekerGainAbilityEffect extends ContinuousEffectImpl { return true; } } - -class MathasFiendSeekerGainLifeEffect extends OneShotEffect { - - MathasFiendSeekerGainLifeEffect() { - super(Outcome.GainLife); - staticText = "and gains 2 life."; - } - - private MathasFiendSeekerGainLifeEffect(final MathasFiendSeekerGainLifeEffect effect) { - super(effect); - } - - @Override - public MathasFiendSeekerGainLifeEffect copy() { - return new MathasFiendSeekerGainLifeEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - for (UUID playerId : game.getOpponents(source.getControllerId())) { - Player player = game.getPlayer(playerId); - if (player != null) { - player.gainLife(2, game, source); - } - } - return true; - } -} diff --git a/Mage.Sets/src/mage/cards/p/PestilentCauldron.java b/Mage.Sets/src/mage/cards/p/PestilentCauldron.java index f5b6b65462b..1df624ed426 100644 --- a/Mage.Sets/src/mage/cards/p/PestilentCauldron.java +++ b/Mage.Sets/src/mage/cards/p/PestilentCauldron.java @@ -6,20 +6,16 @@ import mage.abilities.costs.common.DiscardCardCost; import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.dynamicvalue.common.ControllerGainedLifeCount; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.*; import mage.cards.CardSetInfo; import mage.cards.ModalDoubleFacedCard; import mage.constants.CardType; -import mage.constants.Outcome; import mage.constants.SubType; import mage.constants.TargetController; import mage.filter.FilterCard; import mage.filter.StaticFilters; import mage.filter.predicate.Predicates; -import mage.game.Game; import mage.game.permanent.token.Pest11GainLifeToken; -import mage.players.Player; import mage.target.common.TargetCardInASingleGraveyard; import mage.target.common.TargetCardInYourGraveyard; import mage.watchers.common.PlayerGainedLifeWatcher; @@ -82,7 +78,7 @@ public final class PestilentCauldron extends ModalDoubleFacedCard { // Sorcery // Return up to two target creature, land, and/or planeswalker cards from your graveyard to your hand. Each player gains 4 life. Exile Restorative Burst. this.getRightHalfCard().getSpellAbility().addEffect(new ReturnFromGraveyardToHandTargetEffect()); - this.getRightHalfCard().getSpellAbility().addEffect(new RestorativeBurstEffect()); + this.getRightHalfCard().getSpellAbility().addEffect(new GainLifeAllEffect(4)); this.getRightHalfCard().getSpellAbility().addEffect(new ExileSpellEffect()); this.getRightHalfCard().getSpellAbility().addTarget(new TargetCardInYourGraveyard(0, 2, filter)); } @@ -96,31 +92,3 @@ public final class PestilentCauldron extends ModalDoubleFacedCard { return new PestilentCauldron(this); } } - -class RestorativeBurstEffect extends OneShotEffect { - - RestorativeBurstEffect() { - super(Outcome.GainLife); - staticText = "Each player gains 4 life."; - } - - private RestorativeBurstEffect(final RestorativeBurstEffect effect) { - super(effect); - } - - @Override - public RestorativeBurstEffect copy() { - return new RestorativeBurstEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) { - Player player = game.getPlayer(playerId); - if (player != null) { - player.gainLife(4, game, source); - } - } - return true; - } -} diff --git a/Mage.Sets/src/mage/cards/p/PutridWarrior.java b/Mage.Sets/src/mage/cards/p/PutridWarrior.java index f46b567d50d..e68a0d51708 100644 --- a/Mage.Sets/src/mage/cards/p/PutridWarrior.java +++ b/Mage.Sets/src/mage/cards/p/PutridWarrior.java @@ -4,15 +4,12 @@ import mage.MageInt; import mage.abilities.Ability; import mage.abilities.Mode; import mage.abilities.common.DealsDamageSourceTriggeredAbility; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.GainLifeAllEffect; import mage.abilities.effects.common.LoseLifeAllPlayersEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Outcome; import mage.constants.SubType; -import mage.game.Game; -import mage.players.Player; import java.util.UUID; @@ -31,7 +28,7 @@ public final class PutridWarrior extends CardImpl { // Whenever Putrid Warrior deals damage, choose one - Each player loses 1 life; or each player gains 1 life. Ability ability = new DealsDamageSourceTriggeredAbility(new LoseLifeAllPlayersEffect(1)); - ability.addMode(new Mode(new PutridWarriorGainLifeEffect())); + ability.addMode(new Mode(new GainLifeAllEffect(1))); this.addAbility(ability); } @@ -44,32 +41,3 @@ public final class PutridWarrior extends CardImpl { return new PutridWarrior(this); } } - -class PutridWarriorGainLifeEffect extends OneShotEffect { - - PutridWarriorGainLifeEffect() { - super(Outcome.GainLife); - staticText = "each player gains 1 life"; - } - - private PutridWarriorGainLifeEffect(final PutridWarriorGainLifeEffect effect) { - super(effect); - } - - @Override - public PutridWarriorGainLifeEffect copy() { - return new PutridWarriorGainLifeEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) { - Player player = game.getPlayer(playerId); - if (player != null) { - player.gainLife(1, game, source); - } - } - return true; - } - -} diff --git a/Mage.Sets/src/mage/cards/t/Triskaidekaphobia.java b/Mage.Sets/src/mage/cards/t/Triskaidekaphobia.java index 56990c197fb..b85a311c838 100644 --- a/Mage.Sets/src/mage/cards/t/Triskaidekaphobia.java +++ b/Mage.Sets/src/mage/cards/t/Triskaidekaphobia.java @@ -1,33 +1,34 @@ - package mage.cards.t; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.Mode; -import mage.abilities.triggers.BeginningOfUpkeepTriggeredAbility; import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.GainLifeAllEffect; +import mage.abilities.effects.common.LoseLifeAllPlayersEffect; +import mage.abilities.triggers.BeginningOfUpkeepTriggeredAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Outcome; import mage.game.Game; import mage.players.Player; -import mage.players.PlayerList; + +import java.util.UUID; /** - * * @author fireshoes */ public final class Triskaidekaphobia extends CardImpl { public Triskaidekaphobia(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{3}{B}"); + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{3}{B}"); // At the beginning of your upkeep, choose one - Each player with exactly 13 life loses the game, then each player gains 1 life. // Each player with exactly 13 life loses the game, then each player loses 1 life. Ability ability = new BeginningOfUpkeepTriggeredAbility(new TriskaidekaphobiaGainLifeEffect()); - Mode mode = new Mode(new TriskaidekaphobiaLoseLifeEffect()); - ability.addMode(mode); + ability.addEffect(new GainLifeAllEffect(1).concatBy(", then")); + ability.addMode(new Mode(new TriskaidekaphobiaGainLifeEffect()) + .addEffect(new LoseLifeAllPlayersEffect(1).concatBy(", then"))); this.addAbility(ability); } @@ -45,7 +46,7 @@ class TriskaidekaphobiaGainLifeEffect extends OneShotEffect { TriskaidekaphobiaGainLifeEffect() { super(Outcome.Neutral); - this.staticText = "Each player with exactly 13 life loses the game, then each player gains 1 life"; + this.staticText = "each player with exactly 13 life loses the game"; } private TriskaidekaphobiaGainLifeEffect(final TriskaidekaphobiaGainLifeEffect effect) { @@ -59,60 +60,10 @@ class TriskaidekaphobiaGainLifeEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - int life; - PlayerList playerList = game.getState().getPlayersInRange(source.getControllerId(), game); - for (UUID pid : playerList) { - Player player = game.getPlayer(pid); - if (player != null) { - life = player.getLife(); - if (life == 13) { - player.lost(game); - } - } - } - for (UUID pid : playerList) { - Player player = game.getPlayer(pid); - if (player != null) { - player.gainLife(1, game, source); - } - } - return true; - } -} - -class TriskaidekaphobiaLoseLifeEffect extends OneShotEffect { - - TriskaidekaphobiaLoseLifeEffect() { - super(Outcome.Neutral); - this.staticText = "Each player with exactly 13 life loses the game, then each player loses 1 life"; - } - - private TriskaidekaphobiaLoseLifeEffect(final TriskaidekaphobiaLoseLifeEffect effect) { - super(effect); - } - - @Override - public TriskaidekaphobiaLoseLifeEffect copy() { - return new TriskaidekaphobiaLoseLifeEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - int life; - PlayerList playerList = game.getState().getPlayersInRange(source.getControllerId(), game); - for (UUID pid : playerList) { - Player player = game.getPlayer(pid); - if (player != null) { - life = player.getLife(); - if (life == 13) { - player.lost(game); - } - } - } - for (UUID pid : playerList) { - Player player = game.getPlayer(pid); - if (player != null) { - player.loseLife(1, game, source, false); + for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) { + Player player = game.getPlayer(playerId); + if (player != null && player.getLife() == 13) { + player.lost(game); } } return true; diff --git a/Mage.Sets/src/mage/cards/w/WanderingArchaic.java b/Mage.Sets/src/mage/cards/w/WanderingArchaic.java index e31b06ad2f8..2640d7e4012 100644 --- a/Mage.Sets/src/mage/cards/w/WanderingArchaic.java +++ b/Mage.Sets/src/mage/cards/w/WanderingArchaic.java @@ -4,6 +4,7 @@ import mage.abilities.Ability; import mage.abilities.common.SpellCastOpponentTriggeredAbility; import mage.abilities.costs.Cost; import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.GainLifeAllEffect; import mage.cards.*; import mage.constants.*; import mage.filter.FilterCard; @@ -49,6 +50,7 @@ public final class WanderingArchaic extends ModalDoubleFacedCard { // Sorcery // Each player looks at the top five cards of their library, reveals a land card and/or an instant or sorcery card from among them, then puts the cards they revealed this way into their hand and the rest on the bottom of their library in a random order. Each player gains 3 life. this.getRightHalfCard().getSpellAbility().addEffect(new ExploreTheVastlandsEffect()); + this.getRightHalfCard().getSpellAbility().addEffect(new GainLifeAllEffect(3)); } private WanderingArchaic(final WanderingArchaic card) { @@ -105,7 +107,7 @@ class ExploreTheVastlandsEffect extends OneShotEffect { staticText = "each player looks at the top five cards of their library " + "and may reveal a land card and/or an instant or sorcery card from among them. " + "Each player puts the cards they revealed this way into their hand and the rest " + - "on the bottom of their library in a random order. Each player gains 3 life"; + "on the bottom of their library in a random order."; } private ExploreTheVastlandsEffect(final ExploreTheVastlandsEffect effect) { @@ -133,12 +135,6 @@ class ExploreTheVastlandsEffect extends OneShotEffect { player.moveCards(toHand, Zone.HAND, source, game); player.putCardsOnBottomOfLibrary(cards, game, source, false); } - for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) { - Player player = game.getPlayer(playerId); - if (player != null) { - player.gainLife(3, game, source); - } - } return true; } } diff --git a/Mage/src/main/java/mage/abilities/effects/common/GainLifeAllEffect.java b/Mage/src/main/java/mage/abilities/effects/common/GainLifeAllEffect.java new file mode 100644 index 00000000000..6f164dee867 --- /dev/null +++ b/Mage/src/main/java/mage/abilities/effects/common/GainLifeAllEffect.java @@ -0,0 +1,83 @@ +package mage.abilities.effects.common; + +import mage.abilities.Ability; +import mage.abilities.effects.OneShotEffect; +import mage.constants.Outcome; +import mage.constants.TargetController; +import mage.game.Game; + +import java.util.Collection; +import java.util.Optional; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public class GainLifeAllEffect extends OneShotEffect { + + private final int amount; + private final TargetController targetController; + + public GainLifeAllEffect(int amount) { + this(amount, TargetController.EACH_PLAYER); + } + + public GainLifeAllEffect(int amount, TargetController targetController) { + super(Outcome.Benefit); + this.amount = amount; + this.targetController = targetController; + staticText = makeRule(amount, targetController); + } + + private GainLifeAllEffect(final GainLifeAllEffect effect) { + super(effect); + this.amount = effect.amount; + this.targetController = effect.targetController; + } + + @Override + public GainLifeAllEffect copy() { + return new GainLifeAllEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + for (UUID playerId : getPlayers(targetController, game, source)) { + Optional.ofNullable(playerId) + .map(game::getPlayer) + .ifPresent(player -> player.gainLife(amount, game, source)); + } + return true; + } + + private static Collection getPlayers(TargetController targetController, Game game, Ability source) { + switch (targetController) { + case ANY: + case EACH_PLAYER: + return game.getState().getPlayersInRange(source.getControllerId(), game); + case OPPONENT: + return game.getOpponents(source.getControllerId()); + default: + throw new IllegalArgumentException("TargetController " + targetController + " not supported"); + } + } + + private static String makeRule(int amount, TargetController targetController) { + StringBuilder sb = new StringBuilder("each "); + switch (targetController) { + case ANY: + case EACH_PLAYER: + sb.append("player"); + break; + case OPPONENT: + sb.append("opponent"); + break; + default: + throw new IllegalArgumentException("TargetController " + targetController + " not supported"); + } + sb.append(" gains "); + sb.append(amount); + sb.append(" life"); + return sb.toString(); + } +}