1.34 will support using Groovy to write card scripts

Smoof wrote:Have you thought about using something like Groovy as a dynamic scripting language, so new cards with new card-logic could be added on the fly?
As part of work, I looked at Groovy again. One of our projects is using Gradle, the build system written in Groovy. I did some quick searches and came across http://groovy.codehaus.org/Embedding+Groovy The latest version of the Groovy language supports most of Java, so I did a quick integration. Imagine my surprise when I took one of the card code, rename it to .groovy and it worked without any modifications. I took the opportunity to simplify the Groovy version a little so it was easier to integrate and write.melvin wrote:Yes! Unfortunately I'm not familiar enough with Groovy to check if it can be used to create classes like those we use for card code. I suspect it can, but then I couldn't figure out how to have groovy load a script and get back a class. I'd appreciate any advice on this topic.
Below is the card I tested with. Note that change in the last property from requires_card_code to requires_groovy_code. A preview of 1.34 with groovy scripting is available via our hourly build @ https://buildhive.cloudbees.com/job/mel ... a-1.34.zip
Thanks to smoof for reminding me about Groovy. Look forward to your comments/suggestions for this feature.
Magarena/scripts/Lord_of_Extinction.txt
- Code: Select all
name=Lord of Extinction
url=http://magiccards.info/arb/en/91.html
image=http://magiccards.info/scans/en/arb/91.jpg
value=4.487
rarity=M
type=Creature
subtype=Elemental
cost={3}{B}{G}
timing=smain
requires_groovy_code
- Code: Select all
import magic.model.MagicGame;
import magic.model.MagicPlayer;
import magic.model.MagicPowerToughness;
import magic.model.mstatic.MagicCDA;
// list of abilities
[
new MagicCDA() {
@Override
public void modPowerToughness(final MagicGame game,final MagicPlayer player,final MagicPowerToughness pt) {
final int amount=game.getPlayer(0).getGraveyard().size()+game.getPlayer(1).getGraveyard().size();
pt.set(amount,amount);
}
}
]
- Code: Select all
package magic.card;
import magic.model.MagicGame;
import magic.model.MagicPlayer;
import magic.model.MagicPowerToughness;
import magic.model.mstatic.MagicCDA;
public class Lord_of_Extinction {
public static final MagicCDA CDA = new MagicCDA() {
@Override
public void modPowerToughness(final MagicGame game,final MagicPlayer player,final MagicPowerToughness pt) {
final int amount=game.getPlayer(0).getGraveyard().size()+game.getPlayer(1).getGraveyard().size();
pt.set(amount,amount);
}
};
}