* Reworked GainControlAllEffect that fixed a problem of Varchild, Betrayer of Kjeldor gaining control of creatures entering the battlefield after the Varchild left the battlefield.

This commit is contained in:
LevelX2 2020-01-01 13:37:04 +01:00
parent 3c727eb06b
commit 12c4bacc07
7 changed files with 97 additions and 45 deletions

View file

@ -1,5 +1,6 @@
package mage.cards.a; package mage.cards.a;
import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.LoyaltyAbility; import mage.abilities.LoyaltyAbility;
import mage.abilities.common.PlaneswalkerEntersWithLoyaltyCountersAbility; import mage.abilities.common.PlaneswalkerEntersWithLoyaltyCountersAbility;
@ -20,8 +21,6 @@ import mage.game.Game;
import mage.target.common.TargetCardInGraveyard; import mage.target.common.TargetCardInGraveyard;
import mage.target.common.TargetOpponent; import mage.target.common.TargetOpponent;
import java.util.UUID;
/** /**
* @author TheElk801 * @author TheElk801
*/ */
@ -85,7 +84,8 @@ class AshiokSculptorOfFearsEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
FilterPermanent filter = new FilterCreaturePermanent(); FilterPermanent filter = new FilterCreaturePermanent();
filter.add(new ControllerIdPredicate(source.getFirstTarget())); filter.add(new ControllerIdPredicate(source.getFirstTarget()));
game.addEffect(new GainControlAllEffect(Duration.Custom, filter), source);
new GainControlAllEffect(Duration.Custom, filter).apply(game, source);
return true; return true;
} }
} }

View file

@ -1,4 +1,3 @@
package mage.cards.b; package mage.cards.b;
import java.util.UUID; import java.util.UUID;
@ -26,10 +25,10 @@ public final class Brand extends CardImpl {
} }
public Brand(UUID ownerId, CardSetInfo setInfo) { public Brand(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{R}"); super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{R}");
// Gain control of all permanents you own. <i>(This effect lasts indefinitely.)</i> // Gain control of all permanents you own. <i>(This effect lasts indefinitely.)</i>
this.getSpellAbility().addEffect(new GainControlAllEffect(Duration.EndOfGame, filter)); this.getSpellAbility().addEffect(new GainControlAllEffect(Duration.Custom, filter));
// Cycling {2} // Cycling {2}
this.addAbility(new CyclingAbility(new GenericManaCost(2))); this.addAbility(new CyclingAbility(new GenericManaCost(2)));

View file

@ -1,5 +1,6 @@
package mage.cards.i; package mage.cards.i;
import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.effects.common.CreateTokenEffect; import mage.abilities.effects.common.CreateTokenEffect;
@ -10,8 +11,6 @@ import mage.constants.CardType;
import mage.constants.SubType; import mage.constants.SubType;
import mage.game.permanent.token.ShapeshifterToken; import mage.game.permanent.token.ShapeshifterToken;
import java.util.UUID;
/** /**
* @author TheElk801 * @author TheElk801
*/ */

View file

@ -1,4 +1,3 @@
package mage.cards.r; package mage.cards.r;
import java.util.UUID; import java.util.UUID;
@ -14,13 +13,13 @@ import mage.abilities.effects.common.TapAllEffect;
import mage.abilities.effects.common.continuous.BoostAllEffect; import mage.abilities.effects.common.continuous.BoostAllEffect;
import mage.abilities.effects.common.continuous.GainControlAllEffect; import mage.abilities.effects.common.continuous.GainControlAllEffect;
import mage.abilities.effects.common.continuous.GainControlTargetEffect; import mage.abilities.effects.common.continuous.GainControlTargetEffect;
import mage.constants.SubType;
import mage.constants.SuperType;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Duration; import mage.constants.Duration;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.SuperType;
import mage.constants.TargetController; import mage.constants.TargetController;
import mage.constants.Zone; import mage.constants.Zone;
import mage.filter.common.FilterCreaturePermanent; import mage.filter.common.FilterCreaturePermanent;
@ -113,7 +112,7 @@ class RohgahhOfKherKeepEffect extends OneShotEffect {
permanent.tap(game); permanent.tap(game);
} }
if (opponent != null) { if (opponent != null) {
game.addEffect(new GainControlAllEffect(Duration.Custom, filter, opponent.getId()), source); new GainControlAllEffect(Duration.Custom, filter, opponent.getId()).apply(game, source);
if (permanent != null) { if (permanent != null) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, opponent.getId()); ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, opponent.getId());
effect.setTargetPointer(new FixedTarget(permanent, game)); effect.setTargetPointer(new FixedTarget(permanent, game));

View file

@ -37,10 +37,6 @@ public final class VarchildBetrayerOfKjeldor extends CardImpl {
SubType.SURVIVOR, SubType.SURVIVOR,
"Survivors your opponents control" "Survivors your opponents control"
); );
private static final FilterCreaturePermanent filter2
= new FilterCreaturePermanent(
SubType.SURVIVOR, "all Survivors"
);
static { static {
filter1.add(new ControllerPredicate(TargetController.OPPONENT)); filter1.add(new ControllerPredicate(TargetController.OPPONENT));
@ -74,7 +70,7 @@ public final class VarchildBetrayerOfKjeldor extends CardImpl {
// When Varchild leaves the battlefield, gain control of all Survivors. // When Varchild leaves the battlefield, gain control of all Survivors.
this.addAbility(new LeavesBattlefieldTriggeredAbility( this.addAbility(new LeavesBattlefieldTriggeredAbility(
new GainControlAllEffect(Duration.Custom, filter2), false new GainControlAllEffect(Duration.Custom, new FilterCreaturePermanent(SubType.SURVIVOR, "all Survivors")), false
)); ));
} }

View file

@ -0,0 +1,71 @@
package org.mage.test.cards.single.c18;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
*
* @author LevelX2
*/
public class VarchildBetrayerOfKjeldorTest extends CardTestPlayerBase {
// Varchild - varchild died, then next turn i played an irregular cohort and varchild's controller
// instantly gained control of it. the triggered token entered on varchild's side too.
// Tried rollbacking, same thing happened
@Test
public void testOpponentGetsSurvivorTokens() {
// Whenever Varchild, Betrayer of Kjeldor deals combat damage to a player, that player creates that many 1/1 red Survivor creature tokens.
// Survivors your opponents control can't block, and they can't attack you or a planeswalker you control.
// When Varchild leaves the battlefield, gain control of all Survivors.
addCard(Zone.HAND, playerA, "Varchild, Betrayer of Kjeldor"); // Creature 3/3 - {2}{R}
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Varchild, Betrayer of Kjeldor");
attack(3, playerA, "Varchild, Betrayer of Kjeldor");
setStopAt(3, PhaseStep.POSTCOMBAT_MAIN);
execute();
assertPermanentCount(playerA, "Varchild, Betrayer of Kjeldor", 1);
assertPermanentCount(playerB, "Survivor", 3);
}
@Test
public void testGetControlEffect() {
// Whenever Varchild, Betrayer of Kjeldor deals combat damage to a player, that player creates that many 1/1 red Survivor creature tokens.
// Survivors your opponents control can't block, and they can't attack you or a planeswalker you control.
// When Varchild leaves the battlefield, gain control of all Survivors.
addCard(Zone.HAND, playerA, "Varchild, Betrayer of Kjeldor"); // Creature 3/3 - {2}{R}
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3);
// Changeling
// When Irregular Cohort enters the battlefield, create a 2/2 colorless Shapeshifter creature token with changeling.
addCard(Zone.HAND, playerB, "Irregular Cohort"); // Creature 2/2 - {2}{W}{W}
// Exile target creature. Its controller gains life equal to its power.
addCard(Zone.HAND, playerB, "Swords to Plowshares"); // Instant {W}
addCard(Zone.BATTLEFIELD, playerB, "Plains", 4);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Varchild, Betrayer of Kjeldor");
attack(3, playerA, "Varchild, Betrayer of Kjeldor");
castSpell(3, PhaseStep.POSTCOMBAT_MAIN, playerB, "Swords to Plowshares", "Varchild, Betrayer of Kjeldor");
castSpell(4, PhaseStep.PRECOMBAT_MAIN, playerB, "Irregular Cohort");
setStopAt(4, PhaseStep.POSTCOMBAT_MAIN);
execute();
assertGraveyardCount(playerB, "Swords to Plowshares", 1);
assertExileCount(playerA, "Varchild, Betrayer of Kjeldor", 1);
assertLife(playerA, 23);
assertPermanentCount(playerA, "Survivor", 3);
assertPermanentCount(playerB, "Irregular Cohort", 1);
assertPermanentCount(playerB, "Shapeshifter", 1);
}
}

View file

@ -1,44 +1,42 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mage.abilities.effects.common.continuous; package mage.abilities.effects.common.continuous;
import java.util.UUID; import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.Mode; import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.OneShotEffect;
import mage.constants.Duration; import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.SubLayer;
import mage.filter.FilterPermanent; import mage.filter.FilterPermanent;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.target.targetpointer.FixedTarget;
/** /**
* *
* @author fenhl * @author fenhl
*/ */
public class GainControlAllEffect extends ContinuousEffectImpl { public class GainControlAllEffect extends OneShotEffect {
private final FilterPermanent filter; private final FilterPermanent filter;
private final UUID controllingPlayerId; private final UUID controllingPlayerId;
private final Duration duration;
public GainControlAllEffect(Duration duration, FilterPermanent filter) { public GainControlAllEffect(Duration duration, FilterPermanent filter) {
this(duration, filter, null); this(duration, filter, null);
} }
public GainControlAllEffect(Duration duration, FilterPermanent filter, UUID controllingPlayerId) { public GainControlAllEffect(Duration duration, FilterPermanent filter, UUID controllingPlayerId) {
super(duration, Layer.ControlChangingEffects_2, SubLayer.NA, Outcome.GainControl); super(Outcome.GainControl);
this.filter = filter; this.filter = filter;
this.duration = duration;
this.controllingPlayerId = controllingPlayerId; this.controllingPlayerId = controllingPlayerId;
this.staticText = "Gain control of " + filter.getMessage();
} }
public GainControlAllEffect(final GainControlAllEffect effect) { public GainControlAllEffect(final GainControlAllEffect effect) {
super(effect); super(effect);
this.filter = effect.filter.copy(); this.filter = effect.filter.copy();
this.duration = effect.duration;
this.controllingPlayerId = effect.controllingPlayerId; this.controllingPlayerId = effect.controllingPlayerId;
} }
@ -49,23 +47,13 @@ public class GainControlAllEffect extends ContinuousEffectImpl {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) { for (Permanent permanent : game.getBattlefield()
if (permanent != null) { .getActivePermanents(filter,
if (controllingPlayerId == null) { source.getControllerId(), source.getSourceId(), game)) {
permanent.changeControllerId(source.getControllerId(), game); ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, controllingPlayerId);
} else { effect.setTargetPointer(new FixedTarget(permanent, game));
permanent.changeControllerId(controllingPlayerId, game); game.addEffect(effect, source);
}
}
} }
return true; return true;
} }
@Override
public String getText(Mode mode) {
StringBuilder sb = new StringBuilder();
sb.append("Gain control of ").append(filter.getMessage());
return sb.toString();
}
} }