It is currently 18 Apr 2024, 04:31
   
Text Size

Mana Pool

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

Re: Mana Pool

Postby zerker2000 » 22 Jun 2009, 10:19

Is there any reason against putting a
Code: Select all
if (!mana.contains(getColor(letter +"")))
into Input_PayManaCostUtil.getManaAbilities(card), or at least a
Code: Select all
if(!mana.contains(getColor(letter +""))&&(card.getName() == "Mana Pool"))
for mPool ease of use? (I would suppose it would be placed so:
Code: Select all
  public static ArrayList<String> getManaAbilities(Card card)
  {
    ArrayList<?> check = card.getKeyword();
    ArrayList<String> mana  = new ArrayList<String>();

    char letter;

    for(int i = 0; i < check.size(); i++)
    {
       if(check.get(i).toString().startsWith(manaString) || check.get(i).toString().startsWith("ManaPool:"))
        {
          //gets G from "tap: add G"
          letter = check.get(i).toString().charAt(manaString.length());
          if(!mana.contains(getColor(letter +""))&&(card.getName() == "Mana Pool"))
            mana.add(getColor(letter +""));
        }
    }

    return mana;
  }
... are there any cards that would matter for anyways?
O forest, hold thy wand'ring son
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.


--Eladamri, the Seed of Freyalise
zerker2000
Programmer
 
Posts: 569
Joined: 09 May 2009, 21:40
Location: South Pasadena, CA
Has thanked: 0 time
Been thanked: 0 time

Re: Mana Pool

Postby Rob Cashwalker » 22 Jun 2009, 11:40

I'm not following... what's the intended result of the change?
The Force will be with you, Always.
User avatar
Rob Cashwalker
Programmer
 
Posts: 2167
Joined: 09 Sep 2008, 15:09
Location: New York
Has thanked: 5 times
Been thanked: 40 times

Re: Mana Pool

Postby zerker2000 » 22 Jun 2009, 12:04

Rob Cashwalker wrote:I'm not following... what's the intended result of the change?
It makes mana abilities only count once per color interface-wise, e.g. when you have ~20 mana in your pool from a cradle/academy you will still only have to click on the pool once (and if you have both you won't have to scroll down to the one you need, instead being given the choice between green and blue).
O forest, hold thy wand'ring son
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.


--Eladamri, the Seed of Freyalise
zerker2000
Programmer
 
Posts: 569
Joined: 09 May 2009, 21:40
Location: South Pasadena, CA
Has thanked: 0 time
Been thanked: 0 time

Re: Mana Pool

Postby Mr.Chaos » 22 Jun 2009, 12:31

Maybe just a stoopid suggestion from a non coder but...
Now, if you tap a Gaea's cradle and put 5 mana in the mana pool and then cast a 4mana costing card, you have to click the pool 4 times and select 1 mana each time.
Is it possible to make it so you click to mana pool and then select any number of the mana there and click an OK button and at that point see the selected mana be removed from the pool and used for the cost of a card or ability?

I asked Dennis a similar question about Sacrificing saproling tokens to Nemata, Grove Guardian, so you could sac several at once without going back to Nemata for each and he said that should be possible.
To me, non coder that I am, the mana pool idea feels very similar.
*hides behind the couch to avoid angry looks from programmerpeeps*
](*,) = coder at work, according to a coder.It does explain some of the bugs. :wink:
Mr.Chaos
Tester
 
Posts: 625
Joined: 06 Sep 2008, 08:15
Has thanked: 0 time
Been thanked: 0 time

Re: Mana Pool

Postby zerker2000 » 22 Jun 2009, 12:42

Mr.Chaos wrote:Maybe just a stoopid suggestion from a non coder but...
Now, if you tap a Gaea's cradle and put 5 mana in the mana pool and then cast a 4mana costing card, you have to click the pool 4 times and select 1 mana each time.
Is it possible to make it so you click to mana pool and then select any number of the mana there and click an OK button and at that point see the selected mana be removed from the pool and used for the cost of a card or ability?

I asked Dennis a similar question about Sacrificing saproling tokens to Nemata, Grove Guardian, so you could sac several at once without going back to Nemata for each and he said that should be possible.
To me, non coder that I am, the mana pool idea feels very similar.
*hides behind the couch to avoid angry looks from programmerpeeps*
I don't know about the saprolings, however the if thingy I posted three posts above does make it so that you'd click on the mana pool four times without selections in the process(provided you only have one color of mana in the pool, otherwise you have to select the color).
O forest, hold thy wand'ring son
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.


--Eladamri, the Seed of Freyalise
zerker2000
Programmer
 
Posts: 569
Joined: 09 May 2009, 21:40
Location: South Pasadena, CA
Has thanked: 0 time
Been thanked: 0 time

Re: Mana Pool

Postby Rob Cashwalker » 22 Jun 2009, 13:33

All I can suggest is.. try it. Experiment with it until it works for you, then post the final changes necessary.
The Force will be with you, Always.
User avatar
Rob Cashwalker
Programmer
 
Posts: 2167
Joined: 09 Sep 2008, 15:09
Location: New York
Has thanked: 5 times
Been thanked: 40 times

Re: Mana Pool

Postby DennisBergkamp » 22 Jun 2009, 17:36

I had something different in mind with Nemata, Grove Guardian.
Anyway, I like zerker's solution... I had to make a small change to make his code work correctly though (otherwise I couldn't pay for spells the regular way anymore) :

Code: Select all
public static ArrayList<String> getManaAbilities(Card card)
  {
    ArrayList<?> check = card.getKeyword();
    ArrayList<String> mana  = new ArrayList<String>();

    char letter;

    for(int i = 0; i < check.size(); i++)
    {
       if(check.get(i).toString().startsWith(manaString) || check.get(i).toString().startsWith("ManaPool:"))
        {
          //gets G from "tap: add G"
          letter = check.get(i).toString().charAt(manaString.length());
          if (!card.getName().equals("Mana Pool"))
             mana.add(getColor(letter +""));
         
          else if(!mana.contains(getColor(letter +""))&&(card.getName().equals("Mana Pool")))
             mana.add(getColor(letter +""));
        }
    }

    return mana;
  }
Anyway, I think this is actually a much better way than selecting the amount of mana to be paid from a list initially. Right now you can just quickly click the manapool for however much mana of a single color you want to draw =D>
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Mana Pool

Postby zerker2000 » 25 Jun 2009, 00:58

oh right oops :P by
Code: Select all
if (!mana.contains(getColor(letter +"")))
, or at least a
Code: Select all
if(!mana.contains(getColor(letter +""))&&(card.getName() == "Mana Pool"))
, I meant "Only add the color if it isn't already a choice, or at least do so if we're getting the mana from the mana pool" :P. Personally, I put the first version in mine, since adding a color that is already in the list is kind of redundant.
O forest, hold thy wand'ring son
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.


--Eladamri, the Seed of Freyalise
zerker2000
Programmer
 
Posts: 569
Joined: 09 May 2009, 21:40
Location: South Pasadena, CA
Has thanked: 0 time
Been thanked: 0 time

Re: Mana Pool

Postby zerker2000 » 25 Jun 2009, 03:35

Ok, here's the big one :D(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.
O forest, hold thy wand'ring son
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.


--Eladamri, the Seed of Freyalise
zerker2000
Programmer
 
Posts: 569
Joined: 09 May 2009, 21:40
Location: South Pasadena, CA
Has thanked: 0 time
Been thanked: 0 time

Re: Mana Pool

Postby DennisBergkamp » 01 Jul 2009, 06:14

Somehow, I missed this entire post.... zerker, this looks great :)
Have you made progress since ?
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Mana Pool

Postby zerker2000 » 01 Jul 2009, 06:17

The edit... I Was away from the computer for the last five days though.
O forest, hold thy wand'ring son
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.


--Eladamri, the Seed of Freyalise
zerker2000
Programmer
 
Posts: 569
Joined: 09 May 2009, 21:40
Location: South Pasadena, CA
Has thanked: 0 time
Been thanked: 0 time

Previous

Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 40 guests


Who is online

In total there are 40 users online :: 0 registered, 0 hidden and 40 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 40 guests

Login Form