Ok, here's the big one

(my lats post was a saved draft, figured I'd post it here anyways).
I decided to follow up on the "class ManaPool" idea. Here's what I have so far:
The Classfile(It didn't look like anything important/referenced was in there, and I think rares said it was old experimenting):
- Code: Select all
import java.util.*;
public class ManaPool extends Card
{
public ManaPool()
{
super();
addIntrinsicKeyword("Shroud");
addIntrinsicKeyword("Indestructible");
clear();
}
final String colors = "WUBRG";
private boolean empty = false;
private int[] paid= new int[6];
private int[] has = new int[6];
public ArrayList<String> getColors()
{
ArrayList<String> mana = new ArrayList<String>();
for(int i = 1; i <= 5; i++)
{
if (has[i]>0)
mana.add(Input_PayManaCostUtil.getColor(colors.charAt(i-1)+""));
}
if(has[0]>0) mana.add(Constant.Color.Colorless);
return mana;
}
public void addMana(String mana){
if (mana.length()<=1) addOne(mana);
/*String[] cost=mana.split("");
String Colorless = "";
int cless = 0;
for(String s : cost)
{
if(colors.contains(s))
{
has[colors.indexOf(s) + 1]++;
try{
cless+= Integer.parseInt(Colorless);
Colorless="";
}catch(NumberFormatException ex)
{
throw new RuntimeException("Mana_Pool : Error, noncolor mana cost is not a number - " +Colorless);
}
}
else Colorless.concat(s);
}
has[0]+=cless;*/
}
public void addOne(String Mana)
{
if(Mana.isEmpty()) return;
if(colors.contains(Mana))
{
has[colors.indexOf(Mana) + 1]++;
}
else try
{
has[0]+= Integer.parseInt(Mana);
}
catch(NumberFormatException ex)
{
throw new RuntimeException("Mana_Pool.AddOne : Error, noncolor mana cost is not a number - " + Mana);
}
}
public ManaCost subtractMana(ManaCost m){
String mana = m.toString().replaceAll(" ", "");
if (mana.length()==1)
{
m=subtractOne(m,mana);
return m;
}
String[] cost=mana.split("");
String Colorless = "";
for(String s : cost)
{
if(colors.contains(s))
{
m=subtractOne(m,s);
m=subtractOne(m,Colorless);
Colorless = "";
}
else Colorless.concat(s);
}
m=subtractOne(m , Colorless);
return m;
}
public void subtractOne(String Mana){subtractOne(new ManaCost(Mana),Mana);}
public ManaCost subtractOne(ManaCost manaCost, String Mana)
{
if(Mana.isEmpty()||manaCost.toString().isEmpty()) return manaCost;
if(colors.contains(Mana))
if(has[colors.indexOf(Mana) + 1]>0)
{
manaCost.subtractMana(Input_PayManaCostUtil.getColor(Mana));
has[colors.indexOf(Mana) + 1]--;
paid[colors.indexOf(Mana) + 1]++;
}
else
{
int cless;
try
{
cless = Integer.parseInt(Mana);
}
catch(NumberFormatException ex)
{
throw new RuntimeException("Mana_Pool.SubtractOne : Error, noncolor mana cost is not a number - " + Mana);
}
if(has[0] >= cless)
{
has[0]-=cless;
paid[0]+=cless;
for(int i = 0; i<cless ; i++)
manaCost.subtractMana(Constant.Color.Colorless);
}
}
return manaCost;
}
public void clear(){
Arrays.fill(paid, 0);
Arrays.fill(has, 0);
}
public void paid(){
Arrays.fill(paid, 0);
}
public void unpaid(){
for(int i = 0; i < 6; i++)
has[i]+=paid[i];
Arrays.fill(paid, 0);
}
}
AllZone:
- Code: Select all
public static final ManaPool ManaPool = new ManaPool();
And its references:
-GameAction.newGame
- Code: Select all
Allzone.ManaPool.clear();
- Code: Select all
Card mp = AllZone.ManaPool;
AllZone.Human_Play.add(mp);
-Phase.nextPhase
- Code: Select all
//empty manapool:
AllZone.ManaPool.clear();
--Input_PayManaCost(_Ability):
- Code: Select all
AllZone.ManaPool.paid();
in the beggining of done / in selectCard after "tappedLand.clear();", and
- Code: Select all
AllZone.ManaPool.unpaid();
in selectButtonCancel defore "Card c;".
And of course,
--Input_PayManaCostutil:
-tapCard:
- Code: Select all
if (card == AllZone.ManaPool)
AllZone.ManaPool.subtractOne(getColor2(color));
-getManaCost:
- Code: Select all
if (card == AllZone.ManaPool) return AllZone.ManaPool.getColors();
...Though I am quite sure this is nowhere near optimal, it's a good couple days' coding, and should be expandable. The main things I shall be working on are addMana and subtractMana since those point to their correspoinsing "addOne"'s in all curently referenced situations(i.e. W/U/B/R/G/1). The two main things that need to be done to make it fully functional are adding a getText(that actually makes sense for a mana pool) and replacing all
- Code: Select all
CardList list = new CardList(AllZone.getZone(Constant.Zone.Play, Constant.Player.Human).getCards());
list = list.getName("Mana Pool");
Card mp = list.getCard(0);
...
- Code: Select all
mp.addExtrinsicKeyword("ManaPool:<color");
with "Card mp = AllZone.ManaPool;" and "mp.addMana(<color>);", respectively(or have addMana convert the keywords into "has[<n>]++"-es on startup, or ditch the whole int[] idea and keep using the keywords ... this whole thing is obviously very open for development).
Ok, I don't want to take up the whole page, so I'll wait for comments

.
I edited this several times and finally wrote: added ExtrinsicKeyword, color->index, and getText() methods, used cIndex in the <add/subtract>OneMana, added and used "empty" boolean, so now the class looks like this:
- Code: Select all
import java.util.*;
public class ManaPool extends Card
{
private int cIndex(String c)
{
if(!colors.contains(c)) return 0;
return colors.indexOf(c) + 1;
}
private String indexC(int index)
{
if (index > 0) return "1";
return colors.charAt(index - 1) + "";
}
private void updateKeywords()
{
extrinsicKeyword.clear();
for(int val : has)
for(int i=0; i <= val; i++)
extrinsicKeyword.add("ManaPool:" + indexC(val));
}
private ArrayList<String> extrinsicKeyword = new ArrayList<String>();
public ArrayList<String> getExtrinsicKeyword() {return new ArrayList<String>(extrinsicKeyword);}
public void setExtrinsicKeyword(ArrayList<String> a)
{
extrinsicKeyword = new ArrayList<String>(a);
Arrays.fill(has, 0);
for(String Manaword : extrinsicKeyword)
if (Manaword.startsWith("ManaPool:"))
{
String[] cost=Manaword.split(":");
if (cost[1].length() == 1) has[cIndex(cost[1])]++;
}
this.updateObservers();
}
public void addExtrinsicKeyword(String s)
{
if (s.startsWith("ManaPool:"))
{
extrinsicKeyword.add(s);
addMana(s.split(":")[1]);
}
}
public void removeExtrinsicKeyword(String s)
{
if (s.startsWith("ManaPool:"))
{
updateKeywords();
extrinsicKeyword.remove(s);
subtractOne(s.split(":")[1]);
this.updateObservers();
}
}
public int getExtrinsicKeywordSize() {updateKeywords(); return extrinsicKeyword.size(); }
public ManaPool()
{
super();
setName("Mana Pool");
addIntrinsicKeyword("Shroud");
addIntrinsicKeyword("Indestructible");
clear();
}
public String getText()
{
empty = true;
String res="Mana available:\r\n";
if(has[0]>0) {res+=Integer.toString(has[0]); empty = false;}
for(char c : colors.toCharArray())
{
int n =has[cIndex(c+"")];
for(int i = 0; i< n ; i++)
res +=(c+"");
if (n > 0) {res+="("+Integer.toString(n)+")"; empty = false;}
}
if (empty) res+="None";
return res;
}
final String colors = "WUBRG";
private int[] paid= new int[6];
private int[] has = new int[6];
public ArrayList<String> getColors()
{
ArrayList<String> mana = new ArrayList<String>();
for(int i = 1; i <= 5; i++)
{
if (has[i]>0)
mana.add(Input_PayManaCostUtil.getColor(colors.charAt(i-1)+""));
}
if(has[0]>0) mana.add(Constant.Color.Colorless);
return mana;
}
public void addMana(String mana){
if (mana.length()<=1) {addOne(mana); return;}
String[] cost=mana.split("");
String Colorless = "";
int cless = 0;
for(String s : cost)
{
if(s.isEmpty()) continue;//mana.split gave me a "" for some reason
if(colors.contains(s))
{
has[colors.indexOf(s) + 1]++;
try{
cless+= Integer.parseInt(Colorless);
Colorless="";
}catch(NumberFormatException ex)
{
throw new RuntimeException("Mana_Pool : Error, noncolor mana cost is not a number - " +Colorless);
}
}
else Colorless.concat(s);
}
has[0]+=cless;*/
}
public void addOne(String Mana)
{
if(Mana.isEmpty()) return;
int cInt = cIndex(Mana);
if(cInt > 0)
has[cInt]++;
else try
{
has[cInt]+= Integer.parseInt(Mana);
}
catch(NumberFormatException ex)
{
throw new RuntimeException("Mana_Pool.AddOne : Error, noncolor mana cost is not a number - " + Mana);
}
}
public ManaCost subtractMana(ManaCost m){
if (empty) return;
String mana = m.toString().replaceAll(" ", "");
if (mana.length()==1)
{
m=subtractOne(m,mana);
return m;
}
String[] cost=mana.split("");
String Colorless = "";
for(String s : cost)
{
if(colors.contains(s))
{
m=subtractOne(m,s);
m=subtractOne(m,Colorless);
Colorless = "";
}
else Colorless.concat(s);
}
m=subtractOne(m , Colorless);
return m;
}
public void subtractOne(String Mana){subtractOne(new ManaCost(Mana),Mana);}
public ManaCost subtractOne(ManaCost manaCost, String Mana)
{
if(Mana.isEmpty()||manaCost.toString().isEmpty()) return manaCost;
if(cIndex(Mana) >0 )
{
manaCost.subtractMana(Input_PayManaCostUtil.getColor(Mana));
has[cIndex(Mana)]--;
paid[cIndex(Mana)]++;
}
else
{
int cless;
try
{
cless = Integer.parseInt(Mana);
}
catch(NumberFormatException ex)
{
throw new RuntimeException("Mana_Pool.SubtractOne : Error, noncolor mana cost is not a number - " + Mana);
}
int subcless = cless;
if(has[0] >= cless) {has[0]-=cless; paid[0]+=cless;}
else {paid[0]+=has[0]; subcless=has[0]; has[0]=0;}
for(int i = 0; i<subcless ; i++)
manaCost.subtractMana(Constant.Color.Colorless);
}
return manaCost;
}
public void clear(){
Arrays.fill(paid, 0);
Arrays.fill(has, 0);
}
public void paid(){
Arrays.fill(paid, 0);
}
public void unpaid(){
for(int i = 0; i < 6; i++)
has[i]+=paid[i];
Arrays.fill(paid, 0);
}
}
The extrinsicKeyword methods should theoretically restore the pool to original functionality(i.e. just change "make Card "mana pool"" into "make ManaPool "mana pool"" and it should work same as the old one) while still keeping inside format/methods (e.g. unpaid() to make the mana come back)... I have not tested anything in that regard though. Just basically, if you want to keep the mana pool handling methods as is, and only add in the ManaPool class, change AllZone.newGame to have the mana pool be a ManaPool, and replace what is currently in ManaPool.java with the above.