fixed life total exchanging to allow for rules 118.7, 118.8

This commit is contained in:
BetaSteward 2011-09-30 09:00:29 -04:00
parent c66fb996b8
commit d2aeabc374
4 changed files with 68 additions and 24 deletions

View file

@ -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<LeylineOfPunishment> {
}
class LeylineOfPunishmentEffect1 extends ReplacementEffectImpl<LeylineOfPunishmentEffect1> {
class LeylineOfPunishmentEffect1 extends ContinuousEffectImpl<LeylineOfPunishmentEffect1> {
public LeylineOfPunishmentEffect1() {
super(Duration.WhileOnBattlefield, Outcome.Benefit);
super(Duration.WhileOnBattlefield, Layer.PlayerEffects, SubLayer.NA, Outcome.Benefit);
staticText = "Players can't gain life";
}
@ -87,17 +91,13 @@ class LeylineOfPunishmentEffect1 extends ReplacementEffectImpl<LeylineOfPunishme
@Override
public boolean apply(Game game, Ability source) {
return true;
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
for (UUID playerId: controller.getInRange()) {
Player player = game.getPlayer(playerId);
if (player != null)
player.setCanGainLife(false);
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
return true;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == EventType.GAIN_LIFE) {
return true;
}
return false;

View file

@ -94,8 +94,22 @@ class SoulConduitEffect extends OneShotEffect<SoulConduitEffect> {
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;
}

View file

@ -84,7 +84,11 @@ public interface Player extends MageItem, Copyable<Player> {
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);

View file

@ -102,7 +102,6 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
protected RangeOfInfluence range;
protected Set<UUID> inRange = new HashSet<UUID>();
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<T extends PlayerImpl<T>> 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<T extends PlayerImpl<T>> 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<T extends PlayerImpl<T>> 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<T extends PlayerImpl<T>> 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;
@ -829,13 +843,25 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
}
@Override
public void gainLife(int amount, Game game) {
if (!lifeTotalCanChange) return;
public boolean isCanGainLife() {
return canGainLife;
}
@Override
public void setCanGainLife(boolean canGainLife) {
this.canGainLife = canGainLife;
}
@Override
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