ReplacementEffect optional choice and confirm shuffle effect moved to PlayerController

This commit is contained in:
Maxmtg
2013-05-20 20:08:22 +00:00
parent 933368338b
commit 3fd671c7e7
12 changed files with 79 additions and 87 deletions

View File

@@ -1753,7 +1753,7 @@ public class Card extends GameEntity implements Comparable<Card> {
* @param c
* an ArrayList<String> object.
*/
public final void setChosenCard(final ArrayList<Card> c) {
public final void setChosenCard(final List<Card> c) {
this.chosenCard = c;
}

View File

@@ -39,35 +39,33 @@ public class ChoosePlayerEffect extends SpellAbilityEffect {
for (final Player p : tgtPlayers) {
if ((tgt == null) || p.canBeTargetedBy(sa)) {
Player chosen = null;
if (p.isHuman()) {
// Was if (sa.getActivatingPlayer().isHuman()) but defined player was being
// overwritten by activatingPlayer (or controller if no activator was set).
// Revert if it causes issues and remove Goblin Festival from card database.
final Object o = GuiChoose.one(choiceDesc, choices);
if (null == o) {
return;
}
final Player chosen = (Player) o;
card.setChosenPlayer(chosen);
chosen = GuiChoose.one(choiceDesc, choices);
} else {
if ("Curse".equals(sa.getParam("AILogic"))) {
for (Player pc : choices) {
if (pc.isOpponentOf(p)) {
card.setChosenPlayer(pc);
chosen = pc;
break;
}
}
if (card.getChosenPlayer() == null) {
if (chosen == null) {
System.out.println("No good curse choices. Picking first available: " + choices.get(0));
card.setChosenPlayer(choices.get(0));
chosen = choices.get(0);
}
} else if ("Pump".equals(sa.getParam("AILogic"))) {
card.setChosenPlayer(choices.contains(p) ? p : choices.get(0));
chosen = choices.contains(p) ? p : choices.get(0);
} else {
card.setChosenPlayer(p);
chosen = p;
}
}
if( null != chosen )
card.setChosenPlayer(chosen);
}
}
}

View File

@@ -38,7 +38,6 @@ public class ChooseSourceEffect extends SpellAbilityEffect {
@Override
public void resolve(SpellAbility sa) {
final Card host = sa.getSourceCard();
final ArrayList<Card> chosen = new ArrayList<Card>();
final GameState game = sa.getActivatingPlayer().getGame();
final Target tgt = sa.getTarget();
@@ -126,6 +125,7 @@ public class ChooseSourceEffect extends SpellAbilityEffect {
final int validAmount = StringUtils.isNumeric(numericAmount) ? Integer.parseInt(numericAmount) : CardFactoryUtil.xCount(host, host.getSVar(numericAmount));
for (final Player p : tgtPlayers) {
final List<Card> chosen = new ArrayList<Card>();
if ((tgt == null) || p.canBeTargetedBy(sa)) {
for (int i = 0; i < validAmount; i++) {
if (p.isHuman()) {

View File

@@ -3,18 +3,15 @@ package forge.card.ability.effects;
import java.util.Iterator;
import java.util.List;
import forge.Card;
import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target;
import forge.game.player.Player;
import forge.gui.GuiDialog;
public class ShuffleEffect extends SpellAbilityEffect {
@Override
public void resolve(SpellAbility sa) {
final Card host = sa.getSourceCard();
final boolean optional = sa.hasParam("Optional");
final List<Player> tgtPlayers = getTargetPlayers(sa);
@@ -23,7 +20,7 @@ public class ShuffleEffect extends SpellAbilityEffect {
for (final Player p : tgtPlayers) {
if ((tgt == null) || p.canBeTargetedBy(sa)) {
boolean mustShuffle = !optional || sa.getActivatingPlayer().isComputer() || GuiDialog.confirm(host, "Have " + p + " shuffle?");
boolean mustShuffle = !optional || sa.getActivatingPlayer().getController().confirmAction(sa, null, "Have " + p + " shuffle?");
if (mustShuffle)
p.shuffle();
}

View File

@@ -88,16 +88,10 @@ public class UntapEffect extends SpellAbilityEffect {
for( Card c : sc.getSelected() )
c.untap();
} else {
int count = 0;
while ((list.size() != 0) && (count < num)) {
for (int i = 0; (i < list.size()) && (count < num); i++) {
final Card c = ComputerUtilCard.getBestLandAI(list);
c.untap();
list.remove(c);
count++;
}
for (int count = 0; !list.isEmpty() && count < num; count++) {
final Card c = ComputerUtilCard.getBestLandAI(list);
c.untap();
list.remove(c);
}
}
}

View File

@@ -2751,7 +2751,6 @@ public class CardFactoryUtil {
// need to do it this way because I don't know quite how to
// make TriggerHandler respect BeforePayMana.
if (card.getController().isHuman()) {
final InputSelectCards target = new InputSelectCards(1, 1) {
private static final long serialVersionUID = 1981791992623774490L;
@Override
@@ -3141,54 +3140,46 @@ public class CardFactoryUtil {
final String magnitude = k[1];
// final String player = card.getController();
final int[] numCreatures = new int[1];
final GameState game = card.getGame();
final Command intoPlay = new Command() {
private static final long serialVersionUID = -7530312713496897814L;
private void devour(Card eater, Card dinner) {
eater.addDevoured(dinner);
game.getAction().sacrifice(dinner, null);
final HashMap<String, Object> runParams = new HashMap<String, Object>();
runParams.put("Devoured", dinner);
game.getTriggerHandler().runTrigger(TriggerType.Devoured, runParams, false);
}
@Override
public void run() {
final List<Card> creats = card.getController().getCreaturesInPlay();
final GameState game = card.getGame();
creats.remove(card);
card.clearDevoured();
// System.out.println("Creats size: " + creats.size());
card.clearDevoured();
List<Card> selection = new ArrayList<Card>();
if (card.getController().isHuman()) {
if (creats.size() > 0) {
final List<Card> selection = GuiChoose.order("Devour", "Devouring", -1, creats, null, card);
numCreatures[0] = selection.size();
selection = GuiChoose.order("Devour", "Devouring", -1, creats, null, card);
}
} else {
for(Card c : creats) {
if ((c.getNetAttack() <= 1) && ((c.getNetAttack() + c.getNetDefense()) <= 3))
selection.add(c);
}
}
for (Object o : selection) {
Card dinner = (Card) o;
card.addDevoured(dinner);
game.getAction().sacrifice(dinner, null);
final HashMap<String, Object> runParams = new HashMap<String, Object>();
runParams.put("Devoured", dinner);
card.getController().getGame().getTriggerHandler()
.runTrigger(TriggerType.Devoured, runParams, false);
}
}
} // human
else {
int count = 0;
for (int i = 0; i < creats.size(); i++) {
final Card c = creats.get(i);
if ((c.getNetAttack() <= 1) && ((c.getNetAttack() + c.getNetDefense()) <= 3)) {
card.addDevoured(c);
game.getAction().sacrifice(c, null);
final HashMap<String, Object> runParams = new HashMap<String, Object>();
runParams.put("Devoured", c);
card.getController().getGame().getTriggerHandler()
.runTrigger(TriggerType.Devoured, runParams, false);
count++;
}
}
numCreatures[0] = count;
for (Card dinner : selection) {
devour(card, dinner);
}
final int multiplier = magnitude.equals("X") ? AbilityUtils.calculateAmount(card, magnitude, null)
: Integer.parseInt(magnitude);
final int totalCounters = numCreatures[0] * multiplier;
final int totalCounters = selection.size() * multiplier;
card.addCounter(CounterType.P1P1, totalCounters, true);

View File

@@ -57,7 +57,7 @@ public abstract class ReplacementEffect extends TriggerReplacementBase {
* @return true, if is secondary
*/
public final boolean isSecondary() {
return this.mapParams.containsKey("Secondary");
return this.getMapParams().containsKey("Secondary");
}
/**
@@ -67,24 +67,24 @@ public abstract class ReplacementEffect extends TriggerReplacementBase {
* @param ai
* @return true, if successful
*/
public final boolean aiShouldRun(final SpellAbility sa, Player ai) {
if (this.mapParams.containsKey("AICheckSVar")) {
public final static boolean aiShouldRun(final ReplacementEffect effect, final SpellAbility sa, Player ai) {
if (effect.getMapParams().containsKey("AICheckSVar")) {
System.out.println("aiShouldRun?" + sa);
final String svarToCheck = this.mapParams.get("AICheckSVar");
final String svarToCheck = effect.getMapParams().get("AICheckSVar");
String comparator = "GE";
int compareTo = 1;
if (this.mapParams.containsKey("AISVarCompare")) {
final String fullCmp = this.mapParams.get("AISVarCompare");
if (effect.getMapParams().containsKey("AISVarCompare")) {
final String fullCmp = effect.getMapParams().get("AISVarCompare");
comparator = fullCmp.substring(0, 2);
final String strCmpTo = fullCmp.substring(2);
try {
compareTo = Integer.parseInt(strCmpTo);
} catch (final Exception ignored) {
if (sa == null) {
compareTo = CardFactoryUtil.xCount(this.hostCard, this.hostCard.getSVar(strCmpTo));
compareTo = CardFactoryUtil.xCount(effect.hostCard, effect.hostCard.getSVar(strCmpTo));
} else {
compareTo = AbilityUtils.calculateAmount(this.hostCard, this.hostCard.getSVar(strCmpTo), sa);
compareTo = AbilityUtils.calculateAmount(effect.hostCard, effect.hostCard.getSVar(strCmpTo), sa);
}
}
}
@@ -92,9 +92,9 @@ public abstract class ReplacementEffect extends TriggerReplacementBase {
int left = 0;
if (sa == null) {
left = CardFactoryUtil.xCount(this.hostCard, this.hostCard.getSVar(svarToCheck));
left = CardFactoryUtil.xCount(effect.hostCard, effect.hostCard.getSVar(svarToCheck));
} else {
left = AbilityUtils.calculateAmount(this.hostCard, svarToCheck, sa);
left = AbilityUtils.calculateAmount(effect.hostCard, svarToCheck, sa);
}
System.out.println("aiShouldRun?" + left + comparator + compareTo);
if (Expressions.compare(left, comparator, compareTo)) {

View File

@@ -33,7 +33,6 @@ import forge.game.player.HumanPlay;
import forge.game.player.Player;
import forge.game.zone.ZoneType;
import forge.gui.GuiChoose;
import forge.gui.GuiDialog;
import forge.util.FileSection;
/**
@@ -213,20 +212,11 @@ public class ReplacementHandler {
mapParams.get("OptionalDecider"), effectSA).get(0);
}
if (optDecider.isHuman()) {
final StringBuilder buildQuestion = new StringBuilder("Apply replacement effect of ");
buildQuestion.append(replacementEffect.getHostCard());
buildQuestion.append("?\r\n(");
buildQuestion.append(replacementEffect.toString().replace("CARDNAME", replacementEffect.getHostCard().getName()));
buildQuestion.append(")");
if (!GuiDialog.confirm(replacementEffect.getHostCard(), buildQuestion.toString())) {
return ReplacementResult.NotReplaced;
}
} else {
// AI-logic
if (!replacementEffect.aiShouldRun(effectSA, optDecider)) {
return ReplacementResult.NotReplaced;
}
String effectDesc = replacementEffect.toString().replace("CARDNAME", replacementEffect.getHostCard().getName());
final String question = String.format("Apply replacement effect of %s?\r\n(%s)", replacementEffect.getHostCard(), effectDesc);
boolean confirmed = optDecider.getController().confirmReplacementEffect(replacementEffect, effectSA, question);
if (!confirmed) {
return ReplacementResult.NotReplaced;
}
}

View File

@@ -733,6 +733,8 @@ public class AiController {
AbilitySub subAb = sa.getSubAbility();
return subAb != null && subAb.getAi().chkDrawbackWithSubs(player, subAb);
case Shuffle: // ai could analyze parameter denoting the player to shuffle
return true;
default:
}

View File

@@ -10,6 +10,7 @@ import org.apache.commons.lang3.tuple.ImmutablePair;
import forge.Card;
import forge.GameEntity;
import forge.card.mana.Mana;
import forge.card.replacement.ReplacementEffect;
import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target;
import forge.control.input.Input;
@@ -137,4 +138,5 @@ public abstract class PlayerController {
public abstract Mana chooseManaFromPool(List<Mana> manaChoices);
public abstract String chooseSomeType(String kindOfType, String aiLogic, List<String> validTypes, List<String> invalidTypes);
public abstract boolean confirmReplacementEffect(ReplacementEffect replacementEffect, SpellAbility effectSA, String question);
}

View File

@@ -15,6 +15,7 @@ import forge.CardLists;
import forge.CardPredicates;
import forge.GameEntity;
import forge.card.mana.Mana;
import forge.card.replacement.ReplacementEffect;
import forge.card.spellability.Spell;
import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target;
@@ -278,5 +279,13 @@ public class PlayerControllerAi extends PlayerController {
return ComputerUtil.chooseSomeType(player, kindOfType, aiLogic, invalidTypes);
}
/* (non-Javadoc)
* @see forge.game.player.PlayerController#confirmReplacementEffect(forge.card.replacement.ReplacementEffect, forge.card.spellability.SpellAbility, java.lang.String)
*/
@Override
public boolean confirmReplacementEffect(ReplacementEffect replacementEffect, SpellAbility effectSA, String question) {
return ReplacementEffect.aiShouldRun(replacementEffect, effectSA, player);
}
}

View File

@@ -15,6 +15,7 @@ import forge.Card;
import forge.FThreads;
import forge.GameEntity;
import forge.card.mana.Mana;
import forge.card.replacement.ReplacementEffect;
import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target;
import forge.card.spellability.TargetSelection;
@@ -458,4 +459,12 @@ public class PlayerControllerHuman extends PlayerController {
return GuiChoose.one("Choose a " + kindOfType.toLowerCase() + " type", validTypes);
}
/* (non-Javadoc)
* @see forge.game.player.PlayerController#confirmReplacementEffect(forge.card.replacement.ReplacementEffect, forge.card.spellability.SpellAbility, java.lang.String)
*/
@Override
public boolean confirmReplacementEffect(ReplacementEffect replacementEffect, SpellAbility effectSA, String question) {
return GuiDialog.confirm(replacementEffect.getHostCard(), question);
}
}