Merge pull request #4101 from magefree/phasingFix

Fixed how phasing is implemented
This commit is contained in:
LevelX2 2017-11-02 11:00:33 +01:00 committed by GitHub
commit b4ee3ff1da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 159 additions and 27 deletions

View file

@ -27,11 +27,13 @@
*/ */
package mage.cards.e; package mage.cards.e;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.PhaseOutAllEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.constants.CardType; import mage.constants.CardType;
@ -55,8 +57,7 @@ import mage.target.TargetPlayer;
public class Equipoise extends CardImpl { public class Equipoise extends CardImpl {
public Equipoise(UUID ownerId, CardSetInfo setInfo) { public Equipoise(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{2}{W}"); super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{2}{W}");
// At the beginning of your upkeep, for each land target player controls in excess of the number you control, choose a land he or she controls, then the chosen permanents phase out. Repeat this process for artifacts and creatures. // At the beginning of your upkeep, for each land target player controls in excess of the number you control, choose a land he or she controls, then the chosen permanents phase out. Repeat this process for artifacts and creatures.
Ability ability = new BeginningOfUpkeepTriggeredAbility(new EquipoiseEffect(), TargetController.YOU, false); Ability ability = new BeginningOfUpkeepTriggeredAbility(new EquipoiseEffect(), TargetController.YOU, false);
@ -112,17 +113,12 @@ class EquipoiseEffect extends OneShotEffect {
int numberTargetPlayer = game.getBattlefield().count(filter, source.getSourceId(), targetPlayer.getId(), game); int numberTargetPlayer = game.getBattlefield().count(filter, source.getSourceId(), targetPlayer.getId(), game);
int excess = numberTargetPlayer - numberController; int excess = numberTargetPlayer - numberController;
if (excess > 0) { if (excess > 0) {
FilterPermanent filterChoose = new FilterPermanent(cardType.toString().toLowerCase() + (excess > 1 ? "s":"") +" of target player"); FilterPermanent filterChoose = new FilterPermanent(cardType.toString().toLowerCase() + (excess > 1 ? "s" : "") + " of target player");
filterChoose.add(new ControllerIdPredicate(targetPlayer.getId())); filterChoose.add(new ControllerIdPredicate(targetPlayer.getId()));
filterChoose.add(new CardTypePredicate(cardType)); filterChoose.add(new CardTypePredicate(cardType));
Target target = new TargetPermanent(excess, excess, filterChoose, true); Target target = new TargetPermanent(excess, excess, filterChoose, true);
controller.chooseTarget(outcome, target, source, game); controller.chooseTarget(outcome, target, source, game);
for (UUID permanentId:target.getTargets()) { new PhaseOutAllEffect(target.getTargets()).apply(game, source);
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null) {
permanent.phaseOut(game);
}
}
} }
} }
} }

View file

@ -27,11 +27,14 @@
*/ */
package mage.cards.t; package mage.cards.t;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.PhaseOutAllEffect;
import mage.abilities.keyword.PhasingAbility; import mage.abilities.keyword.PhasingAbility;
import mage.abilities.keyword.TrampleAbility; import mage.abilities.keyword.TrampleAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
@ -41,6 +44,7 @@ import mage.constants.SubType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.SuperType; import mage.constants.SuperType;
import mage.constants.TargetController; import mage.constants.TargetController;
import mage.filter.StaticFilters;
import mage.filter.common.FilterControlledLandPermanent; import mage.filter.common.FilterControlledLandPermanent;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
@ -53,7 +57,7 @@ import mage.players.Player;
public class Taniwha extends CardImpl { public class Taniwha extends CardImpl {
public Taniwha(UUID ownerId, CardSetInfo setInfo) { 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); addSuperType(SuperType.LEGENDARY);
this.subtype.add(SubType.SERPENT); this.subtype.add(SubType.SERPENT);
this.power = new MageInt(7); this.power = new MageInt(7);
@ -99,10 +103,11 @@ class TaniwhaEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (controller != null) { if (controller != null) {
List<UUID> permIds = new ArrayList<>();
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterControlledLandPermanent(), controller.getId(), game)) { 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; return false;
} }

View file

@ -27,11 +27,14 @@
*/ */
package mage.cards.t; package mage.cards.t;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.MageObject; import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.ExileSpellEffect; 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.GainAbilityControllerEffect;
import mage.abilities.effects.common.continuous.LifeTotalCantChangeControllerEffect; import mage.abilities.effects.common.continuous.LifeTotalCantChangeControllerEffect;
import mage.abilities.keyword.ProtectionAbility; import mage.abilities.keyword.ProtectionAbility;
@ -170,10 +173,11 @@ class TeferisProtectionPhaseOutEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (controller != null) { if (controller != null) {
List<UUID> permIds = new ArrayList<>();
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_CONTROLLED_PERMANENT, controller.getId(), game)) { for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_CONTROLLED_PERMANENT, controller.getId(), game)) {
permanent.phaseOut(game); permIds.add(permanent.getId());
} }
return true; return new PhaseOutAllEffect(permIds).apply(game, source);
} }
return false; return false;
} }

View file

@ -27,6 +27,7 @@
*/ */
package mage.cards.t; package mage.cards.t;
import java.util.ArrayList;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
@ -45,8 +46,11 @@ import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.UUID; 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 class TeferisRealm extends CardImpl {
public TeferisRealm(UUID ownerId, CardSetInfo setInfo) { 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); 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. // 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; return false;
} }
game.informPlayers(player.getLogName() + " chooses " + choosenType + "s to phase out"); 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)) { 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; 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;
}
}

View file

@ -78,10 +78,16 @@ public interface Permanent extends Card, Controllable {
boolean isPhasedIn(); boolean isPhasedIn();
boolean isPhasedOutIndirectly();
boolean phaseIn(Game game); boolean phaseIn(Game game);
boolean phaseIn(Game game, boolean onlyDirect);
boolean phaseOut(Game game); boolean phaseOut(Game game);
boolean phaseOut(Game game, boolean indirectPhase);
boolean isMonstrous(); boolean isMonstrous();
void setMonstrous(boolean value); void setMonstrous(boolean value);

View file

@ -89,6 +89,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
protected boolean controlledFromStartOfControllerTurn; protected boolean controlledFromStartOfControllerTurn;
protected int turnsOnBattlefield; protected int turnsOnBattlefield;
protected boolean phasedIn = true; protected boolean phasedIn = true;
protected boolean indirectPhase = false;
protected boolean faceDown; protected boolean faceDown;
protected boolean attacking; protected boolean attacking;
protected int blocking; protected int blocking;
@ -138,6 +139,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
this.controlledFromStartOfControllerTurn = permanent.controlledFromStartOfControllerTurn; this.controlledFromStartOfControllerTurn = permanent.controlledFromStartOfControllerTurn;
this.turnsOnBattlefield = permanent.turnsOnBattlefield; this.turnsOnBattlefield = permanent.turnsOnBattlefield;
this.phasedIn = permanent.phasedIn; this.phasedIn = permanent.phasedIn;
this.indirectPhase = permanent.indirectPhase;
this.faceDown = permanent.faceDown; this.faceDown = permanent.faceDown;
this.attacking = permanent.attacking; this.attacking = permanent.attacking;
this.blocking = permanent.blocking; this.blocking = permanent.blocking;
@ -461,14 +463,32 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
return phasedIn; return phasedIn;
} }
@Override
public boolean isPhasedOutIndirectly() {
return !phasedIn && indirectPhase;
}
@Override @Override
public boolean phaseIn(Game game) { public boolean phaseIn(Game game) {
return phaseIn(game, true);
}
@Override
public boolean phaseIn(Game game, boolean onlyDirect) {
if (!phasedIn) { if (!phasedIn) {
if (!replaceEvent(EventType.PHASE_IN, game)) { if (!replaceEvent(EventType.PHASE_IN, game)
&& ((onlyDirect && !indirectPhase) || (!onlyDirect))) {
this.phasedIn = true; this.phasedIn = true;
this.indirectPhase = false;
if (!game.isSimulation()) { if (!game.isSimulation()) {
game.informPlayers(getLogName() + " phased in"); game.informPlayers(getLogName() + " phased in");
} }
for (UUID attachedId : this.getAttachments()) {
Permanent attachedPerm = game.getPermanent(attachedId);
if (attachedPerm != null) {
attachedPerm.phaseIn(game, false);
}
}
fireEvent(EventType.PHASED_IN, game); fireEvent(EventType.PHASED_IN, game);
return true; return true;
} }
@ -478,9 +498,21 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
@Override @Override
public boolean phaseOut(Game game) { public boolean phaseOut(Game game) {
return phaseOut(game, false);
}
@Override
public boolean phaseOut(Game game, boolean indirectPhase) {
if (phasedIn) { if (phasedIn) {
if (!replaceEvent(EventType.PHASE_OUT, game)) { if (!replaceEvent(EventType.PHASE_OUT, game)) {
for (UUID attachedId : this.getAttachments()) {
Permanent attachedPerm = game.getPermanent(attachedId);
if (attachedPerm != null) {
attachedPerm.phaseOut(game, true);
}
}
this.phasedIn = false; this.phasedIn = false;
this.indirectPhase = indirectPhase;
if (!game.isSimulation()) { if (!game.isSimulation()) {
game.informPlayers(getLogName() + " phased out"); game.informPlayers(getLogName() + " phased out");
} }

View file

@ -1484,16 +1484,15 @@ public abstract class PlayerImpl implements Player, Serializable {
// phasing out is known as phasing out "indirectly." An enchantment or Equipment // phasing out is known as phasing out "indirectly." An enchantment or Equipment
// that phased out indirectly won't phase in by itself, but instead phases in // that phased out indirectly won't phase in by itself, but instead phases in
// along with the card it's attached to. // along with the card it's attached to.
for (UUID attachmentId : permanent.getAttachments()) { Permanent attachedTo = game.getPermanent(permanent.getAttachedTo());
Permanent attachment = game.getPermanent(attachmentId); if (!(attachedTo != null && attachedTo.getControllerId().equals(this.getId()))) {
if (attachment != null) { permanent.phaseOut(game, false);
attachment.phaseOut(game);
}
} }
permanent.phaseOut(game);
} }
for (Permanent permanent : phasedOut) { for (Permanent permanent : phasedOut) {
permanent.phaseIn(game); if (!permanent.isPhasedOutIndirectly()) {
permanent.phaseIn(game);
}
} }
} }