It is currently 09 Sep 2025, 04:44
   
Text Size

X costs?

Post MTG Forge Related Programming Questions Here

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

Re: X costs?

Postby DennisBergkamp » 06 May 2010, 14:48

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.
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: X costs?

Postby slapshot5 » 06 May 2010, 17:47

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
slapshot5
Programmer
 
Posts: 1391
Joined: 03 Jan 2010, 17:47
Location: Mac OS X
Has thanked: 25 times
Been thanked: 68 times

Re: X costs?

Postby DennisBergkamp » 06 May 2010, 18:48

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.
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: X costs?

Postby juzamjedi » 06 May 2010, 19:16

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:
juzamjedi
Tester
 
Posts: 575
Joined: 13 Nov 2008, 08:35
Has thanked: 6 times
Been thanked: 8 times

Re: X costs?

Postby slapshot5 » 06 May 2010, 20:00

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
slapshot5
Programmer
 
Posts: 1391
Joined: 03 Jan 2010, 17:47
Location: Mac OS X
Has thanked: 25 times
Been thanked: 68 times

Re: X costs?

Postby slapshot5 » 07 May 2010, 02:41

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
slapshot5
Programmer
 
Posts: 1391
Joined: 03 Jan 2010, 17:47
Location: Mac OS X
Has thanked: 25 times
Been thanked: 68 times

Re: X costs?

Postby DennisBergkamp » 07 May 2010, 03:04

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.
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: X costs?

Postby slapshot5 » 07 May 2010, 03:28

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
slapshot5
Programmer
 
Posts: 1391
Joined: 03 Jan 2010, 17:47
Location: Mac OS X
Has thanked: 25 times
Been thanked: 68 times

Re: X costs?

Postby DennisBergkamp » 07 May 2010, 18:25

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.
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: X costs?

Postby MageKing17 » 08 May 2010, 06:33

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).)
User avatar
MageKing17
Programmer
 
Posts: 473
Joined: 12 Jun 2008, 20:40
Has thanked: 5 times
Been thanked: 9 times

Re: X costs?

Postby Chris H. » 06 Jun 2010, 10:59

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
User avatar
Chris H.
Forge Moderator
 
Posts: 6320
Joined: 04 Nov 2008, 12:11
Location: Mac OS X Yosemite
Has thanked: 644 times
Been thanked: 643 times

Re: X costs?

Postby Beached As » 06 Jun 2010, 16:50

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.
Beached As
Programmer
 
Posts: 110
Joined: 23 Feb 2010, 07:48
Has thanked: 0 time
Been thanked: 0 time

Re: X costs?

Postby DennisBergkamp » 07 Jun 2010, 03:31

Ahh, duh :roll: Nice job!
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
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 38 guests

Main Menu

User Menu

Our Partners


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 7303 on 15 Jul 2025, 20:46

Users browsing this forum: No registered users and 38 guests

Login Form