From d2aeabc3747604456df1bdacbf40d92738d8c98d Mon Sep 17 00:00:00 2001 From: BetaSteward Date: Fri, 30 Sep 2011 09:00:29 -0400 Subject: [PATCH] fixed life total exchanging to allow for rules 118.7, 118.8 --- .../sets/magic2011/LeylineOfPunishment.java | 30 ++++++------- .../mage/sets/newphyrexia/SoulConduit.java | 14 +++++++ Mage/src/mage/players/Player.java | 6 ++- Mage/src/mage/players/PlayerImpl.java | 42 +++++++++++++++---- 4 files changed, 68 insertions(+), 24 deletions(-) diff --git a/Mage.Sets/src/mage/sets/magic2011/LeylineOfPunishment.java b/Mage.Sets/src/mage/sets/magic2011/LeylineOfPunishment.java index 0d64973570..1f8cda1bfb 100644 --- a/Mage.Sets/src/mage/sets/magic2011/LeylineOfPunishment.java +++ b/Mage.Sets/src/mage/sets/magic2011/LeylineOfPunishment.java @@ -31,17 +31,21 @@ package mage.sets.magic2011; import java.util.UUID; import mage.Constants.CardType; import mage.Constants.Duration; +import mage.Constants.Layer; import mage.Constants.Outcome; import mage.Constants.Rarity; +import mage.Constants.SubLayer; import mage.Constants.Zone; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.ReplacementEffectImpl; import mage.abilities.keyword.LeylineAbility; import mage.cards.CardImpl; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.events.GameEvent.EventType; +import mage.players.Player; /** * @@ -69,10 +73,10 @@ public class LeylineOfPunishment extends CardImpl { } -class LeylineOfPunishmentEffect1 extends ReplacementEffectImpl { +class LeylineOfPunishmentEffect1 extends ContinuousEffectImpl { public LeylineOfPunishmentEffect1() { - super(Duration.WhileOnBattlefield, Outcome.Benefit); + super(Duration.WhileOnBattlefield, Layer.PlayerEffects, SubLayer.NA, Outcome.Benefit); staticText = "Players can't gain life"; } @@ -87,19 +91,15 @@ class LeylineOfPunishmentEffect1 extends ReplacementEffectImpl { int lifePlayer1 = player1.getLife(); int lifePlayer2 = player2.getLife(); + if (lifePlayer1 == lifePlayer2) + return false; + + if (!player1.isLifeTotalCanChange() || !player2.isLifeTotalCanChange()) + return false; + + // 20110930 - 118.7, 118.8 + if (lifePlayer1 < lifePlayer2 && (!player1.isCanGainLife() || !player2.isCanLoseLife())) + return false; + + if (lifePlayer1 > lifePlayer2 && (!player1.isCanLoseLife() || !player2.isCanGainLife())) + return false; + player1.setLife(lifePlayer2, game); player2.setLife(lifePlayer1, game); + return true; } return false; } diff --git a/Mage/src/mage/players/Player.java b/Mage/src/mage/players/Player.java index a87045d9e1..c83c2ee7c5 100644 --- a/Mage/src/mage/players/Player.java +++ b/Mage/src/mage/players/Player.java @@ -84,7 +84,11 @@ public interface Player extends MageItem, Copyable { public int getLife(); public void setLife(int life, Game game); public int loseLife(int amount, Game game); - public void gainLife(int amount, Game game); + public boolean isCanLoseLife(); + public void setCanLoseLife(boolean canLoseLife); + public int gainLife(int amount, Game game); + public boolean isCanGainLife(); + public void setCanGainLife(boolean canGainLife); public boolean isLifeTotalCanChange(); public void setLifeTotalCanChange(boolean lifeTotalCanChange); public int damage(int damage, UUID sourceId, Game game, boolean combatDamage, boolean preventable); diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index ad6529b6bf..0c019b8dcc 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -102,7 +102,6 @@ public abstract class PlayerImpl> implements Player, Ser protected RangeOfInfluence range; protected Set inRange = new HashSet(); protected boolean isTestMode = false; - protected boolean lifeTotalCanChange = true; protected boolean canGainLife = true; protected boolean canLoseLife = true; protected boolean isGameUnderControl = true; @@ -154,7 +153,8 @@ public abstract class PlayerImpl> implements Player, Ser this.passedTurn = player.passedTurn; this.left = player.left; this.range = player.range; - this.lifeTotalCanChange = player.lifeTotalCanChange; + this.canGainLife = player.canGainLife; + this.canLoseLife = player.canLoseLife; for (UUID id: player.inRange) { this.inRange.add(id); } @@ -186,6 +186,8 @@ public abstract class PlayerImpl> implements Player, Ser this.left = false; this.passed = false; this.passedTurn = false; + this.canGainLife = true; + this.canLoseLife = true; Watcher bloodthirst = new BloodthirstWatcher(); bloodthirst.setControllerId(playerId); game.getState().getWatchers().add(bloodthirst); @@ -196,7 +198,8 @@ public abstract class PlayerImpl> implements Player, Ser this.abilities.clear(); this.landsPerTurn = 1; this.maxHandSize = 7; - this.lifeTotalCanChange = true; + this.canGainLife = true; + this.canLoseLife = true; this.topCardRevealed = false; } @@ -808,17 +811,28 @@ public abstract class PlayerImpl> implements Player, Ser @Override public void setLifeTotalCanChange(boolean lifeTotalCanChange) { - this.lifeTotalCanChange = lifeTotalCanChange; + this.canGainLife = lifeTotalCanChange; + this.canLoseLife = lifeTotalCanChange; } @Override public boolean isLifeTotalCanChange() { - return this.lifeTotalCanChange; + return canGainLife | canLoseLife; } + @Override + public boolean isCanLoseLife() { + return canLoseLife; + } + + @Override + public void setCanLoseLife(boolean canLoseLife) { + this.canLoseLife = canLoseLife; + } + @Override public int loseLife(int amount, Game game) { - if (!lifeTotalCanChange) return 0; + if (!canLoseLife) return 0; GameEvent event = new GameEvent(GameEvent.EventType.LOSE_LIFE, playerId, playerId, playerId, amount, false); if (!game.replaceEvent(event)) { this.life -= amount; @@ -827,15 +841,27 @@ public abstract class PlayerImpl> implements Player, Ser } return 0; } + + @Override + public boolean isCanGainLife() { + return canGainLife; + } + @Override + public void setCanGainLife(boolean canGainLife) { + this.canGainLife = canGainLife; + } + @Override - public void gainLife(int amount, Game game) { - if (!lifeTotalCanChange) return; + public int gainLife(int amount, Game game) { + if (!canGainLife) return 0; GameEvent event = new GameEvent(GameEvent.EventType.GAIN_LIFE, playerId, playerId, playerId, amount, false); if (!game.replaceEvent(event)) { this.life += amount; game.fireEvent(GameEvent.getEvent(GameEvent.EventType.GAINED_LIFE, playerId, playerId, playerId, amount)); + return amount; } + return 0; } @Override