From 238e31dcac983a167da9f356a34c1732855149ea Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Tue, 18 Feb 2014 14:41:00 +0100 Subject: [PATCH] Added GainLiverPlayersCost and GainLiveOpponentCost. --- .../common/ControlsPermanentCondition.java | 4 + .../costs/common/ExileFromHandCost.java | 3 +- .../costs/common/GainLiveOpponentCost.java | 84 ++++++++++++++++ .../costs/common/GainLivePlayersCost.java | 95 +++++++++++++++++++ 4 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 Mage/src/mage/abilities/costs/common/GainLiveOpponentCost.java create mode 100644 Mage/src/mage/abilities/costs/common/GainLivePlayersCost.java diff --git a/Mage/src/mage/abilities/condition/common/ControlsPermanentCondition.java b/Mage/src/mage/abilities/condition/common/ControlsPermanentCondition.java index b3121f82b57..993c4bc5ea9 100644 --- a/Mage/src/mage/abilities/condition/common/ControlsPermanentCondition.java +++ b/Mage/src/mage/abilities/condition/common/ControlsPermanentCondition.java @@ -68,6 +68,8 @@ public class ControlsPermanentCondition implements Condition { * {@link #apply(mage.game.Game, mage.abilities.Ability) apply} method invocation. * * @param filter + * @param type + * @param count */ public ControlsPermanentCondition ( FilterPermanent filter, CountType type, int count ) { this.filter = filter; @@ -82,6 +84,8 @@ public class ControlsPermanentCondition implements Condition { * as well. This will force both conditions to apply for this to be true. * * @param filter + * @param type + * @param count * @param conditionToDecorate */ public ControlsPermanentCondition ( FilterPermanent filter, CountType type, int count, Condition conditionToDecorate ) { diff --git a/Mage/src/mage/abilities/costs/common/ExileFromHandCost.java b/Mage/src/mage/abilities/costs/common/ExileFromHandCost.java index f0553648281..48a3ecfd2ff 100644 --- a/Mage/src/mage/abilities/costs/common/ExileFromHandCost.java +++ b/Mage/src/mage/abilities/costs/common/ExileFromHandCost.java @@ -36,6 +36,7 @@ import mage.abilities.Ability; import mage.abilities.costs.CostImpl; import mage.cards.Card; import mage.constants.Outcome; +import mage.constants.Zone; import mage.game.Game; import mage.players.Player; import mage.target.common.TargetCardInHand; @@ -70,7 +71,7 @@ public class ExileFromHandCost extends CostImpl { return false; } this.cards.add(card.copy()); - paid |= card.moveToExile(ability.getSourceId(), "from Hand", ability.getSourceId(), game); + paid |= player.moveCardToExileWithInfo(card, null, null, ability.getSourceId(), game, Zone.HAND); } } return paid; diff --git a/Mage/src/mage/abilities/costs/common/GainLiveOpponentCost.java b/Mage/src/mage/abilities/costs/common/GainLiveOpponentCost.java new file mode 100644 index 00000000000..6c06ed6678e --- /dev/null +++ b/Mage/src/mage/abilities/costs/common/GainLiveOpponentCost.java @@ -0,0 +1,84 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package mage.abilities.costs.common; + +import java.util.UUID; +import mage.abilities.Ability; +import mage.abilities.costs.CostImpl; +import mage.constants.Outcome; +import mage.constants.TargetController; +import mage.filter.FilterPlayer; +import mage.filter.predicate.other.PlayerCanGainLifePredicate; +import mage.filter.predicate.other.PlayerPredicate; +import mage.game.Game; +import mage.players.Player; +import mage.target.TargetPlayer; + +/** + * + * @author LevelX2 + */ +public class GainLiveOpponentCost extends CostImpl { + + private static final FilterPlayer filter = new FilterPlayer("opponent that can gain life"); + + static { + filter.add(new PlayerPredicate(TargetController.OPPONENT)); + filter.add(new PlayerCanGainLifePredicate()); + } + + private final int amount; + + public GainLiveOpponentCost(int amount) { + this.amount = amount; + this.text = new StringBuilder("you may have an opponent gain ").append(amount).append(" life").toString(); + } + + public GainLiveOpponentCost(GainLiveOpponentCost cost) { + super(cost); + this.amount = cost.amount; + } + + @Override + public boolean canPay(UUID sourceId, UUID controllerId, Game game) { + Player controller = game.getPlayer(controllerId); + if (controller != null) { + for (UUID opponentId : game.getOpponents(controllerId)) { + Player player = game.getPlayer(opponentId); + if (player != null && player.isCanGainLife()) { + // at least one opponent must be able to gain life + return true; + } + } + } + return true; + } + + @Override + public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana) { + Player controller = game.getPlayer(controllerId); + if (controller != null) { + TargetPlayer target = new TargetPlayer(1, 1, true, filter); + if (controller.chooseTarget(Outcome.Detriment, target, ability, game)) { + Player opponent = game.getPlayer(target.getFirstTarget()); + if (opponent != null) { + opponent.gainLife(amount, game); + paid = true; + + } + + } + } + return paid; + } + + @Override + public GainLiveOpponentCost copy() { + return new GainLiveOpponentCost(this); + } + +} diff --git a/Mage/src/mage/abilities/costs/common/GainLivePlayersCost.java b/Mage/src/mage/abilities/costs/common/GainLivePlayersCost.java new file mode 100644 index 00000000000..8aafcca2497 --- /dev/null +++ b/Mage/src/mage/abilities/costs/common/GainLivePlayersCost.java @@ -0,0 +1,95 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ + +package mage.abilities.costs.common; + +import java.util.UUID; +import mage.abilities.Ability; +import mage.abilities.costs.CostImpl; +import mage.game.Game; +import mage.players.Player; + +/** + * + * @author LevelX2 + */ +public class GainLivePlayersCost extends CostImpl { + + private final int amount; + + public GainLivePlayersCost(int amount) { + this.amount = amount; + this.text = new StringBuilder("you may have each other player gain ").append(amount).append(" life").toString(); + } + + public GainLivePlayersCost(GainLivePlayersCost cost) { + super(cost); + this.amount = cost.amount; + } + + @Override + public boolean canPay(UUID sourceId, UUID controllerId, Game game) { + Player controller = game.getPlayer(controllerId); + if (controller != null) { + for (UUID playerId: controller.getInRange()) { + if (!playerId.equals(controllerId)) { + Player player = game.getPlayer(playerId); + if (player != null && !player.isCanGainLife()) { + // if only one other player can't gain life, the cost can't be paid + return false; + } + } + + } + } + return true; + } + + @Override + public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana) { + Player controller = game.getPlayer(controllerId); + if (controller != null) { + for (UUID playerId: controller.getInRange()) { + if (!playerId.equals(controllerId)) { + Player player = game.getPlayer(playerId); + if (player != null) { + player.gainLife(amount, game); + } + } + } + paid = true; + } + return paid; + } + + @Override + public GainLivePlayersCost copy() { + return new GainLivePlayersCost(this); + } + +}