Page 1 of 3

enPump keyword

PostPosted: 20 Mar 2010, 23:11
by Chris H.
It took some time, but I think that I was able to modify a copy of the eqPump parsing code and the methods located in CardFactroy.java. So, I have a working copy of an enPump keyword ready to go … except …

When I attempt to cast my test card:

    Enchant Aura Test
    2
    Enchantment Aura
    Enchanted creature gets +3/+0 and has first strike, changeling, deathtouch, exalted, flanking and haste.
    enPump:+3/+0/First Strike & Changeling & Deathtouch & Exalted & Flanking & Haste
    Enchant creature

I get a "Choose" window. One choice is for the "Enchant creature" keyword and the other is for "enPump" keyword. I do not know how to address this situation.

I guess that I could merge in my code and just not add in any enPump keyword cards at this time. What should I do?

Re: enPump keyword

PostPosted: 20 Mar 2010, 23:18
by silly freak
just a wild guess... i suspect you made enPump mostly by copying eqPump. eqPump does two things: the activated equip ability and the static bonus/pump ability. for auras, you need to remove the activated part - that seems to be the second choice, no clue why it comes up on casting and not on the battlefield

Re: enPump keyword

PostPosted: 20 Mar 2010, 23:45
by Chris H.
silly freak wrote:just a wild guess... i suspect you made enPump mostly by copying eqPump. eqPump does two things: the activated equip ability and the static bonus/pump ability. for auras, you need to remove the activated part - that seems to be the second choice, no clue why it comes up on casting and not on the battlefield
`
Yeah, now that you mention it that could explain what i am seeing. I admit that I had little idea what the heck that I was doing. :roll:

Re: enPump keyword

PostPosted: 21 Mar 2010, 21:17
by Chris H.
I added a setDescription to the enchant pump SpellAbility which I placed in CardFActoryUtil.java.

Code: Select all
enchant.setDescription("Test");
`
The choose window displays this text string twice. So there is two spell abilities being created ... so I think that SF is right.

I have looked at the code but I can not figure out what I did wrong. I hope that most of my code is correct and that there is just a small and simple to fix type of problem. So I will place my code here:


CardFactory_Auras.java

Code: Select all
    public static int shouldEnchant(Card c) {
        ArrayList<String> a = c.getKeyword();
        for(int i = 0; i < a.size(); i++)
            if(a.get(i).toString().startsWith("enPump")) return i;
       
        return -1;
    }
`

CardFactory_Auras.java

Code: Select all
if (shouldEnchant(card) != -1) {
            int n = shouldEnchant(card);
            if (n != -1) {
                String parse = card.getKeyword().get(n).toString();
                card.removeIntrinsicKeyword(parse);
               
                String k[] = parse.split(":");
                String keywordsUnsplit = "";
                String extrinsicKeywords[] = {"none"};    // for equips with no keywords to add

                int Power = 0;
                int Tough = 0;
               
                String ptk[] = k[1].split("/");
               
                if (ptk.length == 1)     // keywords in first cell
                {
                   keywordsUnsplit = ptk[0];
                }
               
                else // parse the power/toughness boosts in first two cells
                {
                    for (int i = 0; i < 2; i ++)
                    {
                        if (ptk[i].matches("[\\+\\-][0-9]")) ptk[i] =ptk[i].replace("+", "");
                    }
                    Power = Integer.parseInt(ptk[0].trim());
                    Tough = Integer.parseInt(ptk[1].trim());
                   
                    if (ptk.length > 2)     // keywords in third cell
                        keywordsUnsplit = ptk[2];
                }
               
                if (keywordsUnsplit.length() > 0)    // then there is at least one extrinsic keyword to assign
                {
                    String tempKwds[] = keywordsUnsplit.split("&");
                    extrinsicKeywords = new String[tempKwds.length];
                   
                    for (int i = 0; i < tempKwds.length; i ++)
                    {
                        extrinsicKeywords[i] = tempKwds[i].trim();
                    }
                }

                card.addSpellAbility(CardFactoryUtil.enPump_Enchant(card, Power, Tough, extrinsicKeywords));
                card.addEnchantCommand(CardFactoryUtil.enPump_onEnchant(card, Power, Tough, extrinsicKeywords));
                card.addUnEnchantCommand(CardFactoryUtil.enPump_unEnchant(card, Power, Tough, extrinsicKeywords));
                card.addLeavesPlayCommand(CardFactoryUtil.enPump_LeavesPlay(card, Power, Tough, extrinsicKeywords));
            }
        }// enPump
`

CardFactoryUtil.java

Code: Select all
    public static SpellAbility enPump_Enchant(final Card sourceCard, final int Power, final int Tough, final String[] extrinsicKeywords) {
        final SpellAbility enchant = new Spell(sourceCard) {
         private static final long serialVersionUID = -8259560434384053776L;
         
            public boolean canPlayAI() {
                CardList list = new CardList(AllZone.Computer_Play.getCards());
                list = list.getType("Creature");
               
                if (list.isEmpty()) return false;
               
                //else
                CardListUtil.sortAttack(list);
                CardListUtil.sortFlying(list);
               
                for (int i = 0; i < list.size(); i++) {
                    if (CardFactoryUtil.canTarget(sourceCard, list.get(i))) {
                        setTargetCard(list.get(i));
                        return true;
                    }
                }
                return false;
            }//canPlayAI()

         public void resolve() {
                PlayerZone play = AllZone.getZone(Constant.Zone.Play, sourceCard.getController());
                play.add(sourceCard);
               
                Card c = getTargetCard();
               
                if(AllZone.GameAction.isCardInPlay(c) && CardFactoryUtil.canTarget(sourceCard, c)) {
                   sourceCard.enchantCard(c);
                    //System.out.println("Enchanted: " +getTargetCard());
                }
            }//resolve()
        };//enchant ability
        sourceCard.clearSpellAbility();
        sourceCard.addSpellAbility(enchant);
        enchant.setBeforePayMana(CardFactoryUtil.input_targetCreature(enchant));
        enchant.setDescription("Test");
       
      return enchant;
    }//enPump_Enchant()
   
    public static Command enPump_onEnchant(final Card sourceCard, final int Power, final int Tough, final String[] extrinsicKeywords) {
       
        Command onEnchant = new Command() {
           
         private static final long serialVersionUID = -357890638647936585L;

         public void execute() {
                if (sourceCard.isEnchanting()) {
                    Card crd = sourceCard.getEnchanting().get(0);
                   
                    for(int i = 0; i < extrinsicKeywords.length; i ++) {
                       if (! (extrinsicKeywords[i].equals ("none")) && (! crd.getKeyword().contains(extrinsicKeywords[i])))    // prevent Flying, Flying
                             crd.addExtrinsicKeyword(extrinsicKeywords[i]);
                    }
                   
                    crd.addSemiPermanentAttackBoost(Power);
                    crd.addSemiPermanentDefenseBoost(Tough);
                }
            }//execute()
        };//Command
       
        return onEnchant;
    }//enPump_onEnchant
   
    public static Command enPump_unEnchant(final Card sourceCard, final int Power, final int Tough, final String[] extrinsicKeywords) {
       
       Command onUnEnchant = new Command() {
           
         private static final long serialVersionUID = -7121856650546173401L;

         public void execute() {
                if (sourceCard.isEnchanting()) {
                    Card crd = sourceCard.getEnchanting().get(0);
                   
                    for (int i = 0; i < extrinsicKeywords.length; i ++) {
                       crd.removeExtrinsicKeyword(extrinsicKeywords[i]);
                    }
                   
                    crd.addSemiPermanentAttackBoost(-1 * Power);
                    crd.addSemiPermanentDefenseBoost(-1 * Tough);
                }
            }//execute()
        };//Command
       
        return onUnEnchant;
    }//enPump_unEnchant
   
    public static Command enPump_LeavesPlay(final Card sourceCard, final int Power, final int Tough, final String[] extrinsicKeywords) {
       
       Command onLeavesPlay = new Command() {
          
         private static final long serialVersionUID = -924212760053167271L;

         public void execute() {
                if(sourceCard.isEnchanting()) {
                    Card crd = sourceCard.getEnchanting().get(0);
                    sourceCard.unEnchantCard(crd);
                }
            }//execute()
       };//Command
       
       return onLeavesPlay;
    }

Re: enPump keyword

PostPosted: 21 Mar 2010, 21:28
by silly freak
got it! your enPump_Enchant calls addSpellAbility on sourceCard, and you do so again in the other code block

Code: Select all
card.addSpellAbility(CardFactoryUtil.enPump_Enchant(card, Power, Tough, extrinsicKeywords));

...

SpellAbility enPump_Enchant(final Card sourceCard, final int Power, final int Tough, final String[] extrinsicKeywords) {
    ...
    sourceCard.addSpellAbility(enchant);
    ...
    return enchant;
}

Re: enPump keyword

PostPosted: 21 Mar 2010, 22:02
by Chris H.
silly freak wrote:got it! your enPump_Enchant calls addSpellAbility on sourceCard, and you do so again in the other code block
`
Thank you.

I now see that it was just a simple mistake on my part. :mrgreen:

I removed the extra addSpellAbility from the CardFactoryUtil SpellAbility and everything works as it should.

Re: enPump keyword

PostPosted: 21 Mar 2010, 22:09
by DennisBergkamp
Good stuff! This should enable a bunch of "vanilla" Auras, right?

Re: enPump keyword

PostPosted: 21 Mar 2010, 23:20
by Chris H.
DennisBergkamp wrote:Good stuff! This should enable a bunch of "vanilla" Auras, right?
`
Yep, a whole bunch. With the existing implemented cards to convert over plus the simple "vanilla" types that can now be added as-is plus the cards that will need one of Rob's Drawbacks, etc. ...

I think that this could approach 100 cards total. :shock: :mrgreen:

Re: enPump keyword

PostPosted: 22 Mar 2010, 02:43
by DennisBergkamp
Awesome!!! :mrgreen:

Re: enPump keyword

PostPosted: 22 Mar 2010, 23:54
by Chris H.
I am now working on adding a setDescription() to the enPump code as part of revision # 2. There are three auras with Cycling and I need to have a viewable description in the choose window to display both options.

I have placed a

Code: Select all
{SpellAbility Name}.setDescription("Test");
`
after the spell ability that is located in the CardFactoryUtil.java file but the word "Test" does not appear in the card detail panel.

I had a similar problem when I tried to code a description for the eqPump keyword. I wonder if placing the actual SpellAbility in the CardFactoryUtil.java file rather than inside of one of the CardFactory files could be causing this problem.

I am considering moving just the SpellAbility into the CardFActory_Auras.java file. I could leave the three commands in the CardFactoryUtil.java file. I can not think of any other way to get a spell description to display in the choose window.

Re: enPump keyword

PostPosted: 23 Mar 2010, 02:51
by Rob Cashwalker
could you provide a bit more code? What you've posted is rather out-of context to diagnose.

Re: enPump keyword

PostPosted: 24 Mar 2010, 00:41
by Chris H.
Rob Cashwalker wrote:could you provide a bit more code? What you've posted is rather out-of context to diagnose.
`
Sorry about that.

I added these test cards to cards.txt

Code: Select all
Aura One
1
Enchantment Aura
no text
enPump:+3/+0
Enchant creature

Aura Two
1
Enchantment Aura
no text
Enchant creature
enPump:First Strike & Changeling

Aura Three
1
Enchantment Aura
no text
Enchant creature
enPump:+0/+4/Deathtouch & Exalted

Enchant Aura Test
1
Enchantment Aura
Enchanted creature gets +3/+0 and has first strike, changeling, deathtouch, exalted, flanking and haste.
enPump:+3/+0/First Strike & Changeling & Deathtouch & Exalted & Flanking & Haste
Enchant creature
`

I then slightly changed the code that I merged into the SVN.

This is now the code at the end of the CardFactory_Auras.java

Code: Select all
        if (shouldEnchant(card) != -1) {
            int n = shouldEnchant(card);
            if (n != -1) {
                String parse = card.getKeyword().get(n).toString();
                card.removeIntrinsicKeyword(parse);
               
                String k[] = parse.split(":");
                String keywordsUnsplit = "";
                String extrinsicKeywords[] = {"none"};    // for equips with no keywords to add

                int Power = 0;
                int Tough = 0;
               
                String ptk[] = k[1].split("/");
               
                if (ptk.length == 1)     // keywords in first cell
                {
                   keywordsUnsplit = ptk[0];
                }
               
                else    // parse the power/toughness boosts in first two cells
                {
                    for (int i = 0; i < 2; i ++)
                    {
                        if (ptk[i].matches("[\\+\\-][0-9]")) ptk[i] =ptk[i].replace("+", "");
                    }
                    Power = Integer.parseInt(ptk[0].trim());
                    Tough = Integer.parseInt(ptk[1].trim());
                   
                    if (ptk.length > 2)     // keywords in third cell
                        keywordsUnsplit = ptk[2];
                }
               
                if (keywordsUnsplit.length() > 0)    // then there is at least one extrinsic keyword to assign
                {
                    String tempKwds[] = keywordsUnsplit.split("&");
                    extrinsicKeywords = new String[tempKwds.length];
                   
                    for (int i = 0; i < tempKwds.length; i ++)
                    {
                        extrinsicKeywords[i] = tempKwds[i].trim();
                    }
                }

                card.clearSpellAbility();
                card.addSpellAbility(CardFactoryUtil.enPump_Enchant(card, Power, Tough, extrinsicKeywords));
                card.addEnchantCommand(CardFactoryUtil.enPump_onEnchant(card, Power, Tough, extrinsicKeywords));
                card.addUnEnchantCommand(CardFactoryUtil.enPump_unEnchant(card, Power, Tough, extrinsicKeywords));
                card.addLeavesPlayCommand(CardFactoryUtil.enPump_LeavesPlay(card, Power, Tough, extrinsicKeywords));
            }
        }// enPump
`
and this is now the SpellAbility in CardFactoryUtil.java

Code: Select all
    public static SpellAbility enPump_Enchant(final Card sourceCard, final int Power, final int Tough, final String[] extrinsicKeywords) {
        final SpellAbility enchant = new Spell(sourceCard) {
         private static final long serialVersionUID = -8259560434384053776L;
         
            public boolean canPlayAI() {
                CardList list = new CardList(AllZone.Computer_Play.getCards());
                list = list.getType("Creature");
               
                if (list.isEmpty()) return false;
               
                //else
                CardListUtil.sortAttack(list);
                CardListUtil.sortFlying(list);
               
                for (int i = 0; i < list.size(); i++) {
                    if (CardFactoryUtil.canTarget(sourceCard, list.get(i))) {
                        setTargetCard(list.get(i));
                        return true;
                    }
                }
                return false;
            }//canPlayAI()

         public void resolve() {
                PlayerZone play = AllZone.getZone(Constant.Zone.Play, sourceCard.getController());
                play.add(sourceCard);
               
                Card c = getTargetCard();
               
                if(AllZone.GameAction.isCardInPlay(c) && CardFactoryUtil.canTarget(sourceCard, c)) {
                   sourceCard.enchantCard(c);
                    //System.out.println("Enchanted: " +getTargetCard());
                }
            }//resolve()
        };//enchant ability
        enchant.setBeforePayMana(CardFactoryUtil.input_targetCreature(enchant));
        enchant.setDescription("This is a test spell description");
       
      return enchant;
    }//enPump_Enchant()
`
You will notice that I have just started and I am only trying to get a test string printed on my test cards in the card detail panel. Once I get that much, I can then add the necessary input parameters and pass a string from CardFactory_Auras.java to CardFactoryUtil.java. At that point I can start to build the correct string via string builder and then test the results displayed with my three test cards. :D

Re: enPump keyword

PostPosted: 24 Mar 2010, 03:35
by Rob Cashwalker
Ahh, now at least I know what you're doing.... I don't see why it doesn't work....
Maybe try putting the setDescription in the CardFactory half. Instead of assigning the SpellAbility to the card, make a local copy, set the description, then assign the local copy to the card.

Re: enPump keyword

PostPosted: 25 Mar 2010, 21:32
by Chris H.
I tried a few things and discovered that the Cycling code was missing from CardFactory_Auras.java and I added this code in case someone eventually can get setDescription working. I have not yet had any success. ](*,)

One thing interesting that I learned … if I change the test card type from Enchantment Aura to Enchantment then the setDescription string will appear. I also tried to add the setDescription string to one of the hard coded auras and the setDescription string failed to appear.

I tried to follow Rob's suggestion and got part way and then I got stuck.

Code: Select all
tempCard = new Card;
tempCard.addSpellAbility(CardFactoryUtil.enPump_Enchant(card, Power, Tough, extrinsicKeywords));
`
but at this point I can not figure out how to assign the tempCard to the Card that is being returned. I was a little lost at this point and it may not have made a difference.

So, at some point we may figure this out. Until then, all I can do is convert existing cards and add additional cards that do not have Cycling as an ability. And this will keep me busy for awhile. 8)

Re: enPump keyword

PostPosted: 25 Mar 2010, 23:29
by DennisBergkamp
I'll look into this as well, once I'm done with some of the card shop stuff.