From 34e3bb42db9063dee6fd69874080e940bd60ee4f Mon Sep 17 00:00:00 2001
From: Evan Kranzler <theelk801@gmail.com>
Date: Fri, 25 Jan 2019 10:32:29 -0500
Subject: [PATCH] fixed Rhythm of the Wild not giving Riot to creatures that
 weren't cast

---
 .../src/mage/cards/m/MasterBiomancer.java     | 21 +++---
 .../src/mage/cards/r/RhythmOfTheWild.java     | 71 +++++++++++++++++--
 .../cards/abilities/keywords/RiotTest.java    | 55 +++++++++++++-
 .../mage/abilities/keyword/RiotAbility.java   |  6 +-
 4 files changed, 134 insertions(+), 19 deletions(-)

diff --git a/Mage.Sets/src/mage/cards/m/MasterBiomancer.java b/Mage.Sets/src/mage/cards/m/MasterBiomancer.java
index 79f1c60538..b810e3965c 100644
--- a/Mage.Sets/src/mage/cards/m/MasterBiomancer.java
+++ b/Mage.Sets/src/mage/cards/m/MasterBiomancer.java
@@ -1,7 +1,6 @@
 
 package mage.cards.m;
 
-import java.util.UUID;
 import mage.MageInt;
 import mage.abilities.Ability;
 import mage.abilities.common.SimpleStaticAbility;
@@ -10,7 +9,10 @@ import mage.abilities.effects.ReplacementEffectImpl;
 import mage.abilities.effects.common.continuous.AddCardSubTypeTargetEffect;
 import mage.cards.CardImpl;
 import mage.cards.CardSetInfo;
-import mage.constants.*;
+import mage.constants.CardType;
+import mage.constants.Duration;
+import mage.constants.Outcome;
+import mage.constants.SubType;
 import mage.counters.CounterType;
 import mage.game.Game;
 import mage.game.events.EntersTheBattlefieldEvent;
@@ -19,14 +21,15 @@ import mage.game.events.GameEvent.EventType;
 import mage.game.permanent.Permanent;
 import mage.target.targetpointer.FixedTarget;
 
+import java.util.UUID;
+
 /**
- *
  * @author LevelX2
  */
 public final class MasterBiomancer extends CardImpl {
 
     public MasterBiomancer(UUID ownerId, CardSetInfo setInfo) {
-        super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{2}{G}{U}");
+        super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{G}{U}");
         this.subtype.add(SubType.ELF);
         this.subtype.add(SubType.WIZARD);
 
@@ -34,10 +37,10 @@ public final class MasterBiomancer extends CardImpl {
         this.toughness = new MageInt(4);
 
         // Each other creature you control enters the battlefield with a number of additional +1/+1 counters on it equal to Master Biomancer's power and as a Mutant in addition to its other types.
-        this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new MasterBiomancerEntersBattlefieldEffect()));
+        this.addAbility(new SimpleStaticAbility(new MasterBiomancerEntersBattlefieldEffect()));
     }
 
-    public MasterBiomancer(final MasterBiomancer card) {
+    private MasterBiomancer(final MasterBiomancer card) {
         super(card);
     }
 
@@ -49,12 +52,12 @@ public final class MasterBiomancer extends CardImpl {
 
 class MasterBiomancerEntersBattlefieldEffect extends ReplacementEffectImpl {
 
-    public MasterBiomancerEntersBattlefieldEffect() {
+    MasterBiomancerEntersBattlefieldEffect() {
         super(Duration.WhileOnBattlefield, Outcome.BoostCreature);
-        staticText = "Each other creature you control enters the battlefield with a number of additional +1/+1 counters on it equal to Master Biomancer's power and as a Mutant in addition to its other types";
+        staticText = "Each other creature you control enters the battlefield with a number of additional +1/+1 counters on it equal to {this}'s power and as a Mutant in addition to its other types";
     }
 
-    public MasterBiomancerEntersBattlefieldEffect(MasterBiomancerEntersBattlefieldEffect effect) {
+    private MasterBiomancerEntersBattlefieldEffect(MasterBiomancerEntersBattlefieldEffect effect) {
         super(effect);
     }
 
diff --git a/Mage.Sets/src/mage/cards/r/RhythmOfTheWild.java b/Mage.Sets/src/mage/cards/r/RhythmOfTheWild.java
index be889e972f..f6899c2e47 100644
--- a/Mage.Sets/src/mage/cards/r/RhythmOfTheWild.java
+++ b/Mage.Sets/src/mage/cards/r/RhythmOfTheWild.java
@@ -1,17 +1,21 @@
 package mage.cards.r;
 
-import java.util.UUID;
 import mage.abilities.Ability;
 import mage.abilities.common.SimpleStaticAbility;
+import mage.abilities.effects.ContinuousEffect;
+import mage.abilities.effects.ReplacementEffectImpl;
 import mage.abilities.effects.common.CantBeCounteredControlledEffect;
 import mage.abilities.effects.common.continuous.GainAbilityControlledEffect;
-import mage.abilities.effects.common.continuous.GainAbilityControlledSpellsEffect;
+import mage.abilities.effects.common.continuous.GainAbilityTargetEffect;
+import mage.abilities.keyword.HasteAbility;
 import mage.abilities.keyword.RiotAbility;
 import mage.cards.CardImpl;
 import mage.cards.CardSetInfo;
 import mage.constants.CardType;
 import mage.constants.Duration;
+import mage.constants.Outcome;
 import mage.constants.TargetController;
+import mage.counters.CounterType;
 import mage.filter.FilterPermanent;
 import mage.filter.FilterSpell;
 import mage.filter.common.FilterControlledCreaturePermanent;
@@ -19,6 +23,14 @@ import mage.filter.common.FilterCreatureSpell;
 import mage.filter.predicate.Predicates;
 import mage.filter.predicate.permanent.ControllerPredicate;
 import mage.filter.predicate.permanent.TokenPredicate;
+import mage.game.Game;
+import mage.game.events.EntersTheBattlefieldEvent;
+import mage.game.events.GameEvent;
+import mage.game.permanent.Permanent;
+import mage.players.Player;
+import mage.target.targetpointer.FixedTarget;
+
+import java.util.UUID;
 
 /**
  * @author TheElk801
@@ -44,8 +56,7 @@ public final class RhythmOfTheWild extends CardImpl {
         )));
 
         // Nontoken creatures you control have riot.
-        Ability ability = new SimpleStaticAbility(new GainAbilityControlledSpellsEffect(
-                new RiotAbility(), new FilterCreatureSpell()).setText("Nontoken creatures you control have riot. <i>(They enter the battlefield with your choice of a +1/+1 counter or haste.)</i>"));
+        Ability ability = new SimpleStaticAbility(new RhythmOfTheWildEffect());
         ability.addEffect(new GainAbilityControlledEffect(
                 new RiotAbility(), Duration.WhileOnBattlefield, filter2
         ).setText(""));
@@ -61,3 +72,55 @@ public final class RhythmOfTheWild extends CardImpl {
         return new RhythmOfTheWild(this);
     }
 }
+
+class RhythmOfTheWildEffect extends ReplacementEffectImpl {
+
+    RhythmOfTheWildEffect() {
+        super(Duration.WhileOnBattlefield, Outcome.BoostCreature);
+        staticText = "Nontoken creatures you control have riot. " +
+                "<i>(They enter the battlefield with your choice of a +1/+1 counter or haste.)</i>";
+    }
+
+    private RhythmOfTheWildEffect(RhythmOfTheWildEffect effect) {
+        super(effect);
+    }
+
+    @Override
+    public boolean checksEventType(GameEvent event, Game game) {
+        return event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD;
+    }
+
+    @Override
+    public boolean applies(GameEvent event, Ability source, Game game) {
+        Permanent creature = ((EntersTheBattlefieldEvent) event).getTarget();
+        return creature != null
+                && creature.isControlledBy(source.getControllerId())
+                && creature.isCreature();
+    }
+
+    @Override
+    public boolean replaceEvent(GameEvent event, Ability source, Game game) {
+        Permanent creature = ((EntersTheBattlefieldEvent) event).getTarget();
+        Player player = game.getPlayer(source.getControllerId());
+        if (creature == null || player == null) {
+            return false;
+        }
+        if (player.chooseUse(
+                outcome, "Have " + creature.getLogName() + " enter the battlefield with a +1/+1 counter on it or with haste?",
+                null, "+1/+1 counter", "Haste", source, game
+        )) {
+            game.informPlayers(player.getLogName() + " choose to put a +1/+1 counter on " + creature.getName());
+            creature.addCounters(CounterType.P1P1.createInstance(), source, game, event.getAppliedEffects());
+        } else {
+            ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom);
+            effect.setTargetPointer(new FixedTarget(creature.getId(), creature.getZoneChangeCounter(game) + 1));
+            game.addEffect(effect, source);
+        }
+        return false;
+    }
+
+    @Override
+    public RhythmOfTheWildEffect copy() {
+        return new RhythmOfTheWildEffect(this);
+    }
+}
diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/RiotTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/RiotTest.java
index 41b7b56991..178d1a1e64 100644
--- a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/RiotTest.java
+++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/RiotTest.java
@@ -8,7 +8,6 @@ import org.junit.Test;
 import org.mage.test.serverside.base.CardTestPlayerBase;
 
 /**
- *
  * @author LevelX2
  */
 public class RiotTest extends CardTestPlayerBase {
@@ -17,7 +16,7 @@ public class RiotTest extends CardTestPlayerBase {
      * A creature with riot enters the battlefield with a +1/+1 counter on it or
      * with haste, its controller's choice. This choice is made as the creature
      * enters the battlefield, so no one can respond to the choice.
-     *
+     * <p>
      * The creature will have the chosen bonus the moment it enters the
      * battlefield. If you choose to have the creature gain haste, it keeps
      * haste even after the turn ends. This could matter if another player gains
@@ -113,4 +112,56 @@ public class RiotTest extends CardTestPlayerBase {
         assertAbility(playerA, "Silvercoat Lion", HasteAbility.getInstance(), true);
         assertAbility(playerA, "Silvercoat Lion", new RiotAbility(), true);
     }
+
+    @Test
+    public void RiotRhythmOfTheWildNotCastBoost() {
+        addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2);
+
+        // Creature spells you control can't be countered.
+        // Nontoken creatures you control have riot.
+        addCard(Zone.BATTLEFIELD, playerA, "Rhythm of the Wild", 1);
+
+        // Riot (This creature enters the battleifled with your choice of a +1/+1 counter or haste.)
+        addCard(Zone.HAND, playerA, "Exhume", 1); // Each player returns a creature card from their graveyard to the battlefield
+        addCard(Zone.GRAVEYARD, playerA, "Silvercoat Lion", 1); // Creature {1}{W}  2/2
+
+        castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Exhume");
+        setChoice(playerA, "Yes"); // yes - counter
+
+        setStopAt(1, PhaseStep.BEGIN_COMBAT);
+
+        execute();
+        assertAllCommandsUsed();
+
+        assertPermanentCount(playerA, "Silvercoat Lion", 1);
+        assertPowerToughness(playerA, "Silvercoat Lion", 3, 3);
+        assertAbility(playerA, "Silvercoat Lion", HasteAbility.getInstance(), false);
+        assertAbility(playerA, "Silvercoat Lion", new RiotAbility(), true);
+    }
+
+    @Test
+    public void RiotRhythmOfTheWildNotCastHaste() {
+        addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2);
+
+        // Creature spells you control can't be countered.
+        // Nontoken creatures you control have riot.
+        addCard(Zone.BATTLEFIELD, playerA, "Rhythm of the Wild", 1);
+
+        // Riot (This creature enters the battleifled with your choice of a +1/+1 counter or haste.)
+        addCard(Zone.HAND, playerA, "Exhume", 1); // Each player returns a creature card from their graveyard to the battlefield
+        addCard(Zone.GRAVEYARD, playerA, "Silvercoat Lion", 1); // Creature {1}{W}  2/2
+
+        castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Exhume");
+        setChoice(playerA, "No"); // no - haste
+
+        setStopAt(1, PhaseStep.BEGIN_COMBAT);
+
+        execute();
+        assertAllCommandsUsed();
+
+        assertPermanentCount(playerA, "Silvercoat Lion", 1);
+        assertPowerToughness(playerA, "Silvercoat Lion", 2, 2);
+        assertAbility(playerA, "Silvercoat Lion", HasteAbility.getInstance(), true);
+        assertAbility(playerA, "Silvercoat Lion", new RiotAbility(), false);
+    }
 }
diff --git a/Mage/src/main/java/mage/abilities/keyword/RiotAbility.java b/Mage/src/main/java/mage/abilities/keyword/RiotAbility.java
index 8ce3e97bb5..fe667a08ce 100644
--- a/Mage/src/main/java/mage/abilities/keyword/RiotAbility.java
+++ b/Mage/src/main/java/mage/abilities/keyword/RiotAbility.java
@@ -71,10 +71,8 @@ class RiotReplacementEffect extends ReplacementEffectImpl {
         Permanent creature = ((EntersTheBattlefieldEvent) event).getTarget();
         Player controller = game.getPlayer(source.getControllerId());
         if (creature != null && controller != null) {
-            if (controller.chooseUse(outcome, "Have " + creature.getLogName() + " enter the battlefield with a +1/+1 counter on it or with haste?",null, "+1/+1 counter", "Haste", source, game)) {
-                if (!game.isSimulation()) {
-                    game.informPlayers(controller.getLogName() + " choose to put a +1/+1 counter on " + creature.getName());
-                }
+            if (controller.chooseUse(outcome, "Have " + creature.getLogName() + " enter the battlefield with a +1/+1 counter on it or with haste?", null, "+1/+1 counter", "Haste", source, game)) {
+                game.informPlayers(controller.getLogName() + " choose to put a +1/+1 counter on " + creature.getName());
                 creature.addCounters(CounterType.P1P1.createInstance(), source, game, event.getAppliedEffects());
             } else {
                 game.addEffect(new GainAbilitySourceEffect(HasteAbility.getInstance(), Duration.Custom), source);