* Added logic to remove control effects that refer to permanents of a player that leaves the game.

This commit is contained in:
LevelX2 2016-12-18 16:57:34 +01:00
parent da9e9a1180
commit d85b9943f1
3 changed files with 167 additions and 0 deletions

View file

@ -1066,6 +1066,10 @@ public class ContinuousEffects implements Serializable {
}
}
public HashSet<Ability> getLayeredEffectAbilities(ContinuousEffect effect) {
return layeredEffects.getAbility(effect.getId());
}
/**
* Adds a continuous ability with a reference to a sourceId. It's used for
* effects that cease to exist again So this effects were removed again

View file

@ -72,6 +72,7 @@ import mage.cards.decks.Deck;
import mage.choices.Choice;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.MultiplayerAttackOption;
import mage.constants.Outcome;
import mage.constants.PhaseStep;
@ -2321,6 +2322,23 @@ public abstract class GameImpl implements Game, Serializable {
perm.removeFromCombat(this, true);
}
it.remove();
} else if (perm.getControllerId().equals(player.getId())) {
// and any effects which give that player control of any objects or players end
Effects:
for (ContinuousEffect effect : getContinuousEffects().getLayeredEffects(this)) {
if (effect.hasLayer(Layer.ControlChangingEffects_2)) {
for (Ability ability : getContinuousEffects().getLayeredEffectAbilities(effect)) {
for (Target target : ability.getTargets()) {
for (UUID targetId : target.getTargets()) {
if (targetId.equals(perm.getId())) {
effect.discard();
continue Effects;
}
}
}
}
}
}
}
}
// Then, if that player controlled any objects on the stack not represented by cards, those objects cease to exist.
@ -2332,6 +2350,7 @@ public abstract class GameImpl implements Game, Serializable {
}
}
// Then, if there are any objects still controlled by that player, those objects are exiled.
applyEffects(); // to remove control from effects removed meanwhile
List<Permanent> permanents = this.getBattlefield().getAllActivePermanents(playerId);
for (Permanent permanent : permanents) {
permanent.moveToExile(null, "", null, this);