From d7b7f6c23417db6076fac8424acf1d6397af73ad Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Wed, 28 Aug 2013 15:11:17 +0200 Subject: [PATCH] * Detain effect - Fixed that detained permanents stayed detained until end of game if the controller of the detain effect left/lost the game before detain effect did end (fixes #304). --- .../effects/common/DetainAllEffect.java | 4 ++-- .../effects/common/DetainTargetEffect.java | 3 +-- Mage/src/mage/players/Player.java | 3 +++ Mage/src/mage/players/PlayerImpl.java | 21 +++++++++++++++++-- Mage/src/mage/players/PlayerList.java | 15 +++++++++---- 5 files changed, 36 insertions(+), 10 deletions(-) diff --git a/Mage/src/mage/abilities/effects/common/DetainAllEffect.java b/Mage/src/mage/abilities/effects/common/DetainAllEffect.java index d14f4ace98..301c27866d 100644 --- a/Mage/src/mage/abilities/effects/common/DetainAllEffect.java +++ b/Mage/src/mage/abilities/effects/common/DetainAllEffect.java @@ -114,7 +114,7 @@ class DetainAllRestrictionEffect extends RestrictionEffect public boolean isInactive(Ability source, Game game) { if (game.getPhase().getStep().getType() == PhaseStep.UNTAP && game.getStep().getStepPart() == Step.StepPart.PRE) { - if (game.getActivePlayerId().equals(source.getControllerId())) { + if (game.getActivePlayerId().equals(source.getControllerId()) || game.getPlayer(source.getControllerId()).hasReachedNextTurnAfterLeaving()) { for(UUID targetId :this.getTargetPointer().getTargets(game, source)) { Permanent permanent = game.getPermanent(targetId); if (permanent != null) { diff --git a/Mage/src/mage/players/Player.java b/Mage/src/mage/players/Player.java index 71ed740467..06d39fc238 100644 --- a/Mage/src/mage/players/Player.java +++ b/Mage/src/mage/players/Player.java @@ -315,4 +315,7 @@ public interface Player extends MageItem, Copyable { * @return */ int getPriorityTimeLeft(); + + void setReachedNextTurnAfterLeaving(boolean reachedNextTurnAfterLeaving); + boolean hasReachedNextTurnAfterLeaving(); } diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index e4217c96db..b1fcac2e71 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -29,7 +29,6 @@ package mage.players; import java.io.Serializable; -import java.security.InvalidParameterException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -110,7 +109,6 @@ import mage.target.common.TargetCardInLibrary; import mage.target.common.TargetDiscard; import mage.watchers.common.BloodthirstWatcher; import org.apache.log4j.Logger; -import org.omg.CORBA.DynAnyPackage.Invalid; public abstract class PlayerImpl> implements Player, Serializable { @@ -170,6 +168,11 @@ public abstract class PlayerImpl> implements Player, Ser protected List attachments = new ArrayList(); protected boolean topCardRevealed = false; + + // 800.4i When a player leaves the game, any continuous effects with durations that last until that player's next turn + // or until a specific point in that turn will last until that turn would have begun. + // They neither expire immediately nor last indefinitely. + protected boolean reachedNextTurnAfterLeaving = false; protected UserData userData; @@ -241,6 +244,7 @@ public abstract class PlayerImpl> implements Player, Ser this.passedTurn = player.passedTurn; this.passedAllTurns = player.passedAllTurns; this.priorityTimeLeft = player.getPriorityTimeLeft(); + this.reachedNextTurnAfterLeaving = player.reachedNextTurnAfterLeaving; } @Override @@ -288,6 +292,7 @@ public abstract class PlayerImpl> implements Player, Ser this.turnController = player.getTurnControlledBy(); this.passed = player.isPassed(); this.priorityTimeLeft = player.getPriorityTimeLeft(); + this.reachedNextTurnAfterLeaving = player.hasReachedNextTurnAfterLeaving(); } @Override @@ -326,7 +331,9 @@ public abstract class PlayerImpl> implements Player, Ser this.canLoseLife = true; this.topCardRevealed = false; this.setLife(game.getLife(), game); + this.setReachedNextTurnAfterLeaving(false); game.getState().getWatchers().add(new BloodthirstWatcher(playerId)); + } @Override @@ -2004,4 +2011,14 @@ public abstract class PlayerImpl> implements Player, Ser return quit; } + @Override + public void setReachedNextTurnAfterLeaving(boolean reachedNextTurnAfterLeaving) { + this.reachedNextTurnAfterLeaving = reachedNextTurnAfterLeaving; + } + + @Override + public boolean hasReachedNextTurnAfterLeaving() { + return reachedNextTurnAfterLeaving; + } + } diff --git a/Mage/src/mage/players/PlayerList.java b/Mage/src/mage/players/PlayerList.java index efc2711a7d..eea5d91638 100644 --- a/Mage/src/mage/players/PlayerList.java +++ b/Mage/src/mage/players/PlayerList.java @@ -49,10 +49,15 @@ public class PlayerList extends CircularList { UUID start = this.get(); while (true) { player = game.getPlayer(super.getNext()); - if (!player.hasLeft() && !player.hasLost()) + if (!player.hasLeft() && !player.hasLost()) { + if (!player.hasReachedNextTurnAfterLeaving()) { + player.setReachedNextTurnAfterLeaving(true); + } break; - if (player.getId().equals(start)) + } + if (player.getId().equals(start)) { return null; + } } return player; } @@ -62,10 +67,12 @@ public class PlayerList extends CircularList { UUID start = this.get(); while (true) { player = game.getPlayer(super.getPrevious()); - if (!player.hasLeft() && !player.hasLost()) + if (!player.hasLeft() && !player.hasLost()) { break; - if (player.getId().equals(start)) + } + if (player.getId().equals(start)) { return null; + } } return player; }