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
4 UG UG UG
Sorcery
Draw a card for each creature target player controls, then draw a card for each creature another target player controls.
spDrawCards:NumCardsType/Creature/InPlay

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
Sorcery
Target creature is unblockable this turn. Draw a card.
Draw a card.
spPumpTgt:Unblockable
Cantrip

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

Ambition's Cost
3 B
Sorcery
You draw three cards and you lose 3 life.
spDrawCards:3:LoseLife/3

This is another card that combines two different effects.

Thriss, Nantuko Primus
5 G G
Legendary Creature Insect Druid
5/5
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.

p.s.
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.

7 comments:

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
target=creature
auto=unblockable
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
auto=draw:3
auto=life:-3



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:

[card]
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.)
target=creature
auto=3/3
auto=flying
id=129711
name=Angelic Blessing
rarity=C
type=Sorcery
mana={2}{W}
[/card]

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
spDamageCP:2
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.