source code - 2 new features
by mtgrares
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
8 posts
• Page 1 of 1
source code - 2 new features
by mtgrares » 22 May 2009, 17:33
I wanted to be able to add a card to my quest cardpool, so I made an option in the "AI Deck" menu which you will see if you have a file named "edit" in the MTG Forge directory. I enjoy using new cards but I also play mostly quest, so I wanted to be able to use new cards while I'm questing.
And secondly I wanted to be able to see which cards are new, so the regular non-quest Deck Editor will have a sort menu that lets you sort by name, color, type, mana cost, rarity or "New Card First" which sorts the cards according to their order in cards.txt (This also got me thinking that the Deck Editor should have a option to sort by set, so people can see the newest sets first which is a big task since I have read and generate a bunch set list of card names. Nate's Deckbuilder will easily generate the set lists which good.)
Dennis, as always ask me any questions. I did incorporate this into the 05/03 version to make sure it worked.
And secondly I wanted to be able to see which cards are new, so the regular non-quest Deck Editor will have a sort menu that lets you sort by name, color, type, mana cost, rarity or "New Card First" which sorts the cards according to their order in cards.txt (This also got me thinking that the Deck Editor should have a option to sort by set, so people can see the newest sets first which is a big task since I have read and generate a bunch set list of card names. Nate's Deckbuilder will easily generate the set lists which good.)
Dennis, as always ask me any questions. I did incorporate this into the 05/03 version to make sure it worked.
- Code: Select all
/*
--Gui_Quest_DeckEditor - added this method
public TableModel getTopTableModel()
{
return topModel;
}
--Gui_DeckEditor - added this method
public TableModel getTopTableModel()
{
return topModel;
}
--TableSorter - updated the whole class, use this version
import java.util.*;
@SuppressWarnings("unchecked") // Comparable needs <type>
public class TableSorter implements Comparator
{
private final int column;
private boolean ascending;
private CardList all;
//used by compare()
private Comparable aCom = null;
private Comparable bCom = null;
private Card a;
private Card b;
//used if in_column is 7, new cards first - the order is based on cards.txt
//static because this should only be read once
//static to try to reduce file io operations
private static HashMap<String, Integer> cardsTxt = null;
// 0 1 2 3 4 5 6 7
//private String column[] = {"Qty", "Name", "Cost", "Color", "Type", "Stats", "Rarity"}; New cards first - the order is based on cards.txt
public TableSorter(CardList in_all, int in_column, boolean in_ascending)
{
all = new CardList(in_all.toArray());
column = in_column;
ascending = in_ascending;
if(cardsTxt == null)
cardsTxt = readCardsTxt();
}
//reads the file "cards.txt"
private HashMap readCardsTxt()
{
HashMap<String, Integer> map = new HashMap<String, Integer> ();
ArrayList list = FileUtil.readFile("cards.txt");
for(int i = 0; i < list.size(); i++)
map.put(list.get(i).toString().trim(), new Integer(i));
return map;
}
final public int compare(Object in_a, Object in_b)
{
a = (Card)in_a;
b = (Card)in_b;
if(column == 0)//Qty
{
aCom = new Integer(countCardName(a.getName(), all));
bCom = new Integer(countCardName(b.getName(), all));
}
else if (column == 1)//Name
{
aCom = a.getName();
bCom = b.getName();
}
else if (column == 2)//Cost
{
aCom = new Integer(CardUtil.getConvertedManaCost(a.getManaCost()));
bCom = new Integer(CardUtil.getConvertedManaCost(b.getManaCost()));
if(a.isLand())
aCom = new Integer(-1);
if(b.isLand())
bCom = new Integer(-1);
}
else if (column == 3)//Color
{
aCom = getColor(a);
bCom = getColor(b);
}
else if (column == 4)//Type
{
aCom = getType(a);
bCom = getType(b);
}
else if (column == 5)//Stats, attack and defense
{
aCom = new Float(-1);
bCom = new Float(-1);
if(a.isCreature())
aCom = new Float(a.getBaseAttack() +"." +a.getBaseDefense());
if(b.isCreature())
bCom = new Float(b.getBaseAttack() +"." +b.getBaseDefense());
}
else if (column == 6)//Rarity
{
aCom = getRarity(a);
bCom = getRarity(b);
}
else if (column == 7)//New First
{
aCom = sortNewFirst(a);
bCom = sortNewFirst(b);
}
if(ascending)
return aCom.compareTo(bCom);
else
return bCom.compareTo(aCom);
}//compare()
final private int countCardName(String name, CardList c)
{
int count = 0;
for(int i = 0; i < c.size(); i++)
if(name.equals(c.get(i).getName()))
count++;
return count;
}
final private Integer getRarity(Card c)
{
if(c.getRarity().equals("Common"))
return new Integer(1);
else if(c.getRarity().equals("Uncommon"))
return new Integer(2);
else if(c.getRarity().equals("Rare"))
return new Integer(3);
else if(c.getRarity().equals("Land"))
return new Integer(4);
else
return new Integer(5);
}
final public static String getColor(Card c)
{
ArrayList list = CardUtil.getColors(c);
if(list.size() == 1)
return list.get(0).toString();
return "multi";
}
final private Comparable getType(Card c)
{
return c.getType().toString();
}
final private Comparable sortNewFirst(Card c)
{
if(! cardsTxt.containsKey(c.getName()))
throw new RuntimeException("TableSorter : sortNewFirst() error, Card not found - " +c.getName() +" in hashmap - " +cardsTxt);
return cardsTxt.get(c.getName());
}
}
--Gui_DeckEditor_Menu - updated constructor and one method
public Gui_DeckEditor_Menu(DeckDisplay in_display, Command exit)
{
deckDisplay = in_display;
exitCommand = exit;
//this is added just to make save() and saveAs() work ok
//when first started up, just a silly patch
currentGameType = Constant.GameType.Constructed;
setDeckData("", false);
setupMenu();
setupSortMenu();
}
private void setupSortMenu()
{
JMenuItem name = new JMenuItem("Card Name");
JMenuItem cost = new JMenuItem("Cost");
JMenuItem color = new JMenuItem("Color");
JMenuItem type = new JMenuItem("Type");
JMenuItem stats = new JMenuItem("Power/Toughness");
JMenuItem rarity = new JMenuItem("Rarity");
JMenuItem newFirst = new JMenuItem("Newer Cards First");
JMenu menu = new JMenu("Sort By");
menu.add(name);
menu.add(cost);
menu.add(color);
menu.add(type);
menu.add(stats);
menu.add(rarity);
menu.add(newFirst);
this.add(menu);
//add listeners
name.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ev)
{
//index 1 sorts by card name - for more info see TableSorter
// 0 1 2 3 4 5 6
//private String column[] = {"Qty", "Name", "Cost", "Color", "Type", "Stats", "Rarity"};
Gui_DeckEditor g = (Gui_DeckEditor) deckDisplay;
g.getTopTableModel().sort(1, true);
}
});
cost.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ev)
{
// 0 1 2 3 4 5 6
//private String column[] = {"Qty", "Name", "Cost", "Color", "Type", "Stats", "Rarity"};
Gui_DeckEditor g = (Gui_DeckEditor) deckDisplay;
//sort by type, color, cost
g.getTopTableModel().sort(4, true);
g.getTopTableModel().sort(3, true);
g.getTopTableModel().sort(2, true);
}
});
color.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ev)
{
// 0 1 2 3 4 5 6
//private String column[] = {"Qty", "Name", "Cost", "Color", "Type", "Stats", "Rarity"};
Gui_DeckEditor g = (Gui_DeckEditor) deckDisplay;
//sort by type, cost, color
g.getTopTableModel().sort(4, true);
g.getTopTableModel().sort(2, true);
g.getTopTableModel().sort(3, true);
}
});
type.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ev)
{
// 0 1 2 3 4 5 6
//private String column[] = {"Qty", "Name", "Cost", "Color", "Type", "Stats", "Rarity"};
Gui_DeckEditor g = (Gui_DeckEditor) deckDisplay;
//sort by cost, color, type
g.getTopTableModel().sort(2, true);
g.getTopTableModel().sort(3, true);
g.getTopTableModel().sort(4, true);
}
});
stats.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ev)
{
// 0 1 2 3 4 5 6
//private String column[] = {"Qty", "Name", "Cost", "Color", "Type", "Stats", "Rarity"};
Gui_DeckEditor g = (Gui_DeckEditor) deckDisplay;
g.getTopTableModel().sort(4, true);
g.getTopTableModel().sort(2, true);
g.getTopTableModel().sort(3, true);
g.getTopTableModel().sort(5, true);
}
});
rarity.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ev)
{
// 0 1 2 3 4 5 6
//private String column[] = {"Qty", "Name", "Cost", "Color", "Type", "Stats", "Rarity"};
Gui_DeckEditor g = (Gui_DeckEditor) deckDisplay;
//sort by cost, type, color, rarity
g.getTopTableModel().sort(2, true);
g.getTopTableModel().sort(4, true);
g.getTopTableModel().sort(3, true);
g.getTopTableModel().sort(6, true);
}
});
newFirst.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ev)
{
// 0 1 2 3 4 5 6
//private String column[] = {"Qty", "Name", "Cost", "Color", "Type", "Stats", "Rarity"};
Gui_DeckEditor g = (Gui_DeckEditor) deckDisplay;
g.getTopTableModel().sort(7, true);
}
});
}//setupSortMenu()
- mtgrares
- DEVELOPER
- Posts: 1352
- Joined: 08 Sep 2008, 22:10
- Has thanked: 3 times
- Been thanked: 12 times
Re: source code - 2 new features
by DennisBergkamp » 26 May 2009, 20:01
Not sure if this is due to these changes, or the balanced quest source updates, but I'm getting cards that have an "e" set to their rarity in the quest mode editor.
They remain this way for the rest of the quest (even after winning a bunch of games). Is this intentional, or a bug?
They remain this way for the rest of the quest (even after winning a bunch of games). Is this intentional, or a bug?
-
DennisBergkamp - AI Programmer
- Posts: 2602
- Joined: 09 Sep 2008, 15:46
- Has thanked: 0 time
- Been thanked: 0 time
Re: source code - 2 new features
by Chris H. » 26 May 2009, 21:45
The e is appearing only with the cube set rarity files that were included. When I use my original rarities - full card set files, I see no e's in the rarity column.DennisBergkamp wrote:Not sure if this is due to these changes, or the balanced quest source updates, but I'm getting cards that have an "e" set to their rarity in the quest mode editor.
They remain this way for the rest of the quest (even after winning a bunch of games). Is this intentional, or a bug?
-
Chris H. - Forge Moderator
- Posts: 6320
- Joined: 04 Nov 2008, 12:11
- Location: Mac OS X Yosemite
- Has thanked: 644 times
- Been thanked: 643 times
Re: source code - 2 new features
by GandoTheBard » 27 May 2009, 15:42
I reiterate for those who might have missed it. Do not use the cube set for Quest mode. LOL. Unless you want to be called a cheater that is. 

visit my personal homepage here: http://outofthebrokensky.com
Listen to my podcast with famed AJ_Impy "Freed from the Real" on http://puremtgo.com
Listen to my podcast with famed AJ_Impy "Freed from the Real" on http://puremtgo.com
-
GandoTheBard - Tester
- Posts: 1043
- Joined: 06 Sep 2008, 18:43
- Has thanked: 0 time
- Been thanked: 0 time
Re: source code - 2 new features
by DennisBergkamp » 27 May 2009, 17:11

I still don't understand why the e's appear in there though.
By the way, for the next version, which quest-common.txt, quest-uncommon.txt and quest-rare.txt should I use? The balanced rarities, or the original rarities?
-
DennisBergkamp - AI Programmer
- Posts: 2602
- Joined: 09 Sep 2008, 15:46
- Has thanked: 0 time
- Been thanked: 0 time
Re: source code - 2 new features
by GandoTheBard » 28 May 2009, 16:26
Imho the smaller the set the better. You can mix up the quality a bit to give the pool texture but if you dilute it enough it becomes insane. Some people might prefer that (Chris) but I for one don't lol.
visit my personal homepage here: http://outofthebrokensky.com
Listen to my podcast with famed AJ_Impy "Freed from the Real" on http://puremtgo.com
Listen to my podcast with famed AJ_Impy "Freed from the Real" on http://puremtgo.com
-
GandoTheBard - Tester
- Posts: 1043
- Joined: 06 Sep 2008, 18:43
- Has thanked: 0 time
- Been thanked: 0 time
Re: source code - 2 new features
by mtgrares » 28 May 2009, 19:02
The "e" stands for "error". Lets say that you use some set (common.txt, etc..) and you save you quest files. And later you change or update common.txt, etc... MTG Forge reads common.txt, etc... and doesn't find the card name that is currently in your file, so it shows "error" which is abbreviated to just e. Maybe MTG Forge should return c for common instead of e?
- mtgrares
- DEVELOPER
- Posts: 1352
- Joined: 08 Sep 2008, 22:10
- Has thanked: 3 times
- Been thanked: 12 times
Re: source code - 2 new features
by mtgrares » 28 May 2009, 19:20
I've been using Chris's files and they seem to work pretty well. I get irritated at the large number of worthless 1/1 creatures but that is my only beef (aka problem). A 2/2 is ten times better than a generic 1/1.
- mtgrares
- DEVELOPER
- Posts: 1352
- Joined: 08 Sep 2008, 22:10
- Has thanked: 3 times
- Been thanked: 12 times
8 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 14 guests