From a39cbbb7d723a9a1e07ace2c696fa8fac788f1cd Mon Sep 17 00:00:00 2001
From: Achilles <jeff@delmarus.com>
Date: Sun, 4 Feb 2018 19:22:13 -0600
Subject: [PATCH] - Fixed Simic Manipulator #4479

---
 .../src/mage/cards/s/SimicManipulator.java    | 30 +++++++++++++++++--
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/Mage.Sets/src/mage/cards/s/SimicManipulator.java b/Mage.Sets/src/mage/cards/s/SimicManipulator.java
index 40675ce879..4f0271d879 100644
--- a/Mage.Sets/src/mage/cards/s/SimicManipulator.java
+++ b/Mage.Sets/src/mage/cards/s/SimicManipulator.java
@@ -31,6 +31,7 @@ import java.util.UUID;
 import mage.MageInt;
 import mage.abilities.Ability;
 import mage.abilities.common.SimpleActivatedAbility;
+import mage.abilities.costs.Cost;
 import mage.abilities.costs.common.RemoveVariableCountersSourceCost;
 import mage.abilities.costs.common.TapSourceCost;
 import mage.abilities.effects.common.continuous.GainControlTargetEffect;
@@ -38,12 +39,14 @@ import mage.abilities.keyword.EvolveAbility;
 import mage.cards.CardImpl;
 import mage.cards.CardSetInfo;
 import mage.constants.CardType;
+import mage.constants.ComparisonType;
 import mage.constants.SubType;
 import mage.constants.Duration;
-import mage.constants.TargetAdjustment;
 import mage.constants.Zone;
 import mage.counters.CounterType;
 import mage.filter.common.FilterCreaturePermanent;
+import mage.filter.predicate.mageobject.PowerPredicate;
+import mage.game.Game;
 import mage.target.common.TargetCreaturePermanent;
 
 /**
@@ -60,7 +63,8 @@ import mage.target.common.TargetCreaturePermanent;
  */
 public class SimicManipulator extends CardImpl {
 
-    private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("creature with power less than or equal to the number of +1/+1 counters removed this way");
+    private final UUID originalId;
+    private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("with power less than or equal to the number of +1/+1 counters removed this way");
 
     public SimicManipulator(UUID ownerId, CardSetInfo setInfo) {
         super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{U}{U}");
@@ -77,16 +81,36 @@ public class SimicManipulator extends CardImpl {
         Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new GainControlTargetEffect(Duration.Custom, true), new TapSourceCost());
         ability.addTarget(new TargetCreaturePermanent(filter));
         ability.addCost(new RemoveVariableCountersSourceCost(CounterType.P1P1.createInstance(), 1, "Remove one or more +1/+1 counters from {this}"));
-        ability.setTargetAdjustment(TargetAdjustment.SIMIC_MANIPULATOR);
         this.addAbility(ability);
+        this.originalId = ability.getOriginalId();
+
     }
 
     public SimicManipulator(final SimicManipulator card) {
         super(card);
+        this.originalId = card.originalId;
     }
 
     @Override
     public SimicManipulator copy() {
         return new SimicManipulator(this);
     }
+
+    @Override
+    public void adjustTargets(Ability ability, Game game) {
+        if (ability.getOriginalId().equals(originalId)) {
+            ability.getTargets().clear();
+            int maxPower = 0;
+            FilterCreaturePermanent filter = new FilterCreaturePermanent("creature with power less than or equal to the number of +1/+1 counters removed this way");
+            for (Cost cost : ability.getCosts()) {
+                if (cost instanceof RemoveVariableCountersSourceCost) {
+                    maxPower = ((RemoveVariableCountersSourceCost) cost).getAmount();
+                    break;
+                }
+            }
+            filter.add(new PowerPredicate(ComparisonType.FEWER_THAN, maxPower + 1));
+            TargetCreaturePermanent target = new TargetCreaturePermanent(1, 1, filter, false);
+            ability.addTarget(target);
+        }
+    }
 }