From f63efe14b54e4938096caac8a3355dc57a6a512b Mon Sep 17 00:00:00 2001
From: Merlingilb <daniel.h.e@outlook.de>
Date: Fri, 14 Apr 2023 15:50:09 +0200
Subject: [PATCH] MOM: Added card "Jin-Gitaxias" and its abilities and effects
 (#10036)

* MOM: Added card "Jin-Gitaxias" and its abilities and effects

* rule text improvement

* remove unused imports

---------

Co-authored-by: Daniel Eberhard <daniel.h.e@gmx.de>
Co-authored-by: Evan Kranzler <theelk801@gmail.com>
---
 Mage.Sets/src/mage/cards/j/JinGitaxias.java   |  67 +++++++++
 .../src/mage/cards/t/TheGreatSynthesis.java   | 133 ++++++++++++++++++
 .../src/mage/sets/MarchOfTheMachine.java      |   7 +
 .../mage/abilities/common/SagaAbility.java    |  16 ++-
 4 files changed, 221 insertions(+), 2 deletions(-)
 create mode 100644 Mage.Sets/src/mage/cards/j/JinGitaxias.java
 create mode 100644 Mage.Sets/src/mage/cards/t/TheGreatSynthesis.java

diff --git a/Mage.Sets/src/mage/cards/j/JinGitaxias.java b/Mage.Sets/src/mage/cards/j/JinGitaxias.java
new file mode 100644
index 0000000000..4fd1fe8ae6
--- /dev/null
+++ b/Mage.Sets/src/mage/cards/j/JinGitaxias.java
@@ -0,0 +1,67 @@
+package mage.cards.j;
+
+import mage.MageInt;
+import mage.abilities.Pronoun;
+import mage.abilities.common.SpellCastControllerTriggeredAbility;
+import mage.abilities.condition.common.CardsInHandCondition;
+import mage.abilities.costs.mana.ManaCostsImpl;
+import mage.abilities.decorator.ConditionalActivatedAbility;
+import mage.abilities.effects.common.DrawCardSourceControllerEffect;
+import mage.abilities.effects.common.ExileAndReturnTransformedSourceEffect;
+import mage.abilities.keyword.TransformAbility;
+import mage.abilities.keyword.WardAbility;
+import mage.cards.CardImpl;
+import mage.cards.CardSetInfo;
+import mage.constants.*;
+import mage.filter.FilterSpell;
+import mage.filter.predicate.Predicates;
+import mage.filter.predicate.mageobject.ManaValuePredicate;
+
+import java.util.UUID;
+
+public class JinGitaxias extends CardImpl {
+
+    private static final FilterSpell filter = new FilterSpell("a noncreature spell with mana value 3 or greater");
+
+    static {
+        filter.add(Predicates.not(CardType.CREATURE.getPredicate()));
+        filter.add(new ManaValuePredicate(ComparisonType.MORE_THAN, 2));
+    }
+
+    public JinGitaxias(UUID ownerId, CardSetInfo setInfo) {
+        super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{U}{U}");
+        this.addSuperType(SuperType.LEGENDARY);
+        this.addSubType(SubType.PHYREXIAN);
+        this.addSubType(SubType.PRAETOR);
+        this.power = new MageInt(5);
+        this.toughness = new MageInt(5);
+        this.secondSideCardClazz = mage.cards.t.TheGreatSynthesis.class;
+
+        //Ward {2}
+        this.addAbility(new WardAbility(new ManaCostsImpl<>("{2}"), false));
+
+        //Whenever you cast a noncreature spell with mana value 3 or greater, draw a card.
+        this.addAbility(new SpellCastControllerTriggeredAbility(
+                new DrawCardSourceControllerEffect(1),
+                filter, false
+        ));
+
+        //{3}{U}: Exile Jin-Gitaxias, then return it to the battlefield transformed under its owner’s control. Activate
+        //only as a sorcery and only if you have seven or more cards in hand.
+        this.addAbility(new TransformAbility());
+        ConditionalActivatedAbility conditionalActivatedAbility =
+                new ConditionalActivatedAbility(Zone.BATTLEFIELD, new ExileAndReturnTransformedSourceEffect(Pronoun.IT),
+                        new ManaCostsImpl<>("{3}{U}"), new CardsInHandCondition(ComparisonType.MORE_THAN, 6));
+        conditionalActivatedAbility.setTiming(TimingRule.SORCERY);
+        this.addAbility(conditionalActivatedAbility);
+    }
+
+    private JinGitaxias(final JinGitaxias card) {
+        super(card);
+    }
+
+    @Override
+    public JinGitaxias copy() {
+        return new JinGitaxias(this);
+    }
+}
diff --git a/Mage.Sets/src/mage/cards/t/TheGreatSynthesis.java b/Mage.Sets/src/mage/cards/t/TheGreatSynthesis.java
new file mode 100644
index 0000000000..ec39a1ee3a
--- /dev/null
+++ b/Mage.Sets/src/mage/cards/t/TheGreatSynthesis.java
@@ -0,0 +1,133 @@
+package mage.cards.t;
+
+import mage.abilities.Ability;
+import mage.abilities.common.SagaAbility;
+import mage.abilities.dynamicvalue.common.CardsInControllerHandCount;
+import mage.abilities.effects.OneShotEffect;
+import mage.abilities.effects.common.DestroyAllEffect;
+import mage.abilities.effects.common.DrawCardSourceControllerEffect;
+import mage.abilities.effects.common.ExileSagaAndReturnTransformedEffect;
+import mage.abilities.effects.common.ReturnToHandFromBattlefieldAllEffect;
+import mage.abilities.effects.common.continuous.MaximumHandSizeControllerEffect;
+import mage.cards.*;
+import mage.constants.*;
+import mage.filter.StaticFilters;
+import mage.filter.common.FilterCreaturePermanent;
+import mage.filter.common.FilterNonlandCard;
+import mage.filter.predicate.Predicates;
+import mage.game.Game;
+import mage.players.Player;
+import mage.util.CardUtil;
+
+import java.util.UUID;
+
+public class TheGreatSynthesis extends CardImpl {
+
+    private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("non-Phyrexian creatures");
+
+    static {
+        filter.add(Predicates.not(SubType.PHYREXIAN.getPredicate()));
+    }
+
+    public TheGreatSynthesis(UUID ownerId, CardSetInfo setInfo) {
+        super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "");
+        this.addSubType(SubType.SAGA);
+        this.color.setBlue(true);
+
+        //(As this Saga enters and after your draw step, add a lore counter.)
+        SagaAbility sagaAbility = new SagaAbility(this, false);
+
+        //I — Draw cards equal to the number of cards in your hand. You have no maximum hand size for as long as you
+        //control The Great Synthesis.
+        sagaAbility.addChapterEffect(this, SagaChapter.CHAPTER_I,
+                new DrawCardSourceControllerEffect(CardsInControllerHandCount.instance)
+                        .setText("draw cards equal to the number of cards in your hand"),
+                new MaximumHandSizeControllerEffect(Integer.MAX_VALUE, Duration.WhileOnBattlefield,
+                        MaximumHandSizeControllerEffect.HandSizeModification.SET)
+                        .setText("you have no maximum hand size for as long as you control {this}"));
+
+        //II — Return all non-Phyrexian creatures to their owners' hands.
+        sagaAbility.addChapterEffect(this, SagaChapter.CHAPTER_II, new ReturnToHandFromBattlefieldAllEffect(filter));
+
+        //III — You may cast any number of spells from your hand without paying their mana cost. Exile The Great
+        //Synthesis, then return it to the battlefield <i>(front face up)</i>.
+        sagaAbility.addChapterEffect(this, SagaChapter.CHAPTER_III, new TheGreatSynthesisCastEffect(),
+                new TheGreatSynthesisExileReturnEffect());
+
+        this.addAbility(sagaAbility);
+    }
+
+    private TheGreatSynthesis(final TheGreatSynthesis card) {
+        super(card);
+    }
+
+    @Override
+    public TheGreatSynthesis copy() {
+        return new TheGreatSynthesis(this);
+    }
+}
+
+class TheGreatSynthesisCastEffect extends OneShotEffect {
+    public TheGreatSynthesisCastEffect() {
+        super(Outcome.PlayForFree);
+        this.staticText = "you may cast any number of spells from your hand without paying their mana costs";
+    }
+
+    public TheGreatSynthesisCastEffect(final TheGreatSynthesisCastEffect effect) {
+        super(effect);
+    }
+
+    @Override
+    public TheGreatSynthesisCastEffect copy() {
+        return new TheGreatSynthesisCastEffect(this);
+    }
+
+    @Override
+    public boolean apply(Game game, Ability source) {
+        Player controller = game.getPlayer(source.getControllerId());
+        if (controller == null) {
+            return false;
+        }
+        Cards cards = controller.getHand();
+        CardUtil.castMultipleWithAttributeForFree(controller, source, game, cards, StaticFilters.FILTER_CARD);
+        return true;
+    }
+}
+
+class TheGreatSynthesisExileReturnEffect extends OneShotEffect {
+    public TheGreatSynthesisExileReturnEffect() {
+        super(Outcome.PutCreatureInPlay);
+        staticText = "exile {this}, then return it to the battlefield <i>(front face up)</i>";
+    }
+
+    private TheGreatSynthesisExileReturnEffect(final TheGreatSynthesisExileReturnEffect effect) {
+        super(effect);
+    }
+
+    @Override
+    public TheGreatSynthesisExileReturnEffect copy() {
+        return new TheGreatSynthesisExileReturnEffect(this);
+    }
+
+    @Override
+    public boolean apply(Game game, Ability source) {
+        if (game.getState().getZone(source.getSourceId()) != Zone.BATTLEFIELD) {
+            return false;
+        }
+        Card card = game.getCard(source.getSourceId());
+        if (card == null) {
+            return false;
+        }
+
+        Player player = game.getPlayer(source.getControllerId());
+        if (player == null) {
+            return false;
+        }
+
+        if (!player.moveCards(card, Zone.EXILED, source, game)) {
+            return false;
+        }
+        return player.moveCards(card, Zone.BATTLEFIELD, source, game);
+    }
+
+}
diff --git a/Mage.Sets/src/mage/sets/MarchOfTheMachine.java b/Mage.Sets/src/mage/sets/MarchOfTheMachine.java
index f9348d4d9e..36e71d7698 100644
--- a/Mage.Sets/src/mage/sets/MarchOfTheMachine.java
+++ b/Mage.Sets/src/mage/sets/MarchOfTheMachine.java
@@ -84,6 +84,9 @@ public final class MarchOfTheMachine extends ExpansionSet {
         cards.add(new SetCardInfo("Deeproot Wayfinder", 184, Rarity.RARE, mage.cards.d.DeeprootWayfinder.class));
         cards.add(new SetCardInfo("Deluge of the Dead", 115, Rarity.MYTHIC, mage.cards.d.DelugeOfTheDead.class));
         cards.add(new SetCardInfo("Dismal Backwater", 269, Rarity.COMMON, mage.cards.d.DismalBackwater.class));
+        cards.add(new SetCardInfo("Jin-Gitaxias", 65, Rarity.MYTHIC, mage.cards.j.JinGitaxias.class, NON_FULL_USE_VARIOUS));
+        cards.add(new SetCardInfo("Jin-Gitaxias", 294, Rarity.MYTHIC, mage.cards.j.JinGitaxias.class, NON_FULL_USE_VARIOUS));
+        cards.add(new SetCardInfo("Jin-Gitaxias", 339, Rarity.MYTHIC, mage.cards.j.JinGitaxias.class, NON_FULL_USE_VARIOUS));
         cards.add(new SetCardInfo("Disturbing Conversion", 54, Rarity.COMMON, mage.cards.d.DisturbingConversion.class));
         cards.add(new SetCardInfo("Doomskar Warrior", 185, Rarity.RARE, mage.cards.d.DoomskarWarrior.class));
         cards.add(new SetCardInfo("Dreg Recycler", 100, Rarity.COMMON, mage.cards.d.DregRecycler.class));
@@ -255,6 +258,10 @@ public final class MarchOfTheMachine extends ExpansionSet {
         cards.add(new SetCardInfo("Saiba Cryptomancer", 76, Rarity.COMMON, mage.cards.s.SaibaCryptomancer.class));
         cards.add(new SetCardInfo("Scorn-Blade Berserker", 124, Rarity.UNCOMMON, mage.cards.s.ScornBladeBerserker.class));
         cards.add(new SetCardInfo("Scoured Barrens", 272, Rarity.COMMON, mage.cards.s.ScouredBarrens.class));
+        cards.add(new SetCardInfo("Swiftwater Cliffs", 273, Rarity.MYTHIC, mage.cards.s.SwiftwaterCliffs.class));
+        cards.add(new SetCardInfo("The Great Synthesis", 65, Rarity.MYTHIC, mage.cards.t.TheGreatSynthesis.class, NON_FULL_USE_VARIOUS));
+        cards.add(new SetCardInfo("The Great Synthesis", 294, Rarity.MYTHIC, mage.cards.t.TheGreatSynthesis.class, NON_FULL_USE_VARIOUS));
+        cards.add(new SetCardInfo("The Great Synthesis", 339, Rarity.MYTHIC, mage.cards.t.TheGreatSynthesis.class, NON_FULL_USE_VARIOUS));
         cards.add(new SetCardInfo("Scrappy Bruiser", 162, Rarity.UNCOMMON, mage.cards.s.ScrappyBruiser.class));
         cards.add(new SetCardInfo("Scrollshift", 34, Rarity.COMMON, mage.cards.s.Scrollshift.class));
         cards.add(new SetCardInfo("Sculpted Perfection", 253, Rarity.UNCOMMON, mage.cards.s.SculptedPerfection.class));
diff --git a/Mage/src/main/java/mage/abilities/common/SagaAbility.java b/Mage/src/main/java/mage/abilities/common/SagaAbility.java
index 08a06bc651..5af9a39bc5 100644
--- a/Mage/src/main/java/mage/abilities/common/SagaAbility.java
+++ b/Mage/src/main/java/mage/abilities/common/SagaAbility.java
@@ -37,14 +37,26 @@ public class SagaAbility extends SimpleStaticAbility {
         this(card, SagaChapter.CHAPTER_III);
     }
 
+    public SagaAbility(Card card, boolean showSacText) {
+        this(card, showSacText, SagaChapter.CHAPTER_III);
+    }
+
     public SagaAbility(Card card, SagaChapter maxChapter) {
-        this(card, maxChapter, false);
+        this(card, card.getSecondCardFace() == null, maxChapter);
+    }
+
+    public SagaAbility(Card card, boolean showSacText, SagaChapter maxChapter) {
+        this(card, maxChapter, false, showSacText);
     }
 
     public SagaAbility(Card card, SagaChapter maxChapter, boolean readAhead) {
+        this(card, maxChapter, readAhead, card.getSecondCardFace() == null);
+    }
+
+    public SagaAbility(Card card, SagaChapter maxChapter, boolean readAhead, boolean showSacText) {
         super(Zone.ALL, null);
         this.maxChapter = maxChapter;
-        this.showSacText = card.getSecondCardFace() == null;
+        this.showSacText = showSacText;
         this.readAhead = readAhead;
         this.setRuleVisible(true);
         this.setRuleAtTheTop(true);