From 7ce7c2ad70c96f3df76d0838bc7ddfc46ce5479a Mon Sep 17 00:00:00 2001
From: LevelX2 <ludwig.hirth@online.de>
Date: Thu, 9 Jan 2020 08:25:29 +0100
Subject: [PATCH] * Fixed a problem with P/T of permanets that transform back
 again to the original source card (fixes #6156).

---
 .../abilities/keywords/TransformTest.java     | 29 +++++++++++++++++++
 .../effects/common/TransformSourceEffect.java |  6 ++++
 2 files changed, 35 insertions(+)

diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/TransformTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/TransformTest.java
index c67b2d8bed..fc5e76d11a 100644
--- a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/TransformTest.java
+++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/TransformTest.java
@@ -356,11 +356,40 @@ public class TransformTest extends CardTestPlayerBase {
 
         assertPermanentCount(playerA, "Ravager of the Fells", 0);
         assertPermanentCount(playerA, "Huntmaster of the Fells", 1);
+        assertPowerToughness(playerA,  "Huntmaster of the Fells", 2, 2);
         assertTappedCount("Plains", true, 2);
         assertTappedCount("Wastes", true, 1);
 
     }
+   @Test
+    public void testHuntmasterTransformed() {
+        // Whenever this creature enters the battlefield or transforms into Huntmaster of the Fells, create a 2/2 green Wolf creature token and you gain 2 life.
+        // At the beginning of each upkeep, if no spells were cast last turn, transform Huntmaster of the Fells.
+        // Ravager of the Fells
+        // Whenever this creature transforms into Ravager of the Fells, it deals 2 damage to target opponent and 2 damage to up to one target creature that player controls.
+        // At the beginning of each upkeep, if a player cast two or more spells last turn, transform Ravager of the Fells.
+        addCard(Zone.HAND, playerA, "Huntmaster of the Fells"); // Creature {2}{R}{G}
+        addCard(Zone.HAND, playerA, "Silvercoat Lion", 2);
+        addCard(Zone.BATTLEFIELD, playerA, "Mountain", 2);
+        addCard(Zone.BATTLEFIELD, playerA, "Forest", 2);
+        addCard(Zone.BATTLEFIELD, playerA, "Plains", 3);
 
+        castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Huntmaster of the Fells");
+        castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Silvercoat Lion");
+        castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Silvercoat Lion");
+        setStopAt(4, PhaseStep.PRECOMBAT_MAIN);
+        execute();
+
+        assertLife(playerA, 24);
+        assertLife(playerB, 18);
+        assertPermanentCount(playerA, "Wolf", 2);
+        assertPermanentCount(playerA, "Silvercoat Lion", 2);
+        assertPermanentCount(playerA, "Ravager of the Fells", 0);
+        assertPermanentCount(playerA, "Huntmaster of the Fells", 1);
+        assertPowerToughness(playerA, "Huntmaster of the Fells", 2, 2);
+        
+
+    }
     /**
      * Having cast Phantasmal Image copying my opponent's flipped Thing in the
      * Ice, I was left with a 0/4 Awoken Horror.
diff --git a/Mage/src/main/java/mage/abilities/effects/common/TransformSourceEffect.java b/Mage/src/main/java/mage/abilities/effects/common/TransformSourceEffect.java
index e3636ad588..13e8b95d1f 100644
--- a/Mage/src/main/java/mage/abilities/effects/common/TransformSourceEffect.java
+++ b/Mage/src/main/java/mage/abilities/effects/common/TransformSourceEffect.java
@@ -4,6 +4,7 @@ package mage.abilities.effects.common;
 import mage.MageObject;
 import mage.abilities.Ability;
 import mage.abilities.effects.OneShotEffect;
+import mage.cards.Card;
 import mage.constants.Outcome;
 import mage.game.Game;
 import mage.game.permanent.Permanent;
@@ -55,6 +56,11 @@ public class TransformSourceEffect extends OneShotEffect {
                     if (withoutTrigger) {
                         sourcePermanent.setTransformed(fromDayToNight);
                     } else {
+                        if (sourcePermanent.isTransformed()) {
+                            Card orgCard = game.getCard(source.getSourceId());
+                            sourcePermanent.getPower().modifyBaseValue(orgCard.getPower().getValue());
+                            sourcePermanent.getToughness().modifyBaseValue(orgCard.getToughness().getValue());
+                        }
                         sourcePermanent.transform(game);
                     }
                     if (!game.isSimulation()) {