foul-magics/Mage/src/main/java/mage/abilities/costs/common/PayLoyaltyCost.java
Evan Kranzler a535cb5adc
Refactoring methods which add counters to track which player adds the counters (ready for review) (#7448)
* added parameter for player adding counters to players

* added parameter for player adding counters to cards/permanents

* updated methods to use new parameter

* fixed a few initial errors

* refactored instances of cards that add counters by a player other than the controller

* fixed some instances of incorrect arguments

* refactored abilities that trigger off of a particular player adding counters

* a few more cards that were missed

* [KHM] Implemented Vorinclex, Monstrous Raider

* added test for Vorinclex, Monstrous Raider

* fixed a test failure
2021-01-26 19:06:13 -05:00

68 lines
2.3 KiB
Java

package mage.abilities.costs.common;
import mage.abilities.Ability;
import mage.abilities.costs.Cost;
import mage.abilities.costs.CostImpl;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class PayLoyaltyCost extends CostImpl {
private final int amount;
public PayLoyaltyCost(int amount) {
this.amount = amount;
this.text = Integer.toString(amount);
if (amount > 0) {
this.text = '+' + this.text;
}
}
public PayLoyaltyCost(PayLoyaltyCost cost) {
super(cost);
this.amount = cost.amount;
}
@Override
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
Permanent planeswalker = game.getPermanent(source.getSourceId());
return planeswalker != null && planeswalker.getCounters(game).getCount(CounterType.LOYALTY) + amount >= 0 && planeswalker.canLoyaltyBeUsed(game);
}
/**
* Gatherer Ruling: 10/1/2005: Planeswalkers will enter the battlefield with
* double the normal amount of loyalty counters. However, if you activate an
* ability whose cost has you put loyalty counters on a planeswalker, the
* number you put on isn't doubled. This is because those counters are put
* on as a cost, not as an effect.
*
*/
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
Permanent planeswalker = game.getPermanent(source.getSourceId());
if (planeswalker != null && planeswalker.getCounters(game).getCount(CounterType.LOYALTY) + amount >= 0 && planeswalker.canLoyaltyBeUsed(game)) {
if (amount > 0) {
planeswalker.addCounters(CounterType.LOYALTY.createInstance(amount), source.getControllerId(), ability, game, false);
} else if (amount < 0) {
planeswalker.removeCounters(CounterType.LOYALTY.getName(), Math.abs(amount), source, game);
}
planeswalker.addLoyaltyUsed();
this.paid = true;
}
return paid;
}
@Override
public PayLoyaltyCost copy() {
return new PayLoyaltyCost(this);
}
}