Wednesday, September 9, 2009

More Scriptin with Cards.txt

By enabling cards.txt to implement Magic cards it greatly reduces the programming time that is needed to add new cards. Cards.txt supports a number of effects that are commonly used in Magic such as "damage creature or player", "draw N number of cards", "target creature gets X (like haste or unblockable)", or cantrip (Draw 1 card after this card gets done resolving.)

Biomantic Mastery
Draw a card for each creature target player controls, then draw a card for each creature another target player controls.

Biomantic Mastery is a complex card yet it can be added easily by adding it to cards.txt. The card is also more readable than the same code that was coded using Java.

Touch of Invisibility
3 U
Target creature is unblockable this turn. Draw a card.
Draw a card.

Touch of Invisibility has two effects which adds to the complexity.

Ambition's Cost
3 B
You draw three cards and you lose 3 life.

This is another card that combines two different effects.

Thriss, Nantuko Primus
5 G G
Legendary Creature Insect Druid
abTgtPTPump G T:+5/+5

The last line means that Thriss can pump up the target creature's stats by +5/+5. The activated ability taps this creature and costs "G".

By allowing cards.txt to implement cards itself, it makes adding (and creating) Magic cards very easy.

Unfortunately cards.txt doesn't have any error checking, so if you miss around with it and something fails, you probably won't know that it fails. Error checking is very hard.


willow said...

One of my favorite topics :)

Here's how you would write these cards abilities in Wagic (which, by the way, does not use LUA)

Biomantic Mastery
auto=foreach(creature|battlefield) draw:1

(Based on the fact that there are only 2 players in Wagic, I assume MTGForge does the same)

Touch of Invisibility
auto=draw:1 controller

(the "controller" here is to mean: controller of the spell being cast. The default behaviour in wagic would otherwise be to give life to the target's controller)

Ambition's Cost

Thriss, Nantuko Primus
auto={G}{T}:5/5 target(creature)

nantuko84 said...

willow's variant is more readable for me
and what is the meaning for "auto"?

willow said...

in wagic's card files, each line is a key and a value separated by the "=" symbol.

So, a full card looks like this:

text=Target creature gets +3/+3 and gains flying until end of turn. (It can't be blocked except by creatures with flying or reach.)
name=Angelic Blessing

This allows us to not care about the order in which we write the lines, as they are all clearly identified.
auto was used as the keyword, to mean the opposite of "hardcoded", as in "auto generated code" or something...

Silly Freak said...

for someone not "in the know" (or it's only me because i'm not a native speaker), many of the keywords come in two flavors: ab for activated abilities and sp for spells.
so shock has
and rod of ruin has
abDamageCP 3 T:1

Unknown said...

And who's brilliant idea were all these scripted keywords? [wink wink]

Forge said...

Yours and I'm sure that many people thank you. I know coding some of the abilities was difficult.

Forge said...

Truthfully I wrote about this topic because I couldn't think of anything else to write about but that is how it is most of the time when I write for this blog.