diff --git a/.gitattributes b/.gitattributes index f582f007e79..c2b95053108 100644 --- a/.gitattributes +++ b/.gitattributes @@ -14772,6 +14772,7 @@ src/main/java/forge/card/cardfactory/CardFactoryUtil.java svneol=native#text/pla src/main/java/forge/card/cardfactory/CardStorageReader.java svneol=native#text/plain src/main/java/forge/card/cardfactory/package-info.java svneol=native#text/plain src/main/java/forge/card/cost/Cost.java svneol=native#text/plain +src/main/java/forge/card/cost/CostAddMana.java -text src/main/java/forge/card/cost/CostDamage.java -text src/main/java/forge/card/cost/CostDiscard.java -text src/main/java/forge/card/cost/CostDraw.java -text diff --git a/res/cardsfolder/b/braid_of_fire.txt b/res/cardsfolder/b/braid_of_fire.txt index bb3b7cfec40..690c9faf771 100644 --- a/res/cardsfolder/b/braid_of_fire.txt +++ b/res/cardsfolder/b/braid_of_fire.txt @@ -1,7 +1,7 @@ Name:Braid of Fire ManaCost:1 R Types:Enchantment -Text:Cumulative upkeep-Add R to your mana pool. +K:Cumulative upkeep:AddMana<1/R>:Add R to your mana pool. SVar:RemAIDeck:True SVar:Picture:http://www.wizards.com/global/images/magic/general/braid_of_fire.jpg Oracle:Cumulative upkeep-Add {R} to your mana pool. (At the beginning of your upkeep, put an age counter on this permanent, then sacrifice it unless you pay its upkeep cost for each age counter on it.) \ No newline at end of file diff --git a/src/main/java/forge/card/cost/Cost.java b/src/main/java/forge/card/cost/Cost.java index b8b08d14e80..0601a70b31a 100644 --- a/src/main/java/forge/card/cost/Cost.java +++ b/src/main/java/forge/card/cost/Cost.java @@ -268,6 +268,13 @@ public class Cost { return new CostDiscard(splitStr[0], splitStr[1], description); } + if (parse.startsWith("AddMana<")) { + // AddMana + final String[] splitStr = abCostParse(parse, 3); + final String description = splitStr.length > 2 ? splitStr[2] : null; + return new CostAddMana(splitStr[0], splitStr[1], description); + } + if (parse.startsWith("Sac<")) { final String[] splitStr = abCostParse(parse, 3); final String description = splitStr.length > 2 ? splitStr[2] : null; diff --git a/src/main/java/forge/card/cost/CostAddMana.java b/src/main/java/forge/card/cost/CostAddMana.java new file mode 100644 index 00000000000..c6a02aa30df --- /dev/null +++ b/src/main/java/forge/card/cost/CostAddMana.java @@ -0,0 +1,173 @@ +/* + * Forge: Play Magic: the Gathering. + * Copyright (C) 2011 Forge Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package forge.card.cost; + +import java.util.ArrayList; +import org.apache.commons.lang.StringUtils; + +import forge.Card; +import forge.card.ColorSet; +import forge.card.MagicColor; +import forge.card.ability.AbilityUtils; +import forge.card.mana.Mana; +import forge.card.spellability.SpellAbility; +import forge.game.Game; +import forge.game.GameType; +import forge.game.player.Player; + +/** + * The Class CostAddMana. + */ +public class CostAddMana extends CostPart { + /** + * CostCostAddMana. + * @param amount + * @param playerSelector + */ + public CostAddMana(final String amount, final String type, final String description) { + super(amount, type, description); + } + + /* + * (non-Javadoc) + * + * @see forge.card.cost.CostPart#toString() + */ + @Override + public final String toString() { + final StringBuilder sb = new StringBuilder(); + final Integer i = this.convertAmount(); + sb.append("Add ").append(convertManaAmountType(i, this.getType())); + sb.append(" to your mana pool"); + return sb.toString(); + } + + /** + * convertManaAmountType. + * @param i + * @param type + * @return a String + */ + private String convertManaAmountType(Integer i, String type) { + return StringUtils.repeat(" " + type, i).trim(); + } + + /* + * (non-Javadoc) + * + * @see + * forge.card.cost.CostPart#canPay(forge.card.spellability.SpellAbility, + * forge.Card, forge.Player, forge.card.cost.Cost) + */ + @Override + public final boolean canPay(final SpellAbility ability) { + return true; + } + + /* + * (non-Javadoc) + * + * @see forge.card.cost.CostPart#payAI(forge.card.spellability.SpellAbility, + * forge.Card, forge.card.cost.Cost_Payment) + */ + @Override + public final boolean payAI(final PaymentDecision decision, final Player ai, SpellAbility ability, Card source) { + ColorSet cid = null; + if (ai.getGame().getType() == GameType.Commander) { + cid = ai.getCommander().getRules().getColorIdentity(); + } + ArrayList manaProduced = new ArrayList(); + final String type = this.getType(); + for (int n = 0; n < decision.c; n++) { + if (StringUtils.isNumeric(type)) { + for (int i = Integer.parseInt(type); i > 0; i--) { + manaProduced.add(new Mana(MagicColor.COLORLESS, source, null)); + } + } else { + byte attemptedMana = MagicColor.fromName(type); + if (cid != null) { + if (!cid.hasAnyColor(attemptedMana)) { + attemptedMana = MagicColor.COLORLESS; + } + } + manaProduced.add(new Mana(attemptedMana, source, null)); + } + } + ai.getManaPool().add(manaProduced); + + return true; + } + + /* + * (non-Javadoc) + * + * @see + * forge.card.cost.CostPart#payHuman(forge.card.spellability.SpellAbility, + * forge.Card, forge.card.cost.Cost_Payment) + */ + @Override + public final boolean payHuman(final SpellAbility ability, final Game game) { + final Player activator = ability.getActivatingPlayer(); + final Card source = ability.getSourceCard(); + Integer c = this.convertAmount(); + if (c == null) { + c = AbilityUtils.calculateAmount(source, this.getAmount(), ability); + } + ColorSet cid = null; + if (activator.getGame().getType() == GameType.Commander) { + cid = activator.getCommander().getRules().getColorIdentity(); + } + ArrayList manaProduced = new ArrayList(); + final String type = this.getType(); + for (int n = 0; n < c; n++) { + if (StringUtils.isNumeric(type)) { + for (int i = Integer.parseInt(type); i > 0; i--) { + manaProduced.add(new Mana(MagicColor.COLORLESS, source, null)); + } + } else { + byte attemptedMana = MagicColor.fromName(type); + if (cid != null) { + if (!cid.hasAnyColor(attemptedMana)) { + attemptedMana = MagicColor.COLORLESS; + } + } + manaProduced.add(new Mana(attemptedMana, source, null)); + } + } + activator.getManaPool().add(manaProduced); + return true; + } + + /* + * (non-Javadoc) + * + * @see + * forge.card.cost.CostPart#decideAIPayment(forge.card.spellability.SpellAbility + * , forge.Card, forge.card.cost.Cost_Payment) + */ + @Override + public final PaymentDecision decideAIPayment(final Player ai, final SpellAbility ability, final Card source) { + Integer c = this.convertAmount(); + + if (c == null) { + c = AbilityUtils.calculateAmount(source, this.getAmount(), ability); + } + + return new PaymentDecision(c); + } +} diff --git a/src/main/java/forge/card/mana/ManaPool.java b/src/main/java/forge/card/mana/ManaPool.java index ad89e4ac480..0026457e183 100644 --- a/src/main/java/forge/card/mana/ManaPool.java +++ b/src/main/java/forge/card/mana/ManaPool.java @@ -126,7 +126,7 @@ public class ManaPool { if (isEndOfPhase && !owner.getGame().getPhaseHandler().is(PhaseType.CLEANUP)) { final List pMana = new ArrayList(); for (final Mana mana : this.floatingMana.get(b)) { - if (mana.getManaAbility().isPersistentMana()) { + if (mana.getManaAbility()!= null && mana.getManaAbility().isPersistentMana()) { pMana.add(mana); } } diff --git a/src/main/java/forge/game/phase/Upkeep.java b/src/main/java/forge/game/phase/Upkeep.java index ecaee839264..458e5cc1bf5 100644 --- a/src/main/java/forge/game/phase/Upkeep.java +++ b/src/main/java/forge/game/phase/Upkeep.java @@ -79,7 +79,6 @@ public class Upkeep extends Phase { public final void executeAt() { game.getStack().freezeStack(); - Upkeep.upkeepBraidOfFire(game); Upkeep.upkeepUpkeepCost(game); // sacrifice unless upkeep cost is paid Upkeep.upkeepEcho(game); diff --git a/src/main/java/forge/game/player/HumanPlay.java b/src/main/java/forge/game/player/HumanPlay.java index 9a64e97b2bf..08c9f253d28 100644 --- a/src/main/java/forge/game/player/HumanPlay.java +++ b/src/main/java/forge/game/player/HumanPlay.java @@ -22,6 +22,7 @@ import forge.card.ability.effects.CharmEffect; import forge.card.ability.effects.FlipCoinEffect; import forge.card.cardfactory.CardFactoryUtil; import forge.card.cost.Cost; +import forge.card.cost.CostAddMana; import forge.card.cost.CostDamage; import forge.card.cost.CostDiscard; import forge.card.cost.CostDraw; @@ -367,6 +368,17 @@ public class HumanPlay { } } + else if (part instanceof CostAddMana) { + if (!GuiDialog.confirm(source, "Do you want to add " + + ((CostAddMana) part).toString() + + " to your mana pool?" + orString)) { + return false; + } + if (!part.payHuman(sourceAbility, p.getGame())) { + return false; + } + } + else if (part instanceof CostMill) { final int amount = getAmountFromPart(part, source, sourceAbility); final List list = p.getCardsIn(ZoneType.Library);