- Split OppGainLife costs into the two types, "you may have an opponent gain" and "you may have each other player gain"

This commit is contained in:
moomarc
2013-01-07 15:33:25 +00:00
parent 5c0ed575cb
commit daee42b4da
7 changed files with 256 additions and 17 deletions

1
.gitattributes vendored
View File

@@ -13336,6 +13336,7 @@ src/main/java/forge/card/cost/CostDamage.java -text
src/main/java/forge/card/cost/CostDiscard.java -text
src/main/java/forge/card/cost/CostExile.java -text
src/main/java/forge/card/cost/CostGainLife.java -text
src/main/java/forge/card/cost/CostGainLifeEachOther.java -text
src/main/java/forge/card/cost/CostMana.java -text
src/main/java/forge/card/cost/CostMill.java -text
src/main/java/forge/card/cost/CostPart.java -text

View File

@@ -5,7 +5,7 @@ Text:no text
A:SP$ ChooseType | Cost$ 3 U | Defined$ You | Type$ Creature | SubAbility$ ApplyPressure | SpellDescription$ Choose a creature type. If you control more creatures of that type than each other player, you gain control of all creatures of that type. (This effect lasts indefinitely.)
SVar:ApplyPressure:DB$ GainControl | AllValid$ Creature.ChosenType | NewController$ You | ConditionCheckSVar$ YourPeerGroup | ConditionSVarCompare$ GTY | References$ YourPeerGroup,Y
SVar:YourPeerGroup:Count$Valid Creature.ChosenType+YouCtrl
SVar:Y:Count$Valid Creature.ChosenType+YouDontCtrl
SVar:Y:PlayerCountOther$HighestValid Creature.ChosenType+YouCtrl
SVar:RemAIDeck:True
SVar:RemRandomDeck:True
SVar:Rarity:Rare

View File

@@ -3,7 +3,7 @@ ManaCost:3 G
Types:Sorcery
Text:no text
A:SP$ DestroyAll | Cost$ 3 G | ValidCards$ Enchantment | SpellDescription$ Destroy all enchantments.
A:SP$ DestroyAll | Cost$ OppGainLife<6> | ValidCards$ Enchantment | IsPresent$ Forest.YouCtrl | PrecostDesc$ If you control a Forest, rather than pay CARDNAME's mana cost, | CostDesc$ you may have each other player gain 6 life | SpellDescription$ .
A:SP$ DestroyAll | Cost$ OthersEachGainLife<6> | ValidCards$ Enchantment | IsPresent$ Forest.YouCtrl | PrecostDesc$ If you control a Forest, rather than pay CARDNAME's mana cost, | CostDesc$ you may have each other player gain 6 life | SpellDescription$ .
SVar:Rarity:Common
SVar:Picture:http://www.wizards.com/global/images/magic/general/reverent_silence.jpg
SetInfo:NMS|Common|http://magiccards.info/scans/en/ne/111.jpg

View File

@@ -3,7 +3,7 @@ ManaCost:3 G
Types:Creature Beast
Text:no text
PT:2/2
SVar:AltCost:Cost$ OppGainLife<5> | IsPresent$ Forest.YouCtrl | Description$ If you control a Forest, rather than pay Skyshroud Cutter's mana cost, you may have each other player gain 5 life.
SVar:AltCost:Cost$ OthersEachGainLife<5> | IsPresent$ Forest.YouCtrl | Description$ If you control a Forest, rather than pay Skyshroud Cutter's mana cost, you may have each other player gain 5 life.
SVar:Rarity:Common
SVar:Picture:http://www.wizards.com/global/images/magic/general/skyshroud_cutter.jpg
SetInfo:NMS|Common|http://magiccards.info/scans/en/ne/118.jpg

View File

@@ -154,6 +154,7 @@ public class Cost {
private static final String ADD_STR = "AddCounter<";
private static final String LIFE_STR = "PayLife<";
private static final String LIFE_GAIN_STR = "OppGainLife<";
private static final String EACH_OTHER_LIFE_GAIN_STR = "OthersEachGainLife<";
private static final String DAMAGE_STR = "DamageYou<";
private static final String MILL_STR = "Mill<";
private static final String DISC_STR = "Discard<";
@@ -249,6 +250,14 @@ public class Cost {
this.costParts.add(new CostGainLife(splitStr[0]));
}
while (parse.contains(Cost.EACH_OTHER_LIFE_GAIN_STR)) {
// PayLife<LifeCost>
final String[] splitStr = this.abCostParse(parse, Cost.EACH_OTHER_LIFE_GAIN_STR, 1);
parse = this.abUpdateParse(parse, Cost.EACH_OTHER_LIFE_GAIN_STR);
this.costParts.add(new CostGainLifeEachOther(splitStr[0]));
}
while (parse.contains(Cost.DAMAGE_STR)) {
// PayLife<LifeCost>
final String[] splitStr = this.abCostParse(parse, Cost.DAMAGE_STR, 1);

View File

@@ -17,11 +17,14 @@
*/
package forge.card.cost;
import java.util.ArrayList;
import java.util.List;
import forge.Card;
import forge.GameActionUtil;
import forge.card.abilityfactory.AbilityFactory;
import forge.card.spellability.SpellAbility;
import forge.game.player.Player;
import forge.gui.GuiChoose;
/**
* The Class CostGainLife.
@@ -66,7 +69,7 @@ public class CostGainLife extends CostPart {
@Override
public final String toString() {
final StringBuilder sb = new StringBuilder();
sb.append("Have each other player gain ").append(this.getAmount()).append(" Life");
sb.append("Have an opponent gain ").append(this.getAmount()).append(" life");
return sb.toString();
}
@@ -90,11 +93,17 @@ public class CostGainLife extends CostPart {
@Override
public final boolean canPay(final SpellAbility ability, final Card source, final Player activator, final Cost cost) {
final Integer amount = this.convertAmount();
if ((amount != null) && !activator.getOpponent().canGainLife()) {
return false;
boolean oppCanGainLife = false;
if (amount != null) {
for (final Player opp : activator.getOpponents()) {
if (opp.canGainLife()) {
oppCanGainLife = true;
break;
}
}
}
return true;
return oppCanGainLife;
}
/*
@@ -105,7 +114,13 @@ public class CostGainLife extends CostPart {
*/
@Override
public final void payAI(final Player ai, final SpellAbility ability, final Card source, final CostPayment payment) {
ai.getOpponent().gainLife(this.getLastPaidAmount(), null);
final List<Player> oppsThatCanGainLife = new ArrayList<Player>();
for (final Player opp : ai.getOpponents()) {
if (opp.canGainLife()) {
oppsThatCanGainLife.add(opp);
}
}
oppsThatCanGainLife.get(0).gainLife(this.getLastPaidAmount(), null);
}
/*
@@ -132,17 +147,26 @@ public class CostGainLife extends CostPart {
}
}
final StringBuilder sb = new StringBuilder();
sb.append(source.getName()).append(" - Have each other player gain ").append(c).append(" Life?");
final List<Player> oppsThatCanGainLife = new ArrayList<Player>();
for (final Player opp : activator.getOpponents()) {
if (opp.canGainLife()) {
oppsThatCanGainLife.add(opp);
}
}
if (GameActionUtil.showYesNoDialog(source, sb.toString()) && activator.getOpponent().canGainLife()) {
activator.getOpponent().gainLife(c, null);
this.setLastPaidAmount(c);
payment.setPaidManaPart(this);
} else {
final StringBuilder sb = new StringBuilder();
sb.append(source.getName()).append(" - Choose an opponent to gain ").append(c).append(" life:");
final Player chosenToGain = GuiChoose.oneOrNone(sb.toString(), oppsThatCanGainLife);
if (null == chosenToGain) {
payment.setCancel(true);
payment.getRequirements().finishPaying();
return false;
} else {
final Player chosen = chosenToGain;
chosen.gainLife(c, null);
this.setLastPaidAmount(c);
payment.setPaidManaPart(this);
}
return true;
}
@@ -168,7 +192,15 @@ public class CostGainLife extends CostPart {
c = AbilityFactory.calculateAmount(source, this.getAmount(), ability);
}
}
if (!ai.getOpponent().canGainLife()) {
final List<Player> oppsThatCanGainLife = new ArrayList<Player>();
for (final Player opp : ai.getOpponents()) {
if (opp.canGainLife()) {
oppsThatCanGainLife.add(opp);
}
}
if (oppsThatCanGainLife.size() == 0) {
return false;
}
this.setLastPaidAmount(c);

View File

@@ -0,0 +1,197 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package forge.card.cost;
import forge.Card;
import forge.GameActionUtil;
import forge.card.abilityfactory.AbilityFactory;
import forge.card.spellability.SpellAbility;
import forge.game.player.Player;
/**
* The Class CostGainLife.
*/
public class CostGainLifeEachOther extends CostPart {
private int lastPaidAmount = 0;
/**
* Gets the last paid amount.
*
* @return the last paid amount
*/
public final int getLastPaidAmount() {
return this.lastPaidAmount;
}
/**
* Sets the last paid amount.
*
* @param paidAmount
* the new last paid amount
*/
public final void setLastPaidAmount(final int paidAmount) {
this.lastPaidAmount = paidAmount;
}
/**
* Instantiates a new cost gain life.
*
* @param amount
* the amount
*/
public CostGainLifeEachOther(final String amount) {
this.setAmount(amount);
}
/*
* (non-Javadoc)
*
* @see forge.card.cost.CostPart#toString()
*/
@Override
public final String toString() {
final StringBuilder sb = new StringBuilder();
sb.append("Have each other player gain ").append(this.getAmount()).append(" life");
return sb.toString();
}
/*
* (non-Javadoc)
*
* @see forge.card.cost.CostPart#refund(forge.Card)
*/
@Override
public void refund(final Card source) {
}
/*
* (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, final Card source, final Player activator, final Cost cost) {
final Integer amount = this.convertAmount();
if (amount != null) {
for (final Player otherP : activator.getAllOtherPlayers()) {
if (!otherP.canGainLife()) {
return false;
}
}
}
return true;
}
/*
* (non-Javadoc)
*
* @see forge.card.cost.CostPart#payAI(forge.card.spellability.SpellAbility,
* forge.Card, forge.card.cost.Cost_Payment)
*/
@Override
public final void payAI(final Player ai, final SpellAbility ability, final Card source, final CostPayment payment) {
for (final Player otherP : ai.getAllOtherPlayers()) {
otherP.gainLife(this.getLastPaidAmount(), null);
}
}
/*
* (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 Card source, final CostPayment payment) {
final String amount = this.getAmount();
final Player activator = ability.getActivatingPlayer();
final int life = activator.getLife();
Integer c = this.convertAmount();
if (c == null) {
final String sVar = ability.getSVar(amount);
// Generalize this
if (sVar.equals("XChoice")) {
c = CostUtil.chooseXValue(source, ability, life);
} else {
c = AbilityFactory.calculateAmount(source, amount, ability);
}
}
for (final Player other : activator.getAllOtherPlayers()) {
// each other player MUST be able to gain life
if (!other.canGainLife()) {
payment.setCancel(true);
payment.getRequirements().finishPaying();
return false;
}
}
final StringBuilder sb = new StringBuilder();
sb.append(source.getName()).append(" - Have each other player gain ").append(c).append(" life?");
if (GameActionUtil.showYesNoDialog(source, sb.toString())) {
for (final Player playerToGain : activator.getAllOtherPlayers()) {
playerToGain.gainLife(c, null);
this.setLastPaidAmount(c);
payment.setPaidManaPart(this);
}
} else {
payment.setCancel(true);
payment.getRequirements().finishPaying();
return false;
}
return true;
}
/*
* (non-Javadoc)
*
* @see
* forge.card.cost.CostPart#decideAIPayment(forge.card.spellability.SpellAbility
* , forge.Card, forge.card.cost.Cost_Payment)
*/
@Override
public final boolean decideAIPayment(final Player ai, final SpellAbility ability, final Card source, final CostPayment payment) {
Integer c = this.convertAmount();
if (c == null) {
final String sVar = ability.getSVar(this.getAmount());
// Generalize this
if (sVar.equals("XChoice")) {
return false;
} else {
c = AbilityFactory.calculateAmount(source, this.getAmount(), ability);
}
}
for (final Player otherP : ai.getAllOtherPlayers()) {
if (!otherP.canGainLife()) {
return false;
}
}
this.setLastPaidAmount(c);
return true;
}
}