diff --git a/Mage.Sets/src/mage/cards/g/GerrardsHourglassPendant.java b/Mage.Sets/src/mage/cards/g/GerrardsHourglassPendant.java index d8e0b385681..e3692b6174f 100644 --- a/Mage.Sets/src/mage/cards/g/GerrardsHourglassPendant.java +++ b/Mage.Sets/src/mage/cards/g/GerrardsHourglassPendant.java @@ -1,14 +1,12 @@ package mage.cards.g; -import mage.MageObject; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; -import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.common.SkipExtraTurnsAbility; import mage.abilities.costs.common.ExileSourceCost; import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.effects.OneShotEffect; -import mage.abilities.effects.ReplacementEffectImpl; import mage.abilities.keyword.FlashAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; @@ -17,12 +15,14 @@ import mage.filter.FilterCard; import mage.filter.predicate.Predicates; import mage.filter.predicate.card.PutIntoGraveFromBattlefieldThisTurnPredicate; import mage.game.Game; -import mage.game.events.GameEvent; import mage.players.Player; import mage.watchers.common.CardsPutIntoGraveyardWatcher; import java.util.UUID; +/** + * @author PurpleCrowbar + */ public final class GerrardsHourglassPendant extends CardImpl { public GerrardsHourglassPendant(UUID ownerId, CardSetInfo setInfo) { @@ -33,7 +33,7 @@ public final class GerrardsHourglassPendant extends CardImpl { this.addAbility(FlashAbility.getInstance()); // If a player would begin an extra turn, that player skips that turn instead. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GerrardsHourglassPendantSkipExtraTurnsEffect())); + this.addAbility(new SkipExtraTurnsAbility()); // {4}, {T}, Exile Gerrard's Hourglass Pendant: Return to the battlefield tapped all artifact, creature, // enchantment, and land cards in your graveyard that were put there from the battlefield this turn. @@ -54,44 +54,6 @@ public final class GerrardsHourglassPendant extends CardImpl { } } -class GerrardsHourglassPendantSkipExtraTurnsEffect extends ReplacementEffectImpl { - - GerrardsHourglassPendantSkipExtraTurnsEffect() { - super(Duration.WhileOnBattlefield, Outcome.Detriment); - staticText = "If a player would begin an extra turn, that player skips that turn instead"; - } - - private GerrardsHourglassPendantSkipExtraTurnsEffect(final GerrardsHourglassPendantSkipExtraTurnsEffect effect) { - super(effect); - } - - @Override - public GerrardsHourglassPendantSkipExtraTurnsEffect copy() { - return new GerrardsHourglassPendantSkipExtraTurnsEffect(this); - } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - Player player = game.getPlayer(event.getPlayerId()); - MageObject sourceObject = game.getObject(source); - if (player != null && sourceObject != null) { - game.informPlayers(sourceObject.getLogName() + ": Extra turn of " + player.getLogName() + " skipped"); - } - return true; - } - - @Override - public boolean checksEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.EXTRA_TURN; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - return true; - } - -} - class GerrardsHourglassPendantReanimateEffect extends OneShotEffect { private static final FilterCard filter = new FilterCard(); diff --git a/Mage.Sets/src/mage/cards/s/Stranglehold.java b/Mage.Sets/src/mage/cards/s/Stranglehold.java index fb7992b0193..f0d42ce4821 100644 --- a/Mage.Sets/src/mage/cards/s/Stranglehold.java +++ b/Mage.Sets/src/mage/cards/s/Stranglehold.java @@ -1,12 +1,11 @@ - package mage.cards.s; import java.util.UUID; import mage.MageObject; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.common.SkipExtraTurnsAbility; import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; -import mage.abilities.effects.ReplacementEffectImpl; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; @@ -28,10 +27,10 @@ public final class Stranglehold extends CardImpl { super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{3}{R}"); // Your opponents can't search libraries. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new OpponentsCantSearchLibarariesEffect())); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new OpponentsCantSearchLibrariesEffect())); // If an opponent would begin an extra turn, that player skips that turn instead. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new StrangleholdSkipExtraTurnsEffect())); + this.addAbility(new SkipExtraTurnsAbility(true)); } private Stranglehold(final Stranglehold card) { @@ -44,20 +43,20 @@ public final class Stranglehold extends CardImpl { } } -class OpponentsCantSearchLibarariesEffect extends ContinuousRuleModifyingEffectImpl { +class OpponentsCantSearchLibrariesEffect extends ContinuousRuleModifyingEffectImpl { - OpponentsCantSearchLibarariesEffect() { + OpponentsCantSearchLibrariesEffect() { super(Duration.WhileOnBattlefield, Outcome.Benefit, true, false); staticText = "Your opponents can't search libraries"; } - private OpponentsCantSearchLibarariesEffect(final OpponentsCantSearchLibarariesEffect effect) { + private OpponentsCantSearchLibrariesEffect(final OpponentsCantSearchLibrariesEffect effect) { super(effect); } @Override - public OpponentsCantSearchLibarariesEffect copy() { - return new OpponentsCantSearchLibarariesEffect(this); + public OpponentsCantSearchLibrariesEffect copy() { + return new OpponentsCantSearchLibrariesEffect(this); } @Override @@ -80,42 +79,3 @@ class OpponentsCantSearchLibarariesEffect extends ContinuousRuleModifyingEffectI return controller != null && controller.hasOpponent(event.getPlayerId(), game); } } - -class StrangleholdSkipExtraTurnsEffect extends ReplacementEffectImpl { - - StrangleholdSkipExtraTurnsEffect() { - super(Duration.WhileOnBattlefield, Outcome.Detriment); - staticText = "If an opponent would begin an extra turn, that player skips that turn instead"; - } - - private StrangleholdSkipExtraTurnsEffect(final StrangleholdSkipExtraTurnsEffect effect) { - super(effect); - } - - @Override - public StrangleholdSkipExtraTurnsEffect copy() { - return new StrangleholdSkipExtraTurnsEffect(this); - } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - Player player = game.getPlayer(event.getPlayerId()); - MageObject sourceObject = game.getObject(source); - if (player != null && sourceObject != null) { - game.informPlayers(sourceObject.getLogName() + ": Extra turn of " + player.getLogName() + " skipped"); - } - return true; - } - - @Override - public boolean checksEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.EXTRA_TURN; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - Player controller = game.getPlayer(source.getControllerId()); - return controller != null && controller.hasOpponent(event.getPlayerId(), game); - } - -} diff --git a/Mage.Sets/src/mage/cards/t/TroubleInPairs.java b/Mage.Sets/src/mage/cards/t/TroubleInPairs.java new file mode 100644 index 00000000000..dfffc3f5fd2 --- /dev/null +++ b/Mage.Sets/src/mage/cards/t/TroubleInPairs.java @@ -0,0 +1,98 @@ +package mage.cards.t; + +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.common.SkipExtraTurnsAbility; +import mage.abilities.effects.common.DrawCardSourceControllerEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.players.Player; +import mage.watchers.common.CardsDrawnThisTurnWatcher; +import mage.watchers.common.CastSpellLastTurnWatcher; + +import java.util.*; + +/** + * @author PurpleCrowbar + */ +public final class TroubleInPairs extends CardImpl { + + public TroubleInPairs(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{2}{W}{W}"); + + // If an opponent would begin an extra turn, that player skips that turn instead. + this.addAbility(new SkipExtraTurnsAbility(true)); + + // Whenever an opponent attacks you with two or more creatures, draws their second card each turn, or casts their second spell each turn, you draw a card. + this.addAbility(new TroubleInPairsTriggeredAbility()); + } + + private TroubleInPairs(final TroubleInPairs card) { + super(card); + } + + @Override + public TroubleInPairs copy() { + return new TroubleInPairs(this); + } +} + +class TroubleInPairsTriggeredAbility extends TriggeredAbilityImpl { + + TroubleInPairsTriggeredAbility() { + super(Zone.BATTLEFIELD, new DrawCardSourceControllerEffect(1)); + } + + private TroubleInPairsTriggeredAbility(final TroubleInPairsTriggeredAbility ability) { + super(ability); + } + + @Override + public TroubleInPairsTriggeredAbility copy() { + return new TroubleInPairsTriggeredAbility(this); + } + + @Override + public boolean checkEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.DECLARED_ATTACKERS + || event.getType() == GameEvent.EventType.DREW_CARD + || event.getType() == GameEvent.EventType.SPELL_CAST; + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + Player controller = game.getPlayer(getControllerId()); + if (controller == null || !game.getOpponents(getControllerId()).contains(event.getPlayerId())) { + return false; + } + switch (event.getType()) { + // Whenever an opponent attacks you with two or more creatures + case DECLARED_ATTACKERS: + return game + .getCombat() + .getAttackers() + .stream() + .map(uuid -> game.getCombat().getDefendingPlayerId(uuid, game)) + .filter(getControllerId()::equals) + .count() >= 2; + // Whenever an opponent draws their second card each turn + case DREW_CARD: + CardsDrawnThisTurnWatcher drawWatcher = game.getState().getWatcher(CardsDrawnThisTurnWatcher.class); + return drawWatcher != null && drawWatcher.getCardsDrawnThisTurn(event.getPlayerId()) == 2; + // Whenever an opponent casts their second spell each turn + case SPELL_CAST: + CastSpellLastTurnWatcher spellWatcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class); + return spellWatcher != null && spellWatcher.getAmountOfSpellsPlayerCastOnCurrentTurn(event.getPlayerId()) == 2; + } + + return false; + } + + @Override + public String getRule() { + return "Whenever an opponent attacks you with two or more creatures, draws their second " + + "card each turn, or casts their second spell each turn, you draw a card."; + } +} diff --git a/Mage.Sets/src/mage/cards/u/UginsNexus.java b/Mage.Sets/src/mage/cards/u/UginsNexus.java index 7722a23d950..6069ea6d735 100644 --- a/Mage.Sets/src/mage/cards/u/UginsNexus.java +++ b/Mage.Sets/src/mage/cards/u/UginsNexus.java @@ -1,10 +1,9 @@ - package mage.cards.u; import java.util.UUID; -import mage.MageObject; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.common.SkipExtraTurnsAbility; import mage.abilities.effects.ReplacementEffectImpl; import mage.abilities.effects.common.turn.AddExtraTurnControllerEffect; import mage.cards.CardImpl; @@ -12,10 +11,8 @@ import mage.cards.CardSetInfo; import mage.constants.*; import mage.game.Game; import mage.game.events.GameEvent; -import mage.game.events.GameEvent.EventType; import mage.game.events.ZoneChangeEvent; import mage.game.permanent.Permanent; -import mage.players.Player; /** * @@ -28,7 +25,7 @@ public final class UginsNexus extends CardImpl { this.supertype.add(SuperType.LEGENDARY); // If a player would begin an extra turn, that player skips that turn instead. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new UginsNexusSkipExtraTurnsEffect())); + this.addAbility(new SkipExtraTurnsAbility()); // If Ugin's Nexus would be put into a graveyard from the battlefield, instead exile it and take an extra turn after this one. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new UginsNexusExileEffect())); @@ -44,44 +41,6 @@ public final class UginsNexus extends CardImpl { } } -class UginsNexusSkipExtraTurnsEffect extends ReplacementEffectImpl { - - UginsNexusSkipExtraTurnsEffect() { - super(Duration.WhileOnBattlefield, Outcome.Detriment); - staticText = "If a player would begin an extra turn, that player skips that turn instead"; - } - - private UginsNexusSkipExtraTurnsEffect(final UginsNexusSkipExtraTurnsEffect effect) { - super(effect); - } - - @Override - public UginsNexusSkipExtraTurnsEffect copy() { - return new UginsNexusSkipExtraTurnsEffect(this); - } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - Player player = game.getPlayer(event.getPlayerId()); - MageObject sourceObject = game.getObject(source); - if (player != null && sourceObject != null) { - game.informPlayers(sourceObject.getLogName() + ": Extra turn of " + player.getLogName() + " skipped"); - } - return true; - } - - @Override - public boolean checksEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.EXTRA_TURN; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - return true; - } - -} - class UginsNexusExileEffect extends ReplacementEffectImpl { UginsNexusExileEffect() { @@ -124,5 +83,4 @@ class UginsNexusExileEffect extends ReplacementEffectImpl { } return false; } - } diff --git a/Mage.Sets/src/mage/sets/MurdersAtKarlovManorCommander.java b/Mage.Sets/src/mage/sets/MurdersAtKarlovManorCommander.java index a7258cf0d20..8b23fe7d453 100644 --- a/Mage.Sets/src/mage/sets/MurdersAtKarlovManorCommander.java +++ b/Mage.Sets/src/mage/sets/MurdersAtKarlovManorCommander.java @@ -36,7 +36,7 @@ public final class MurdersAtKarlovManorCommander extends ExpansionSet { cards.add(new SetCardInfo("Ash Barrens", 248, Rarity.UNCOMMON, mage.cards.a.AshBarrens.class)); cards.add(new SetCardInfo("Ashcloud Phoenix", 147, Rarity.MYTHIC, mage.cards.a.AshcloudPhoenix.class)); cards.add(new SetCardInfo("Austere Command", 56, Rarity.RARE, mage.cards.a.AustereCommand.class)); - cards.add(new SetCardInfo("Azorius Chancery", 249, Rarity.COMMON, mage.cards.a.AzoriusChancery.class)); + cards.add(new SetCardInfo("Azorius Chancery", 249, Rarity.UNCOMMON, mage.cards.a.AzoriusChancery.class)); cards.add(new SetCardInfo("Azorius Signet", 224, Rarity.UNCOMMON, mage.cards.a.AzoriusSignet.class)); cards.add(new SetCardInfo("Baleful Strix", 200, Rarity.RARE, mage.cards.b.BalefulStrix.class)); cards.add(new SetCardInfo("Beast Whisperer", 166, Rarity.RARE, mage.cards.b.BeastWhisperer.class)); @@ -113,7 +113,7 @@ public final class MurdersAtKarlovManorCommander extends ExpansionSet { cards.add(new SetCardInfo("Hooded Hydra", 171, Rarity.MYTHIC, mage.cards.h.HoodedHydra.class)); cards.add(new SetCardInfo("Hornet Queen", 172, Rarity.RARE, mage.cards.h.HornetQueen.class)); cards.add(new SetCardInfo("Hostile Desert", 266, Rarity.RARE, mage.cards.h.HostileDesert.class)); - cards.add(new SetCardInfo("Hydroid Krasis", 212, Rarity.MYTHIC, mage.cards.h.HydroidKrasis.class)); + cards.add(new SetCardInfo("Hydroid Krasis", 212, Rarity.RARE, mage.cards.h.HydroidKrasis.class)); cards.add(new SetCardInfo("Idol of Oblivion", 229, Rarity.RARE, mage.cards.i.IdolOfOblivion.class)); cards.add(new SetCardInfo("Imperial Hellkite", 155, Rarity.RARE, mage.cards.i.ImperialHellkite.class)); cards.add(new SetCardInfo("Inspiring Statuary", 230, Rarity.RARE, mage.cards.i.InspiringStatuary.class)); @@ -135,7 +135,7 @@ public final class MurdersAtKarlovManorCommander extends ExpansionSet { cards.add(new SetCardInfo("Labyrinth of Skophos", 272, Rarity.RARE, mage.cards.l.LabyrinthOfSkophos.class)); cards.add(new SetCardInfo("Lazav, the Multifarious", 214, Rarity.MYTHIC, mage.cards.l.LazavTheMultifarious.class)); cards.add(new SetCardInfo("Lifecrafter's Bestiary", 231, Rarity.RARE, mage.cards.l.LifecraftersBestiary.class)); - cards.add(new SetCardInfo("Lonely Sandbar", 273, Rarity.UNCOMMON, mage.cards.l.LonelySandbar.class)); + cards.add(new SetCardInfo("Lonely Sandbar", 273, Rarity.COMMON, mage.cards.l.LonelySandbar.class)); cards.add(new SetCardInfo("Lonis, Cryptozoologist", 215, Rarity.RARE, mage.cards.l.LonisCryptozoologist.class)); cards.add(new SetCardInfo("Loran of the Third Path", 71, Rarity.RARE, mage.cards.l.LoranOfTheThirdPath.class)); cards.add(new SetCardInfo("Martial Impetus", 72, Rarity.UNCOMMON, mage.cards.m.MartialImpetus.class)); @@ -198,7 +198,7 @@ public final class MurdersAtKarlovManorCommander extends ExpansionSet { cards.add(new SetCardInfo("Scavenger Grounds", 287, Rarity.RARE, mage.cards.s.ScavengerGrounds.class)); cards.add(new SetCardInfo("Scourge of the Throne", 160, Rarity.RARE, mage.cards.s.ScourgeOfTheThrone.class)); cards.add(new SetCardInfo("Scroll of Fate", 235, Rarity.RARE, mage.cards.s.ScrollOfFate.class)); - cards.add(new SetCardInfo("Seal of Cleansing", 80, Rarity.UNCOMMON, mage.cards.s.SealOfCleansing.class)); + cards.add(new SetCardInfo("Seal of Cleansing", 80, Rarity.COMMON, mage.cards.s.SealOfCleansing.class)); cards.add(new SetCardInfo("Search the Premises", 81, Rarity.RARE, mage.cards.s.SearchThePremises.class)); cards.add(new SetCardInfo("Seaside Citadel", 288, Rarity.UNCOMMON, mage.cards.s.SeasideCitadel.class)); cards.add(new SetCardInfo("Secluded Steppe", 289, Rarity.COMMON, mage.cards.s.SecludedSteppe.class)); @@ -261,6 +261,8 @@ public final class MurdersAtKarlovManorCommander extends ExpansionSet { cards.add(new SetCardInfo("Toxic Deluge", 142, Rarity.RARE, mage.cards.t.ToxicDeluge.class)); cards.add(new SetCardInfo("Trail of Mystery", 192, Rarity.RARE, mage.cards.t.TrailOfMystery.class)); cards.add(new SetCardInfo("Tranquil Thicket", 309, Rarity.COMMON, mage.cards.t.TranquilThicket.class)); + cards.add(new SetCardInfo("Trouble in Pairs", 15, Rarity.RARE, mage.cards.t.TroubleInPairs.class, NON_FULL_USE_VARIOUS)); + cards.add(new SetCardInfo("Trouble in Pairs", 326, Rarity.RARE, mage.cards.t.TroubleInPairs.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("Twilight Prophet", 143, Rarity.MYTHIC, mage.cards.t.TwilightProphet.class)); cards.add(new SetCardInfo("Ugin's Mastery", 53, Rarity.RARE, mage.cards.u.UginsMastery.class)); cards.add(new SetCardInfo("Ulvenwald Mysteries", 193, Rarity.UNCOMMON, mage.cards.u.UlvenwaldMysteries.class)); diff --git a/Mage/src/main/java/mage/abilities/common/DrawNthCardTriggeredAbility.java b/Mage/src/main/java/mage/abilities/common/DrawNthCardTriggeredAbility.java index 1265b781146..4389e8b1519 100644 --- a/Mage/src/main/java/mage/abilities/common/DrawNthCardTriggeredAbility.java +++ b/Mage/src/main/java/mage/abilities/common/DrawNthCardTriggeredAbility.java @@ -6,15 +6,12 @@ import mage.abilities.effects.Effect; import mage.abilities.hint.Hint; import mage.abilities.hint.ValueHint; import mage.constants.TargetController; -import mage.constants.WatcherScope; import mage.constants.Zone; import mage.game.Game; import mage.game.events.GameEvent; import mage.players.Player; import mage.util.CardUtil; -import mage.watchers.Watcher; - -import java.util.*; +import mage.watchers.common.CardsDrawnThisTurnWatcher; /** * @author TheElk801 @@ -37,7 +34,6 @@ public class DrawNthCardTriggeredAbility extends TriggeredAbilityImpl { public DrawNthCardTriggeredAbility(Zone zone, Effect effect, boolean optional, TargetController targetController, int cardNumber) { super(zone, effect, optional); - this.addWatcher(new DrawCardWatcher()); this.targetController = targetController; this.cardNumber = cardNumber; this.addHint(hint); @@ -77,7 +73,8 @@ public class DrawNthCardTriggeredAbility extends TriggeredAbilityImpl { default: throw new IllegalArgumentException("TargetController " + targetController + " not supported"); } - return DrawCardWatcher.checkEvent(event.getPlayerId(), event, game, cardNumber); + CardsDrawnThisTurnWatcher watcher = game.getState().getWatcher(CardsDrawnThisTurnWatcher.class); + return watcher != null && watcher.getCardsDrawnThisTurn(event.getPlayerId()) == cardNumber; } public String generateTriggerPhrase() { @@ -98,35 +95,3 @@ public class DrawNthCardTriggeredAbility extends TriggeredAbilityImpl { return new DrawNthCardTriggeredAbility(this); } } - -class DrawCardWatcher extends Watcher { - - private final Map> drawMap = new HashMap<>(); - - DrawCardWatcher() { - super(WatcherScope.GAME); - } - - @Override - public void watch(GameEvent event, Game game) { - if (event.getType() != GameEvent.EventType.DREW_CARD) { - return; - } - if (!drawMap.containsKey(event.getPlayerId())) { - drawMap.putIfAbsent(event.getPlayerId(), new ArrayList<>()); - } - drawMap.get(event.getPlayerId()).add(event.getId()); - } - - @Override - public void reset() { - super.reset(); - drawMap.clear(); - } - - static boolean checkEvent(UUID playerId, GameEvent event, Game game, int cardNumber) { - Map> drawMap = game.getState().getWatcher(DrawCardWatcher.class).drawMap; - return drawMap.containsKey(playerId) && Objects.equals(drawMap.get(playerId).size(), cardNumber) && event.getId().equals(drawMap.get(playerId).get(cardNumber - 1)); - } - -} diff --git a/Mage/src/main/java/mage/abilities/common/SkipExtraTurnsAbility.java b/Mage/src/main/java/mage/abilities/common/SkipExtraTurnsAbility.java new file mode 100644 index 00000000000..f10b273a002 --- /dev/null +++ b/Mage/src/main/java/mage/abilities/common/SkipExtraTurnsAbility.java @@ -0,0 +1,83 @@ +package mage.abilities.common; + +import mage.MageObject; +import mage.abilities.Ability; +import mage.abilities.effects.ReplacementEffectImpl; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.constants.Zone; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.players.Player; + +/** + * @author PurpleCrowbar + */ +public class SkipExtraTurnsAbility extends SimpleStaticAbility { + + private final boolean onlyOpponents; + + public SkipExtraTurnsAbility() { + this(false); + } + + public SkipExtraTurnsAbility(boolean onlyOpponents) { + super(Zone.BATTLEFIELD, new SkipExtraTurnsEffect(onlyOpponents)); + this.onlyOpponents = onlyOpponents; + } + + private SkipExtraTurnsAbility(final SkipExtraTurnsAbility ability) { + super(ability); + this.onlyOpponents = ability.onlyOpponents; + } + + @Override + public SkipExtraTurnsAbility copy() { + return new SkipExtraTurnsAbility(this); + } + + @Override + public String getRule() { + return "If a" + (onlyOpponents ? "n opponent" : " player") + " would begin an extra turn, that player skips that turn instead."; + } +} + +class SkipExtraTurnsEffect extends ReplacementEffectImpl { + + private final boolean onlyOpponents; + + SkipExtraTurnsEffect(boolean onlyOpponents) { + super(Duration.WhileOnBattlefield, Outcome.Detriment); + this.onlyOpponents = onlyOpponents; + } + + private SkipExtraTurnsEffect(final SkipExtraTurnsEffect effect) { + super(effect); + this.onlyOpponents = effect.onlyOpponents; + } + + @Override + public SkipExtraTurnsEffect copy() { + return new SkipExtraTurnsEffect(this); + } + + @Override + public boolean replaceEvent(GameEvent event, Ability source, Game game) { + Player player = game.getPlayer(event.getPlayerId()); + MageObject sourceObject = game.getObject(source); + if (player != null && sourceObject != null) { + game.informPlayers(sourceObject.getLogName() + ": Extra turn of " + player.getLogName() + " skipped"); + } + return true; + } + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.EXTRA_TURN; + } + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + return !onlyOpponents || game.getPlayer(source.getControllerId()).hasOpponent(event.getPlayerId(), game); + } +}