Page 4 of 4

Re: X costs?

PostPosted: 06 May 2010, 14:48
by DennisBergkamp
Hmm, I started out supporting this, but then I had enough trouble getting the simplest case of X costs to work, so I never really revisited this. But I'll look at the code again and see if I can get this to work.

Re: X costs?

PostPosted: 06 May 2010, 17:47
by slapshot5
One of the hangups for me was I didn't know where all to look in the code for places to modify? Is there a short-list of places to look for the X-cost code? If so, I can start looking at this myself. I've poked around a little, and the solution wasn't straight-forward from what I could tell.

I've done next to nothing with mana abilities thus far.

-slapshot5

Re: X costs?

PostPosted: 06 May 2010, 18:48
by DennisBergkamp
Check:

MagicStack.add
CardFactoryUtil.xCount
Card.getXManaCost, Card.setXManaCost, Card.addXManaCost...
SpellAbility.isXCost, SpellAbility.setIsXCost

Then in CardFactory there's a piece of code that looks like this, way at the end starting on line 19832:

Code: Select all
if (card.getManaCost().contains("X"))
        {
           SpellAbility sa = card.getSpellAbility()[0];
          sa.setIsXCost(true);
          
           if (card.getManaCost().startsWith("X X"))
              sa.setXManaCost("2");
           else if (card.getManaCost().startsWith("X"))
              sa.setXManaCost("1");
        }//X
As you can see, I already kind of started with the double X. I haven't tested it yet though (but I guess you said it didn't work).

I *think* those are all of the places.

Re: X costs?

PostPosted: 06 May 2010, 19:16
by juzamjedi
It would be nice if X costs could be canceled or reduced in the middle of casting the spell. For example in a draft game I was in the middle of casting Blaze, I accidentally tap too much and I can't cast Tarmogoyf. Oops! :oops:

Re: X costs?

PostPosted: 06 May 2010, 20:00
by slapshot5
Dennis -

Before you spend too much time looking into this, it looks like this may well work for the simple case.

I just assumed it didn't since no double X spells were implemented. I'll look at it tonight and test some cards.

-slapshot5

Re: X costs?

PostPosted: 07 May 2010, 02:41
by slapshot5
Well,

We definitely don't support X costs in activated abilities like Orcish Settlers or Whetwheel.

We do support "X X" for Instants/Sorceries. Recall generally works, but my input isn't quite working correctly. I'll post that back in the input thread I started.

I'm not having luck adding "X" costs for abilities. I added code at the bottom of CardFactory.java to loop throughCard.getSpells() getManaCost().contains("X"), and setting it this way, but no luck.

Someone else better versed in this will probably have to tale a look.

-slapshot5

Re: X costs?

PostPosted: 07 May 2010, 03:04
by DennisBergkamp
That's cool to see that X X actually works (I never really tested this, since I thought it wouldn't work).

Right now we code X cost in abilities differently. Look at Helix Pinnacle in CardFactory for an example.

Re: X costs?

PostPosted: 07 May 2010, 03:28
by slapshot5
Oh, right. I remember using Helix Pinnacle once or twice. Ideally, we should be able to handle this like other spells though. Whetwheel was just requested. Maybe I'll gve that a try in the spirit of Helix Pinnacle to check "X X" costs...

-slapshot5

Re: X costs?

PostPosted: 07 May 2010, 18:25
by DennisBergkamp
X X Costs should be very easy in the ability part also, just look at this part of the code:
Code: Select all
...
Integer.parseInt(s);
ability.setManaCost(s);
...
Just multiply the integer value of "s" by 2, before it sets the manacost.

Re: X costs?

PostPosted: 08 May 2010, 06:33
by MageKing17
Incantus handles multiple Xs by counting the number of times X appears in the cost and multiplying the user's choice by that amount. The advantage is that this can even handle a triple-X cost (or even a quadruple-X cost), despite such things not existing. The disadvantage is that there's no way to insert a color restriction in the current system (like with Drain Life).

(If anyone wants to see the code involved, BitBucket provides (Cost.py shouldn't have changed in my last release).)

Re: X costs?

PostPosted: 06 Jun 2010, 10:59
by Chris H.
Chris H. wrote:I guess that cards with non-MultiKicker X costs are limited to sorceries and instants at this time. I tried to code the following card and it did not ask for the X costs. When I changed the type in cards.txt to sorcery and then cast this card it asked me to input the X cost. I guess that MultiKicker is different in that there is code to allow us to pay for the kicks.

Code: Select all
Ivy Elemental
X G
Creature Elemental
Ivy Elemental enters the battlefield with X +1/+1 counters on it.
0/0
`
Code: Select all
        //*************** START *********** START **************************
        else if(cardName.equals("Ivy Elemental"))
        {
           final Ability ability = new Ability(card, "0") {
                @Override
                public void resolve() {
                    card.addCounter(Counters.P1P1, card.getXManaCostPaid());
                    card.setXManaCostPaid(0);
                }
            };
           
            StringBuilder sb = new StringBuilder();
            sb.append(cardName);
            sb.append(" - enters the battlefield with X +1/+1 counters on it.");
            ability.setStackDescription(sb.toString());
           
            final Command comesIntoPlay = new Command() {
            private static final long serialVersionUID = -6463000686862814506L;

            public void execute() {
                    AllZone.Stack.add(ability);
                }
            };
           
            card.addComesIntoPlayCommand(comesIntoPlay);
        }//*************** END ************ END **************************
`
I woke up this morning and checked the SVN to see that Beached as figured this out and had just added this card and a few other similar cards. Wow, thank you. :D

Re: X costs?

PostPosted: 06 Jun 2010, 16:50
by Beached As
lol this one stumped me for a bit. I was wondering why sorceries could pay X costs but creatures couldn't. I've learnt that anything that effects sorceries and instants only is in CardFactory.java so i had a look and found the code which allows cards to pay X costs and just pasted it into CardFactory_Creatures.java. Then all was swell.

Re: X costs?

PostPosted: 07 Jun 2010, 03:31
by DennisBergkamp
Ahh, duh :roll: Nice job!