mirror of
https://github.com/magefree/mage.git
synced 2025-12-27 22:12:03 -08:00
implement [MH3] Jolted Away
This commit is contained in:
parent
8e3b8f0368
commit
6efdce1e4e
4 changed files with 71 additions and 9 deletions
|
|
@ -4,6 +4,8 @@ package mage.abilities.costs.common;
|
|||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.Cost;
|
||||
import mage.abilities.costs.CostImpl;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.dynamicvalue.common.StaticValue;
|
||||
import mage.counters.CounterType;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
|
|
@ -11,18 +13,20 @@ import mage.util.CardUtil;
|
|||
|
||||
import java.util.UUID;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author emerald000
|
||||
*/
|
||||
public class PayEnergyCost extends CostImpl {
|
||||
|
||||
private final int amount;
|
||||
private final DynamicValue amount;
|
||||
|
||||
public PayEnergyCost(int amount) {
|
||||
this(StaticValue.get(amount), makeText(amount));
|
||||
}
|
||||
|
||||
public PayEnergyCost(DynamicValue amount, String text) {
|
||||
this.amount = amount;
|
||||
this.text = makeText(amount);
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public PayEnergyCost(PayEnergyCost cost) {
|
||||
|
|
@ -33,14 +37,16 @@ public class PayEnergyCost extends CostImpl {
|
|||
@Override
|
||||
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
|
||||
Player player = game.getPlayer(controllerId);
|
||||
return player != null && player.getCountersCount(CounterType.ENERGY) >= amount;
|
||||
int energyToPayAmount = amount.calculate(game, ability, null);
|
||||
return player != null && player.getCountersCount(CounterType.ENERGY) >= energyToPayAmount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
|
||||
Player player = game.getPlayer(controllerId);
|
||||
if (player != null && player.getCountersCount(CounterType.ENERGY) >= amount) {
|
||||
player.loseCounters(CounterType.ENERGY.getName(), amount, source, game);
|
||||
int energyToPayAmount = amount.calculate(game, ability, null);
|
||||
if (player != null && player.getCountersCount(CounterType.ENERGY) >= energyToPayAmount) {
|
||||
player.loseCounters(CounterType.ENERGY.getName(), energyToPayAmount, source, game);
|
||||
paid = true;
|
||||
}
|
||||
return paid;
|
||||
|
|
|
|||
|
|
@ -35,16 +35,20 @@ public class PayLifeCost extends CostImpl {
|
|||
|
||||
@Override
|
||||
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
|
||||
Player player = game.getPlayer(controllerId);
|
||||
if (player == null) {
|
||||
return false;
|
||||
}
|
||||
//118.4. If a cost or effect allows a player to pay an amount of life greater than 0,
|
||||
//the player may do so only if their life total is greater than or equal to the
|
||||
//amount of the payment. If a player pays life, the payment is subtracted from their
|
||||
//life total; in other words, the player loses that much life. (Players can always pay 0 life.)
|
||||
int lifeToPayAmount = amount.calculate(game, ability, null);
|
||||
// Paying 0 life is not considered paying any life.
|
||||
if (lifeToPayAmount > 0 && !game.getPlayer(controllerId).canPayLifeCost(ability)) {
|
||||
if (lifeToPayAmount > 0 && !player.canPayLifeCost(ability)) {
|
||||
return false;
|
||||
}
|
||||
return game.getPlayer(controllerId).getLife() >= lifeToPayAmount || lifeToPayAmount == 0;
|
||||
return player.getLife() >= lifeToPayAmount || lifeToPayAmount == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue