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()) {
|
for (SpellAbility s : c.getBasicSpells()) {
|
||||||
Spell spell = (Spell) s;
|
Spell spell = (Spell) s;
|
||||||
s.setActivatingPlayer(controller);
|
s.setActivatingPlayer(controller);
|
||||||
SpellAbilityRestriction res = s.getRestrictions();
|
|
||||||
// timing restrictions still apply
|
// 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);
|
sas.add(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -206,6 +205,8 @@ public class PlayEffect extends SpellAbilityEffect {
|
|||||||
|
|
||||||
if (sa.hasParam("WithoutManaCost")) {
|
if (sa.hasParam("WithoutManaCost")) {
|
||||||
if (controller.isHuman()) {
|
if (controller.isHuman()) {
|
||||||
|
// controller.getGame().getActionPlay().playSpellAbilityForFree(tgtSA);
|
||||||
|
|
||||||
final SpellAbility newSA = tgtSA.copy();
|
final SpellAbility newSA = tgtSA.copy();
|
||||||
final Cost cost = new Cost(tgtCard, "", false);
|
final Cost cost = new Cost(tgtCard, "", false);
|
||||||
if (newSA.getPayCosts() != null) {
|
if (newSA.getPayCosts() != null) {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package forge.game.ai;
|
|||||||
|
|
||||||
import java.security.InvalidParameterException;
|
import java.security.InvalidParameterException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -38,6 +39,7 @@ import forge.card.ability.ApiType;
|
|||||||
import forge.card.cardfactory.CardFactoryUtil;
|
import forge.card.cardfactory.CardFactoryUtil;
|
||||||
import forge.card.cost.CostDiscard;
|
import forge.card.cost.CostDiscard;
|
||||||
import forge.card.cost.CostPart;
|
import forge.card.cost.CostPart;
|
||||||
|
import forge.card.spellability.Spell;
|
||||||
import forge.card.spellability.SpellAbility;
|
import forge.card.spellability.SpellAbility;
|
||||||
import forge.card.spellability.SpellPermanent;
|
import forge.card.spellability.SpellPermanent;
|
||||||
import forge.game.GameActionUtil;
|
import forge.game.GameActionUtil;
|
||||||
@@ -731,5 +733,34 @@ public class AiController {
|
|||||||
public boolean getBooleanProperty(AiProps propName) {
|
public boolean getBooleanProperty(AiProps propName) {
|
||||||
return Boolean.parseBoolean(AiProfileUtil.getAIProp(getPlayer().getLobbyPlayer(), 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) {
|
public static final void playStack(final SpellAbility sa, final AIPlayer ai, final GameState game) {
|
||||||
sa.setActivatingPlayer(ai);
|
sa.setActivatingPlayer(ai);
|
||||||
if (ComputerUtilCost.canPayCost(sa, ai)) {
|
if (!ComputerUtilCost.canPayCost(sa, ai))
|
||||||
final Card source = sa.getSourceCard();
|
return;
|
||||||
if (sa.isSpell() && !source.isCopiedSpell()) {
|
|
||||||
sa.setSourceCard(game.getAction().moveToStack(source));
|
final Card source = sa.getSourceCard();
|
||||||
}
|
if (sa.isSpell() && !source.isCopiedSpell()) {
|
||||||
final Cost cost = sa.getPayCosts();
|
sa.setSourceCard(game.getAction().moveToStack(source));
|
||||||
if (cost == null) {
|
}
|
||||||
ComputerUtilMana.payManaCost(ai, sa);
|
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);
|
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");
|
playForMiracleCost.setStackDescription(card.getName() + " - Cast via Miracle");
|
||||||
|
|
||||||
// TODO Convert this to a Trigger
|
// 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.setStackDescription(card.getName() + " - Miracle.");
|
||||||
miracleTrigger.setActivatingPlayer(card.getOwner());
|
miracleTrigger.setActivatingPlayer(card.getOwner());
|
||||||
miracleTrigger.setTrigger(true);
|
miracleTrigger.setTrigger(true);
|
||||||
@@ -3149,36 +3149,24 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private final class MiracleTrigger extends Ability {
|
private final class MiracleTrigger extends Ability {
|
||||||
private final Card card;
|
|
||||||
private final SpellAbility miracle;
|
private final SpellAbility miracle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Write javadoc for Constructor.
|
* TODO: Write javadoc for Constructor.
|
||||||
* @param sourceCard
|
* @param sourceCard
|
||||||
* @param manaCost
|
* @param manaCost
|
||||||
* @param card
|
|
||||||
* @param miracle
|
* @param miracle
|
||||||
*/
|
*/
|
||||||
private MiracleTrigger(Card sourceCard, ManaCost manaCost, Card card, SpellAbility miracle) {
|
private MiracleTrigger(Card sourceCard, ManaCost manaCost, SpellAbility miracle) {
|
||||||
super(sourceCard, manaCost);
|
super(sourceCard, manaCost);
|
||||||
this.card = card;
|
|
||||||
this.miracle = miracle;
|
this.miracle = miracle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resolve() {
|
public void resolve() {
|
||||||
miracle.setActivatingPlayer(card.getOwner());
|
miracle.setActivatingPlayer(getSourceCard().getOwner());
|
||||||
// pay miracle cost here.
|
// pay miracle cost here.
|
||||||
if (card.getOwner().isHuman()) {
|
getSourceCard().getOwner().getController().playMiracle(miracle, getSourceCard());
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -112,4 +112,6 @@ public abstract class PlayerController {
|
|||||||
/** p = target player, validCards - possible discards, min cards to discard */
|
/** 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 List<Card> chooseCardsToDiscardFrom(Player p, SpellAbility sa, List<Card> validCards, int min);
|
||||||
public abstract Card chooseCardToDredge(List<Card> dredgers);
|
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) {
|
public void playFromSuspend(Card c) {
|
||||||
final List<SpellAbility> choices = c.getBasicSpells();
|
final List<SpellAbility> choices = c.getBasicSpells();
|
||||||
c.setSuspendCast(true);
|
c.setSuspendCast(true);
|
||||||
for (final SpellAbility sa : choices) {
|
getAi().chooseAndPlaySa(choices, true, true);
|
||||||
//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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@@ -112,24 +97,7 @@ public class PlayerControllerAi extends PlayerController {
|
|||||||
@Override
|
@Override
|
||||||
public boolean playCascade(Card cascadedCard, Card source) {
|
public boolean playCascade(Card cascadedCard, Card source) {
|
||||||
final List<SpellAbility> choices = cascadedCard.getBasicSpells();
|
final List<SpellAbility> choices = cascadedCard.getBasicSpells();
|
||||||
|
return null != getAi().chooseAndPlaySa(choices, false, true);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -269,4 +237,9 @@ public class PlayerControllerAi extends PlayerController {
|
|||||||
return brains.chooseCardToDredge(dredgers);
|
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;
|
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