mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 21:12:04 -08:00
[NCC] Implemented Gavel of the Righteous
This commit is contained in:
parent
6fd4b46ca8
commit
3e0f305e0b
5 changed files with 159 additions and 15 deletions
|
|
@ -3,12 +3,19 @@ package mage.abilities.costs.common;
|
|||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.Cost;
|
||||
import mage.abilities.costs.CostImpl;
|
||||
import mage.choices.Choice;
|
||||
import mage.choices.ChoiceImpl;
|
||||
import mage.constants.Outcome;
|
||||
import mage.counters.Counter;
|
||||
import mage.counters.CounterType;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.util.CardUtil;
|
||||
import mage.util.RandomUtil;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
|
@ -20,15 +27,18 @@ public class RemoveCountersSourceCost extends CostImpl {
|
|||
private final String name;
|
||||
|
||||
public RemoveCountersSourceCost(Counter counter) {
|
||||
this.amount = counter.getCount();
|
||||
this.name = counter.getName();
|
||||
this.text = new StringBuilder("remove ").append((amount == 1 ? CounterType.findArticle(counter.getName()) : CardUtil.numberToText(amount)))
|
||||
.append(' ').append(name).append(" counter").append((amount != 1 ? "s" : ""))
|
||||
this.amount = counter != null ? counter.getCount() : 1;
|
||||
this.name = counter != null ? counter.getName() : "";
|
||||
this.text = new StringBuilder("remove ")
|
||||
.append((amount == 1 ? CounterType.findArticle(counter.getName()) : CardUtil.numberToText(amount)))
|
||||
.append(name.isEmpty() ? "" : (' ' + name))
|
||||
.append(" counter")
|
||||
.append((amount != 1 ? "s" : ""))
|
||||
.append(" from {this}").toString();
|
||||
|
||||
}
|
||||
|
||||
public RemoveCountersSourceCost(RemoveCountersSourceCost cost) {
|
||||
private RemoveCountersSourceCost(RemoveCountersSourceCost cost) {
|
||||
super(cost);
|
||||
this.amount = cost.amount;
|
||||
this.name = cost.name;
|
||||
|
|
@ -42,9 +52,41 @@ public class RemoveCountersSourceCost extends CostImpl {
|
|||
|
||||
@Override
|
||||
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
|
||||
Permanent permanent = game.getPermanent(source.getSourceId());
|
||||
if (permanent != null && permanent.getCounters(game).getCount(name) >= amount) {
|
||||
permanent.removeCounters(name, amount, source, game);
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
|
||||
if (player == null || permanent == null) {
|
||||
return paid;
|
||||
}
|
||||
String toRemove;
|
||||
if (name.isEmpty()) {
|
||||
Set<String> toChoose = permanent.getCounters(game).keySet();
|
||||
switch (toChoose.size()) {
|
||||
case 0:
|
||||
return paid;
|
||||
case 1:
|
||||
toRemove = RandomUtil.randomFromCollection(toChoose);
|
||||
break;
|
||||
case 2:
|
||||
Iterator<String> iterator = toChoose.iterator();
|
||||
String choice1 = iterator.next();
|
||||
String choice2 = iterator.next();
|
||||
toRemove = player.chooseUse(
|
||||
Outcome.UnboostCreature, "Choose a type of counter to remove",
|
||||
null, choice1, choice2, source, game
|
||||
) ? choice1 : choice2;
|
||||
break;
|
||||
default:
|
||||
Choice choice = new ChoiceImpl(true);
|
||||
choice.setChoices(toChoose);
|
||||
choice.setMessage("Choose a type of counter to remove");
|
||||
player.choose(Outcome.UnboostCreature, choice, game);
|
||||
toRemove = choice.getChoice();
|
||||
}
|
||||
} else {
|
||||
toRemove = name;
|
||||
}
|
||||
if (permanent.getCounters(game).getCount(toRemove) >= amount) {
|
||||
permanent.removeCounters(toRemove, amount, source, game);
|
||||
this.paid = true;
|
||||
}
|
||||
return paid;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package mage.abilities.dynamicvalue.common;
|
|||
import mage.abilities.Ability;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.counters.Counter;
|
||||
import mage.counters.CounterType;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
|
@ -15,14 +16,25 @@ public class CountersSourceCount implements DynamicValue {
|
|||
this.counterType = counterType;
|
||||
}
|
||||
|
||||
public CountersSourceCount(final CountersSourceCount countersCount) {
|
||||
protected CountersSourceCount(final CountersSourceCount countersCount) {
|
||||
this.counterType = countersCount.counterType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int calculate(Game game, Ability sourceAbility, Effect effect) {
|
||||
Permanent permanent = sourceAbility.getSourcePermanentOrLKI(game);
|
||||
return permanent != null ? permanent.getCounters(game).getCount(counterType) : 0;
|
||||
if (permanent == null) {
|
||||
return 0;
|
||||
}
|
||||
return counterType != null
|
||||
? permanent
|
||||
.getCounters(game)
|
||||
.getCount(counterType)
|
||||
: permanent
|
||||
.getCounters(game)
|
||||
.values()
|
||||
.stream()
|
||||
.mapToInt(Counter::getCount).sum();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -37,6 +49,6 @@ public class CountersSourceCount implements DynamicValue {
|
|||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return counterType + " counter on {this}";
|
||||
return (counterType != null ? counterType.toString() + ' ' : "") + "counter on {this}";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue