updated cards which phase things out to properly handle indirect phasing

(#4071)
This commit is contained in:
Evan Kranzler 2017-10-10 14:31:00 -04:00
parent 3d20e4dbef
commit fdf3f831ca
5 changed files with 112 additions and 20 deletions

View file

@ -27,11 +27,13 @@
*/
package mage.cards.e;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.PhaseOutAllEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
@ -116,12 +118,7 @@ class EquipoiseEffect extends OneShotEffect {
filterChoose.add(new CardTypePredicate(cardType));
Target target = new TargetPermanent(excess, excess, filterChoose, true);
controller.chooseTarget(outcome, target, source, game);
for (UUID permanentId : target.getTargets()) {
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null) {
permanent.phaseOut(game);
}
}
new PhaseOutAllEffect(target.getTargets()).apply(game, source);
}
}
}

View file

@ -27,11 +27,14 @@
*/
package mage.cards.t;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.PhaseOutAllEffect;
import mage.abilities.keyword.PhasingAbility;
import mage.abilities.keyword.TrampleAbility;
import mage.cards.CardImpl;
@ -41,6 +44,7 @@ import mage.constants.SubType;
import mage.constants.Outcome;
import mage.constants.SuperType;
import mage.constants.TargetController;
import mage.filter.StaticFilters;
import mage.filter.common.FilterControlledLandPermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -53,7 +57,7 @@ import mage.players.Player;
public class Taniwha extends CardImpl {
public Taniwha(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{3}{U}{U}");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{U}{U}");
addSuperType(SuperType.LEGENDARY);
this.subtype.add(SubType.SERPENT);
this.power = new MageInt(7);
@ -61,10 +65,10 @@ public class Taniwha extends CardImpl {
// Trample
this.addAbility(TrampleAbility.getInstance());
// Phasing
this.addAbility(PhasingAbility.getInstance());
// At the beginning of your upkeep, all lands you control phase out.
this.addAbility(new BeginningOfUpkeepTriggeredAbility(new TaniwhaEffect(), TargetController.YOU, false));
}
@ -99,10 +103,11 @@ class TaniwhaEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
List<UUID> permIds = new ArrayList<>();
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterControlledLandPermanent(), controller.getId(), game)) {
permanent.phaseOut(game);
permIds.add(permanent.getId());
}
return true;
return new PhaseOutAllEffect(permIds).apply(game, source);
}
return false;
}

View file

@ -27,11 +27,14 @@
*/
package mage.cards.t;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.ExileSpellEffect;
import mage.abilities.effects.common.PhaseOutAllEffect;
import mage.abilities.effects.common.continuous.GainAbilityControllerEffect;
import mage.abilities.effects.common.continuous.LifeTotalCantChangeControllerEffect;
import mage.abilities.keyword.ProtectionAbility;
@ -170,14 +173,11 @@ class TeferisProtectionPhaseOutEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
List<UUID> permIds = new ArrayList<>();
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_CONTROLLED_PERMANENT, controller.getId(), game)) {
Permanent attachedTo = game.getPermanent(permanent.getAttachedTo());
// don't phase out auras directly if they're attached to your stuff
if (!(attachedTo != null && attachedTo.getControllerId().equals(controller.getId()))) {
permanent.phaseOut(game);
}
permIds.add(permanent.getId());
}
return true;
return new PhaseOutAllEffect(permIds).apply(game, source);
}
return false;
}

View file

@ -27,6 +27,7 @@
*/
package mage.cards.t;
import java.util.ArrayList;
import mage.abilities.Ability;
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
@ -45,8 +46,11 @@ import mage.game.permanent.Permanent;
import mage.players.Player;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import mage.abilities.effects.common.PhaseOutAllEffect;
import mage.filter.common.FilterControlledLandPermanent;
/**
*
@ -55,7 +59,7 @@ import java.util.UUID;
public class TeferisRealm extends CardImpl {
public TeferisRealm(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{1}{U}{U}");
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{1}{U}{U}");
addSuperType(SuperType.WORLD);
// At the beginning of each player's upkeep, that player chooses artifact, creature, land, or non-Aura enchantment. All nontoken permanents of that type phase out.
@ -135,10 +139,11 @@ class TeferisRealmEffect extends OneShotEffect {
return false;
}
game.informPlayers(player.getLogName() + " chooses " + choosenType + "s to phase out");
List<UUID> permIds = new ArrayList<>();
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, controller.getId(), game)) {
permanent.phaseOut(game);
permIds.add(permanent.getId());
}
return true;
return new PhaseOutAllEffect(permIds).apply(game, source);
}
return false;
}

View file

@ -0,0 +1,85 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.effects.common;
import java.util.List;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
* This class should only be used within the application of another effect
*
* @author TheElk801
*/
public class PhaseOutAllEffect extends OneShotEffect {
private final List<UUID> idList;
public PhaseOutAllEffect(List<UUID> idList) {
super(Outcome.Neutral);
this.idList = idList;
}
public PhaseOutAllEffect(final PhaseOutAllEffect effect) {
super(effect);
this.idList = effect.idList;
}
@Override
public PhaseOutAllEffect copy() {
return new PhaseOutAllEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
// First we phase out everything that isn't attached to anything
// Anything attached to these permanents will phase out indirectly
for (UUID permanentId : idList) {
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null) {
Permanent attachedTo = game.getPermanent(permanent.getAttachedTo());
if (attachedTo == null) {
permanent.phaseOut(game);
}
}
}
// Once this is done, we'll have permanents which are attached to something but haven't phased out
// These will be phased out directly
for (UUID permanentId : idList) {
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null && permanent.isPhasedIn()) {
permanent.phaseOut(game);
}
}
return true;
}
}