mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 04:08:01 +00:00
renamed GameActionPlay.playSpellAbilityForFree into playCardWithoutPayingManaCost
PlayEffect.java - optimized the part which plays the spell
This commit is contained in:
@@ -13,10 +13,6 @@ import forge.CardLists;
|
||||
import forge.Singletons;
|
||||
import forge.card.ability.AbilityUtils;
|
||||
import forge.card.ability.SpellAbilityEffect;
|
||||
import forge.card.cost.Cost;
|
||||
import forge.card.cost.CostPart;
|
||||
import forge.card.cost.CostPartMana;
|
||||
import forge.card.mana.ManaCost;
|
||||
import forge.card.spellability.Spell;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.card.spellability.SpellAbilityRestriction;
|
||||
@@ -203,52 +199,27 @@ public class PlayEffect extends SpellAbilityEffect {
|
||||
tgtSA.getTarget().setMandatory(true);
|
||||
}
|
||||
|
||||
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) {
|
||||
for (final CostPart part : newSA.getPayCosts().getCostParts()) {
|
||||
if (!(part instanceof CostPartMana)) {
|
||||
cost.getCostParts().add(part);
|
||||
}
|
||||
}
|
||||
}
|
||||
newSA.setPayCosts(cost);
|
||||
newSA.setManaCost(ManaCost.NO_COST);
|
||||
newSA.setDescription(newSA.getDescription() + " (without paying its mana cost)");
|
||||
game.getActionPlay().playSpellAbility(newSA, activator);
|
||||
if (remember) {
|
||||
source.addRemembered(tgtSA.getSourceCard());
|
||||
}
|
||||
} else {
|
||||
if (tgtSA instanceof Spell) {
|
||||
Spell spell = (Spell) tgtSA;
|
||||
if (spell.canPlayFromEffectAI(!optional, true) || !optional) {
|
||||
ComputerUtil.playSpellAbilityWithoutPayingManaCost((AIPlayer)controller, tgtSA, game);
|
||||
if (remember) {
|
||||
source.addRemembered(tgtSA.getSourceCard());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean noManaCost = sa.hasParam("WithoutManaCost");
|
||||
if (controller.isHuman()) {
|
||||
SpellAbility newSA = noManaCost ? tgtSA.copyWithNoManaCost() : tgtSA;
|
||||
game.getActionPlay().playSpellAbility(newSA, activator);
|
||||
} else {
|
||||
if (controller.isHuman()) {
|
||||
game.getActionPlay().playSpellAbility(tgtSA, activator);
|
||||
} else {
|
||||
if (tgtSA instanceof Spell) {
|
||||
Spell spell = (Spell) tgtSA;
|
||||
if (spell.canPlayFromEffectAI(!optional, false) || !optional) {
|
||||
if (tgtSA instanceof Spell) { // Isn't it ALWAYS a spell?
|
||||
Spell spell = (Spell) tgtSA;
|
||||
if (spell.canPlayFromEffectAI(!optional, noManaCost) || !optional) {
|
||||
if (noManaCost) {
|
||||
ComputerUtil.playSpellAbilityWithoutPayingManaCost((AIPlayer)controller, tgtSA, game);
|
||||
} else {
|
||||
ComputerUtil.playStack(tgtSA, (AIPlayer)controller, game);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (remember) {
|
||||
source.addRemembered(tgtSA.getSourceCard());
|
||||
} else
|
||||
remember = false; // didn't play spell
|
||||
}
|
||||
}
|
||||
if (remember) {
|
||||
source.addRemembered(tgtSA.getSourceCard());
|
||||
}
|
||||
|
||||
}
|
||||
} // end resolve
|
||||
|
||||
|
||||
@@ -31,6 +31,8 @@ import forge.Singletons;
|
||||
import forge.card.ability.AbilityUtils;
|
||||
import forge.card.ability.ApiType;
|
||||
import forge.card.cost.Cost;
|
||||
import forge.card.cost.CostPart;
|
||||
import forge.card.cost.CostPartMana;
|
||||
import forge.card.mana.Mana;
|
||||
import forge.card.mana.ManaCost;
|
||||
import forge.control.input.Input;
|
||||
@@ -1203,6 +1205,22 @@ public abstract class SpellAbility implements ISpellAbility {
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
|
||||
public SpellAbility copyWithNoManaCost() {
|
||||
final SpellAbility newSA = this;
|
||||
final Cost cost = new Cost(this.getSourceCard(), "", false);
|
||||
if (newSA.getPayCosts() != null) {
|
||||
for (final CostPart part : newSA.getPayCosts().getCostParts()) {
|
||||
if (!(part instanceof CostPartMana)) {
|
||||
cost.getCostParts().add(part);
|
||||
}
|
||||
}
|
||||
}
|
||||
newSA.setPayCosts(cost);
|
||||
newSA.setManaCost(ManaCost.NO_COST);
|
||||
newSA.setDescription(newSA.getDescription() + " (without paying its mana cost)");
|
||||
return newSA;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
||||
@@ -60,7 +60,7 @@ public class GameActionPlay {
|
||||
}
|
||||
|
||||
sa.setActivatingPlayer(player);
|
||||
this.playSpellAbilityForFree(sa);
|
||||
this.playSpellAbilityWithoutPayingManaCost(sa);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,7 +71,7 @@ public class GameActionPlay {
|
||||
* @param sa
|
||||
* a {@link forge.card.spellability.SpellAbility} object.
|
||||
*/
|
||||
public final void playSpellAbilityForFree(final SpellAbility sa) {
|
||||
public final void playSpellAbilityWithoutPayingManaCost(final SpellAbility sa) {
|
||||
final Card source = sa.getSourceCard();
|
||||
setSplitCardState(source, sa); // Split card support
|
||||
|
||||
|
||||
@@ -55,14 +55,12 @@ import forge.card.mana.ManaCost;
|
||||
import forge.card.spellability.Ability;
|
||||
import forge.card.spellability.AbilityManaPart;
|
||||
import forge.card.spellability.AbilitySub;
|
||||
import forge.card.spellability.Spell;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.card.spellability.SpellAbilityRestriction;
|
||||
import forge.control.input.Input;
|
||||
import forge.control.input.InputPayDiscardCost;
|
||||
import forge.control.input.InputPayManaExecuteCommands;
|
||||
import forge.control.input.InputPayReturnCost;
|
||||
import forge.game.ai.ComputerUtil;
|
||||
import forge.game.event.CardDamagedEvent;
|
||||
import forge.game.event.LifeLossEvent;
|
||||
import forge.game.player.AIPlayer;
|
||||
@@ -279,24 +277,10 @@ public final class GameActionUtil {
|
||||
revealed.remove(rippledCards[i]);
|
||||
}
|
||||
} else {
|
||||
final List<SpellAbility> choices = rippledCards[i].getBasicSpells();
|
||||
|
||||
for (final SpellAbility sa : choices) {
|
||||
//Spells
|
||||
if (sa instanceof Spell) {
|
||||
Spell spell = (Spell) sa;
|
||||
if (!spell.canPlayFromEffectAI(false, true)) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (!sa.canPlayAI() && !sa.getSourceCard().isType("Legendary")) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
ComputerUtil.playSpellAbilityWithoutPayingManaCost((AIPlayer)p, sa, game);
|
||||
AIPlayer ai = (AIPlayer) p;
|
||||
SpellAbility saPlayed = ai.getAi().chooseAndPlaySa(rippledCards[i].getBasicSpells(), false, true);
|
||||
if ( saPlayed != null )
|
||||
revealed.remove(rippledCards[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -335,10 +319,8 @@ public final class GameActionUtil {
|
||||
c.addExtrinsicKeyword("Ripple:4");
|
||||
}
|
||||
|
||||
final List<String> a = c.getKeyword();
|
||||
for (int x = 0; x < a.size(); x++) {
|
||||
if (a.get(x).toString().startsWith("Ripple")) {
|
||||
final String parse = c.getKeyword().get(x).toString();
|
||||
for (String parse : c.getKeyword()) {
|
||||
if (parse.startsWith("Ripple")) {
|
||||
final String[] k = parse.split(":");
|
||||
this.doRipple(c, Integer.valueOf(k[1]), controller);
|
||||
}
|
||||
|
||||
@@ -239,10 +239,10 @@ public class ComputerUtil {
|
||||
|
||||
final Card source = sa.getSourceCard();
|
||||
if (sa.isSpell() && !source.isCopiedSpell()) {
|
||||
sa.setSourceCard(Singletons.getModel().getGame().getAction().moveToStack(source));
|
||||
sa.setSourceCard(ai.getGame().getAction().moveToStack(source));
|
||||
}
|
||||
|
||||
Singletons.getModel().getGame().getStack().add(sa);
|
||||
ai.getGame().getStack().add(sa);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -254,20 +254,7 @@ public class ComputerUtil {
|
||||
* a {@link forge.card.spellability.SpellAbility} object.
|
||||
*/
|
||||
public static final void playSpellAbilityWithoutPayingManaCost(final AIPlayer ai, final SpellAbility sa, final GameState game) {
|
||||
final SpellAbility newSA = sa.copy();
|
||||
final Cost cost = new Cost(sa.getSourceCard(), "", false);
|
||||
if (newSA.getPayCosts() != null) {
|
||||
for (final CostPart part : newSA.getPayCosts().getCostParts()) {
|
||||
if (!(part instanceof CostPartMana)) {
|
||||
cost.getCostParts().add(part);
|
||||
}
|
||||
}
|
||||
}
|
||||
newSA.setPayCosts(cost);
|
||||
newSA.setManaCost(ManaCost.ZERO);
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append(sa.getDescription()).append(" (without paying its mana cost)");
|
||||
newSA.setDescription(sb.toString());
|
||||
final SpellAbility newSA = sa.copyWithNoManaCost();
|
||||
newSA.setActivatingPlayer(ai);
|
||||
|
||||
if (!ComputerUtilCost.canPayAdditionalCosts(newSA, ai, game)) {
|
||||
@@ -279,7 +266,7 @@ public class ComputerUtil {
|
||||
newSA.setSourceCard(game.getAction().moveToStack(source));
|
||||
}
|
||||
|
||||
final CostPayment pay = new CostPayment(cost, newSA, game);
|
||||
final CostPayment pay = new CostPayment(newSA.getPayCosts(), newSA, game);
|
||||
pay.payComputerCosts(ai, game);
|
||||
|
||||
game.getStack().add(newSA);
|
||||
|
||||
@@ -119,7 +119,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
*/
|
||||
@Override
|
||||
public void playSpellAbilityForFree(SpellAbility copySA) {
|
||||
game.getActionPlay().playSpellAbilityForFree(copySA);
|
||||
game.getActionPlay().playSpellAbilityWithoutPayingManaCost(copySA);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -630,7 +630,7 @@ public final class GuiDisplayUtil {
|
||||
|
||||
sa.setActivatingPlayer(p);
|
||||
game.getAction().moveToHand(forgeCard); // this is really needed
|
||||
game.getActionPlay().playSpellAbilityForFree(sa);
|
||||
game.getActionPlay().playSpellAbilityWithoutPayingManaCost(sa);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user