forked from External/mage
[MH2] Implemented Carth the Lion (#7848)
* [MH2] Implemented Carth the Lion * [MH2] Carth the Lion - Fixed loyalty cost modification * Fix copy constructor and add getters/setters * Call sourceObject.adjustCosts before checking cost modifications * Add unit test * Added additional comments, checks and tests; Co-authored-by: Oleg Agafonov <jaydi85@gmail.com>
This commit is contained in:
parent
3ea08e1e7b
commit
29d3f96340
7 changed files with 353 additions and 24 deletions
|
|
@ -1,20 +1,27 @@
|
|||
|
||||
|
||||
package mage.abilities.costs.common;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.LoyaltyAbility;
|
||||
import mage.abilities.costs.Cost;
|
||||
import mage.abilities.costs.VariableCostImpl;
|
||||
import mage.counters.CounterType;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class PayVariableLoyaltyCost extends VariableCostImpl {
|
||||
public class PayVariableLoyaltyCost extends VariableCostImpl {
|
||||
|
||||
// dynamic x cost modification from effects like Carth the Lion
|
||||
// GUI only (applies to -X value on X announce)
|
||||
// Example:
|
||||
// - counters: 3
|
||||
// - cost modification: +1
|
||||
// - max possible X to pay: 4
|
||||
private int costModification = 0;
|
||||
|
||||
public PayVariableLoyaltyCost() {
|
||||
super("loyality counters to remove");
|
||||
|
|
@ -23,17 +30,18 @@ public class PayVariableLoyaltyCost extends VariableCostImpl {
|
|||
|
||||
public PayVariableLoyaltyCost(final PayVariableLoyaltyCost cost) {
|
||||
super(cost);
|
||||
this.costModification = cost.costModification;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PayVariableLoyaltyCost copy() {
|
||||
return new PayVariableLoyaltyCost(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
|
||||
Permanent planeswalker = game.getPermanent(source.getSourceId());
|
||||
return planeswalker!= null && planeswalker.canLoyaltyBeUsed(game);
|
||||
return planeswalker != null && planeswalker.canLoyaltyBeUsed(game);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -43,12 +51,33 @@ public class PayVariableLoyaltyCost extends VariableCostImpl {
|
|||
|
||||
@Override
|
||||
public int getMaxValue(Ability source, Game game) {
|
||||
int maxValue = 0;
|
||||
Permanent permanent = game.getPermanent(source.getSourceId());
|
||||
if (permanent != null) {
|
||||
maxValue = permanent.getCounters(game).getCount(CounterType.LOYALTY.getName());
|
||||
if (permanent == null) {
|
||||
return 0;
|
||||
}
|
||||
return maxValue;
|
||||
|
||||
int maxValue = permanent.getCounters(game).getCount(CounterType.LOYALTY.getName());
|
||||
|
||||
// apply cost modification
|
||||
if (source instanceof LoyaltyAbility) {
|
||||
LoyaltyAbility copiedAbility = ((LoyaltyAbility) source).copy();
|
||||
permanent.adjustCosts(copiedAbility, game);
|
||||
game.getContinuousEffects().costModification(copiedAbility, game);
|
||||
for (Cost cost : copiedAbility.getCosts()) {
|
||||
if (cost instanceof PayVariableLoyaltyCost) {
|
||||
maxValue += ((PayVariableLoyaltyCost) cost).getCostModification();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Math.max(0, maxValue);
|
||||
}
|
||||
|
||||
public int getCostModification() {
|
||||
return costModification;
|
||||
}
|
||||
|
||||
public void setCostModification(int costModification) {
|
||||
this.costModification = costModification;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue