mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +00:00
- "Upto" parameter in draw effect
- Added Temporary Truce
This commit is contained in:
@@ -216,6 +216,7 @@ public class DrawAi extends SpellAbilityAi {
|
||||
} else {
|
||||
// Don't draw too many cards and then risk discarding cards
|
||||
// at EOT
|
||||
// TODO: "NextUpkeep" is deprecated
|
||||
if (!(sa.hasParam("NextUpkeep") || (sa instanceof AbilitySub)) && !mandatory) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import forge.card.cardfactory.CardFactoryUtil;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.card.spellability.Target;
|
||||
import forge.game.player.Player;
|
||||
import forge.gui.GuiChoose;
|
||||
import forge.gui.GuiDialog;
|
||||
|
||||
public class ChooseNumberEffect extends SpellAbilityEffect {
|
||||
@@ -43,44 +42,22 @@ public class ChooseNumberEffect extends SpellAbilityEffect {
|
||||
final String sMax = sa.getParamOrDefault("Max", "99");
|
||||
final int max = StringUtils.isNumeric(sMax) ? Integer.parseInt(sMax) : CardFactoryUtil.xCount(card, card.getSVar(sMax));
|
||||
|
||||
final String[] choices = new String[max + 1];
|
||||
if (!random) {
|
||||
// initialize the array
|
||||
for (int i = min; i <= max; i++) {
|
||||
choices[i] = Integer.toString(i);
|
||||
}
|
||||
}
|
||||
|
||||
final List<Player> tgtPlayers = getTargetPlayers(sa);
|
||||
final Target tgt = sa.getTarget();
|
||||
|
||||
for (final Player p : tgtPlayers) {
|
||||
if ((tgt == null) || p.canBeTargetedBy(sa)) {
|
||||
if (p.isHuman()) {
|
||||
int chosen;
|
||||
if (random) {
|
||||
final Random randomGen = new Random();
|
||||
chosen = randomGen.nextInt(max - min) + min;
|
||||
final String message = "Randomly chosen number: " + chosen;
|
||||
GuiDialog.message(message, card.toString());
|
||||
} else if (sa.hasParam("ListTitle")) {
|
||||
final Object o = GuiChoose.one(sa.getParam("ListTitle"), choices);
|
||||
if (null == o) {
|
||||
return;
|
||||
}
|
||||
chosen = Integer.parseInt((String) o);
|
||||
} else {
|
||||
final Object o = GuiChoose.one("Choose a number", choices);
|
||||
if (null == o) {
|
||||
return;
|
||||
}
|
||||
chosen = Integer.parseInt((String) o);
|
||||
}
|
||||
card.setChosenNumber(chosen);
|
||||
|
||||
int chosen;
|
||||
if (random) {
|
||||
final Random randomGen = new Random();
|
||||
chosen = randomGen.nextInt(max - min) + min;
|
||||
final String message = "Randomly chosen number: " + chosen;
|
||||
GuiDialog.message(message, card.toString());
|
||||
} else {
|
||||
// TODO - not implemented
|
||||
String title = sa.hasParam("ListTitle") ? sa.getParam("ListTitle") : "Choose a number";
|
||||
chosen = p.getController().chooseNumber(sa, title, min, max);
|
||||
}
|
||||
card.setChosenNumber(chosen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,12 +37,13 @@ public class DrawEffect extends SpellAbilityEffect {
|
||||
@Override
|
||||
public void resolve(SpellAbility sa) {
|
||||
final Card source = sa.getSourceCard();
|
||||
int numCards = sa.hasParam("NumCards") ? AbilityUtils.calculateAmount(sa.getSourceCard(), sa.getParam("NumCards"), sa) : 1;
|
||||
final int numCards = sa.hasParam("NumCards") ? AbilityUtils.calculateAmount(sa.getSourceCard(), sa.getParam("NumCards"), sa) : 1;
|
||||
|
||||
|
||||
final Target tgt = sa.getTarget();
|
||||
|
||||
final boolean optional = sa.hasParam("OptionalDecider");
|
||||
final boolean upto = sa.hasParam("Upto");
|
||||
|
||||
|
||||
for (final Player p : getDefinedPlayersBeforeTargetOnes(sa)) {
|
||||
@@ -50,8 +51,12 @@ public class DrawEffect extends SpellAbilityEffect {
|
||||
if (optional && !p.getController().confirmAction(sa, null, "Do you want to draw " + Lang.nounWithAmount(numCards, " card") + "?"))
|
||||
continue;
|
||||
|
||||
//TODO: remove this deprecation exception
|
||||
final List<Card> drawn = p.drawCards(numCards);
|
||||
int actualNum = numCards;
|
||||
if (upto) {
|
||||
actualNum = p.getController().chooseNumber(sa, "Choose a number", 0, numCards);
|
||||
}
|
||||
|
||||
final List<Card> drawn = p.drawCards(actualNum);
|
||||
if (sa.hasParam("Reveal")) {
|
||||
p.getGame().getAction().reveal(drawn, p);
|
||||
}
|
||||
|
||||
@@ -855,5 +855,15 @@ public class AiController {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public int chooseNumber(SpellAbility sa, String title, int min, int max) {
|
||||
//TODO: AILogic
|
||||
if ("GainLife".equals(sa.getParam("AILogic"))) {
|
||||
if (player.getLife() < 5 || player.getCardsIn(ZoneType.Hand).size() >= player.getMaxHandSize()) {
|
||||
return min;
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -142,4 +142,6 @@ public abstract class PlayerController {
|
||||
public abstract List<Card> chooseCardsToDiscardToMaximumHandSize(int numDiscard);
|
||||
public abstract boolean payManaOptional(Card card, Cost cost, String prompt, ManaPaymentPurpose purpose);
|
||||
|
||||
public abstract int chooseNumber(SpellAbility sa, String title, int min, int max);
|
||||
|
||||
}
|
||||
|
||||
@@ -350,4 +350,9 @@ public class PlayerControllerAi extends PlayerController {
|
||||
// AI would play everything. But limits to one copy of (Leyline of Singularity) and (Gemstone Caverns)
|
||||
return brains.chooseSaToActivateFromOpeningHand(usableFromOpeningHand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int chooseNumber(SpellAbility sa, String title, int min, int max) {
|
||||
return brains.chooseNumber(sa, title, min, max);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,6 +269,15 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
return options.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int chooseNumber(SpellAbility sa, String title, int min, int max) {
|
||||
final String[] choices = new String[max + 1];
|
||||
for (int i = min; i <= max; i++) {
|
||||
choices[i] = Integer.toString(i);
|
||||
}
|
||||
return Integer.parseInt(GuiChoose.one(title, choices));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player chooseSinglePlayerForEffect(List<Player> options, SpellAbility sa, String title) {
|
||||
// Human is supposed to read the message and understand from it what to choose
|
||||
|
||||
Reference in New Issue
Block a user