Cleanup: ExileUntilSourceLeavesEffect (#10527)

* Refactor OnLeaveReturnExiledAbility
to accommodate hand zone as well as battlefield
* Cleanup Brain Maggot and Kitesail Freebooter
* Refactor to include delayed trigger with main effect
* minor cleanup
* merge fix
* further adjustments
* Cleanup Valki, God of Lies
* fix test choices
This commit is contained in:
xenohedron 2023-07-04 20:38:59 -04:00 committed by GitHub
parent d629776b54
commit 4d6644d095
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
71 changed files with 168 additions and 489 deletions

View file

@ -30,21 +30,25 @@ import mage.util.CardUtil;
*
* @author LevelX2
*/
public class OnLeaveReturnExiledToBattlefieldAbility extends DelayedTriggeredAbility {
public class OnLeaveReturnExiledAbility extends DelayedTriggeredAbility {
public OnLeaveReturnExiledToBattlefieldAbility() {
super(new ReturnExiledPermanentsEffect(), Duration.OneUse);
public OnLeaveReturnExiledAbility() {
this(Zone.BATTLEFIELD);
}
public OnLeaveReturnExiledAbility(Zone zone) {
super(new ReturnExiledPermanentsEffect(zone), Duration.OneUse);
this.usesStack = false;
this.setRuleVisible(false);
}
public OnLeaveReturnExiledToBattlefieldAbility(final OnLeaveReturnExiledToBattlefieldAbility ability) {
public OnLeaveReturnExiledAbility(final OnLeaveReturnExiledAbility ability) {
super(ability);
}
@Override
public OnLeaveReturnExiledToBattlefieldAbility copy() {
return new OnLeaveReturnExiledToBattlefieldAbility(this);
public OnLeaveReturnExiledAbility copy() {
return new OnLeaveReturnExiledAbility(this);
}
@Override
@ -66,13 +70,17 @@ public class OnLeaveReturnExiledToBattlefieldAbility extends DelayedTriggeredAbi
class ReturnExiledPermanentsEffect extends OneShotEffect {
public ReturnExiledPermanentsEffect() {
private final Zone zone;
ReturnExiledPermanentsEffect(Zone zone) {
super(Outcome.Benefit);
this.zone = zone;
this.staticText = "Return exiled permanents";
}
public ReturnExiledPermanentsEffect(final ReturnExiledPermanentsEffect effect) {
super(effect);
this.zone = effect.zone;
}
@Override
@ -87,7 +95,7 @@ class ReturnExiledPermanentsEffect extends OneShotEffect {
if (sourceObject != null && controller != null) {
ExileZone exile = getExileIfPossible(game, source);
if (exile != null) {
return controller.moveCards(new LinkedHashSet<>(exile.getCards(game)), Zone.BATTLEFIELD, source, game, false, false, true, null);
return controller.moveCards(new LinkedHashSet<>(exile.getCards(game)), zone, source, game, false, false, true, null);
}
}
return false;

View file

@ -2,11 +2,13 @@ package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.common.delayed.OnLeaveReturnExiledAbility;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.target.Target;
import mage.util.CardUtil;
/**
@ -15,12 +17,28 @@ import mage.util.CardUtil;
*/
public class ExileUntilSourceLeavesEffect extends OneShotEffect {
private final Zone returnToZone;
/**
* Exiles target(s) until source leaves battlefield
* Includes effect that returns exiled card to battlefield when source leaves
*/
public ExileUntilSourceLeavesEffect() {
this(Zone.BATTLEFIELD);
}
/**
* Exiles target(s) until source leaves battlefield
* @param returnToZone The zone to which the exiled card will be returned when source leaves
*/
public ExileUntilSourceLeavesEffect(Zone returnToZone) {
super(Outcome.Removal);
this.returnToZone = returnToZone;
}
public ExileUntilSourceLeavesEffect(final ExileUntilSourceLeavesEffect effect) {
super(effect);
this.returnToZone = effect.returnToZone;
}
@Override
@ -32,7 +50,7 @@ public class ExileUntilSourceLeavesEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
// If Banishing Light leaves the battlefield before its triggered ability resolves, the target permanent won't be exiled.
// If source permanent leaves the battlefield before its triggered ability resolves, the target permanent won't be exiled.
if (permanent == null) {
return false;
}
@ -41,7 +59,11 @@ public class ExileUntilSourceLeavesEffect extends OneShotEffect {
if (targetPointer != null) { // Grasping Giant
effect.setTargetPointer(targetPointer);
}
return effect.apply(game, source);
if (effect.apply(game, source)) {
game.addDelayedTriggeredAbility(new OnLeaveReturnExiledAbility(returnToZone), source);
return true;
}
return false;
}
@Override