remove some playertype checks

This commit is contained in:
Maxmtg
2014-01-31 19:57:59 +00:00
parent 59665029d2
commit 096f41172d
4 changed files with 67 additions and 145 deletions

View File

@@ -1,11 +1,9 @@
package forge.game.ability.effects; package forge.game.ability.effects;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import forge.ai.ComputerUtilCard;
import forge.card.ColorSet; import forge.card.ColorSet;
import forge.card.MagicColor; import forge.card.MagicColor;
import forge.card.mana.ManaCostShard; import forge.card.mana.ManaCostShard;
@@ -19,7 +17,6 @@ import forge.game.player.Player;
import forge.game.spellability.AbilityManaPart; import forge.game.spellability.AbilityManaPart;
import forge.game.spellability.SpellAbility; import forge.game.spellability.SpellAbility;
import forge.game.spellability.TargetRestrictions; import forge.game.spellability.TargetRestrictions;
import forge.game.zone.ZoneType;
public class ManaEffect extends SpellAbilityEffect { public class ManaEffect extends SpellAbilityEffect {
@@ -45,8 +42,6 @@ public class ManaEffect extends SpellAbilityEffect {
int amount = sa.hasParam("Amount") ? AbilityUtils.calculateAmount(card, sa.getParam("Amount"), sa) : 1; int amount = sa.hasParam("Amount") ? AbilityUtils.calculateAmount(card, sa.getParam("Amount"), sa) : 1;
if (tgt == null || p.canBeTargetedBy(sa)) { if (tgt == null || p.canBeTargetedBy(sa)) {
Player activator = sa.getActivatingPlayer(); Player activator = sa.getActivatingPlayer();
// AI color choice is set in ComputerUtils so only human players need to make a choice
if (activator.isHuman()) {
//String colorsNeeded = abMana.getExpressChoice(); //String colorsNeeded = abMana.getExpressChoice();
String[] colorsProduced = abMana.getComboColors().split(" "); String[] colorsProduced = abMana.getComboColors().split(" ");
@@ -62,43 +57,18 @@ public class ManaEffect extends SpellAbilityEffect {
for (int nMana = 1; nMana <= amount; nMana++) { for (int nMana = 1; nMana <= amount; nMana++) {
String choice = ""; String choice = "";
byte chosenColor = activator.getController().chooseColor("Select Mana to Produce", sa, colorOptions); byte chosenColor = activator.getController().chooseColor("Select Mana to Produce", sa, colorOptions);
if (chosenColor == 0) { if (chosenColor == 0)
final StringBuilder sb = new StringBuilder(); throw new RuntimeException("AbilityFactoryMana::manaResolve() - " + activator + " color mana choice is empty for " + card.getName());
sb.append("AbilityFactoryMana::manaResolve() - Human color mana choice is empty for ");
sb.append(card.getName());
throw new RuntimeException(sb.toString());
} else {
choice = MagicColor.toShortString(chosenColor); choice = MagicColor.toShortString(chosenColor);
if (nMana != 1) { if (nMana != 1) {
choiceString.append(" "); choiceString.append(" ");
} }
choiceString.append(choice); choiceString.append(choice);
} }
} game.action.nofityOfValue(sa, card, activator + " picked" + choiceString, activator);
abMana.setExpressChoice(choiceString.toString()); abMana.setExpressChoice(choiceString.toString());
} }
else {
// TODO: Add some logic for AI choice (ArsenalNut 2012/09/16)
if (!sa.hasParam("AILogic") || sa.getParam("AILogic").equals("MostProminentInComputerHand")) {
String chosen = MagicColor.Constant.BLACK;
List<Card> hand = new ArrayList<Card>(activator.getCardsIn(ZoneType.Hand));
hand.addAll(activator.getCardsIn(ZoneType.Stack));
chosen = ComputerUtilCard.getMostProminentColor(hand);
if (chosen.equals("")) {
chosen = MagicColor.Constant.BLACK;
}
game.action.nofityOfValue(sa, card, "Computer picked" + chosen, activator);
String manaString = "";
for (int i = 0; i < amount; i++) {
manaString = manaString + MagicColor.toShortString(chosen) + " ";
}
abMana.setExpressChoice(manaString);
}
if (abMana.getExpressChoice().isEmpty() && amount > 0) {
System.out.println("AbilityFactoryMana::manaResolve() - combo mana color choice is empty for " + card.getName());
}
}
}
} }
} }
else if (abMana.isAnyMana()) { else if (abMana.isAnyMana()) {
@@ -106,57 +76,26 @@ public class ManaEffect extends SpellAbilityEffect {
if (tgt == null || p.canBeTargetedBy(sa)) { if (tgt == null || p.canBeTargetedBy(sa)) {
Player act = sa.getActivatingPlayer(); Player act = sa.getActivatingPlayer();
// AI color choice is set in ComputerUtils so only human players need to make a choice // AI color choice is set in ComputerUtils so only human players need to make a choice
if (act.isHuman()) {
String colorsNeeded = abMana.getExpressChoice(); String colorsNeeded = abMana.getExpressChoice();
String choice = ""; String choice = "";
if (colorsNeeded.length() == 1) {
choice = colorsNeeded;
}
else {
ColorSet colorMenu = null; ColorSet colorMenu = null;
if (colorsNeeded.length() > 1 && colorsNeeded.length() < 5) {
byte mask = 0; byte mask = 0;
//loop through colors to make menu //loop through colors to make menu
for (int nChar = 0; nChar < colorsNeeded.length(); nChar++) { for (int nChar = 0; nChar < colorsNeeded.length(); nChar++) {
mask |= forge.card.MagicColor.fromName(colorsNeeded.substring(nChar, nChar + 1)); mask |= MagicColor.fromName(colorsNeeded.charAt(nChar));
} }
colorMenu = ColorSet.fromMask(mask); colorMenu = ColorSet.fromMask(mask);
}
else {
colorMenu = ColorSet.fromNames(MagicColor.Constant.ONLY_COLORS);
}
byte val = act.getController().chooseColor("Select Mana to Produce", sa, colorMenu); byte val = act.getController().chooseColor("Select Mana to Produce", sa, colorMenu);
if (0 == val) { if (0 == val) {
final StringBuilder sb = new StringBuilder(); throw new RuntimeException("AbilityFactoryMana::manaResolve() - " + act + " color mana choice is empty for " + card.getName());
sb.append("AbilityFactoryMana::manaResolve() - Human color mana choice is empty for ");
sb.append(card.getName());
throw new RuntimeException(sb.toString());
} }
choice = MagicColor.toShortString(val); choice = MagicColor.toShortString(val);
}
game.action.nofityOfValue(sa, card, act + " picked " + choice, act);
abMana.setExpressChoice(choice); abMana.setExpressChoice(choice);
} }
else {
if (abMana.getExpressChoice().isEmpty()) {
final String logic = sa.hasParam("AILogic") ? sa.getParam("AILogic") : null;
String chosen = MagicColor.Constant.BLACK;
if (logic == null || logic.equals("MostProminentInComputerHand")) {
chosen = ComputerUtilCard.getMostProminentColor(act.getCardsIn(ZoneType.Hand));
}
if (chosen.equals("")) {
chosen = MagicColor.Constant.GREEN;
}
game.action.nofityOfValue(sa, card, "Computer picked " + chosen, act);
abMana.setExpressChoice(MagicColor.toShortString(chosen));
}
if (abMana.getExpressChoice().isEmpty()) {
final StringBuilder sb = new StringBuilder();
sb.append("AbilityFactoryMana::manaResolve() - any color mana choice is empty for ");
sb.append(card.getName());
throw new RuntimeException(sb.toString());
}
}
}
} }
} }
else if (abMana.isSpecialMana()) { else if (abMana.isSpecialMana()) {
@@ -166,7 +105,8 @@ public class ManaEffect extends SpellAbilityEffect {
if (type.equals("EnchantedManaCost")) { if (type.equals("EnchantedManaCost")) {
Card enchanted = card.getEnchantingCard(); Card enchanted = card.getEnchantingCard();
if (enchanted != null ) { if (enchanted == null )
continue;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
int generic = enchanted.getManaCost().getGenericCost(); int generic = enchanted.getManaCost().getGenericCost();
@@ -187,8 +127,6 @@ public class ManaEffect extends SpellAbilityEffect {
} }
abMana.setExpressChoice(sb.toString().trim()); abMana.setExpressChoice(sb.toString().trim());
} }
}
if (abMana.getExpressChoice().isEmpty()) { if (abMana.getExpressChoice().isEmpty()) {
System.out.println("AbilityFactoryMana::manaResolve() - special mana effect is empty for " + sa.getSourceCard().getName()); System.out.println("AbilityFactoryMana::manaResolve() - special mana effect is empty for " + sa.getSourceCard().getName());

View File

@@ -53,7 +53,7 @@ public class ManaReflectedEffect extends SpellAbilityEffect {
* a {@link forge.game.player.Player} object. * a {@link forge.game.player.Player} object.
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
private static String generatedReflectedMana(final SpellAbility sa, final Collection<String> colors, final Player player) { private String generatedReflectedMana(final SpellAbility sa, final Collection<String> colors, final Player player) {
// Calculate generated mana here for stack description and resolving // Calculate generated mana here for stack description and resolving
final int amount = sa.hasParam("Amount") ? AbilityUtils.calculateAmount(sa.getSourceCard(), sa.getParam("Amount"), sa) : 1; final int amount = sa.hasParam("Amount") ? AbilityUtils.calculateAmount(sa.getSourceCard(), sa.getParam("Amount"), sa) : 1;
@@ -64,12 +64,7 @@ public class ManaReflectedEffect extends SpellAbilityEffect {
} else if (colors.size() == 1) { } else if (colors.size() == 1) {
baseMana = MagicColor.toShortString(colors.iterator().next()); baseMana = MagicColor.toShortString(colors.iterator().next());
} else { } else {
if (player.isHuman()) {
baseMana = MagicColor.toShortString(player.getController().chooseColor("Select Mana to Produce", sa, ColorSet.fromNames(colors))); baseMana = MagicColor.toShortString(player.getController().chooseColor("Select Mana to Produce", sa, ColorSet.fromNames(colors)));
} else {
// AI doesn't really have anything here yet
baseMana = sa.getManaPart().getExpressChoice();
}
} }
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();

View File

@@ -551,8 +551,14 @@ public class PlayerControllerAi extends PlayerController {
@Override @Override
public byte chooseColor(String message, SpellAbility sa, ColorSet colors) { public byte chooseColor(String message, SpellAbility sa, ColorSet colors) {
final String c = ComputerUtilCard.getMostProminentColor(player.getCardsIn(ZoneType.Hand)); // You may switch on sa.getApi() here and use sa.getParam("AILogic")
List<Card> hand = new ArrayList<Card>(player.getCardsIn(ZoneType.Hand));
if( sa.getApi() == ApiType.Mana )
hand.addAll(player.getCardsIn(ZoneType.Stack));
final String c = ComputerUtilCard.getMostProminentColor(hand);
byte chosenColorMask = MagicColor.fromName(c); byte chosenColorMask = MagicColor.fromName(c);
if ((colors.getColor() & chosenColorMask) != 0) { if ((colors.getColor() & chosenColorMask) != 0) {
return chosenColorMask; return chosenColorMask;
} else { } else {

View File

@@ -224,21 +224,6 @@ public class MagicStack /* extends MyObservable */ implements Iterable<SpellAbil
this.frozenStack.clear(); this.frozenStack.clear();
} }
/**
* <p>
* removeFromFrozenStack.
* </p>
* @param sa
* a SpellAbility.
*/
public final void removeFromFrozenStack(SpellAbility sa) {
SpellAbilityStackInstance si = this.getInstanceFromSpellAbility(sa);
this.frozenStack.remove(si);
if (this.frozenStack.isEmpty()) {
clearFrozen();
}
}
/** /**
* <p> * <p>
* setResolving. * setResolving.
@@ -484,8 +469,6 @@ public class MagicStack /* extends MyObservable */ implements Iterable<SpellAbil
if (!this.simultaneousStackEntryList.isEmpty()) { if (!this.simultaneousStackEntryList.isEmpty()) {
chooseOrderOfSimultaneousStackEntryAll(); chooseOrderOfSimultaneousStackEntryAll();
// Why should we pass priority after adding something to a stack?
// game.getPhaseHandler().passPriority();
} }
} }