made a few methods with descriptive names to wrap that payManaCost with 5 parameters

corrected the extra mana calculation for Nether Void and Spelltithe Enforcer
This commit is contained in:
Maxmtg
2013-05-18 06:57:02 +00:00
parent 594e1e7cf6
commit bdc11dd9e7
5 changed files with 48 additions and 57 deletions

View File

@@ -4,7 +4,7 @@ Types:World Enchantment
T:Mode$ SpellCast | ValidCard$ Card | ValidActivatingPlayer$ Player | TriggerZones$ Battlefield | Execute$ TrigCounter | TriggerDescription$ Whenever a player casts a spell, counter it unless its controller pays 3. T:Mode$ SpellCast | ValidCard$ Card | ValidActivatingPlayer$ Player | TriggerZones$ Battlefield | Execute$ TrigCounter | TriggerDescription$ Whenever a player casts a spell, counter it unless its controller pays 3.
SVar:TrigCounter:DB$ Counter | Cost$ 0 | UnlessCost$ 3 | Defined$ TriggeredSpellAbility | UnlessPayer$ TriggeredCardController SVar:TrigCounter:DB$ Counter | Cost$ 0 | UnlessCost$ 3 | Defined$ TriggeredSpellAbility | UnlessPayer$ TriggeredCardController
SVar:RemRandomDeck:True SVar:RemRandomDeck:True
SVar:SpellsNeedExtraMana:3 SVar:AI_SpellsNeedExtraMana:3
SVar:Picture:http://www.wizards.com/global/images/magic/general/nether_void.jpg SVar:Picture:http://www.wizards.com/global/images/magic/general/nether_void.jpg
Oracle:Whenever a player casts a spell, counter it unless its controller pays {3}. Oracle:Whenever a player casts a spell, counter it unless its controller pays {3}.
SetInfo:LEG Rare SetInfo:LEG Rare

View File

@@ -4,7 +4,7 @@ Types:Creature Elephant Wizard
PT:3/3 PT:3/3
T:Mode$ SpellCast | ValidCard$ Card | ValidActivatingPlayer$ Opponent | TriggerZones$ Battlefield | Execute$ TrigSac | TriggerDescription$ Whenever an opponent casts a spell, that player sacrifices a permanent unless he or she pays {1}. T:Mode$ SpellCast | ValidCard$ Card | ValidActivatingPlayer$ Opponent | TriggerZones$ Battlefield | Execute$ TrigSac | TriggerDescription$ Whenever an opponent casts a spell, that player sacrifices a permanent unless he or she pays {1}.
SVar:TrigSac:DB$ Sacrifice | Defined$ TriggeredCardController | SacValid$ Permanent | SacMessage$ Permanent | UnlessCost$ 1 | UnlessPayer$ TriggeredCardController SVar:TrigSac:DB$ Sacrifice | Defined$ TriggeredCardController | SacValid$ Permanent | SacMessage$ Permanent | UnlessCost$ 1 | UnlessPayer$ TriggeredCardController
SVar:SpellsNeedExtraMana:1 SVar:AI_SpellsNeedExtraMana:1 Opponent
SVar:Picture:http://www.wizards.com/global/images/magic/general/spelltithe_enforcer.jpg SVar:Picture:http://www.wizards.com/global/images/magic/general/spelltithe_enforcer.jpg
Oracle:Whenever an opponent casts a spell, that player sacrifices a permanent unless he or she pays {1}. Oracle:Whenever an opponent casts a spell, that player sacrifices a permanent unless he or she pays {1}.
SetInfo:GPT Rare SetInfo:GPT Rare

View File

@@ -489,7 +489,6 @@ public class ChangeZoneAi extends SpellAbilityAi {
* @return Card * @return Card
*/ */
private static Card chooseCreature(final Player ai, List<Card> list) { private static Card chooseCreature(final Player ai, List<Card> list) {
Card card = null;
Combat combat = new Combat(); Combat combat = new Combat();
combat.initiatePossibleDefenders(ai); combat.initiatePossibleDefenders(ai);
List<Card> attackers = ai.getOpponent().getCreaturesInPlay(); List<Card> attackers = ai.getOpponent().getCreaturesInPlay();
@@ -504,16 +503,14 @@ public class ChangeZoneAi extends SpellAbilityAi {
for (Card c : list) { for (Card c : list) {
SpellAbility spell = c.getFirstSpellAbility(); SpellAbility spell = c.getFirstSpellAbility();
spell.setActivatingPlayer(ai); spell.setActivatingPlayer(ai);
if (ComputerUtilMana.payManaCost(spell, ai, true, 0, false)) { if (ComputerUtilMana.hasEnoughManaSourcesToCast(spell, ai))
card = c; return c;
break;
} }
return null;
} }
} else {
// not urgent, get the largest creature possible // not urgent, get the largest creature possible
card = ComputerUtilCard.getBestCreatureAI(list); return ComputerUtilCard.getBestCreatureAI(list);
}
return card;
} }
// ************************************************************************************* // *************************************************************************************
@@ -865,7 +862,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
System.out.println("5 Life or less, trying to find something castable."); System.out.println("5 Life or less, trying to find something castable.");
CardLists.sortByCmcDesc(nonLands); CardLists.sortByCmcDesc(nonLands);
for (Card potentialCard : nonLands) { for (Card potentialCard : nonLands) {
if (ComputerUtilMana.payManaCost(potentialCard.getFirstSpellAbility(), ai, true, 0, false)) { if (ComputerUtilMana.hasEnoughManaSourcesToCast(potentialCard.getFirstSpellAbility(), ai)) {
choice = potentialCard; choice = potentialCard;
break; break;
} }
@@ -976,7 +973,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
System.out.println("5 Life or less, trying to find something castable."); System.out.println("5 Life or less, trying to find something castable.");
CardLists.sortByCmcDesc(nonLands); CardLists.sortByCmcDesc(nonLands);
for (Card potentialCard : nonLands) { for (Card potentialCard : nonLands) {
if (ComputerUtilMana.payManaCost(potentialCard.getFirstSpellAbility(), ai, true, 0, false)) { if (ComputerUtilMana.hasEnoughManaSourcesToCast(potentialCard.getFirstSpellAbility(), ai)) {
choice = potentialCard; choice = potentialCard;
break; break;
} }
@@ -1210,7 +1207,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
for (Card cardInHand : hand) { for (Card cardInHand : hand) {
final SpellAbility spell = cardInHand.getFirstSpellAbility(); final SpellAbility spell = cardInHand.getFirstSpellAbility();
spell.setActivatingPlayer(ai); spell.setActivatingPlayer(ai);
canCastSomething |= ComputerUtilMana.payManaCost(spell, ai, true, 0, false); canCastSomething |= ComputerUtilMana.hasEnoughManaSourcesToCast(spell, ai);
} }
if (!canCastSomething) { if (!canCastSomething) {
System.out.println("Pulling a land as there are none in hand, less than 4 on the board, and nothing in hand is castable."); System.out.println("Pulling a land as there are none in hand, less than 4 on the board, and nothing in hand is castable.");
@@ -1229,7 +1226,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
System.out.println("5 Life or less, trying to find something castable."); System.out.println("5 Life or less, trying to find something castable.");
CardLists.sortByCmcDesc(fetchList); CardLists.sortByCmcDesc(fetchList);
for (Card potentialCard : fetchList) { for (Card potentialCard : fetchList) {
if (ComputerUtilMana.payManaCost(potentialCard.getFirstSpellAbility(), ai, true, 0, false)) { if (ComputerUtilMana.hasEnoughManaSourcesToCast(potentialCard.getFirstSpellAbility(), ai)) {
c = potentialCard; c = potentialCard;
break; break;
} }

View File

@@ -23,6 +23,7 @@ import forge.card.spellability.SpellAbility;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
import forge.util.MyRandom; import forge.util.MyRandom;
import forge.util.TextUtil;
/** /**
* TODO: Write javadoc for this type. * TODO: Write javadoc for this type.
@@ -346,10 +347,14 @@ public class ComputerUtilCost {
// Check for stuff like Nether Void // Check for stuff like Nether Void
int extraManaNeeded = 0; int extraManaNeeded = 0;
if (sa instanceof Spell) { if (sa instanceof Spell) {
for (Player opp : player.getOpponents()) { for (Card c : player.getGame().getCardsIn(ZoneType.Battlefield)) {
for (Card c : opp.getCardsIn(ZoneType.Battlefield)) { final String snem = c.getSVar("AI_SpellsNeedExtraMana");
final String snem = c.getSVar("SpellsNeedExtraMana");
if (!StringUtils.isBlank(snem)) { if (!StringUtils.isBlank(snem)) {
String[] parts = TextUtil.split(snem, ' ');
boolean meetsRestriction = parts.length == 1 || player.isValid(parts[1], c.getController(), c);
if(!meetsRestriction)
continue;
try { try {
extraManaNeeded += Integer.parseInt(snem); extraManaNeeded += Integer.parseInt(snem);
} catch (final NumberFormatException e) { } catch (final NumberFormatException e) {
@@ -358,13 +363,9 @@ public class ComputerUtilCost {
} }
} }
} }
}
if (!ComputerUtilMana.payManaCost(sa, player, true, extraManaNeeded, true)) { return ComputerUtilMana.canPayManaCost(sa, player, extraManaNeeded)
return false; && CostPayment.canPayAdditionalCosts(sa.getPayCosts(), sa);
}
return CostPayment.canPayAdditionalCosts(sa.getPayCosts(), sa);
} // canPayCost() } // canPayCost()
public static boolean willPayUnlessCost(SpellAbility sa, Player payer, SpellAbility ability, boolean alreadyPaid, List<Player> payers) { public static boolean willPayUnlessCost(SpellAbility sa, Player payer, SpellAbility ability, boolean alreadyPaid, List<Player> payers) {

View File

@@ -8,8 +8,6 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
@@ -44,6 +42,19 @@ import forge.util.maps.TreeMapOfLists;
*/ */
public class ComputerUtilMana { public class ComputerUtilMana {
public static boolean canPayManaCost(final SpellAbility sa, final Player ai, final int extraMana) {
return payManaCost(sa, ai, true, extraMana, true);
}
// Does not check if mana sources can be used right now, just checks for potential chance.
public static boolean hasEnoughManaSourcesToCast(final SpellAbility sa, final Player ai) {
return payManaCost(sa, ai, true, 0, false);
}
public static boolean payManaCost(final Player ai, final SpellAbility sa) {
return payManaCost(sa, ai, false, 0, true);
}
/** /**
* <p> * <p>
* payManaCost. * payManaCost.
@@ -62,7 +73,7 @@ public class ComputerUtilMana {
* @return a boolean. * @return a boolean.
* @since 1.0.15 * @since 1.0.15
*/ */
public static boolean payManaCost(final SpellAbility sa, final Player ai, final boolean test, final int extraMana, boolean checkPlayable) { private static boolean payManaCost(final SpellAbility sa, final Player ai, final boolean test, final int extraMana, boolean checkPlayable) {
ManaCostBeingPaid cost = ComputerUtilMana.calculateManaCost(sa, test, extraMana); ManaCostBeingPaid cost = ComputerUtilMana.calculateManaCost(sa, test, extraMana);
final Card card = sa.getSourceCard(); final Card card = sa.getSourceCard();
@@ -363,18 +374,6 @@ public class ComputerUtilMana {
} }
/**
* <p>
* payManaCost.
* </p>
*
* @param sa
* a {@link forge.card.spellability.SpellAbility} object.
*/
public static boolean payManaCost(final Player ai, final SpellAbility sa) {
return payManaCost(sa, ai, false, 0, true);
}
/** /**
* Find all mana sources. * Find all mana sources.
* @param manaAbilityMap * @param manaAbilityMap
@@ -634,17 +633,11 @@ public class ComputerUtilMana {
* @since 1.0.15 * @since 1.0.15
*/ */
public static int determineLeftoverMana(final SpellAbility sa, final Player player) { public static int determineLeftoverMana(final SpellAbility sa, final Player player) {
for (int i = 1; i < 100; i++)
if (!canPayManaCost(sa, player, i))
return i - 1;
int xMana = 0; return 99;
for (int i = 1; i < 99; i++) {
if (!payManaCost(sa, player, true, i, true)) {
break;
}
xMana = i;
}
return xMana;
} }
// Returns basic mana abilities plus "reflected mana" abilities // Returns basic mana abilities plus "reflected mana" abilities
@@ -655,7 +648,7 @@ public class ComputerUtilMana {
* *
* @return a {@link java.util.ArrayList} object. * @return a {@link java.util.ArrayList} object.
*/ */
public static final ArrayList<SpellAbility> getAIPlayableMana(Card c) { private static final ArrayList<SpellAbility> getAIPlayableMana(Card c) {
final ArrayList<SpellAbility> res = new ArrayList<SpellAbility>(); final ArrayList<SpellAbility> res = new ArrayList<SpellAbility>();
for (final SpellAbility a : c.getManaAbility()) { for (final SpellAbility a : c.getManaAbility()) {