changed how phasing is handled

This commit is contained in:
Evan Kranzler 2017-10-10 13:35:41 -04:00
parent 51f0e92103
commit 3d20e4dbef
5 changed files with 41 additions and 17 deletions

View file

@ -55,8 +55,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,12 +111,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()) { for (UUID permanentId : target.getTargets()) {
Permanent permanent = game.getPermanent(permanentId); Permanent permanent = game.getPermanent(permanentId);
if (permanent != null) { if (permanent != null) {
permanent.phaseOut(game); permanent.phaseOut(game);

View file

@ -171,7 +171,11 @@ class TeferisProtectionPhaseOutEffect extends OneShotEffect {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (controller != null) { if (controller != null) {
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); 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);
}
} }
return true; return true;
} }

View file

@ -78,9 +78,11 @@ 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 indirectPhase); boolean phaseIn(Game game, boolean onlyDirect);
boolean phaseOut(Game game); boolean phaseOut(Game game);

View file

@ -464,18 +464,31 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
} }
@Override @Override
public boolean phaseIn(Game game) { public boolean isPhasedOutIndirectly() {
return phaseIn(game, false); return !phasedIn && indirectPhase;
} }
@Override @Override
public boolean phaseIn(Game game, boolean indirectPhase) { 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;
} }
@ -492,7 +505,14 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
public boolean phaseOut(Game game, boolean indirectPhase) { 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);
}
} }
} }