It is currently 24 Apr 2024, 04:53
   
Text Size

Buncha code (on making mana pools and abilities)

Post MTG Forge Related Programming Questions Here

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

Buncha code (on making mana pools and abilities)

Postby zerker2000 » 06 Jul 2009, 11:34

OK, so here's what I've done so far(or all of it I could find) to mutilate the old manaCost system:
--What follow are cleaned(mostly comment-wise) classes/modified methods, my versions of all related classfiles(except cardFactory :-& ) are attached.

ManaPool.java and Ability_Mana.java, the new classes:
Code: Select all
import java.util.*;

public class ManaPool extends Card
{
   boolean[] spendAsCless ={true,true,true,true,true,true};
   boolean spendAll = true;
   private int cIndex(String s)
   {
      //String c =(s.length()==1 ? s : Input_PayManaCostUtil.getColor2(s));
      if(!colors.contains(s)) return 0;
      return colors.indexOf(s) + 1;
   }
   private String indexC(int index)
   {
      if (index == 0) return "1";
      return colors.charAt(index - 1) + "";
   }
   private void updateKeywords()
   {
      extrinsicKeyword.clear();
      for(int val=0;val<6;val++)
         for(int i=0; i < has[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(String contents){this(); this.addMana(contents);}
   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(int j=0; j<colors.length();j++){char c=colors.charAt(j);
         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 static String colors = "WUBRG";
   private boolean empty = false;
   private int[] paid= new int[6];
   private int[] has = new int[6];
   
   public static String oraclize(String manaCost){
      //if(!manaCost.contains(" ")) return manaCost;
      String[] parts = manaCost.split(" ");
      String res="";
      for (String s : parts)
      {
         if (s.length()==2) s=s.charAt(0)+"/"+s.charAt(1);
         if (s.length()==3) s="(" + s + ")";
         if (s.equals("S")) s="oSi";//for if/when we implement snow mana
         if (s.equals("X")) s="(X)";//X costs?
         res +=s;
      }      
      return res;
   }
   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(Ability_Mana am){addMana(!am.Mana().contains("X") ? am.Mana() : am.Mana().replaceAll("X", am.getX()+""));}
   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]++;
            if (!Colorless.isEmpty())
            {
               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 static String[] getManaParts(Ability_Mana manaAbility){return getManaParts(manaAbility.Mana());}//wrapper
   public static String[] getManaParts(String Mana_2)//turns "G G" -> {"G","G"}, "2 UG"->"{"2","U/G"}, "B W U R G" -> {"B","W","U","R","G"}, etc.
   {
      String Mana=Mana_2;
      if (Mana.isEmpty()) return null;
      Mana=oraclize(Mana);
      try
      {
         String[] Colorless = {Integer.parseInt(Mana)+""};
         return Colorless;
      }
      catch(NumberFormatException ex)   {}
      
      ArrayList<String> res= new ArrayList<String>();
      int Colorless = 0;
      String clessString = "";
      boolean parentheses=false;
      String current="";
      
      for(int i=0; i<Mana.length();i++){char c=Mana.charAt(i);
         if (c=='('){parentheses=true; continue;}//Split cost handling ("(" +<W/U/B/R/G/2> + "/" + <W/U/B/R/G> + ")")
         else if(parentheses){
            if(c!=')') {current+=c; continue;}
            else {
               parentheses=false;
               res.add(current);
               current="";
               continue;
            }
         }
         String s = c+"";
         if(colors.contains(s))
         {
            res.add(s);
            if(clessString.isEmpty()) continue;
            try
            {
               Colorless += Integer.parseInt(clessString);
            }
            catch(NumberFormatException ex)
            {
               throw new RuntimeException("Mana_Pool.getManaParts : Error, sum of noncolor mana parts is not a number - " + clessString);
            }
            clessString = "";
         }
         else clessString+=s;
      }
      if(Colorless > 0) res.add(0, Colorless+"");
      return res.toArray(new String[0]);
   }
   public ManaCost subtractMana(ManaCost m){
      spendAll = true;
      String mana = oraclize(m.toString());
      if (empty || mana.equals(null)) return m;
      if (mana.length()==1)
      {
         m=subtractOne(m,mana);
         return m;
      }
      String[] cost=getManaParts(m.toString()+"");
      for(String s : cost)
         m=subtractOne(m, s);
      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 )
      {
           if(!manaCost.isNeeded(Mana) || has[cIndex(Mana)]==0) return manaCost;
           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);
         }
         if (cless == 0) return manaCost;
         if (cless == 1)
            if(1<=has[0] && manaCost.isNeeded(Constant.Color.Colorless)){
               has[0]--;
               paid[0]++;
               manaCost.subtractMana(Constant.Color.Colorless);
               return manaCost;
            }
         /*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++){
            if(manaCost.isNeeded(Constant.Color.Colorless))
              manaCost.subtractMana(Constant.Color.Colorless);
         }
         spendascless:
         for(int i = 0; i<=5; i++)
         {
            while(has[i]>0 && cless>0)
            {
               String[] yesno = {"Yes","No"};
               if(i>0 && !spendAsCless[i])
                  if(AllZone.Display.getChoiceOptional(
                     "Spend "+Input_PayManaCostUtil.getColor(indexC(i)) + " as colorless?"
                     ,yesno).equals("No")) continue spendascless;
               manaCost=subtractOne(manaCost, indexC(i));
               cless--;
               spendAsCless[i]=spendAll;
            }
            spendAsCless[i]=false;
         }*/
         if(cless>totalMana()) {manaCost=subtractOne(manaCost,totalMana()+""); return manaCost;}
         while(totalMana()>0 && cless>0)
         {
            if (has[0]>0){manaCost=subtractOne(manaCost,"1"); cless--; continue;}
            String chosen;
            String [] choices=getColors().toArray(new String[0]);
            chosen=choices[0];
            if (getColors().size()> 1)
               chosen = (String)AllZone.Display.getChoiceOptional("Choose mana to spend as colorless", choices);
            if (chosen == null) {spendAll = false; return manaCost;}
            manaCost=subtractOne(manaCost,Input_PayManaCostUtil.getColor2(chosen));
            cless--;
         }
      }
      return manaCost;
   }

   public int hasMana(String color){
      String s =(color.length()==1? color : Input_PayManaCostUtil.getColor2(color));
      Mana_Part.checkSingleMana(s);
      return(has[cIndex(s)]);
   }
   public int totalMana(){
      int res = 0;
      for (int n : has)
         res += n;
      return res;
   }
   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);
   }

}
Code: Select all
import java.util.*;

abstract public class Ability_Mana extends SpellAbility implements java.io.Serializable
{
   private ArrayList<Command> runcommands = new ArrayList<Command>();
   public String orig;
   private String Mana;
   private static final long serialVersionUID = 8292723782268822439L;
   /*public Ability_Mana(Card sourceCard, String mana)
    {
   this(sourceCard, "0");
    }*/
   public boolean isTapAbility(){return isTapAbility(orig);}
   private static boolean isTapAbility(String orig){
      String cost = orig.split(":")[0];
      cost = cost.replaceAll("tap", "T");
      return (cost.contains("T"));
   }
    public Ability_Mana(Card sourceCard, String orig)
    {
   super(isTapAbility(orig) ? SpellAbility.Ability_Tap : SpellAbility.Ability, sourceCard);
   this.orig=orig;
   String[] parts = orig.split(":");
   Mana=parts[1];
   Mana = Mana.replaceAll(" add ", "");
   setStackDescription("Add "+ Mana +" to your mana pool.");
   Mana = Mana.replaceAll(" ", "");
   setDescription(orig);
   
   String cost=parts[0];
   cost = cost.replaceAll("tap", "T");
   //cost = cost.replaceAll("T, ", "");
   setManaCost(cost.replaceAll("T", "").split(",")[0]);
   if (getManaCost().equals("")) setManaCost("0");   
   //pain lands
   runcommands.add(new Command(){private static final long serialVersionUID = 1L;
   public void execute(){
    ArrayList<String> pain = new ArrayList<String>();
    pain.add("Battlefield Forge");
    pain.add("Caves of Koilos");
    pain.add("Llanowar Wastes");
    pain.add("Shivan Reef");
    pain.add("Yavimaya Coast");
    pain.add("Adarkar Wastes");
    pain.add("Brushland");
    pain.add("Karplusan Forest");
    pain.add("Underground River");
    pain.add("Sulfurous Springs");
    if(pain.contains(getSourceCard().getName()) && !Mana.equals("1"))
      AllZone.GameAction.getPlayerLife(getController()).subtractLife(1);}});
   }
    public boolean equals(Object o)//Mana abilities with equal descriptions are considered equal, please take this into account
      {return(o instanceof Ability_Mana ? ((Ability_Mana)o).orig.equals(orig) : false);}
    public boolean equalsIgnoreMana(Ability_Mana ma)
    {
       String noManaDesc=orig.substring(0,orig.indexOf(Mana));
       noManaDesc+=orig.substring(orig.indexOf(Mana)+Mana.length());
       String noManaDesc_2=ma.orig.substring(0,ma.orig.indexOf(Mana));
       noManaDesc_2+=ma.orig.substring(ma.orig.indexOf(Mana)+Mana.length());
       return noManaDesc.equals(noManaDesc_2);
    }
   
    public void resolve(){
       AllZone.ManaPool.addMana(this);
         if(!runcommands.isEmpty())
         for(Command c : runcommands) c.execute();
    }
    public int getX(){return getSourceCard().getX();}//override these when not defined by card,
   public void setX(int X){getSourceCard().setX(X);}//i.e. "T, remove X charge counters from {name}: add X+1 <color> mana to your mana pool"
    public String Mana(){return Mana;}//override for all non-X variable mana,
    public String getController(){return getSourceCard().getController();}
   
    public boolean canPlay()
    {
   Card card = getSourceCard();
   if(AllZone.GameAction.isCardInPlay(card) &&(!isTapAbility() || card.isUntapped()))
   {
      if(card.isFaceDown())
         return false;
      
        if(card.isArtifact() && card.isCreature())
           return !(card.hasSickness() && isTapAbility());

       if(card.isCreature() && (!card.hasSickness() || !isTapAbility()))
      return true;
       else if(card.isArtifact() || card.isGlobalEnchantment() || card.isLand())
      return true;
   }
   return false;
    }
}
Input_PayManaCostUtil(getColor methods about the only thing unchanged):
Code: Select all
import java.util.*;

public class Input_PayManaCostUtil
{
  //Mostly a wrapper, subtracts mana from pool if it's the pool, gets / resolves mana ability and subtracts mana it produces otherwise;
  public static ManaCost tapCard(Card card, ManaCost manaCost)
  {
    if(card instanceof ManaPool) return ((ManaPool)card).subtractMana(manaCost);
   ArrayList<Ability_Mana> abilities = getManaAbilities(card);

    if(abilities.isEmpty())
      return manaCost;
    String cneeded="";
    for(String color : Constant.Color.Colors)
       if(manaCost.isNeeded(color))
          cneeded+=getColor2(color);
    Iterator<Ability_Mana> it = abilities.iterator();//you can't remove unneded abilities inside a for(am:abilities) loop :(
    while(it.hasNext())
    {
       Ability_Mana ma = it.next();
       boolean needed = false;
       String canMake = ma.Mana();
       for(int i=0; i<cneeded.length();i++){char color=cneeded.charAt(i);
          if (canMake.contains(color+"")) needed=true;}
       if (!needed) it.remove();
    }   
    //String color;
    Ability_Mana chosen = abilities.get(0);
    if(1 < abilities.size())
    {
      chosen = (Ability_Mana) AllZone.Display.getChoice("Choose mana ability", abilities.toArray());
    }
    {
       AllZone.GameAction.playSpellAbility(chosen);
       for(String c : ManaPool.getManaParts(chosen))
       {
          //if(c.equals("")) continue; //(was) some sort of glitch(when I used chosen.Mana().Split(""))
             AllZone.ManaPool.subtractOne(manaCost, c);
       }
       AllZone.Human_Play.updateObservers();//DO NOT REMOVE THIS, otherwise the cards don't always tap (copied)
      return manaCost;   
    }
  }
  public static ArrayList<Ability_Mana> getManaAbilities(Card card)
  {
    //if (card instanceof ManaPool) return ((ManaPool)card).getManaAbility() //unused
    ArrayList<Ability_Mana> choices  = new ArrayList<Ability_Mana>();

    //String m;

    for(SpellAbility sa : card.getSpellAbility())
    {
       if(sa instanceof Ability_Mana)
        {
         
         /*m = ((Ability_Mana)sa).Mana;
          if (m.equals("G") || m.equals("U") || m.equals("W") ||
                  m.equals("B") || m.equals("R") || m.equals("1"))
          m=getColor(m);
          choices.add(getColor(m));*/
         choices.add((Ability_Mana)sa);
        }
    }

    return choices;
  }
/*
  public static boolean isManaNeeded(String color, ManaCost manaCost)
   {
    //do not use the orginal, get new object
    manaCost = new ManaCost(manaCost.toString());
    manaCost.subtractMana(color);

    String s = manaCost.toString().trim();
    if(s != "" && s.charAt(0) == '-')//is this mana needed?
      return false;
    else
      return true;
  }
*/
  //color is like "G", returns "Green"
  public static String getColor(String color)
  {
    Map<String, String> m = new HashMap<String, String>();
    m.put("G", Constant.Color.Green);
    m.put("R", Constant.Color.Red);
    m.put("U", Constant.Color.Blue);
    m.put("B", Constant.Color.Black);
    m.put("W", Constant.Color.White);

    Object o = m.get(color);

    if(o == null)
      o = Constant.Color.Colorless;


    return o.toString();
  }
 
  public static String getColor2(String color)
  {
     Map<String, String> m = new HashMap<String, String>();
     m.put(Constant.Color.Green, "G");
     m.put(Constant.Color.Red, "R");
     m.put(Constant.Color.Blue, "U");
     m.put(Constant.Color.Black, "B");
     m.put(Constant.Color.White, "W");
     m.put(Constant.Color.Colorless, "1");
     
     Object o = m.get(color);
   
     return o.toString();
  }
 
}
Comment tappedLand code in Input_PayManaCost and Input_PayManaCost_Ability (which I think would be a lot better off merged into one function that checks whether or not the source SpellAbility is a spell):
Code: Select all
    //private final ArrayList<Card> tappedLand = new ArrayList<Card>();
...
    //tappedLand.add(card);
...
    /*Card c;
    for(int i = 0; i < tappedLand.size(); i++)
    {
      c = (Card)tappedLand.get(i);
      c.untap();
    }
    tappedLand.clear();*/
AllZone.ManaPool:
Code: Select all
>    public static final ManaPool ManaPool = new ManaPool();
references eclipse found for it:
-Ability_Mana and InputPayManaCost-s above
-Phase.nextPhase() (replace the old mp clearing code with):
Code: Select all
     AllZone.ManaPool.clear();
-GameAction.newGame (once again, replace "new Card...add(mp) with):
Code: Select all
    Card mp = AllZone.ManaPool;
    AllZone.Human_Play.add(mp);
references found for Ability_Mana:
-ManaPool and Input_PayManaCostUtil
-itself.equals methods
-MagicStack:
Code: Select all
 public void add(SpellAbility sp)
  {
>     if(sp instanceof Ability_Mana) sp.resolve(); else
      push(sp);
  }
-and cardFactory:
Code: Select all
private final int shouldManaAbility(Card c){
        ArrayList<String> a = c.getKeyword();
        for (int i = 0; i < a.size(); i++)
           if (a.get(i).toString().contains(": add "))
              return i;
       
        return -1;
    }
Code: Select all
while (shouldManaAbility(card) != -1)
    {
       int n = shouldManaAbility(card);
       if (n != -1)
       {
          String parse = card.getKeyword().get(n).toString();
          card.removeIntrinsicKeyword(parse);
         
          final Ability_Mana ability = new Ability_Mana(card, parse)
          {
              private static final long serialVersionUID = -113811381138L;
             
              public boolean canPlayAI()
              {
                 return false;
              }
           };
           ability.setDescription(parse);
           card.addSpellAbility(ability);
       }
    }


Also, the X methods, I think I called them somewhere( the following is in Card):
Code: Select all
private int X = 0;
Code: Select all
public void setX(int i){X = i;}
  public int getX() { return X; }
Once again, the main reason I'm posting thess is that I seem to have gotten rid of all the primary bugs, so now is the time to modify it to fit. One thing that might cause a problem is the extreme click-reducing, which I think I was planning to regulate somehow using spendAll. Anyways, just add this in, check how well it works, and post the results here :P.
Attachments
classfiles.zip
Zip of all the aforementioned files.
(23.32 KiB) Downloaded 384 times
Last edited by zerker2000 on 17 Jul 2009, 11:37, edited 1 time in total.
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: Buncha code

Postby zerker2000 » 10 Jul 2009, 20:22

Put a crutch in Card for things that use getKeyword() to fetch mana abilities, AI can now use basic lands again! :P Ability_Mana.
Code: Select all
   public boolean isBasic(){return(orig.startsWith("tap:") && "W U B R G 1".contains(Mana()));}
   
Card.
Code: Select all
  public ArrayList<String> getKeyword()     
  {
     ArrayList<String> a1 = new ArrayList<String>(getIntrinsicKeyword());
     ArrayList<String> a2 = new ArrayList<String>(getExtrinsicKeyword());
     a1.addAll(a2);
>     for(SpellAbility sa : getSpellAbility())
>        if(sa instanceof Ability_Mana && ((Ability_Mana)sa).isBasic()  && !a1.contains(((Ability_Mana)sa).orig))
>           a1.add(((Ability_Mana)sa).orig);
     return a1;
  }
...
  public String getText()
  {
    if(isInstant() || isSorcery())
    {
      String s = getSpellText();
      SpellAbility[] sa = getSpellAbility();
      for(int i = 0; i < sa.length; i++)
        s += sa[i].toString() +"\r\n";

      return s;
    }

    String s = "";
    ArrayList<String> keyword = getKeyword();
>    String mAbilityString ="tap: add W; tap: add U; tap: add B; tap: add R; tap: add G; tap: add 1";
    for(int i = 0; i < keyword.size(); i++)
    {
>      if(mAbilityString.contains(keyword.get(i))) continue;//i.e. if it's already a SpellAbility
      if(i != 0)
        s += ", ";
      s += keyword.get(i).toString();
    }

    s += "\r\n" +text +"\r\n";

    SpellAbility[] sa = getSpellAbility();
    for(int i = 0; i < sa.length; i++)
    {
      //presumes the first SpellAbility added to this card, is the "main" spell
      //skip the first SpellAbility for creatures, since it says "Summon this creature"
      //looks bad on the Gui card detail
      if(isPermanent() && i != 0)
        s += sa[i].toString() +"\r\n";
    }

    return s.trim();
  }//getText()
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: Buncha code

Postby zerker2000 » 17 Jul 2009, 11:28

Patch files found between mine and 6/12, somewhat cleaned of recent additions(that I have found)/whitespace mismatches.
Diffs.zip
Clean plz, I have a plane to catch within next 12 hours :P.
(24 KiB) Downloaded 334 times


EDIT: On the slim chance someone sees this by then, does anyone know how to export an eclipse project as one file( besides rar/jar archiving)?
Attachments
CardAbilityPool.zip
Card, Ability_Mana, and ManaPool(.java)
(10.01 KiB) Downloaded 359 times
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: Buncha code (on making mana pools and abilities)

Postby DennisBergkamp » 19 Jul 2009, 10:42

What would be the easiest way of merging these changes? Just create them from the code you posted or use the attachments?
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Buncha code (on making mana pools and abilities)

Postby Rob Cashwalker » 20 Jul 2009, 04:48

I think you should use the attached java files, and just merge the changes, using the posted code sections as a guide to make sure it's all there.

I'm hoping his changes make for a completely proper mana pool. I felt very good about having done it in the first place, as much of a hack it was... but damnit-- it worked! That's the great thing about how this project is evolving.
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: Buncha code (on making mana pools and abilities)

Postby frwololo » 21 Jul 2009, 05:28

DennisBergkamp wrote:What would be the easiest way of merging these changes? Just create them from the code you posted or use the attachments?
just use the diff files with an utility such as patch, it should do all the changes automatically.
frwololo
DEVELOPER
 
Posts: 265
Joined: 21 Jun 2008, 04:33
Has thanked: 0 time
Been thanked: 3 times

Re: Buncha code (on making mana pools and abilities)

Postby DennisBergkamp » 25 Jul 2009, 19:49

Damn, I've merged all of the changes but now I can't get the thing to run anymore... there are no compile errors though.
And of course I didn't make any backups whatsoever :(
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Buncha code (on making mana pools and abilities)

Postby DennisBergkamp » 25 Jul 2009, 20:08

ARGH this is not good, everything's broken now :(
I'm gonna try and revert all changes...
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Buncha code (on making mana pools and abilities)

Postby zerker2000 » 26 Jul 2009, 12:21

Yes, the diff files from the second post Were generated for use with the patch command.
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: Buncha code (on making mana pools and abilities)

Postby DennisBergkamp » 26 Jul 2009, 15:12

The main problem seems to happen because of this piece of code:

Code: Select all
     for(SpellAbility sa : getSpellAbility())
   if(sa instanceof Ability_Mana && ((Ability_Mana)sa).isBasic()  && !a1.contains(((Ability_Mana)sa).orig))
           a1.add(((Ability_Mana)sa).orig);
Anyway, once you're back from Russia zerker, I'll post my source. maybe you can compare it with yours and spot the problem(s).
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Buncha code (on making mana pools and abilities)

Postby zerker2000 » 27 Jul 2009, 17:43

DennisBergkamp wrote:The main problem seems to happen because of this piece of code:
Code: Select all
     for(SpellAbility sa : getSpellAbility())
   if(sa instanceof Ability_Mana && ((Ability_Mana)sa).isBasic()  && !a1.contains(((Ability_Mana)sa).orig))
           a1.add(((Ability_Mana)sa).orig);
Have you tried debugging? I remember a bunch of problems arising because of the keyword code, however I think I fixed all of them. If the problem is an infinite loop at startup, check to make sure CardFactory uses getInstrinsicKeyword instead of getKeyword for Ability_Mana parsing. Another possibility is leaving getKeyword and getText as is, and changing all instances of
Code: Select all
String manastring="tap: add";
for(String s : card.getKeyword())
  if(s.startsWith(manastring)){
    String color=s.substring(8);
to
Code: Select all
for(SpellAbility sa : card.getSpellAbility())
  if(sa instanceof Ability_Mana && ((Ability_Mana)sa).isBasic())
    String color=((Ability_Mana)sa).mana;
, which I don't think is in too many places.
Anyway, once you're back from Russia zerker, I'll post my source. maybe you can compare it with yours and spot the problem(s).
Bad idea: I return on August 31st, with school starting the next day: therefore, I am in no condition to work on forge for about the next month and a half, and I hope mana abilities will be in a release by then.
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


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 38 guests


Who is online

In total there are 38 users online :: 0 registered, 0 hidden and 38 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 38 guests

Login Form