Friday, September 25, 2020

XMage, Adding MutateAbility (1)

 Got gp66 forked repo to work on. Trying to test Gemrazer to implement

1. target controlled permanent non-human

@@ -2,36 +2,48 @@ package mage.cards.g;
 
 import mage.MageInt;
 import mage.abilities.Ability;
 import mage.abilities.common.MutatesSourceTriggeredAbility;
 import mage.abilities.effects.common.DestroyTargetEffect;
+import mage.abilities.effects.common.AttachEffect;
 ...
 import mage.constants.CardType;
+import mage.constants.Outcome;
 import mage.constants.SubType;
 import mage.constants.TargetController;
 import mage.filter.FilterPermanent;
 import mage.filter.common.FilterArtifactOrEnchantmentPermanent;
+import mage.filter.common.FilterControlledCreaturePermanent;
 import mage.target.TargetPermanent;
+import mage.constants.SubType;
+import mage.filter.predicate.Predicates;

...
 
public final class Gemrazer extends CardImpl {
 
-    private static final FilterPermanent filter
+	private static final FilterPermanent filter
             = new FilterArtifactOrEnchantmentPermanent("artifact or enchantment an opponent controls");
 
     static {
         filter.add(TargetController.OPPONENT.getControllerPredicate());
     }
 
+    private static final FilterPermanent filterCreatureNonHuman
+            = new FilterControlledCreaturePermanent("non-human creature you control");
+    
+    static {
+    	filterCreatureNonHuman.add(Predicates.not(SubType.HUMAN.getPredicate()));
+    }
+

@@ -43,10 +55,15 @@ public final class Gemrazer extends CardImpl {
         // Reach
         this.addAbility(ReachAbility.getInstance());
 
         // Trample
         this.addAbility(TrampleAbility.getInstance());
+        
+        // Whenever this creature mutates, attach to a controlled non-human creature
+        Ability abilityAttach = new MutatesSourceTriggeredAbility(new AttachEffect(Outcome.Mutate));
+        abilityAttach.addTarget(new TargetPermanent(filterCreatureNonHuman));
+        this.addAbility(abilityAttach);
 
         // Whenever this creature mutates, destroy target artifact or enchantment an opponent controls.
         Ability ability = new MutatesSourceTriggeredAbility(new DestroyTargetEffect());
         ability.addTarget(new TargetPermanent(filter));
         this.addAbility(ability);

2. Test the ability of mutated creature

 @Test
    public void testCastMutate() {
        addCard(Zone.BATTLEFIELD, playerA, "Forest", 2);
        addCard(Zone.BATTLEFIELD, playerA, "Plains", 1);
        addCard(Zone.BATTLEFIELD, playerA, "Flourishing Fox",1);
        addCard(Zone.HAND, playerA, "Gemrazer",1);

        castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Gemrazer using mutate");
        // But why no addTarget to flourishing fox ??
        
        setStrictChooseMode(true);
        setStopAt(1, PhaseStep.BEGIN_COMBAT);
        execute();
        assertAllCommandsUsed();

        assertAbility(playerA, "Gemrazer", new CyclingAbility(new ManaCostsImpl("{1}")), true);
        assertHandCount(playerA, 0);
    }

The test result so far so good

Todo:

Ask for the mutation on top or bottom of the targeted non-human creature.


No comments: