mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 04:08:01 +00:00
Play miracle moved to PlayerControllers
a method to choose and play a sa out of a list extracted and moved to AiController
This commit is contained in:
@@ -114,9 +114,8 @@ public class PlayEffect extends SpellAbilityEffect {
|
||||
for (SpellAbility s : c.getBasicSpells()) {
|
||||
Spell spell = (Spell) s;
|
||||
s.setActivatingPlayer(controller);
|
||||
SpellAbilityRestriction res = s.getRestrictions();
|
||||
// timing restrictions still apply
|
||||
if (res.checkTimingRestrictions(c, s) && spell.canPlayFromEffectAI(false, true)) {
|
||||
if (s.getRestrictions().checkTimingRestrictions(c, s) && spell.canPlayFromEffectAI(false, true)) {
|
||||
sas.add(s);
|
||||
}
|
||||
}
|
||||
@@ -206,6 +205,8 @@ public class PlayEffect extends SpellAbilityEffect {
|
||||
|
||||
if (sa.hasParam("WithoutManaCost")) {
|
||||
if (controller.isHuman()) {
|
||||
// controller.getGame().getActionPlay().playSpellAbilityForFree(tgtSA);
|
||||
|
||||
final SpellAbility newSA = tgtSA.copy();
|
||||
final Cost cost = new Cost(tgtCard, "", false);
|
||||
if (newSA.getPayCosts() != null) {
|
||||
|
||||
@@ -19,6 +19,7 @@ package forge.game.ai;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
@@ -38,6 +39,7 @@ import forge.card.ability.ApiType;
|
||||
import forge.card.cardfactory.CardFactoryUtil;
|
||||
import forge.card.cost.CostDiscard;
|
||||
import forge.card.cost.CostPart;
|
||||
import forge.card.spellability.Spell;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.card.spellability.SpellPermanent;
|
||||
import forge.game.GameActionUtil;
|
||||
@@ -731,5 +733,34 @@ public class AiController {
|
||||
public boolean getBooleanProperty(AiProps propName) {
|
||||
return Boolean.parseBoolean(AiProfileUtil.getAIProp(getPlayer().getLobbyPlayer(), propName));
|
||||
}
|
||||
|
||||
/** Returns the spell ability which has already been played - use it for reference only */
|
||||
public SpellAbility chooseAndPlaySa(boolean mandatory, boolean withoutPayingManaCost, final SpellAbility... list) {
|
||||
return chooseAndPlaySa(Arrays.asList(list), mandatory, withoutPayingManaCost);
|
||||
}
|
||||
/** Returns the spell ability which has already been played - use it for reference only */
|
||||
public SpellAbility chooseAndPlaySa(final List<SpellAbility> choices, boolean mandatory, boolean withoutPayingManaCost) {
|
||||
for (final SpellAbility sa : choices) {
|
||||
//Spells
|
||||
if (sa instanceof Spell) {
|
||||
if (!((Spell) sa).canPlayFromEffectAI(mandatory, withoutPayingManaCost)) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (sa.canPlayAI()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ( withoutPayingManaCost )
|
||||
ComputerUtil.playSpellAbilityWithoutPayingManaCost(player, sa, game);
|
||||
else if (!ComputerUtilCost.canPayCost(sa, player))
|
||||
continue;
|
||||
else
|
||||
ComputerUtil.playStack(sa, player, game);
|
||||
return sa;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -207,20 +207,21 @@ public class ComputerUtil {
|
||||
*/
|
||||
public static final void playStack(final SpellAbility sa, final AIPlayer ai, final GameState game) {
|
||||
sa.setActivatingPlayer(ai);
|
||||
if (ComputerUtilCost.canPayCost(sa, ai)) {
|
||||
final Card source = sa.getSourceCard();
|
||||
if (sa.isSpell() && !source.isCopiedSpell()) {
|
||||
sa.setSourceCard(game.getAction().moveToStack(source));
|
||||
}
|
||||
final Cost cost = sa.getPayCosts();
|
||||
if (cost == null) {
|
||||
ComputerUtilMana.payManaCost(ai, sa);
|
||||
if (!ComputerUtilCost.canPayCost(sa, ai))
|
||||
return;
|
||||
|
||||
final Card source = sa.getSourceCard();
|
||||
if (sa.isSpell() && !source.isCopiedSpell()) {
|
||||
sa.setSourceCard(game.getAction().moveToStack(source));
|
||||
}
|
||||
final Cost cost = sa.getPayCosts();
|
||||
if (cost == null) {
|
||||
ComputerUtilMana.payManaCost(ai, sa);
|
||||
game.getStack().add(sa);
|
||||
} else {
|
||||
final CostPayment pay = new CostPayment(cost, sa, game);
|
||||
if (pay.payComputerCosts(ai, game)) {
|
||||
game.getStack().add(sa);
|
||||
} else {
|
||||
final CostPayment pay = new CostPayment(cost, sa, game);
|
||||
if (pay.payComputerCosts(ai, game)) {
|
||||
game.getStack().add(sa);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3122,7 +3122,7 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
|
||||
playForMiracleCost.setStackDescription(card.getName() + " - Cast via Miracle");
|
||||
|
||||
// TODO Convert this to a Trigger
|
||||
final Ability miracleTrigger = new MiracleTrigger(card, ManaCost.ZERO, card, playForMiracleCost);
|
||||
final Ability miracleTrigger = new MiracleTrigger(card, ManaCost.ZERO, playForMiracleCost);
|
||||
miracleTrigger.setStackDescription(card.getName() + " - Miracle.");
|
||||
miracleTrigger.setActivatingPlayer(card.getOwner());
|
||||
miracleTrigger.setTrigger(true);
|
||||
@@ -3149,36 +3149,24 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
|
||||
*
|
||||
*/
|
||||
private final class MiracleTrigger extends Ability {
|
||||
private final Card card;
|
||||
private final SpellAbility miracle;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for Constructor.
|
||||
* @param sourceCard
|
||||
* @param manaCost
|
||||
* @param card
|
||||
* @param miracle
|
||||
*/
|
||||
private MiracleTrigger(Card sourceCard, ManaCost manaCost, Card card, SpellAbility miracle) {
|
||||
private MiracleTrigger(Card sourceCard, ManaCost manaCost, SpellAbility miracle) {
|
||||
super(sourceCard, manaCost);
|
||||
this.card = card;
|
||||
this.miracle = miracle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolve() {
|
||||
miracle.setActivatingPlayer(card.getOwner());
|
||||
miracle.setActivatingPlayer(getSourceCard().getOwner());
|
||||
// pay miracle cost here.
|
||||
if (card.getOwner().isHuman()) {
|
||||
if (GuiDialog.confirm(card, card + " - Drawn. Pay Miracle Cost?")) {
|
||||
game.getActionPlay().playSpellAbility(miracle, miracle.getActivatingPlayer());
|
||||
}
|
||||
} else {
|
||||
Spell spell = (Spell) miracle;
|
||||
if (spell.canPlayFromEffectAI(false, false)) {
|
||||
ComputerUtil.playStack(miracle, (AIPlayer) card.getOwner(), game);
|
||||
}
|
||||
}
|
||||
getSourceCard().getOwner().getController().playMiracle(miracle, getSourceCard());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -112,4 +112,6 @@ public abstract class PlayerController {
|
||||
/** p = target player, validCards - possible discards, min cards to discard */
|
||||
public abstract List<Card> chooseCardsToDiscardFrom(Player p, SpellAbility sa, List<Card> validCards, int min);
|
||||
public abstract Card chooseCardToDredge(List<Card> dredgers);
|
||||
|
||||
public abstract void playMiracle(SpellAbility miracle, Card card);
|
||||
}
|
||||
|
||||
@@ -88,22 +88,7 @@ public class PlayerControllerAi extends PlayerController {
|
||||
public void playFromSuspend(Card c) {
|
||||
final List<SpellAbility> choices = c.getBasicSpells();
|
||||
c.setSuspendCast(true);
|
||||
for (final SpellAbility sa : choices) {
|
||||
//Spells
|
||||
if (sa instanceof Spell) {
|
||||
Spell spell = (Spell) sa;
|
||||
if (!spell.canPlayFromEffectAI(true, true)) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (sa.canPlayAI()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
ComputerUtil.playSpellAbilityWithoutPayingManaCost(player, sa, game);
|
||||
break;
|
||||
}
|
||||
getAi().chooseAndPlaySa(choices, true, true);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -112,24 +97,7 @@ public class PlayerControllerAi extends PlayerController {
|
||||
@Override
|
||||
public boolean playCascade(Card cascadedCard, Card source) {
|
||||
final List<SpellAbility> choices = cascadedCard.getBasicSpells();
|
||||
|
||||
for (final SpellAbility sa : choices) {
|
||||
sa.setActivatingPlayer(getPlayer());
|
||||
//Spells
|
||||
if (sa instanceof Spell) {
|
||||
Spell spell = (Spell) sa;
|
||||
if (!spell.canPlayFromEffectAI(false, true)) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (!sa.canPlayAI()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
ComputerUtil.playSpellAbilityWithoutPayingManaCost(player, sa, game);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return null != getAi().chooseAndPlaySa(choices, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -269,4 +237,9 @@ public class PlayerControllerAi extends PlayerController {
|
||||
return brains.chooseCardToDredge(dredgers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playMiracle(SpellAbility miracle, Card card) {
|
||||
getAi().chooseAndPlaySa(false, false, miracle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -338,4 +338,14 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.game.player.PlayerController#playMiracle(forge.card.spellability.SpellAbility, forge.Card)
|
||||
*/
|
||||
@Override
|
||||
public void playMiracle(SpellAbility miracle, Card card) {
|
||||
if (GuiDialog.confirm(card, card + " - Drawn. Play for Miracle Cost?")) {
|
||||
game.getActionPlay().playSpellAbility(miracle, getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user