mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
remove gui calls from add/remove counters effects
This commit is contained in:
@@ -12,7 +12,6 @@ import forge.game.spellability.SpellAbility;
|
|||||||
import forge.game.trigger.TriggerType;
|
import forge.game.trigger.TriggerType;
|
||||||
import forge.game.zone.Zone;
|
import forge.game.zone.Zone;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
import forge.gui.GuiChoose;
|
|
||||||
|
|
||||||
public class CountersPutEffect extends SpellAbilityEffect {
|
public class CountersPutEffect extends SpellAbilityEffect {
|
||||||
@Override
|
@Override
|
||||||
@@ -78,22 +77,13 @@ public class CountersPutEffect extends SpellAbilityEffect {
|
|||||||
final int max = sa.hasParam("MaxFromEffect") ? Integer.parseInt(sa.getParam("MaxFromEffect")) : -1;
|
final int max = sa.hasParam("MaxFromEffect") ? Integer.parseInt(sa.getParam("MaxFromEffect")) : -1;
|
||||||
|
|
||||||
if (sa.hasParam("UpTo")) {
|
if (sa.hasParam("UpTo")) {
|
||||||
final Integer[] integers = new Integer[counterAmount + 1];
|
counterAmount = sa.getActivatingPlayer().getController().chooseNumber(sa, "How many counters?", 0, counterAmount);
|
||||||
for (int j = 0; j <= counterAmount; j++) {
|
|
||||||
integers[j] = Integer.valueOf(j);
|
|
||||||
}
|
|
||||||
final Integer i = GuiChoose.oneOrNone("How many counters?", integers);
|
|
||||||
if (null == i) {
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
counterAmount = i.intValue();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Card> tgtCards = getDefinedCardsOrTargeted(sa);
|
List<Card> tgtCards = getDefinedCardsOrTargeted(sa);
|
||||||
|
|
||||||
for (final Card tgtCard : tgtCards) {
|
for (final Card tgtCard : tgtCards) {
|
||||||
counterAmount = (sa.usesTargeting() && sa.hasParam("DividedAsYouChoose")) ? sa.getTargetRestrictions().getDividedValue(tgtCard) : counterAmount;
|
counterAmount = sa.usesTargeting() && sa.hasParam("DividedAsYouChoose") ? sa.getTargetRestrictions().getDividedValue(tgtCard) : counterAmount;
|
||||||
if (!sa.usesTargeting() || tgtCard.canBeTargetedBy(sa)) {
|
if (!sa.usesTargeting() || tgtCard.canBeTargetedBy(sa)) {
|
||||||
if (max != -1) {
|
if (max != -1) {
|
||||||
counterAmount = max - tgtCard.getCounters(counterType);
|
counterAmount = max - tgtCard.getCounters(counterType);
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package forge.game.ability.effects;
|
package forge.game.ability.effects;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import forge.game.Game;
|
import forge.game.Game;
|
||||||
@@ -9,11 +7,11 @@ import forge.game.ability.AbilityUtils;
|
|||||||
import forge.game.ability.SpellAbilityEffect;
|
import forge.game.ability.SpellAbilityEffect;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
import forge.game.card.CounterType;
|
import forge.game.card.CounterType;
|
||||||
|
import forge.game.player.PlayerController;
|
||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
import forge.game.spellability.TargetRestrictions;
|
import forge.game.spellability.TargetRestrictions;
|
||||||
import forge.game.zone.Zone;
|
import forge.game.zone.Zone;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
import forge.gui.GuiChoose;
|
|
||||||
|
|
||||||
public class CountersRemoveEffect extends SpellAbilityEffect {
|
public class CountersRemoveEffect extends SpellAbilityEffect {
|
||||||
@Override
|
@Override
|
||||||
@@ -57,9 +55,9 @@ public class CountersRemoveEffect extends SpellAbilityEffect {
|
|||||||
final Card card = sa.getSourceCard();
|
final Card card = sa.getSourceCard();
|
||||||
final Game game = card.getGame();
|
final Game game = card.getGame();
|
||||||
final String type = sa.getParam("CounterType");
|
final String type = sa.getParam("CounterType");
|
||||||
int counterAmount = 0;
|
int cntToRemove = 0;
|
||||||
if (!sa.getParam("CounterNum").equals("All") && !sa.getParam("CounterNum").equals("Remembered")) {
|
if (!sa.getParam("CounterNum").equals("All") && !sa.getParam("CounterNum").equals("Remembered")) {
|
||||||
counterAmount = AbilityUtils.calculateAmount(sa.getSourceCard(), sa.getParam("CounterNum"), sa);
|
cntToRemove = AbilityUtils.calculateAmount(sa.getSourceCard(), sa.getParam("CounterNum"), sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
CounterType counterType = null;
|
CounterType counterType = null;
|
||||||
@@ -83,90 +81,44 @@ public class CountersRemoveEffect extends SpellAbilityEffect {
|
|||||||
if ((tgt == null) || tgtCard.canBeTargetedBy(sa)) {
|
if ((tgt == null) || tgtCard.canBeTargetedBy(sa)) {
|
||||||
final Zone zone = game.getZoneOf(tgtCard);
|
final Zone zone = game.getZoneOf(tgtCard);
|
||||||
if (sa.getParam("CounterNum").equals("All")) {
|
if (sa.getParam("CounterNum").equals("All")) {
|
||||||
counterAmount = tgtCard.getCounters(counterType);
|
cntToRemove = tgtCard.getCounters(counterType);
|
||||||
} else if (sa.getParam("CounterNum").equals("Remembered")) {
|
} else if (sa.getParam("CounterNum").equals("Remembered")) {
|
||||||
counterAmount = tgtCard.getCountersAddedBy(card, counterType);
|
cntToRemove = tgtCard.getCountersAddedBy(card, counterType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PlayerController pc = sa.getActivatingPlayer().getController();
|
||||||
|
|
||||||
if (type.matches("Any")) {
|
if (type.matches("Any")) {
|
||||||
while (counterAmount > 0 && tgtCard.hasCounters()) {
|
while (cntToRemove > 0 && tgtCard.hasCounters()) {
|
||||||
final Map<CounterType, Integer> tgtCounters = tgtCard.getCounters();
|
final Map<CounterType, Integer> tgtCounters = tgtCard.getCounters();
|
||||||
CounterType chosenType = null;
|
|
||||||
int chosenAmount;
|
|
||||||
if (sa.getActivatingPlayer().isHuman()) {
|
CounterType chosenType = pc.chooseCounterType(tgtCounters.keySet(), sa, "Select type of counters to remove");
|
||||||
final ArrayList<CounterType> typeChoices = new ArrayList<CounterType>();
|
String prompt = "Select the number of " + chosenType.getName() + " counters to remove";
|
||||||
// get types of counters
|
int chosenAmount = pc.chooseNumber(sa, prompt, 1, Math.max(cntToRemove, tgtCounters.get(chosenType)));
|
||||||
for (CounterType key : tgtCounters.keySet()) {
|
|
||||||
if (tgtCounters.get(key) > 0) {
|
|
||||||
typeChoices.add(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (typeChoices.size() > 1) {
|
|
||||||
String prompt = "Select type counters to remove";
|
|
||||||
chosenType = GuiChoose.one(prompt, typeChoices);
|
|
||||||
} else {
|
|
||||||
chosenType = typeChoices.get(0);
|
|
||||||
}
|
|
||||||
chosenAmount = tgtCounters.get(chosenType);
|
|
||||||
if (chosenAmount > counterAmount) {
|
|
||||||
chosenAmount = counterAmount;
|
|
||||||
}
|
|
||||||
// make list of amount choices
|
|
||||||
|
|
||||||
if (chosenAmount > 1) {
|
|
||||||
final List<Integer> choices = new ArrayList<Integer>();
|
|
||||||
for (int i = 1; i <= chosenAmount; i++) {
|
|
||||||
choices.add(Integer.valueOf(i));
|
|
||||||
}
|
|
||||||
String prompt = "Select the number of " + chosenType.getName() + " counters to remove";
|
|
||||||
chosenAmount = GuiChoose.one(prompt, choices);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// TODO: ArsenalNut (06 Feb 12)computer needs
|
|
||||||
// better logic to pick a counter type and probably
|
|
||||||
// an initial target
|
|
||||||
// find first nonzero counter on target
|
|
||||||
for (CounterType key : tgtCounters.keySet()) {
|
|
||||||
if (tgtCounters.get(key) > 0) {
|
|
||||||
chosenType = (CounterType) key;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// subtract all of selected type
|
|
||||||
chosenAmount = tgtCounters.get(chosenType);
|
|
||||||
if (chosenAmount > counterAmount) {
|
|
||||||
chosenAmount = counterAmount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tgtCard.subtractCounter(chosenType, chosenAmount);
|
tgtCard.subtractCounter(chosenType, chosenAmount);
|
||||||
if (rememberRemoved) {
|
if (rememberRemoved) {
|
||||||
for (int i = 0; i < chosenAmount; i++) {
|
for (int i = 0; i < chosenAmount; i++) {
|
||||||
card.addRemembered(chosenType);
|
card.addRemembered(chosenType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
counterAmount -= chosenAmount;
|
cntToRemove -= chosenAmount;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (zone.is(ZoneType.Battlefield) || zone.is(ZoneType.Exile)) {
|
if (zone.is(ZoneType.Battlefield) || zone.is(ZoneType.Exile)) {
|
||||||
if (sa.hasParam("UpTo") && sa.getActivatingPlayer().isHuman()) {
|
if (sa.hasParam("UpTo"))
|
||||||
final ArrayList<String> choices = new ArrayList<String>();
|
cntToRemove = pc.chooseNumber(sa, "Select the number of " + type + " counters to remove", 0, cntToRemove);
|
||||||
for (int i = 0; i <= counterAmount; i++) {
|
|
||||||
choices.add("" + i);
|
|
||||||
}
|
|
||||||
final String prompt = "Select the number of " + type + " counters to remove";
|
|
||||||
final String o = GuiChoose.one(prompt, choices);
|
|
||||||
counterAmount = Integer.parseInt(o);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (rememberRemoved) {
|
if (rememberRemoved) {
|
||||||
if (counterAmount > tgtCard.getCounters(counterType)) {
|
if (cntToRemove > tgtCard.getCounters(counterType)) {
|
||||||
counterAmount = tgtCard.getCounters(counterType);
|
cntToRemove = tgtCard.getCounters(counterType);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < counterAmount; i++) {
|
for (int i = 0; i < cntToRemove; i++) {
|
||||||
card.addRemembered(counterType);
|
card.addRemembered(counterType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tgtCard.subtractCounter(counterType, counterAmount);
|
tgtCard.subtractCounter(counterType, cntToRemove);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -520,6 +520,11 @@ public class PlayerControllerAi extends PlayerController {
|
|||||||
@Override
|
@Override
|
||||||
public CounterType chooseCounterType(Collection<CounterType> options, SpellAbility sa, String prompt) {
|
public CounterType chooseCounterType(Collection<CounterType> options, SpellAbility sa, String prompt) {
|
||||||
// may write a smarter AI if you need to (with calls to AI-clas for given API ability)
|
// may write a smarter AI if you need to (with calls to AI-clas for given API ability)
|
||||||
|
|
||||||
|
// TODO: ArsenalNut (06 Feb 12)computer needs
|
||||||
|
// better logic to pick a counter type and probably
|
||||||
|
// an initial target
|
||||||
|
// find first nonzero counter on target
|
||||||
return Iterables.getFirst(options, null);
|
return Iterables.getFirst(options, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user