MagicWars 1.2.0 - Script your card - Part I

Today I will continue describing how to create your own card in MagicWars starting version 1.2.0 (that will be published soon). At the moment, we have about 200 script cards and they work fine.
Let's get cracking!
Before reading this article, you'll need to read all about where and how cards are stored now here: http://www.slightlymagic.net/forum/viewtopic.php?f=45&t=1938
First, I'd like to write about Groovy Closures in groovy script, this is what can be found by google:
A Groovy Closure is like a "code block" or a method pointer. It is a piece of code that is defined and then executed at a later point.
Yep, it's true. You write code, then pass it as a parameter and it will be executed later in the game. It is put into "{" and "}" symbols. For well-known Shock the closure is: {dealDamage($target, 2, $this)}
So later it will be executed with injected $target that can be permanent or player and $this that is card itself.
When you create your card, you should follow these two steps:
1. First add spell or ability (using addSpell, addAbility, addAbilityTap, addAbilityTriggered, etc.)
2. Then add specific parameters for just added spell or ability (setCondition, setTrigger, setTarget, setSpecificTarget, addKicker, etc.)
Tip: in cards/scripts you can find common.g that contains all API function you can use.
Adding a spell or an ability
addSpell(Closure) - add any spell without any targeting or condition or spell that you will set parameters later (Step 2.)
mana cost is taken from card description
examples:
Cost - mana cost to pay
May - is Yes\No question that will be asked before paying for ability
Cost and May are optional parameters with default values "0" and "" correspondingly
examples:
- the same as Ability but permanent will also be tapped as a cost
addTriggeredAbility(Closure[,Cost="0"[,May=""]])
- ability that will be triggered by some condition. you do need to set trigger condition later in the script by setTrigger function that will be described later
examples:
Let's get cracking!
Before reading this article, you'll need to read all about where and how cards are stored now here: http://www.slightlymagic.net/forum/viewtopic.php?f=45&t=1938
First, I'd like to write about Groovy Closures in groovy script, this is what can be found by google:
A Groovy Closure is like a "code block" or a method pointer. It is a piece of code that is defined and then executed at a later point.
Yep, it's true. You write code, then pass it as a parameter and it will be executed later in the game. It is put into "{" and "}" symbols. For well-known Shock the closure is: {dealDamage($target, 2, $this)}
So later it will be executed with injected $target that can be permanent or player and $this that is card itself.
When you create your card, you should follow these two steps:
1. First add spell or ability (using addSpell, addAbility, addAbilityTap, addAbilityTriggered, etc.)
2. Then add specific parameters for just added spell or ability (setCondition, setTrigger, setTarget, setSpecificTarget, addKicker, etc.)
Tip: in cards/scripts you can find common.g that contains all API function you can use.
Adding a spell or an ability
addSpell(Closure) - add any spell without any targeting or condition or spell that you will set parameters later (Step 2.)
mana cost is taken from card description
examples:
- Code: Select all
//Wrath of God
addSpell({
for (creature in $allCreatures) {
destroyNoRegeneration(creature)
}
})
- Code: Select all
// Roar of the Wurm
addSpell({
def token = createToken(card,"name=Wurm,type=Creature&Wurm,
color=Green,abilities=no,power=6,toughness=6");
addPermanent(token);
})
addFlashback("3 G") // <-- this just adds Flashback to the spell
Cost - mana cost to pay
May - is Yes\No question that will be asked before paying for ability
Cost and May are optional parameters with default values "0" and "" correspondingly
examples:
- Code: Select all
// Ant Queen (M10)
addAbility({
def token = createToken(card, "name=Insect,type=Creature&Insect,
color=Green,abilities=no,power=1,toughness=1");
addPermanent(token);
}, "1 G")
- the same as Ability but permanent will also be tapped as a cost
addTriggeredAbility(Closure[,Cost="0"[,May=""]])
- ability that will be triggered by some condition. you do need to set trigger condition later in the script by setTrigger function that will be described later
examples:
- Code: Select all
// Reckless Scholar (ZEN)
addAbilityTap({
drawCard($target, 1)
def discard = Action($this, {
discardCard($targetPlayer, $chosen);
})
discard.setTargetPlayerID($target)
discard.setNeedsDiscardCard(true)
run(discard)
})
setTarget("Player")
- Code: Select all
// Hagra Crocodile (ZEN)
addAbilityTriggered("Landfall - Whenever a land enters the battlefield
under your control, Hagra Crocodile gets +2/+2 until end of turn.",
{
pumpUntilEOT($this, 2, 2)
})
setCondition({
return $card.isLand() && $card.controller == $this.controller
})
setTrigger("@moveToZone,from=Any,to=Battlefield")