Fix “an opponent gains life” costs worded as optional

This commit is contained in:
Fenhl 2016-04-14 11:09:38 +00:00
parent 41ba4c9540
commit eca6ccd6bd

View file

@ -1,85 +1,85 @@
/* /*
* To change this license header, choose License Headers in Project Properties. * To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates * To change this template file, choose Tools | Templates
* and open the template in the editor. * and open the template in the editor.
*/ */
package mage.abilities.costs.common; package mage.abilities.costs.common;
import java.util.UUID; import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.costs.Cost; import mage.abilities.costs.Cost;
import mage.abilities.costs.CostImpl; import mage.abilities.costs.CostImpl;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.TargetController; import mage.constants.TargetController;
import mage.filter.FilterPlayer; import mage.filter.FilterPlayer;
import mage.filter.predicate.other.PlayerCanGainLifePredicate; import mage.filter.predicate.other.PlayerCanGainLifePredicate;
import mage.filter.predicate.other.PlayerPredicate; import mage.filter.predicate.other.PlayerPredicate;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.target.TargetPlayer; import mage.target.TargetPlayer;
/** /**
* *
* @author LevelX2 * @author LevelX2
*/ */
public class GainLifeOpponentCost extends CostImpl { public class GainLifeOpponentCost extends CostImpl {
private static final FilterPlayer filter = new FilterPlayer("opponent that can gain life"); private static final FilterPlayer filter = new FilterPlayer("opponent that can gain life");
static { static {
filter.add(new PlayerPredicate(TargetController.OPPONENT)); filter.add(new PlayerPredicate(TargetController.OPPONENT));
filter.add(new PlayerCanGainLifePredicate()); // you can't pay the costs by letting a player gain life that can't get life by rule changing effect filter.add(new PlayerCanGainLifePredicate()); // you can't pay the costs by letting a player gain life that can't get life by rule changing effect
} }
private final int amount; private final int amount;
public GainLifeOpponentCost(int amount) { public GainLifeOpponentCost(int amount) {
this.amount = amount; this.amount = amount;
this.text = new StringBuilder("you may have an opponent gain ").append(amount).append(" life").toString(); this.text = new StringBuilder("an opponent gains ").append(amount).append(" life").toString();
} }
public GainLifeOpponentCost(GainLifeOpponentCost cost) { public GainLifeOpponentCost(GainLifeOpponentCost cost) {
super(cost); super(cost);
this.amount = cost.amount; this.amount = cost.amount;
} }
@Override @Override
public boolean canPay(Ability ability, UUID sourceId, UUID controllerId, Game game) { public boolean canPay(Ability ability, UUID sourceId, UUID controllerId, Game game) {
Player controller = game.getPlayer(controllerId); Player controller = game.getPlayer(controllerId);
if (controller != null) { if (controller != null) {
for (UUID opponentId : game.getOpponents(controllerId)) { for (UUID opponentId : game.getOpponents(controllerId)) {
Player player = game.getPlayer(opponentId); Player player = game.getPlayer(opponentId);
if (player != null && player.isCanGainLife()) { if (player != null && player.isCanGainLife()) {
// at least one opponent must be able to gain life // at least one opponent must be able to gain life
return true; return true;
} }
} }
} }
return true; return true;
} }
@Override @Override
public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana, Cost costToPay) { public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana, Cost costToPay) {
Player controller = game.getPlayer(controllerId); Player controller = game.getPlayer(controllerId);
if (controller != null) { if (controller != null) {
TargetPlayer target = new TargetPlayer(1, 1, true, filter); TargetPlayer target = new TargetPlayer(1, 1, true, filter);
if (controller.chooseTarget(Outcome.Detriment, target, ability, game)) { if (controller.chooseTarget(Outcome.Detriment, target, ability, game)) {
Player opponent = game.getPlayer(target.getFirstTarget()); Player opponent = game.getPlayer(target.getFirstTarget());
if (opponent != null) { if (opponent != null) {
opponent.gainLife(amount, game); opponent.gainLife(amount, game);
paid = true; paid = true;
} }
} }
} }
return paid; return paid;
} }
@Override @Override
public GainLifeOpponentCost copy() { public GainLifeOpponentCost copy() {
return new GainLifeOpponentCost(this); return new GainLifeOpponentCost(this);
} }
} }