Added Input stackability.

Fixed Angle of Despair to say What you're going to do to the "target permanent",
Drekvac from "Discard a card, then sacrifice Drekvac if discarded card was a creature" to original "you may discard noncreature card. If you choose not to(buttonUtil.enableOnlyCancel), sac Drekvac"
Fixed mana curve smoothing: now AI land smoothing will simply print an error line and continue if there isn't enough land to smooth.
This commit is contained in:
jendave
2011-08-06 02:47:39 +00:00
parent 19dae61e1e
commit 7dbe8ea57a
6 changed files with 20 additions and 213 deletions

1
.gitattributes vendored
View File

@@ -61,7 +61,6 @@ src/forge/CardList.java svneol=native#text/plain
src/forge/CardListFilter.java svneol=native#text/plain
src/forge/CardListUtil.java svneol=native#text/plain
src/forge/CardPanel.java svneol=native#text/plain
src/forge/CardParser.java svneol=native#text/plain
src/forge/CardUtil.java svneol=native#text/plain
src/forge/Combat.java svneol=native#text/plain
src/forge/CombatPlaneswalker.java svneol=native#text/plain

View File

@@ -1,6 +1,6 @@
program/mail=mtgrares@yahoo.com
program/forum=http://www.slightlymagic.net/forum/viewforum.php?f=26
program/version=MTG Forge -- official beta: 09/11/02, SVN revision: 73
program/version=MTG Forge -- official beta: 09/11/02, SVN revision: 74
tokens--file=AllTokens.txt

View File

@@ -2745,18 +2745,21 @@ public class CardFactory_Creatures {
public void showMessage()
{
AllZone.Display.showMessage("Discard from your hand a non-creature card");
ButtonUtil.disableAll();
ButtonUtil.enableOnlyCancel();
}
public void selectCard(Card c, PlayerZone zone)
{
if(zone.is(Constant.Zone.Hand))
if(zone.is(Constant.Zone.Hand) && c.isCreature())
{
AllZone.GameAction.discard(c);
if(c.isCreature())
AllZone.GameAction.sacrifice(card);
stop();
}
}
public void selectButtonCancel()
{
AllZone.GameAction.sacrifice(card);
stop();
}
};//Input
final SpellAbility ability = new Ability(card, "0")
@@ -10737,7 +10740,7 @@ public class CardFactory_Creatures {
if (all.size() != 0) {
if(card.getController().equals(Constant.Player.Human)) {
AllZone.InputControl.setInput(CardFactoryUtil.input_targetSpecific(ability, all, "Select target permanent.", true));
AllZone.InputControl.setInput(CardFactoryUtil.input_targetSpecific(ability, all, "Select target permanent to destroy.", true));
ButtonUtil.disableAll();
}
else if (card.getController().equals(Constant.Player.Computer)) {

View File

@@ -1,197 +0,0 @@
package forge;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
public class CardParser {
enum name
{
EXIT, MAKE, SET, GET, INPUT, ADD, PUT, IF, PAROPEN;
public String toString(){return name().charAt(0) + name().toLowerCase().substring(1);}
}
HashMap<String, name> parseCommand = new HashMap<String, name>();
public void init()//call where appropriate
{
parseCommand.put("{", name.PAROPEN);
for (name n : name.values())
if(!n.toString().equals("Paropen"))
parseCommand.put(n.toString(), n);
}
static HashMap<String, Class<Object>> parseClass;
static HashMap<Class<Object>, String> unParseClass;
static HashMap<String, Method> parseSet;
static HashMap<String, Method> parseGet;
static HashMap<String, Method> parseIf;
static HashMap<String, PlayerZone> parseZone;
ArrayList<Object> all;
HashMap<String, Integer> labels;
public Card getNextCard(BufferedReader reader) throws IOException
{
labels.clear();
final Card res = new Card();
res.setName(reader.readLine());
all.add(res);
labels.put("maincard", 0);
parseCommand(reader, true).execute();
return res;
}
@SuppressWarnings({ "serial", "unchecked" })
Command parseCommand(BufferedReader reader, boolean linesleft) throws IOException
{
final String command = reader.readLine().trim();
if(command.isEmpty() || command.equals ("}"))
{
linesleft = false;
return Command.Blank;
}
final String[] pieces = command.split(" ");
switch(parseCommand.get(pieces[0])){
case EXIT: return null;
case PAROPEN:
boolean cont = true;
final CommandList todo = new CommandList();
while(cont) todo.add(parseCommand(reader, cont));
return new Command(){ public void execute()
{
for(Command c : todo)
{
if(c != null)
c.execute();
else
break;
}
}};
case MAKE:
String varname = command.split(" named ")[1];
final int where = all.size() - 1;
labels.put(varname, where);
return new Command(){ public void execute()
{
try {
all.set(where, parseClass.get(command.substring(5).split(" named ")[0]).newInstance());
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//where parseClass is a Map<String, Class> containing values like <"activated ability", Ability.Class>
}
};
//where unParseClass is a Map<Class, String> containing values like <Input.Class, "input">
case SET:
final Object destObject = fetchValue(pieces[1]);
final String setMethod = unParseClass.get(destObject.getClass()) + command.split(" to ")[0].substring(command.indexOf(" ", 4));
final Object sourceValue = fetchValue(command.split(" to ")[1]);
return new Command(){ public void execute(){ try {
parseSet.get(setMethod).invoke(destObject, sourceValue);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}}};
//where parseSet is a Map<String, Method> containing values like <"card name", Card.setName>
case GET:
final Object whose_2 = fetchValue(pieces[1]);
final String how_2 = unParseClass.get(whose_2.getClass()) + command.split(" to ")[0].substring(command.indexOf(" ", 4));
String label2 = command.split(" named ")[1];
final int where_2 = all.size() - 1;
labels.put(label2, where_2);
final Object what_2 = fetchValue(command.split(" to ")[1]);
return new Command(){ public void execute(){ try {
all.set(where_2, parseGet.get(how_2).invoke(whose_2, what_2));
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}}};
//where parseGet is a Map<String, Method> containing values like <"spell or ability mana cost", SpellAbility.setManaCost>
case INPUT:
final Object in = fetchValue(pieces[1]);
if(!(in instanceof Input)) throw new IllegalArgumentException("Error : " + command.split(" named ")[1] + " is not an Input");
return new Command(){ public void execute(){ AllZone.InputControl.setInput((Input)in);}};
case ADD:
final SpellAbility sa = (SpellAbility)fetchValue(pieces[1]);
final Card card = (Card)fetchValue(command.split(" to ")[1]);
return new Command(){ public void execute(){ card.addSpellAbility(sa);}};//TODO: Counters?
case PUT:
final Card card_2 = (Card)fetchValue(pieces[1]);
final PlayerZone zone = parseZone.get(command.split(" in ")[1]);
//where parseZone is a Map<String, PLayerZone> ... i.e. <"battlefield", AllZone.Play>
return new Command(){ public void execute(){AllZone.GameAction.moveTo(zone, card_2);}};
case IF:
final Object whose_3 = fetchValue(pieces[1]);
final Object arg1 = fetchValue(pieces[1]);
final boolean not = pieces[2].equals("not");
final Command res = parseCommand(reader, linesleft);
final Method todo_2 = parseIf.get(unParseClass.get(whose_3.getClass()) + command.substring(command.indexOf(" ", 3) + (not ? 0 : 4)));
//where parseIf is a Map... <"input equals", Input.equals>, <"card in play", Card.inPlay>
Class[] need = todo_2.getParameterTypes();
final Object[] args = new Object[need.length];
if(need.length == 1) args[1] = fetchValue(pieces[pieces.length-1]);
return new Command(){ public void execute(){
try {
if(todo_2.invoke(arg1, args).equals(false) ^ not) res.execute();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}}};
default:
throw new IllegalArgumentException("Command not supported: " + command);
}
}
Object fetchValue(String label){return fetchValue(label, Object.class);}
@SuppressWarnings("serial")
Object fetchValue(final String label, Class<Object> type)
{
if(labels.containsKey(label))
return all.get(labels.get(label));
if(label.contains("\""))
{
if(String.class.isInstance(type))
return label.substring(1, label.length() - 1);
if(CommandArgs.class.isInstance(type));
return new CommandArgs(){@SuppressWarnings("unchecked")
public void execute(Object o)
{
if(o instanceof ArrayList && ((ArrayList<Object>)o).size() == 2 && ((ArrayList<Object>)o).get(0) instanceof SpellAbility && ((ArrayList<Object>)o).get(1) instanceof Card)
{
SpellAbility sa = ((SpellAbility)((ArrayList<Object>)o).get(0));
Card c= ((Card)((ArrayList<Object>)o).get(1));
CardList cl = new CardList();
cl.add(c);
String[] s = {label};
if(!cl.getValidCards(s).isEmpty())//TODO: Bettter way?
sa.setTargetCard(c);
}
}};
}
return all.get(labels.get(label)); //i.e. throw exception
}
}

View File

@@ -912,7 +912,7 @@ private Card getCurrentCard(int ID)
library.add(13, land.get(5));
library.add(16, land.get(6));
}
catch(NullPointerException e)
catch(IndexOutOfBoundsException e)
{
System.err.println("Error: cannot smooth mana curve, not enough land");
return in;

View File

@@ -1,24 +1,20 @@
package forge;
import java.util.*;
@SuppressWarnings("unused") // java.util.*
//@SuppressWarnings("unused") // java.util.*
public class InputControl extends MyObservable implements java.io.Serializable
{
private static final long serialVersionUID = 3955194449319994301L;
private Input input;
static int n = 0;
private Stack<Input> inputStack = new Stack<Input>();
public void setInput(final Input in)
{
if(!(input == null || input instanceof Input_StackNotEmpty))
AllZone.Stack.add(new Ability(AllZone.ManaPool, "no cost", "Delayed Input")//TODO: source other than mp?
{
public void resolve() {
AllZone.InputControl.setInput(in);
}
});
else input = in;
inputStack.add(input);
input = in;
updateObservers();
}
public void resetInput()
@@ -34,6 +30,12 @@ package forge;
if(input != null)
return input;
else if(inputStack.size() > 0)
{
setInput(inputStack.pop());
return input;
}
else if(AllZone.Stack.size() > 0)
{