From 776928c76c66a4fa66549507af0f946659808846 Mon Sep 17 00:00:00 2001 From: spjspj Date: Tue, 17 Apr 2018 02:13:48 +1000 Subject: [PATCH] Continuing implementation of Planechase. --- Mage/src/main/java/mage/game/GameImpl.java | 2 +- .../planes/AcademyAtTolariaWestPlane.java | 75 ++++++++++++++++++- .../command/planes/EdgeOfMalacolPlane.java | 14 +++- .../planes/HedronFieldsOfAgadeemPlane.java | 5 ++ .../game/command/planes/TheEonFogPlane.java | 45 ++++++++++- .../command/planes/UndercityReachesPlane.java | 10 ++- 6 files changed, 141 insertions(+), 10 deletions(-) diff --git a/Mage/src/main/java/mage/game/GameImpl.java b/Mage/src/main/java/mage/game/GameImpl.java index 7f2ae4f357..c72ddb6fad 100644 --- a/Mage/src/main/java/mage/game/GameImpl.java +++ b/Mage/src/main/java/mage/game/GameImpl.java @@ -1077,7 +1077,7 @@ public abstract class GameImpl implements Game, Serializable { // 20180408 - 901.5 if (gameOptions.planeChase) { Plane plane = Plane.getRandomPlane(); - plane.setControllerId(getActivePlayerId()); + plane.setControllerId(startingPlayerId); addPlane(plane, null, getActivePlayerId()); state.setPlaneChase(this, gameOptions.planeChase); } diff --git a/Mage/src/main/java/mage/game/command/planes/AcademyAtTolariaWestPlane.java b/Mage/src/main/java/mage/game/command/planes/AcademyAtTolariaWestPlane.java index 31e6718c84..63b6894692 100644 --- a/Mage/src/main/java/mage/game/command/planes/AcademyAtTolariaWestPlane.java +++ b/Mage/src/main/java/mage/game/command/planes/AcademyAtTolariaWestPlane.java @@ -33,17 +33,23 @@ import mage.abilities.Ability; import mage.abilities.common.ActivateIfConditionActivatedAbility; import mage.abilities.common.BeginningOfEndStepTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.condition.common.HellbentCondition; +import mage.abilities.condition.Condition; import mage.abilities.condition.common.MainPhaseStackEmptyCondition; import mage.abilities.costs.mana.GenericManaCost; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.dynamicvalue.common.StaticValue; import mage.abilities.effects.Effect; -import mage.abilities.effects.common.DrawCardSourceControllerEffect; +import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.RollPlanarDieEffect; import mage.abilities.effects.common.discard.DiscardHandControllerEffect; +import mage.constants.Outcome; import mage.constants.TargetController; import mage.constants.Zone; +import mage.game.Game; import mage.game.command.Plane; +import mage.players.Player; import mage.target.Target; +import mage.util.CardUtil; import mage.watchers.common.PlanarRollWatcher; /** @@ -57,7 +63,7 @@ public class AcademyAtTolariaWestPlane extends Plane { this.setExpansionSetCodeForImage("PCA"); // At the beginning of your end step, if you have 0 cards in hand, draw seven cards - Ability ability = new BeginningOfEndStepTriggeredAbility(Zone.COMMAND, new DrawCardSourceControllerEffect(7), TargetController.ANY, HellbentCondition.instance, false); + Ability ability = new BeginningOfEndStepTriggeredAbility(Zone.COMMAND, new DrawCardsActivePlayerEffect(7), TargetController.ANY, HellbentAPCondition.instance, false); this.getAbilities().add(ability); // Active player can roll the planar die: Whenever you roll {CHAOS}, discard your hand @@ -77,3 +83,66 @@ public class AcademyAtTolariaWestPlane extends Plane { this.getAbilities().add(new SimpleStaticAbility(Zone.ALL, new PlanarDieRollCostIncreasingEffect(chaosAbility.getOriginalId()))); } } + +class DrawCardsActivePlayerEffect extends OneShotEffect { + + protected DynamicValue amount; + + public DrawCardsActivePlayerEffect(int amount) { + this(new StaticValue(amount)); + } + + public DrawCardsActivePlayerEffect(DynamicValue amount) { + super(Outcome.DrawCard); + this.amount = amount.copy(); + setText(); + } + + public DrawCardsActivePlayerEffect(final DrawCardsActivePlayerEffect effect) { + super(effect); + this.amount = effect.amount.copy(); + } + + @Override + public DrawCardsActivePlayerEffect copy() { + return new DrawCardsActivePlayerEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + if (game.getState().getCurrentPlane() != null) { + if (!game.getState().getCurrentPlane().getName().equalsIgnoreCase("Plane - Academy at Tolaria West")) { + return false; + } + } + + Player player = game.getPlayer(game.getActivePlayerId()); + if (player != null) { + player.drawCards(amount.calculate(game, source, this), game); + return true; + } + return false; + } + + private void setText() { + StringBuilder sb = new StringBuilder(); + sb.append("draw ").append(CardUtil.numberToText(amount.toString())).append(" cards"); + staticText = sb.toString(); + } + +} + +enum HellbentAPCondition implements Condition { + + instance; + + @Override + public boolean apply(Game game, Ability source) { + return game.getPlayer(game.getActivePlayerId()).getHand().isEmpty(); + } + + @Override + public String toString() { + return "if you have no cards in hand"; + } +} diff --git a/Mage/src/main/java/mage/game/command/planes/EdgeOfMalacolPlane.java b/Mage/src/main/java/mage/game/command/planes/EdgeOfMalacolPlane.java index 54653f8bf9..56cf30cd30 100644 --- a/Mage/src/main/java/mage/game/command/planes/EdgeOfMalacolPlane.java +++ b/Mage/src/main/java/mage/game/command/planes/EdgeOfMalacolPlane.java @@ -29,15 +29,17 @@ package mage.game.command.planes; import java.util.ArrayList; import java.util.List; +import java.util.UUID; import mage.abilities.Ability; -import mage.abilities.Mode; import mage.abilities.common.ActivateIfConditionActivatedAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.condition.common.MainPhaseStackEmptyCondition; import mage.abilities.costs.mana.GenericManaCost; +import mage.abilities.decorator.ConditionalContinuousEffect; import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; import mage.abilities.effects.Effect; import mage.abilities.effects.common.RollPlanarDieEffect; +import mage.abilities.effects.common.SkipUntapStepEffect; import mage.abilities.effects.common.UntapAllControllerEffect; import mage.abilities.effects.common.counter.AddCountersTargetEffect; import mage.constants.Duration; @@ -120,11 +122,19 @@ class EdgeOfMalacolEffect extends ContinuousRuleModifyingEffectImpl { public boolean applies(GameEvent event, Ability source, Game game) { // Prevent untap event of creatures of target player if (game.getTurn().getStepType() == PhaseStep.UNTAP) { + if (game.getState().getCurrentPlane() != null) { + if (!game.getState().getCurrentPlane().getName().equalsIgnoreCase("Plane - Edge of Malacol")) { + return false; + } + } Permanent permanent = game.getPermanent(event.getTargetId()); - if (permanent != null && filter.match(permanent, game)) { + if (permanent != null && filter.match(permanent, game) && permanent.getControllerId() == game.getActivePlayerId()) { + UUID oldController = source.getControllerId(); + source.setControllerId(game.getActivePlayerId()); Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(2)); effect.setTargetPointer(new FixedTarget(permanent, game)); effect.apply(game, source); + source.setControllerId(oldController); return true; } } diff --git a/Mage/src/main/java/mage/game/command/planes/HedronFieldsOfAgadeemPlane.java b/Mage/src/main/java/mage/game/command/planes/HedronFieldsOfAgadeemPlane.java index e3206a4be9..0b3b3ca70f 100644 --- a/Mage/src/main/java/mage/game/command/planes/HedronFieldsOfAgadeemPlane.java +++ b/Mage/src/main/java/mage/game/command/planes/HedronFieldsOfAgadeemPlane.java @@ -117,6 +117,11 @@ class HedronFieldsOfAgadeemRestrictionEffect extends RestrictionEffect { @Override public boolean applies(Permanent permanent, Ability source, Game game) { + if (game.getState().getCurrentPlane() != null) { + if (!game.getState().getCurrentPlane().getName().equalsIgnoreCase("Plane - Hedron Fields of Agadeem")) { + return false; + } + } return filter.match(permanent, source.getSourceId(), source.getControllerId(), game); } } diff --git a/Mage/src/main/java/mage/game/command/planes/TheEonFogPlane.java b/Mage/src/main/java/mage/game/command/planes/TheEonFogPlane.java index f599e40077..f952056ac7 100644 --- a/Mage/src/main/java/mage/game/command/planes/TheEonFogPlane.java +++ b/Mage/src/main/java/mage/game/command/planes/TheEonFogPlane.java @@ -34,14 +34,18 @@ import mage.abilities.common.ActivateIfConditionActivatedAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.condition.common.MainPhaseStackEmptyCondition; import mage.abilities.costs.mana.GenericManaCost; +import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; import mage.abilities.effects.Effect; import mage.abilities.effects.common.RollPlanarDieEffect; -import mage.abilities.effects.common.SkipUntapStepEffect; import mage.abilities.effects.common.UntapAllControllerEffect; +import mage.constants.Duration; +import mage.constants.Outcome; import mage.constants.TargetController; import mage.constants.Zone; import mage.filter.common.FilterControlledPermanent; +import mage.game.Game; import mage.game.command.Plane; +import mage.game.events.GameEvent; import mage.target.Target; import mage.watchers.common.PlanarRollWatcher; @@ -56,7 +60,7 @@ public class TheEonFogPlane extends Plane { this.setExpansionSetCodeForImage("PCA"); // All players miss their untap step - Ability ability = new SimpleStaticAbility(Zone.COMMAND, new SkipUntapStepEffect()); + Ability ability = new SimpleStaticAbility(Zone.COMMAND, new TheEonFogSkipUntapStepEffect(Duration.Custom, true)); this.getAbilities().add(ability); // Active player can roll the planar die: Whenever you roll {CHAOS}, untap all permanents you control @@ -76,3 +80,40 @@ public class TheEonFogPlane extends Plane { this.getAbilities().add(new SimpleStaticAbility(Zone.ALL, new PlanarDieRollCostIncreasingEffect(chaosAbility.getOriginalId()))); } } + +class TheEonFogSkipUntapStepEffect extends ContinuousRuleModifyingEffectImpl { + + boolean allPlayers = false; + + public TheEonFogSkipUntapStepEffect() { + super(Duration.WhileOnBattlefield, Outcome.Neutral, false, false); + this.allPlayers = false; + staticText = "Players skip their untap steps"; + } + + public TheEonFogSkipUntapStepEffect(Duration d, boolean allPlayers) { + super(d, Outcome.Neutral, false, false); + this.allPlayers = allPlayers; + staticText = "Players skip their untap steps"; + } + + public TheEonFogSkipUntapStepEffect(final TheEonFogSkipUntapStepEffect effect) { + super(effect); + this.allPlayers = effect.allPlayers; + } + + @Override + public TheEonFogSkipUntapStepEffect copy() { + return new TheEonFogSkipUntapStepEffect(this); + } + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + if (game.getState().getCurrentPlane() != null) { + if (!game.getState().getCurrentPlane().getName().equalsIgnoreCase("Plane - The Eon Fog")) { + return false; + } + } + return event.getType() == GameEvent.EventType.UNTAP_STEP; + } +} diff --git a/Mage/src/main/java/mage/game/command/planes/UndercityReachesPlane.java b/Mage/src/main/java/mage/game/command/planes/UndercityReachesPlane.java index 9f3ba9642a..d15724ba1b 100644 --- a/Mage/src/main/java/mage/game/command/planes/UndercityReachesPlane.java +++ b/Mage/src/main/java/mage/game/command/planes/UndercityReachesPlane.java @@ -29,14 +29,16 @@ package mage.game.command.planes; import java.util.ArrayList; import java.util.List; +import static jdk.nashorn.internal.objects.NativeRegExp.source; import mage.abilities.Ability; import mage.abilities.TriggeredAbilityImpl; import mage.abilities.common.ActivateIfConditionActivatedAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.condition.common.MainPhaseStackEmptyCondition; import mage.abilities.costs.mana.GenericManaCost; +import mage.abilities.dynamicvalue.common.StaticValue; import mage.abilities.effects.Effect; -import mage.abilities.effects.common.DrawCardSourceControllerEffect; +import mage.abilities.effects.common.DrawCardTargetEffect; import mage.abilities.effects.common.RollPlanarDieEffect; import mage.abilities.effects.common.continuous.MaximumHandSizeControllerEffect; import mage.abilities.effects.common.continuous.MaximumHandSizeControllerEffect.HandSizeModification; @@ -53,6 +55,7 @@ import mage.game.events.GameEvent; import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; import mage.target.Target; +import mage.target.targetpointer.FixedTarget; import mage.watchers.common.PlanarRollWatcher; /** @@ -96,7 +99,7 @@ public class UndercityReachesPlane extends Plane { class UndercityReachesTriggeredAbility extends TriggeredAbilityImpl { public UndercityReachesTriggeredAbility() { - super(Zone.COMMAND, new DrawCardSourceControllerEffect(1), true); + super(Zone.COMMAND, null, true); } public UndercityReachesTriggeredAbility(final UndercityReachesTriggeredAbility ability) { @@ -118,6 +121,9 @@ class UndercityReachesTriggeredAbility extends TriggeredAbilityImpl { if (((DamagedPlayerEvent) event).isCombatDamage()) { Permanent creature = game.getPermanent(event.getSourceId()); if (creature != null) { + Effect effect = new DrawCardTargetEffect(new StaticValue(1), false, true); + effect.setTargetPointer(new FixedTarget(creature.getControllerId())); + effect.apply(game, null); return true; } }