As said before, the rules of the games are described in the file mtg.xml in the src/main/resources/tbs directory. You will often search within this file to get some already written tests, actions or abilities, so let's see the structure of this file.
The mtg.xml starts with the <tbs> element, which stands for "Turn Based Strategy". Some of the attributes specify the XML schema location, the XML name space, some others specify the name of the game, the version and the author. We also have information about the picture of the back of the cards file.
Magic Project also implements a database management for informations on cards not related to the rules, like the picture of the card, the flavor text or the artist. All these informations can be grabbed automatically from various sites by just providing a well formed XML proxy file.
The <database-properties> element in the mtg.xml file is used to declare the different informations understood by Magic Project. You will find below an extract of this element from the mtg.xml file.
<database-properties> <property name="card.artist-credit" type="java.lang.String" translate="false" /> <property name="card.flavor-text" type="java.lang.String" translate="false" /> <property name="card.sets" type="java.util.List" translate="true" /> <property name="card.text" type="java.lang.String" translate="false" /> <property name="card.id" type="java.lang.String" translate="false" /> <property name="card.set" type="java.lang.String" translate="true" /> <property name="card.version" type="java.lang.String" translate="false" /> </database-properties>
Magic Project dynamically download the mana symbols needed to display the abilities from the Wizards of the Coast web site for copyright considerations. The <mana-symbols> element stands for giving Magic Project all the information needed to properly download these symbols.
The element <license> just give a description of the license linked to the game referenced in the mtg.xml file. You will find an extract of this license description below :
<licence> This program is not published, produced or supported by Wizards Of The Coast(TM), Inc. Magic The Gathering(TM) and Wizards Of The Coast(R) Inc. are registered trademarks owned by Wizards Of The Coast(R) Inc., a subsidiary of Hasbro, Inc. </licence>
Most of the elements of the Magic the Gathering game implementation in Magic Project are referenced by integer values. To make rules readable by a human, we can also use aliases for specific integer values, which are declared within the <aliases> element.
Let's look at the different available aliases.
These aliases are used in many different situations :
| Name of the alias |
| none |
| all |
| abortme |
| abort |
| destroy |
| manapool |
| manacost |
| threshold |
All the different types of damage can be tested using this set of available aliases :
| Name of the alias |
| damage-normal |
| damage-combat |
| damage-cannot-be-prevented |
| damage-cannot-be-redirected |
| damage-cannot-be-regenerated |
| damage-cannot-be-prevented-redirected |
| damage-can-prevent |
The position of a card in a zone can be referenced using these aliases :
| Name of the alias |
| top |
| bottom |
The following aliases are used in damage prevention :
| Name of the alias |
| damage-any |
| damage-combat-only |
| damage-combat-can-be-prevented |
| damage-can-be-prevented |
| damage-can-be-redirected |
| damage-can-be-regenerated |
The following aliases are used for phase indexes :
| Name of the alias |
| precombat-main |
| eoc.index |
| postcombat-main |
The following aliases are used for game static indexes, they are reseted each turn :
| Name of the alias |
| attack-step-index |
| nb-attacking-group |
| assignment-configuration |
| assignment-configuration-int |
| beginning-of-combat-target-lists |
| normal-next-player |
| skipping-turn |
| turnid |
| nbattacking |
The following aliases are used for registers dedicated to cards or players :
| Name of the alias |
| colorless |
| black |
| blue |
| green |
| red |
| white |
| state |
| damage |
| combat.assignedto |
| free0 |
| free1 |
The following aliases are used for registers dedicated to cards :
| Name of the alias |
| combat.toassign |
| power |
| toughness |
| loyalty |
| planeswalker-ability |
| special-abilities |
The following aliases are used for registers dedicated to players :
| Name of the alias |
| poison |
| life |
| mulligan |
| creatures-moved-in-graveyard-from-play-this-turn |
| damage-dealt-this-turn |
| hand-vibility-modifiers |
| initialized |
| land-remain-to-cast |
| maxi-cards-in-hand |
| playedland |
The following aliases are used for card types :
| Name of the alias |
| mana-source |
| permanent |
| instant |
| tribal |
| sorcery |
The following aliases are used for permanent types :
| Name of the alias |
| enchantment |
| local-enchantment |
| global-enchantment |
| land |
| swamp |
| island |
| forest |
| mountain |
| plains |
| creature |
| artifact |
| artifact-creature |
| planeswalker |
The following aliases are used for phases :
| Name of the alias |
| untap |
| upkeep |
| draw |
| main |
| declare-attack |
| declare-attacking |
| declare-blocking |
| combat-deals |
| eoc |
| eot |
| cleanup |
The following aliases are used for protection types :
| Name of the alias |
| protection-from-idcard |
| protection-from-enchantments |
| protection-from-creatures |
| protection-from-artifacts |
| protection-from-color |
| protection-from-black |
| protection-from-blue |
| protection-from-green |
| protection-from-red |
| protection-from-white |
| protection-from-property |
| protection-from-goblins |
| protection-from-kavu |
| protection-from-gorgons |
| protection-from-clerics |
| protection-from-beasts |
| protection-from-dragons |
| protection-from-spirits |
| protection-from-arcane |
| protection-from-snow |
The following aliases are used for categories of shroud property :
| Name of the alias |
| untargetable-by-idcard |
| untargetable-by-creature |
| untargetable-by-sorcery |
| untargetable-by-enchant |
| untargetable-by-artifact |
| shroud |
| Name of the alias |
| double-strike |
| first-strike |
| flying |
| rampage |
| trample |
| snow |
| protection-from-spells |
| protection-from-abilities |
| untap-under-condition |
| basic-land |
| attacks-if-able |
| banding |
| shadow |
| fear |
| islandwalk |
| forestwalk |
| swampwalk |
| plainswalk |
| mountainwalk |
| reach |
| vigilance |
| haste |
| does-not-untap |
| wall-can-attack |
| cannot-attack |
| cannot-block |
| artifact-damage-reduced-to-0 |
| spell-damage-reduced-to-0 |
| creature-damage-reduced-to-0 |
| damage-reduced-to-0 |
| sorcery-damage-reduced-to-0 |
| token |
| defender |
| indestructible |
| unblockable |
| cannot-be-enchanted |
| enchant-world |
| desert |
| lair |
| locus |
| equipment |
| desertwalk |
| cannot-be-countered |
| cannot-use-T |
| sunburst |
| protection-from-monocolored |
| protection-from-multicolored |
| protection-from-all-colors |
| flash |
| morph |
| snow-islandwalk |
| snow-forestwalk |
| snow-swampwalk |
| snow-plainswalk |
| snow-mountainwalk |
| nonbasic-landwalk |
| convoke |
| may-not-untap |
| legendary-landwalk |
| cannot-be-blocked-by-artifacts |
| cannot-be-blocked-by-walls |
| phasing |
| aura |
| block-as-shadow |
| block-only-flying |
| horsemanship |
| arcane |
| shrine |
| legend |
| changeling |
| jace |
| garruk |
| ajani |
| liliana |
| chandra |
All the declared creatures types available in Magic Project are listed below :
| Name of the alias |
| FIRST_SUB_TYPE |
| advisor |
| anemone |
| angel |
| anteater |
| antelope |
| ape |
| archer |
| archon |
| artificer |
| assassin |
| assembly-worker |
| atog |
| aurochs |
| avatar |
| badger |
| barbarian |
| basilisk |
| bat |
| bear |
| beast |
| beeble |
| berserker |
| bird |
| blinkmoth |
| boar |
| bringer |
| brushwagg |
| camarid |
| camel |
| caribou |
| carrier |
| cat |
| centaur |
| cephalid |
| chimera |
| citizen |
| cleric |
| cockatrice |
| construct |
| coward |
| crab |
| crocodile |
| cyclops |
| dauthi |
| demon |
| deserter |
| devil |
| djinn |
| dragon |
| drake |
| dreadnought |
| drone |
| druid |
| dryad |
| dwarf |
| efreet |
| egg |
| elder |
| elemental |
| elephant |
| elf |
| elk |
| eye |
| faerie |
| ferret |
| fish |
| flagbearer |
| fox |
| frog |
| fungus |
| gargoyle |
| giant |
| gnome |
| goat |
| goblin |
| golem |
| gorgon |
| graveborn |
| gremlin |
| griffin |
| hag |
| harpy |
| hellion |
| hippo |
| homarid |
| homunculus |
| horror |
| horse |
| hound |
| human |
| hydra |
| illusion |
| imp |
| incarnation |
| insect |
| jellyfish |
| juggernaut |
| kavu |
| kirin |
| kithkin |
| knight |
| kobold |
| kor |
| kraken |
| lammasu |
| leech |
| leviathan |
| lhurgoyf |
| licid |
| lizard |
| manticore |
| masticore |
| mercenary |
| merfolk |
| metathran |
| minion |
| minotaur |
| monger |
| mongoose |
| monk |
| moonfolk |
| mutant |
| myr |
| mystic |
| nautilus |
| nephilim |
| nightmare |
| nightstalker |
| ninja |
| nomad |
| octopus |
| ogre |
| ooze |
| orb |
| orc |
| orgg |
| ouphe |
| ox |
| oyster |
| pegasus |
| pentavite |
| pest |
| phelddagrif |
| phoenix |
| pincher |
| pirate |
| plant |
| prism |
| rabbit |
| rat |
| rebel |
| reflection |
| rhino |
| rigger |
| rogue |
| rukh |
| salamander |
| samurai |
| sand |
| saproling |
| satyr |
| scarecrow |
| scorpion |
| scout |
| serf |
| serpent |
| shade |
| shaman |
| shapeshifter |
| sheep |
| skeleton |
| slith |
| sliver |
| slug |
| snake |
| soldier |
| soltari |
| spawn |
| specter |
| spellshaper |
| sphinx |
| spider |
| spike |
| spirit |
| splinter |
| sponge |
| squid |
| squirrel |
| starfish |
| survivor |
| tetravite |
| thalakos |
| thopter |
| thrull |
| treefolk |
| triskelavite |
| troll |
| turtle |
| unicorn |
| vampire |
| vedalken |
| viashino |
| volver |
| wall |
| warrior |
| weird |
| whale |
| wildebeest |
| will-o'-the-wisp |
| witch |
| wizard |
| wolf |
| wolverine |
| wombat |
| worm |
| wraith |
| wurm |
| yeti |
| zombie |
| zubera |
| fillette |
| LAST_SUB_TYPE |
A bunch of integer registers (like life) are allocated to each player. the elements <registers-first-player> and <registers-first-player> are declared to the initialization of these registers. You will find below an extract of theses elements from the mtg.xml file :
<registers-first-player> <register index="life" value="20" /> <register index="maxi-cards-in-hand" value="7" /> <register index="land-remain-to-cast" value="1" /> <register index="hand-vibility-modifiers" value="0" /> <register index="playedland" value="0" /> <register index="mulligan" value="7" /> </registers-first-player> <registers-second-player> <register index="life" value="20" /> <register index="maxi-cards-in-hand" value="7" /> <register index="hand-vibility-modifiers" value="0" /> <register index="playedland" value="0" /> <register index="mulligan" value="7" /> </registers-second-player>
The next element <phases> declare the different phases of a turn in the implemented game. It also specifies which type of spells are playable during these phases.
For any card in game with a specific state (like summoning sickness), Magic Project interprets the <state-pictures> element to get the picture and the test associated to each state. If the index and state attributes are provided, Magic Project will make a bitwise compare with the index value of card's registers and the given state value. width and height values determines the size of the picture to display on the card. You can make Magic Project positioning automatically the picture (trailing) by setting the x and the y attributes to -1.
In Magic the Gathering game, some actions are linked to a picture. This is true for the action "tap" for example. The element <action-pictures> declares the different pictures associated to actions.
The element <tooltip-filters> informs Magic Project of the amount of informations to show on cards depending on various tests (for example, it is not necessary to show the colors of a land card since all of them are colorless).
The static modifiers are modifications that apply to cards automatically since they verify the associated test. They are declared with the <static-modifiers> element. We will find in this element, for example, the static modifiers that give any basic land type the ability to produce the associated mana by tapping it, the static modifier for a play-using-morph creature or the ability of cards with flash to be cast at any time.
You will find below an example of the static modifier for creatures with the morph ability :
<static-modifier filter-zone="play">
<modifiers>
<register-indirection index="power" value="2" operation="set" layer="internal" />
<register-indirection index="toughness" value="2" operation="set" layer="internal" />
<idcard-modifier idcard="creature" operation="set" layer="internal" />
<property-modifier operation="remove" property="all" layer="internal"/>
<color-modifier operation="clear" />
</modifiers>
<while>
<and>
<has-property property="morph" />
<not>
<is-face-up />
</not>
</and>
</while>
</static-modifier>
In the element <abilities>, we can find all the abilities associated directly to the general management of the game.
The element starts with the system abilities (declared with the <system-ability> elements) that allow players to play the attack phase, initializes the game, implements the draw and the discard phase, implements the mulligan, manages and initializes the turn, manages the lethal damage or the manaburn, implements the legend rule, implements the enchant world rules or the limitation while playing lands.
These declarations are followed by the replacement abilities, which stand for abilities that trigger on specific actions and replace theses actions dynamically by other actions. They are declared using the <replacement-ability> element. We will find here the replacement abilities that trigger when a token goes to the graveyard (in fact it is put out of the game), that trigger when a card is played using flashback (when the spell resolves, it goes out of the game) or that trigger when a card is played with buyback (when the spell resolves, it goes to its owner's hand).
The layout of the game is also described in the XML file using the <layout> element. Common panels and zones are declared within.
This is the most important part of the XML file for card rules writers. Identified by the element <references>, it contains a set of tests, actions, abilities or attachments that can be referenced from your card XML code. Warning : Declaration order is important, you cannot refers to an ability or a test that has not previously been declared.
These are described within the nested <tests> element. We can find the following references :
| Reference name | Description |
| has-imprinted-card | Returns true if there is an imprinted card on the current card. |
| hellbent | Returns true if there is no cards in your hand. |
| once-each-turn | Has this "once each turn" ability not been played ? |
| tested-just-summoned | Has the tested card just been summoned ? |
| just-summoned | Has the current card just been summoned ? |
| before-attackers-declaration | Is the current phase your attackers declaration phase ? |
| during-your-untap | Is the current phase your untap phase ? |
| during-modifier-untap | Is the current phase the untap phase of controller of modifier creator ? |
| during-your-upkeep | Is the current phase your upkeep phase ? |
| during-oppponent-upkeep | Is the current phase is an oppponent's upkeep phase ? |
| during-your-draw | Is the current phase your draw phase ? |
| during-your-precombat-main | Is the current phase your pre-combat main phase ? |
| during-your-main | Is the current phase one of your main phases ? |
| during-your-combat | Is the current phase your combat phase ? |
| during-your-eot | Is the current phase your end of turn phase ? |
| threshold | Does the tested card controller graveyard contain at least an amount of cards greater or equal to the number identified by the threshold register of that card ? |
| tested-is-attacking | Is the tested card attacking ? |
| first-target-is-attacking | Is the first card in the target list attacking ? |
| is-attacking | Is the current card attacking ? |
| saved-is-attacking | Is the saved card attacking ? |
| tested-is-blocking | Is the tested card blocking ? |
| first-target-is-blocking | Is the first card in the target list blocking ? |
| is-blocking | Is the current card blocking ? |
| tested-is-blocked | Has the tested card been blocked ? |
| is-blocked | Has the current card been blocked ? |
| is-untapped-under-condition | Has the tested card been untapped manually ? |
| tested-has-combat-damage-to-assign | Does the tested card have combat damage to assign ? |
| tested-is-unblocked | Has the tested card not been blocked ? |
| is-unblocked | Has the current card not been blocked ? |
| tested-in-combat | Is the tested card in combat ? |
| in-combat | Is the current card in combat ? |
| cantap | Can the current card tap ? |
| can-use-T | Can the current card use the {T} ability (in addition to the previous test, this one tests whether the current card is not affected by a limitation that doesn't allow it to tap) ? |
| has-counter | Is there a private card counter ? This counter is not visible for players. Also see init-counter ability. |
| is-multicolored | Is the tested card a multicolored card (it has at least two colors) ? |
| this-is-multicolored | Is the current card a multicolored card (it has at least two colors) ? |
| is-monocolored | Is the tested card a mono-colored card ? |
| this-is-monocolored | Is the current card a mono-colored card ? |
| is-colored | Is the tested card a colored card (it has at least one color) ? |
| this-is-colored | Is the current card a colored card (it has at least one color) ? |
| is-target | Is the tested card target ? |
| is-targetable-land | Is the tested card a target land ? |
| is-targetable-spell | Is the tested card a target spell ? |
| valid-damage-source | This test must return true to design a valid damage source. |
| is-targetable-damage-source | This test must return true to design a target damage source. |
| is-targetable-ability | To have an ability being targeted properly, this test must return true. |
| is-targetable-activated-ability | To have an activated ability being targeted properly, this test must return true. |
| is-targetable-triggered-ability | To have a triggered ability being targeted properly, this test must return true. |
| is-targetable-activated-triggered-ability | To have an activated or triggered ability being targeted properly, this test must return true. |
| is-targetable-creature | To have a creature being targeted properly, this test must return true. |
| is-targetable-artifact | To have an artifact being targeted properly, this test must return true. |
| is-targetable-tappable | To have an tappable permanent (creature, artifact or land) being targetted properly, this test must return true. |
| is-basic-land | Is the tested card a basic land ? |
| is-nonbasic-land | Is the tested card a non-basic land ? |
| only-for-artifact-spell | Test used to apply restrictions on the use of mana that can only be used to pay artifact spells mana cost (Mishra's Workshop for example). |
| only-for-colored-spell | Test used to apply restrictions on the use of mana that can only be used to pay multicolored spells mana cost. |
| only-for-cumulative-upkeep | Test used to apply restrictions on the use of mana that can only be used to pay cumulative upkeep mana costs. (Mishra's Workshop for example). |
| valid-block | To be chosen to block the current attacking, the tested card must verify that this test returns true. |
| is-targetable-player | To have a player being targeted properly, this test must return true. |
| is-targetable-dealtable | To have a dealtable (creature of player) being targeted properly, this test must return true. |
| is-targetable-artifact-creature | To have an artifact creature being targeted properly, this test must return true. |
| is-targetable-enchantment | To have an enchantment being targeted properly, this test must return true. |
| is-targetable-local-enchantment | To have an aura being targeted properly, this test must return true. |
| can-attack | Can the tested card attack ? |
| valid-enchant | Test used for the attachment of an aura to the enchanted permanent. |
| valid-enchant-land | Test used for the attachment of an aura to the enchanted land. |
| valid-enchant-creature | Test used for the attachment of an aura to the enchanted creature. |
| valid-enchant-enchantment | Test used for the attachment of an aura to the enchanted artifact creature. |
| valid-enchant-artifact-creature | Test used for the attachment of an aura to the enchanted artifact creature. |
| valid-enchant-artifact | Test used for the attachment of an aura to the enchanted artefact. |
| valid-equip-creature | Test used for the attachment of an equipment to the equipped creature. |
| valid-to-enchant | Internal test used to select a valid card to enchant (do not use this directly). |
| valid-creature-to-enchant | Test used to select a valid creature to enchant. |
| valid-enchantment-to-enchant | Test used to select a valid enchantment to enchant. |
| valid-land-to-enchant | Test used to select a valid land to enchant. |
| valid-permanent-to-enchant | Test used to select a valid permanent to enchant. |
| valid-artifact-creature-to-enchant | Test used to select a valid artifact creature to enchant. |
| valid-artifact-to-enchant | Test used to select a valid artifact to enchant. |
| valid-to-equip | Internal test used check the equip stills valid (do not use this directly). |
| valid-creature-to-equip | Internal test used check the equip stills valid for the equiped creature. |
| valid-equip | Internal test used to select a valid card to equip (do not use this directly). |
| valid-equip-creature | Test used to select a valid creature to equip. |
| died-card | This test is used by update-toughness and update-damage abilities. |
| priv_blocking-tested-counter | Test only used by combat-damage assignments ability to check the creatures blocking the super.tested card. |
| priv_blocked-by-tested-counter | Test only used by combat-damage assignments ability to check the creatures blocked by the super.tested card. |
| priv_currentplayer-has-to-discard | Test used during the discard phase to verify if the current player has to discard cards from his hand. |
| flashback-used | Has the flashback been used ? |
| buyback-used | Has the buyback been paid for this spell ? |
| kicker-used | Has the kicker been paid for this spell ? |
| kicker2-used | Has the second kicker been paid for this spell ? |
| entwine-used | Has the entwine been paid for this spell ? |
| has-no-more-fading | Returns true if the current card has no more fading counter on it. |
| has-no-more-time | Returns true if the current card has no more time counter on it. |
| can-regenerate | Can the creature generate ? This test cannot be used in event test. |
| is-valid-blocking-creature-for-targeted-attacking | ? |
| has-at-least-one-valid-blocking-creature | ? |
| valid-creature-equip | Test used to select a proper target for an equipment. |
These are described within the nested <actions> element. Some reference are MACRO([value],[test]), which means that you can dynamically append a test to the referenced action or pass a value to the referenced action (if value is specified in the parenthesis just after MACRO). We can find the following references :
| Reference name | Description |
| affinity | MACRO(counter-test) : Affinity for counter-test. Example : Dross Golem |
| phase-out | Phase out the cards of target list. |
| counter | Counters the spell(s) in the target list. |
| use-once-each-turn | Marks the ability that referenced this action as already been used this turn. |
| target-permanent-enchant | MACRO(test) : allows you to target a valid permanent to enchant. |
| all-creatures | MACRO(test) : targets all the creatures in play. |
| creatures-you-control | MACRO(test) : targets all creatures in play that you control. |
| all-lands | MACRO(test) : targets all the lands in play. |
| all-artifacts | MACRO(test) : targets all the artifacts in play. |
| all-enchantments | MACRO(test) : targets all the enchantments in play. |
| target-for-attachment | MACRO(test) : allows you to target a valid permanent to have the current card to be attached to this target (works for equipments and auras). |
| target-creature-enchant | MACRO(test) : allows you to target a valid creature to enchant. |
| target-land-enchant | MACRO(test) : allows you to target a valid land to enchant. |
| target-artifact-enchant | MACRO(test) : allows you to target a valid artifact to enchant. |
| target-damage-source | MACRO(test) : allows you to target a valid damage source. |
| target-local-enchantment | MACRO(test) : allows you to target a valid aura in play. |
| target-enchantment | MACRO(test) : allows you to target a valid enchantment in play. |
| target-land | MACRO(test) : allows you to target a valid land in play. |
| target-creature | MACRO(test) : allows you to target a valid creature in play. |
| target-artifact | MACRO(test) : allows you to target a valid artifact in play. |
| target-artifact-creature | MACRO(test) : allows you to target a valid artifact creature in play. |
| target-permanent | MACRO(test) : allows you to target a valid permanent. |
| target-noncreature-artifact | MACRO(test) : allows you to target a valid non-creature artifact in play. |
| target-nonartifact-creature | MACRO(test) : allows you to target a valid non-artifact creature in play. |
| target-tappable | MACRO(test) : allows you to target a valid permanent that can be tapped. |
| target-player | MACRO(test) : allows you to target a valid player. |
| choose-player | MACRO(test) : allows you to choose a player (no target action). |
| target-opponent | MACRO(test) : allows you to target a valid opponent. |
| target-dealtable | MACRO(test) : allows you to target a valid dealtable (which is either a player or a permanent that can be dealt damage). |
| target-card | MACRO(test) : allows you to target a valid card in play (equivalent to target-permanent). |
| target-spell | MACRO(test) : allows you to target a valid spell in the stack. |
| target-ability | MACRO(test) : allows you to target a valid ability in the stack. |
| target-activated-ability | MACRO(test) : allows you to target a valid activated ability in the stack. |
| target-triggered-ability | MACRO(test) : allows you to target a valid triggered ability in the stack. |
| target-activated-triggered-ability | MACRO(test) : allows you to target a valid activated or triggered ability in the stack. |
| search-lib-up-to-player | MACRO(value,test) : allows the player in the first position of the target list to search within his library up to value cards (he can cancel the operation). |
| search-lib-up-to | MACRO(value,test) : allows you to search within your library up to value cards (you can cancel the operation). |
| search-lib | MACRO(test) : allows you to search within your library for one card (you cannot cancel the operation). |
| search-lib-player | MACRO(value,test) : allows the player in the first position of the target list to search within his library up to value cards (he cannot cancel the operation). |
| search-lib-reveal | MACRO(value,test) : allows you to search within your library up to value cards and reveal them (you cannot cancel the operation). |
| reveal | Reveals the cards in the target list to everyone and wait until the opponent decide to stop looking at your revealed cards. |
| look | Allows you to look at the cards in the target list and wait until you decide to stop looking at these cards. |
| look-at-the-top | Allows you to look at the top card of your library. The 'face-down' action should be call juste after. |
| finish-spell | Moves the card referencing this action to its owner's graveyard. |
| shuffle-in-lib | Moves the cards in the target list to their owner libraries and shuffle the library of owner of the last card. |
| shuffle-in-libs | Moves the cards in the target list to their owner libraries and shuffle all libraries. |
| prepare-extra-turn | Prepares the game to let you play another turn after this one. |
| T | Tap the card referencing this action. |
| remove-from-combat | Removes the cards in the target list from combat. |
| regenerate | Adds to the card referencing this action a replacement ability that triggers when this card is dealt lethal damage and replaces this action by removing this card from combat (if apply) and removing all damages that apply to it. This ability lasts until the end of the turn. |
| regenerate-target | Apply the regenerate action to the last card in the target list. |
| regenerate-attached-to | Apply the regenerate action to the card attached to the card referencing this action. |
| remove-all-damage | Removes all damages that apply to the cards in the target list. |
| restore-library-visibility | Restores the visibility for you of the libraries of the players in the target list (TODO). |
| restore-hand-visibility | Restores the visibility of the hands of the players in the target list for the opponent (checks whether the opponent has a special ability to permanently have the right to see your hand). |
| add-1-1-until-eot | Cards in the target list get -1/-1 until the end of the turn. |
| add-2-2-until-eot | Cards in the target list get -2/-2 until the end of the turn. |
| add-3-3-until-eot | Cards in the target list get -3/-3 until the end of the turn. |
| add-4-4-until-eot | Cards in the target list get -4/-4 until the end of the turn. |
| add+1+1-until-eot | Cards in the target list get +1/+1 until the end of the turn. |
| add+7+7-until-eot | Cards in the target list get +7/+7 until the end of the turn. |
| add+6+6-until-eot | Cards in the target list get +6/+6 until the end of the turn. |
| add+1-1-until-eot | Cards in the target list get +1/-1 until the end of the turn. |
| add+2-2-until-eot | Cards in the target list get +2/-2 until the end of the turn. |
| add+3-3-until-eot | Cards in the target list get +3/-3 until the end of the turn. |
| add-2+2-until-eot | Cards in the target list get -2/+2 until the end of the turn. |
| add-1+1-until-eot | Cards in the target list get +1/-1 until the end of the turn. |
| add+2-1-until-eot | Cards in the target list get +2/-1 until the end of the turn. |
| add-1-0-until-eot | Cards in the target list get -1/-0 until the end of the turn. |
| add+1+2-until-eot | Cards in the target list get +1/+2 until the end of the turn. |
| add+2+2-until-eot | Cards in the target list get +2/+2 until the end of the turn. |
| add+3+3-until-eot | Cards in the target list get +3/+3 until the end of the turn. |
| add+4+4-until-eot | Cards in the target list get +4/+4 until the end of the turn. |
| add+5+5-until-eot | Cards in the target list get +5/+5 until the end of the turn. |
| add+2+1-until-eot | Cards in the target list get +2/+1 until the end of the turn. |
| add+3+0-until-eot | Cards in the target list get +3/+0 until the end of the turn. |
| add+4+0-until-eot | Cards in the target list get +4/+0 until the end of the turn. |
| add+2+0-until-eot | Cards in the target list get +2/+0 until the end of the turn. |
| add+2+0-until-eoc | Cards in the target list get +2/+0 until the end of the combat. |
| add+1+0-until-eot | Cards in the target list get +1/+0 until the end of the turn. |
| add+0+1-until-eot | Cards in the target list get +0/+1 until the end of the turn. |
| add+0+2-until-eot | Cards in the target list get +0/+2 until the end of the turn. |
| add+0+3-until-eot | Cards in the target list get +0/+3 until the end of the turn. |
| add+0+5-until-eot | Cards in the target list get +0/+5 until the end of the turn. |
| add-2-0-until-eot | Cards in the target list get -2/+0 until the end of the turn. Example : Ivory Charm |
| gain-1-1-until-eot | The card referencing this action gets -1/-1 until the end of the turn. |
| gain+1+1-until-eot | The card referencing this action gets +1/+1 until the end of the turn. |
| gain+1+0-until-eot | The card referencing this action gets +1/+0 until the end of the turn. |
| gain+2+0-until-eot | The card referencing this action gets +2/+0 until the end of the turn. |
| gain+0+1-until-eot | The card referencing this action gets +0/+1 until the end of the turn. |
| gain+0+2-until-eot | The card referencing this action gets +0/+2 until the end of the turn. |
| gain+2+2-until-eot | The card referencing this action gets +2/+2 until the end of the turn. |
| gain+3+3-until-eot | The card referencing this action gets +3/+3 until the end of the turn. |
| gain+1+2-until-eot | The card referencing this action gets +1/+2 until the end of the turn. |
| gain+1-1-until-eot | The card referencing this action gets +1/-1 until the end of the turn. |
| unblockable-until-eot | Cards in the target list become unblockable until the end of the turn. |
| flying-until-eot | Cards in the target list gain flying until the end of the turn. Example : Raka Disciple |
| changeling-until-eot | Cards in the target list gain flying until the end of the turn. Example : Blades of Velis Vel |
| fear-until-eot | Cards in the target list gain fear until the end of the turn (they are unblockable except by black or artifact creatures). |
| shadow-until-eot | Cards in the target list gain shadow until the end of the turn (they can bloc or be blocked only by creatures with shadow). |
| wall-can-attack-until-eot | Cards in the target list are allowed to attack this turn (if possible) even if they have defender. |
| haste-until-eot | Cards in the target list gain haste until the end of the turn (they can attack the turn they came into play). |
| trample-until-eot | Cards in the target list gain trample until the end of the turn. |
| banding-until-eot | Cards in the target list gain banding until the end of the turn. |
| first-strike-until-eot | Cards in the target list gain first strike until the end of the turn. |
| double-strike-until-eot | Cards in the target list gain double strike until the end of the turn. |
| vigilance-until-eot | Cards in the target list gain vigilance until the end of the turn (attacking does not cause them to tap). |
| shroud-until-eot | Cards in the target list can't be the target of spells of abilities until the end of the turn. |
| reach-until-eot | Cards in the target list can block as if they had flying until the end of the turn. |
| attacks-if-able-until-eot | Cards in the target list attack if able until the end of the turn. |
| cannot-block-until-eot | Cards in the target list cannot block until the end of the turn. |
| cannot-attack-until-eot | Cards in the target list cannot attack until the end of the turn. |
| forestwalk-until-eot | Cards in the target list gain forestwalk until the end of the turn. |
| islandwalk-until-eot | Cards in the target list gain islandwalk until the end of the turn. |
| protection-from-red-until-eot | Cards in the target list gain protection from red until the end of the turn. |
| protection-from-black-until-eot | Cards in the target list gain protection from black until the end of the turn. |
| does-not-untap-next-untap | Cards in the target list don't untap during their controller's next untap step. |
| return-to-hand | Returns the cards in the target list to their owner's hand. |
| move-library-top | Moves the cards in the target list to the top of their owner's library. |
| move-library-bottom | Moves the cards in the target list to the bottom of their owner's library. |
| remove-from-game | Removes the cards in the target list from the game (they are moved to the side zone, [TODO] creating a dedicated zone for such cards should be considered). |
| put-in-graveyard | Puts the cards in the target list in their owner's graveyard. |
| mill-a-card Déplace la carte du dessus de la bibliothèque du dernier joueur ciblé dans son cimetière. | Puts the top card of target player's library to his graveyard. |
| draw-a-card | Makes the players in the target list draw a card. Example : Bandage |
| remove-a-card-from-library | Makes the players in the target list removes the top card of their library from the game. The target list is cleared after this operation. |
| remove-a-card-from-graveyard | Allows the players in the target list to choose a card from their graveyard to be removed from the game. The target list is cleared after this operation. |
| draw-a-card-next-upkeep | Makes you draw a card during the next turn upkeep. Example : Heal |
| opponent-draw-a-card-next-upkeep | Makes the opponent draw a card during the next turn upkeep. |
| pay-life | MACRO(value) : makes the controller of the card referencing this action pay value points of life. Beware, a test must be used to check whether the player have enough life to play this action (check mtg.xml for more information). |
| gain-life | MACRO(value) : makes the controller of the card referencing this action gain value points of life. |
| gain-life-target | MACRO(value) : makes the targets of the card referencing this action gain value points of life. |
| lose-life | MACRO(value) : makes the controller of the card referencing this action loose value points of life. |
| lose-life-target | MACRO(value) : makes the players in the target list loose value points of life. |
| discard | MACRO(value,test) : makes you choose value cards from your hand and discard them. |
| discard-random | MACRO(value,test) : makes you discard value cards at random from your hand. |
| opponent-discards | MACRO(value,test) : makes the opponent choose value cards from his hand and discard them. |
| discard-a-player | MACRO(value,test) : makes you choose value cards from the hand of the players in the target list and discard them. |
| player-discard | MACRO(value,test) : makes the player in the first position in the target list choose value cards from his hand and discard them. |
| player-discard-random | MACRO(value,test) : makes the player in the first position in the target list discard value cards from his hand at random. |
| player-discard-up-to | MACRO(value,test) : makes the player in the first position in the target list choose up to value cards from his hand and discard them. |
| discard-cards_noname | Moves the cards in the target list to their owner's graveyard (this action is not named). |
| discard-cards | Moves the cards in the target list to their owner's graveyard. |
| destroy | Destroys the cards in the target-list. |
| bury | Destroys the cards in the target-list. The destroyed card cannot be regenerated. |
| destroy-target-eot | Destroys the first card of the target-list at the end of turn. |
| destroy-target-eoc | Destroys the first card of the target-list at the end of combat. |
| remove-from-game-target-eot | Removes from game the first card of the target-list at the end of turn. |
| return-to-play-target-eot | Returns to play the first card of the target-list at the end of turn. |
| sacrifice-this | Sacrifices this card (Move the card into the graveyard of his/her owner). |
| sacrifice-a-creature | MACRO(test) : Sacrifices value chosen creatures. |
| sacrifice-any-creature | MACRO(value,test) : Sacrifice sany chosen creatures. |
| sacrifice-a-permanent | MACRO(value,test) : Sacrifices value chosen permanents. |
| opponent-sacrifice-a-permanent | MACRO(value,test) : Makes the opponent sacrifice value chosen permanents. |
| opponent-sacrifice-a-creature | MACRO(value,test) : Makes the opponent sacrifices value chosen creatures. |
| sacrifice-an-artifact | MACRO(value,test) : Sacrifices value chosen artifacts. |
| sacrifice-an-enchantment | MACRO(value,test) : Sacrifices value chosen enchantments. |
| opponent-sacrifice-an-enchantment | MACRO(value,test) : Makes the opponent sacrifice value chosen enchantments. |
| opponent-sacrifice-an-artifact | MACRO(value,test) : Makes the opponent sacrifice value chosen artifacts. |
| sacrifice-a-land | MACRO(value,test) : Sacrifices value chosen lands. |
| opponent-sacrifice-a-land | MACRO(value,test) : Makes the opponent sacrifices value chosen lands. |
| sacrifice | Sacrifices the cards of the target-list. |
| redirect-all-to-this | Redirects the all damage from first target to this card until end of turn. |
| redirect-1-from-this | Redirects the next 1 damage from this to the first target until end of turn. Example : Nomads en-Kor |
| redirect-2-from-this | Redirects the next 2 damage from this to the first target until end of turn. |
| redirect-3-from-this | Redirects the next 3 damage from this to the first target until end of turn. |
| redirect-all-from-this | Redirects all damage from this to the first target until end of turn. |
| redirect-all | Redirects the all damage from first target to the second target until end of turn. |
| redirect-1 | Redirects the next 1 damage from first target to the second target until end of turn. |
| redirect-2 | Redirects the next 2 damage from first target to the second target until end of turn. |
| redirect-3 | Redirects the next 3 damage from first target to the second target until end of turn. |
| redirect-1-to-this | Redirects the next 1 damage from first target to this card until end of turn. Example : Daughter of Autumn |
| redirect-2-to-this | Redirects the next 2 damage from first target to this card until end of turn. |
| redirect-3-to-this | Redirects the next 3 damage from first target to this card until end of turn. |
| prevent-1-on-this | Prevents the next 1 damage dealt to this card until end of turn. Example : Ordruun Commando |
| prevent-all-on-this | Prevents all damages dealt to this card until end of turn. Example : Deftblade Elite |
| prevent-all-from-this | Prevents all damages dealt by this card until end of turn. Example : Deftblade Elite |
| prevent-1 | Prevents the next 1 damage dealt to the last target card until end of turn. Example : Heal, Samite Healer |
| prevent-2 | Prevents the next 2 damage dealt to the last target card until end of turn. Example : Elvish Healer |
| prevent-3 | Prevents the next 3 damage dealt to the last target card until end of turn. Example : Healing Salve |
| prevent-4 | Prevents the next 4 damage dealt to the last target card until end of turn. Example : Hallowed Healer |
| prevent-5 | Prevents the next 5 damage dealt to the last target card until end of turn. Example : Abuna's Chant |
| prevent-6 | Prevents the next 6 damage dealt to the last target card until end of turn. Example : Recuperate |
| prevent-x | Prevents the next X damage dealt to the last target card until end of turn. Example : Alabaster Potion |
| prevent-all | Prevents all damage dealt to the last target card until end of turn. Example : Circle of Protection: Black |
| prevent-all-combat-on-target | Prevents all combat damage dealt to the last target card until end of turn. |
| prevent-all-from | Prevents all damages dealt by the last target card until end of turn. |
| prevent-all-combat-damage | Prevents all combat damage this turn. Example : Moment's Peace |
| deals-no-combat-damage | Prevents all the combat damages that would be assigned by the first target this turn. |
| put-in-play | Put in play this card under owner's control. |
| move-to-play | Move target cards to play under owner's control. |
| choose-damage-source | Chooses a card that could damage something. Example : Circle of Protection: Black |
| buyback | Active the buyback option for the current spell. Example : Constant Mists |
| flashback | Active the flashback option for the current spell. Example : Moment's Peace |
| kicker | Active the first kicker option for the current spell. Example : Duskwalker |
| kicker2 | Active the first kicker option for the current spell. Example : Cetavolver |
| entwine | Active the first entwine option for the current spell. Example : Dream's Grip |
| planeswalker-ability-used | change the planeswalker index to used. Example : Jace Beleren |
| skip-next-turn | Makes the owner of the current card skip his next turn. |
| target-equipable-creature | Targets a creature could be equiped by the current card. Example : Grifter's Blade |
| equip | Equips the last target with the current card (that should be an equipment). |
| radiance | Radiance option implementation. Example : Rally the Righteous |
| morph | Morph ability implementation : face up the card. Example : Aphetto Alchemist |
| imprint-card | This imprints the last target of target list into the card owning this action. The imprinted card is stored as 'private-object' component in the card. |
| load-imprinted-card | Load the imprinted card into the target list. If there is no imprinted card, an error is thrown. Use the 'has-imprinted-card' test. |
| pay-x | Pay colorless X manas. Example : Fireball |
| pay-xx | Pay colorless XX manas. Example : Decree of Justice |
| blocks-this-if-able | Forces the last target to block the current card during the next combat if able. |
| amplify | Amplify MACRO([value]) action. Example : Daru Stinger |
| clash | 501.10. Clash 501.10a To clash, a player reveals the top card of his or her library. That player may then put that card on the bottom of his or her library. 501.10b "Clash with an opponent" means "Choose an opponent. You and that opponent each clash." 501.10c A player wins a clash if that player revealed a card with a higher converted mana cost than all other cards revealed in that clash. the Macro actions are the actions that occur if you win the clash. MACRO([actions]) Example : Adder-Staff Boggart |
These are described within the nested <abilities> element. Using these references is the best way to accelerate card developement and maintenance since repetitive code are place in this place. So if you find some abilities appearing often in cards, this is the right place to add a reference to share with the community of card rules developers. The project team will make infinite effort to add this ability detection in our card generator for the Oracle. Some abilities work as macro by accepting one or two actions lists. We can find the following references :
| Reference name | Description |
| suspend | Trigerred ability relative to the management of the suspend ability. It is used by the cast-suspend ability. The ability triggers at the beginning of your upkeep and remove one time mark from the card that reference this ability then if there is no more time mark on this card, it is put into play. TODO : the card must be considered to have been played during the turn when the card has been put into play and not during the turn when the suspend ability has been cast, this information is relevant for all cards that use the storm ability. An example of the use of this ability is available throught the Lotus Bloom card. |
| cast-suspend | MACRO(actions, actions) : this activated ability must be referenced by any card using the suspend ability. It allows the owner of the card to cast the spell associated through the suspension mode and dynamically add to the removed from the game card the suspend trigerred ability. The first <actions> macro is used to specify the cost of the suspend ability. The second <actions> is called after removing the card from the game and allows you to implement the addition of time marks to the card removed from the game. An example of the use of this ability is available through the Lotus Bloom card. |
| provoke | Provoke trigger implementation. |
| graft | Graft trigger implementation. Moves a +1/+1 counter from this to a card coming into play. |
| modular | Modular trigger implementation. Moves counters from this card to target artifact creature |
| soulshift1 | 502.39. Soulshift 502.39a Soulshift is a triggered ability. "Soulshift N" means "When this permanent is put into a graveyard from play, you may return target Spirit card with converted mana cost N or less from your graveyard to your hand." 502.39b If a permanent has multiple instances of soulshift, each triggers separately. |
| madness | Madness implementation. "If you discard this card, you may play it for its madness cost instead of putting it into your graveyard." The way it is implemented it may be bugged with "samurai of the pale curtain" or "leyline of the void" in play. It may have problems with "Teferi" when it is created and with "Storm" ability counter. It needs an action for the madness cost on parameter and another action for the spell effect. |
| cycling | Moves the card referencing this action to its owner's graveyard, and allows the card's owner to draw a card from its library. This ability is a macro, an actions list must be provided as parameter. Example : Sunfire Balm |
| evoke | Evoke is an alternative cost. Playing a creature by paying its evoke cost rather than its mana cost causes that creature to be sacrificed when it comes into play. Example : AEthersnipe |
| evoke-flash | Evoke is an alternative cost. Playing a creature by paying its evoke cost rather than its mana cost causes that creature to be sacrificed when it comes into play. Example : AEthersnipe |
| forecast | Forecast {macro actions} : {macro actions}. |
| tap-add-B | {T} : add one black mana to your mana pool. |
| tap-add-U | {T} : add one blue mana to your mana pool. |
| tap-add-G | {T} : add one green mana to your mana pool. |
| tap-add-R | {T} : add one red mana to your mana pool. |
| tap-add-W | {T} : add one white mana to your mana pool. |
| tap-add-C | {T} : add one colorless mana to your mana pool. |
| cast-enchant | {T} : to put a local enchantment into play, attached to a valid permanent. |
| cast-enchant-flash | {T} : to put a local enchantment with flash into play, attached to a valid permanent. |
| cast-spell | {T} : to put in play a permanent, paying it's manacost. |
| morph | Use morph ability. |
| cast-morph | {T} : to put in play a morph card, paying 3. |
| cast-flash | {T} : to put in play a permanent using flash ability, paying it's manacost. |
| cast-land | {T} : to play a land. |
| echo | MACRO([action]) The echo ability. This reference accept as macro an action to substitute the default pay-mana action. |
| prevent-all-on-this | Prevents all damages dealt to this card. |
| prevent-all-on-attachedto | Prevents all damages dealt to attached card. |
| deals-no-combat-damage | The saved card deals no combat damage. |
| bloodthirst1 | Bloodthirst 1 implementation. Example : Bloodscale Prowler |
| bloodthirst2 | Bloodthirst 2 implementation. Example : Scab-Clan Mauler |
| bloodthirst3 | Bloodthirst 3 implementation. Example : Ghor-Clan Savage |
| dredge1 | Dredge 1 implementation. Example : Grave-Shell Scarab |
| dredge2 | Dredge 2 implementation. |
| dredge3 | Dredge 3 implementation. Example : Darkblast |
| dredge4 | Dredge 5 implementation. |
| dredge5 | Dredge 5 implementation. |
| dredge6 | Dredge 6 implementation. |
| transmute | Transmute implementation. Example : Perplex |
| rampage1 | Rampage 1 implementation. Example : Balduvian War-Makers |
| rampage2 | Rampage 2 implementation. Example : Balduvian War-Makers |
| rampage3 | Rampage 3 implementation. Example : Craw Giant |
| rampage4 | Rampage 4 implementation. Example : Teeka's Dragon |
| eot-sacrifice | At end of turn, sacrifice this card. Example : Dragon Whelp |
| regenerate | Regenerate the saved card if possible. This ability should appear directly within the card abilities but used with create-ability action. |
| shapeshifter-ability | Whenever a creature comes into play, THIS becomes a copy of that creature and gains this ability. Example : Unstable Shapeshifter |
| lifelink | whenever THIS (context creature) deals damage, you gain that much life. Example: Kjeldoran Gargoyle, Exalted Angel |
| deathtouch | whenever THIS (context creature) deals damage to a creature, destroy that creature. Example: Moonglove Winnower |
| cast-spell-kicker | {T} : to put in play a permanent, paying it's manacost and a kicker. This macro works only for single paid kicker. There are two <actions> nodes for this macro, respectivly corresponding to the kicker's cost and the associated effect. |
| cast-spell-kicker2 | {T} : to put in play a permanent, paying it's manacost and the second kicker. This macro works only for single paid kicker. There are two <actions> nodes for this macro, respectivly corresponding to the kicker's cost and the associated effect. |
| cast-spell-kicker12 | {T} : to put in play a permanent, paying it's manacost and the first and second kicker. This macro works only for two paid kickers. There are four <actions> nodes for this macro, respectivly corresponding to the first, then the second kicker's cost and the associated effect of respectivly first and second kicker. |
| amplify-1 | Amplify 1 ability. Example : Daru Stinger |
| amplify-2 | Amplify 2 ability. Example : Daru Stinger |
| amplify-3 | Amplify 3 ability. Example : Daru Stinger |
These are described within the nested <attachments> element. We can find the following references :
| Reference name | Description |
| enchant-creature | Use this reference to attach 'enchant: creature' auras to a valid creature to enchant. |
Magic Project is also capable to apply constraints on actions if they match the <action> child elements. These constraints are dynamically appended using the given operation (usually set to "and") to the test associated with the matched action. Theses constraints are declared using the <action-constraints> element. You will find here constraints concerning the ability to equip a creature with an equipment artifact for example (it's impossible to equip a creature if the equipment is also a creature in addition to its artifact type) :
<constraint operation="and">
<test>
<and>
<not>
<has-idcard idcard="creature" card="this" />
</not>
<has-property property="equipment" card="this" />
</and>
</test>
<actions>
<attach name="equip" />
</actions>
</constraint>
<constraint operation="and">
<test>
<and>
<not>
<has-idcard idcard="creature" card="this" />
</not>
<has-property property="equipment" card="this" />
</and>
</test>
<actions>
<pay-mana />
</actions>
</constraint>
Magic Project can manage additional costs using the <additional-costs> element.
The last part of the XML file is dedicated to the objects, which can be considered as counters (ice, poison, +1/+1, etc.). These are declared using the <objects> element.
As mentioned before, each card in a game such Magic the Gathering can hold its own specific rules. In Magic Project, we have to write one XML file per card to implement. The content of the file describe the rules of the card in the same language than the large XML file of the card game.
The best way to describe the structure of these files is to look at an example, why not coding the card from the Starter edition, Angel of Light ?
This example will make you know what the most important parts of a XML card rules description XML file are. Below you will find a picture of this card :

Let's start by looking at this card code :
<?xml version="1.0" encoding="ISO-8859-1"?> <card xmlns="http://sourceforge.net/projects/firemox" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://sourceforge.net/projects/firemox ../../validator.xsd" name="Angel of Light"> <rules-author-comment>riclas</rules-author-comment> <init> <registers> <register index="white" value="1"/> <register index="colorless" value="4"/> <register index="power" value="3"/> <register index="toughness" value="3"/> </registers> <colors>white</colors> <idcards>creature</idcards> <properties>vigilance flying angel</properties> </init> <abilities> <ability ref="cast-spell"/> </abilities> </card>
The declaration of the card always starts with the <card> element. It must specify the parameters xmlns (the XML namespace of the current file), xmlns:xsi (the XML namespace for the schema related elements and attributes), xsi:schemaLocation (which specify the location of the XML schema used to validate the structure of the file) and the name (which stands for the card's name in English without replacing or deleting any characters).
<card xmlns="http://sourceforge.net/projects/firemox" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://sourceforge.net/projects/firemox ../../validator.xsd" name="Angel of Light">
This is immediately followed by the <rules-author-comment> element which usually holds information about the author of the XML code of the card (which is generally set to its name of pseudo).
<rules-author-comment>riclas</rules-author-comment>
This element can be followed by a comment reminding the Oracle version of the rules of the card if it has been generated by the Oracle to XML tool.
The next element is the <init> element which holds all the static informations of the card. You will find in this element :
In the example, the card costs 4W and it has a power/toughness of 3/3.
<registers> <register index="white" value="1"/> <register index="colorless" value="4"/> <register index="power" value="3"/> <register index="toughness" value="3"/> </registers>
In the example, the card is a white card.
<colors>white</colors>
The example shows that the card is a creature.
<idcards>creature</idcards>
The example shows that the creature is an Angel with Flying and Vigilance (attacking doesn't it to tap) abilities.
<properties>vigilance flying angel</properties>
The next element is dedicated to abilities. The only ability declared is a reference to the cast-spell ability from the mtg.xml file. This ability allows the owner of this card to pay the casting cost of it in order to play it from its hand.
<abilities> <ability ref="cast-spell"/> </abilities>
Now you are aware of the basic structure of a card, it's a good idea to look at example of cards somewhat more complicated to implement.
This card is somewhat complicated to implement : it has interactions with the events concerning movement of cards and it has to check whether two cards share a permanent type. Below you will find a picture of this card :

Let's start by looking at this card code :
<?xml version="1.0" encoding="ISO-8859-1"?>
<card xmlns="http://sourceforge.net/projects/firemox" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://sourceforge.net/projects/firemox ../../validator.xsd"
name="Cloudstone Curio">
<rules-author-comment>Hoani CROSS</rules-author-comment>
<init>
<registers>
<register index="colorless" value="3"/>
</registers>
<idcards>artifact</idcards>
</init>
<abilities>
<ability ref="cast-spell"/>
<triggered-ability zone="play">
<moved-card>
<source-test>
<not>
<in-zone zone="play"/>
</not>
</source-test>
<destination-test>
<and>
<in-zone zone="play"/>
<controller player="you"/>
<not>
<has-idcard idcard="artifact"/>
</not>
</and>
</destination-test>
</moved-card>
<cost>
<choice cancel="true">
<either>
<target type="card" mode="choose" restriction-zone="play" raise-event="false">
<test>
<and>
<controller player="you"/>
<not>
<is target="context.card"/>
</not>
<sup right="0">
<left>
<and>
<left>
<card-types card="context.card"/>
</left>
<right>
<card-types card="tested"/>
</right>
</and>
</left>
</sup>
</and>
</test>
</target>
</either>
</choice>
</cost>
<effects>
<action ref="return-to-hand"/>
</effects>
</triggered-ability>
</abilities>
</card>
The <init> element let us know that this card is an artifact with a mana cost of 3.
<init> <registers> <register index="colorless" value="3"/> </registers> <idcards>artifact</idcards> </init>
Let's observe the abilities of the card because you will find there the most important parts of the card implementation.
The first ability is for sure used to let the owner of this card cast it.
<ability ref="cast-spell"/>
The main ability of the card is a trigerred ability that triggers only when the card is in play :
<triggered-ability zone="play">
The card abily starts with "Whenever a nonartifact permanent comes into play under your control". Thus the ability will trigger if a card is moved from a zone different from the play zone to the play zone and only if the moved card is an non-artifact card that you control.
<moved-card>
<source-test>
<not>
<in-zone zone="play"/>
</not>
</source-test>
<destination-test>
<and>
<in-zone zone="play"/>
<controller player="you"/>
<not>
<has-idcard idcard="artifact"/>
</not>
</and>
</destination-test>
</moved-card>
This ability has a hidden cost : targetting a valid permanent to eventually return to its owner's hand. That's why the next element is a <cost> element :
<cost>
<choice cancel="true">
<either>
<target type="card" mode="choose" restriction-zone="play" raise-event="false">
<test>
<and>
<controller player="you"/>
<not>
<is target="context.card"/>
</not>
<sup right="0">
<left>
<and>
<left>
<card-types card="context.card"/>
</left>
<right>
<card-types card="tested"/>
</right>
</and>
</left>
</sup>
</and>
</test>
</target>
</either>
</choice>
</cost>
The controller of the card has the choice to target or not the permanent, that's why you'll see the following element with the attribute cancel set to true :
<choice cancel="true"> <either> <target type="card" mode="choose" restriction-zone="play" raise-event="false">