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