Adding new cards with Groovy
by ubeefx
Moderators: ubeefx, beholder, melvin, ShawnieBoy, Lodici, CCGHQ Admins
Re: Adding new cards with Groovy
by ShawnieBoy » 05 Jan 2014, 03:08
Having a problem with defining tokens. I wasn't expecting that the definitions are updated for all tokens if the definition changes. With the code below, if more Ooze tokens are created, the older Oozes become the new X/X values.
How best can I sneak the value x into the MagicPlayTokensAction?
How best can I sneak the value x into the MagicPlayTokensAction?
- Code: Select all
[
new MagicSpellCardEvent() {
@Override
public MagicEvent getEvent(final MagicCardOnStack cardOnStack,final MagicPayedCost payedCost) {
final int x=payedCost.getX();
return new MagicEvent(
cardOnStack,
this,
"Put "+x+" "+x+"/"+x+" green Ooze creature tokens onto the battlefield."
);
}
@Override
public void executeEvent(final MagicGame game, final MagicEvent event) {
final MagicPlayer player=event.getPlayer();
final MagicCardDefinition oozeDef = TokenCardDefinitions.get("green Ooze creature token");
int x = event.getCardOnStack().getX();
oozeDef.setPowerToughness(x,x);
game.doAction(new MagicPlayTokensAction(
player,
oozeDef,
x
));
}
}
]
- Code: Select all
name=green Ooze creature token
token=Ooze
image=http://magiccards.info/extras/token/shards-of-alara/ooze.jpg
value=2
type=Creature
subtype=Ooze
color=g
cost={0}
-
ShawnieBoy - Programmer
- Posts: 601
- Joined: 02 Apr 2012, 22:42
- Location: UK
- Has thanked: 80 times
- Been thanked: 50 times
Re: Adding new cards with Groovy
by melvin » 05 Jan 2014, 06:41
MagicCardDefinition is shared among all the cards with the same definition, so it is not a good idea to modify it. The best way to accomplish the X/X Oooze is to use MagicAddStaticAction to add a MagicStatic that sets the pt to X/X. So the steps are:
1) create the action MagicPlayTokenAction as a variable, i.e. final MagicPlayTokenAction act = new MagicPlayTokenAction(...). This variable is needed to retrieve the permanent created later with getPermanent().
2) create the token by calling doAction, i.e. game.doAction(act)
3) game.doAction(new MagicAddStaticAction(act.getPermanent(), new MagicStatic(MagicLayer.SetPT) { <see Elvish_Branchbender.groovy> }))
1) create the action MagicPlayTokenAction as a variable, i.e. final MagicPlayTokenAction act = new MagicPlayTokenAction(...). This variable is needed to retrieve the permanent created later with getPermanent().
2) create the token by calling doAction, i.e. game.doAction(act)
3) game.doAction(new MagicAddStaticAction(act.getPermanent(), new MagicStatic(MagicLayer.SetPT) { <see Elvish_Branchbender.groovy> }))
-
melvin - AI Programmer
- Posts: 1062
- Joined: 21 Mar 2010, 12:26
- Location: Singapore
- Has thanked: 36 times
- Been thanked: 459 times
Re: Adding new cards with Groovy
by ShawnieBoy » 05 Jan 2014, 15:00
Thanks so much for that, that'll work perfect for the other cards, however I've hit a snag.
the getPermanent() only returns one Permanent. Would it be worth adding a getPermanents<Collection>() specific to the MagicPlayTokensAction (plural) instead of the default from MagicPutIntoPlayAction()?
the getPermanent() only returns one Permanent. Would it be worth adding a getPermanents<Collection>() specific to the MagicPlayTokensAction (plural) instead of the default from MagicPutIntoPlayAction()?
-
ShawnieBoy - Programmer
- Posts: 601
- Joined: 02 Apr 2012, 22:42
- Location: UK
- Has thanked: 80 times
- Been thanked: 50 times
Re: Adding new cards with Groovy
by melvin » 06 Jan 2014, 02:13
Sure, sounds logical to have a getPermanents method to MagicPlayTokens action so it is possible to retrieve the permanents created later. Go ahead and add it, just post here if you run into any issues.
-
melvin - AI Programmer
- Posts: 1062
- Joined: 21 Mar 2010, 12:26
- Location: Singapore
- Has thanked: 36 times
- Been thanked: 459 times
Re: Adding new cards with Groovy
by ember hauler » 10 Jan 2014, 08:50
I'm a bit confused with given_ability= and enchant= - which one to use and when?
For example, here is Rancor:
And here is Spirit Link:
What is the correct way?
Also, what is the difference between "creature" and "pos creature"?
For example, here is Rancor:
- Code: Select all
name=Rancor
url=http://magiccards.info/arc/en/67.html
image=http://mtgimage.com/card/rancor.jpg
value=4.582
rarity=C
type=Enchantment
subtype=Aura
cost={G}
given_pt=2/0
given_ability=trample
timing=aura
enchant=trample,pos creature
ability=dies effect Return SN from the graveyard to its owner's hand.
And here is Spirit Link:
- Code: Select all
name=Spirit Link
url=http://magiccards.info/10e/en/45.html
image=http://mtgimage.com/card/spirit%20link.jpg
value=4.024
rarity=U
type=Enchantment
subtype=Aura
cost={W}
timing=aura
enchant=lifelink,creature
requires_groovy_code
What is the correct way?
Also, what is the difference between "creature" and "pos creature"?
- ember hauler
- Posts: 79
- Joined: 14 Aug 2013, 08:13
- Has thanked: 27 times
- Been thanked: 14 times
Re: Adding new cards with Groovy
by ember hauler » 10 Jan 2014, 09:01
Ok, I figured out that given_ability=lifelink is missing in Spirit Link to make correct calculation of life gained in groovy code. But why enchant=lifelink is still there?
- ember hauler
- Posts: 79
- Joined: 14 Aug 2013, 08:13
- Has thanked: 27 times
- Been thanked: 14 times
Re: Adding new cards with Groovy
by melvin » 10 Jan 2014, 12:02
given_ability=<ability> means enchanted permanent gains <ability>
enchant=<hint1>,<hint2 target> give the AI some hints as to how to pick a target, there are custom heuristics for trample, first strike, and a few other common auras. pos and neg is to hint to the AI whether to prioritize its own permanents (pos) or the opponents (neg).
enchant=<hint1>,<hint2 target> give the AI some hints as to how to pick a target, there are custom heuristics for trample, first strike, and a few other common auras. pos and neg is to hint to the AI whether to prioritize its own permanents (pos) or the opponents (neg).
-
melvin - AI Programmer
- Posts: 1062
- Joined: 21 Mar 2010, 12:26
- Location: Singapore
- Has thanked: 36 times
- Been thanked: 459 times
Re: Adding new cards with Groovy
by ShawnieBoy » 10 Jan 2014, 13:00
Sorry to rain on your parade, but Spirit Loop doesn't give Lifelink, it does "when enchanted creature deals damage, you gain that much life." Very similar but different. Lifelink is a state based effect which doesn't use the stack and is an ability which doesn't stack with itself. The second option uses the stack (so you can die if it's on the stack and you have 0 life), and stacks with Lifelink and other damage/lifegain options.
-
ShawnieBoy - Programmer
- Posts: 601
- Joined: 02 Apr 2012, 22:42
- Location: UK
- Has thanked: 80 times
- Been thanked: 50 times
Re: Adding new cards with Groovy
by ember hauler » 12 Jan 2014, 20:22
Ok, thanks!melvin wrote:given_ability=<ability> means enchanted permanent gains <ability>
enchant=<hint1>,<hint2 target> give the AI some hints as to how to pick a target, there are custom heuristics for trample, first strike, and a few other common auras. pos and neg is to hint to the AI whether to prioritize its own permanents (pos) or the opponents (neg).
I guess the script for Spirit Loop which I submitted should be corrected again:
enchant=lifelink,pos creature
(as a hint for AI).
- ember hauler
- Posts: 79
- Joined: 14 Aug 2013, 08:13
- Has thanked: 27 times
- Been thanked: 14 times
Re: Adding new cards with Groovy
by ember hauler » 12 Jan 2014, 20:23
Cool, it's good to know the difference.ShawnieBoy wrote:Sorry to rain on your parade, but Spirit Loop doesn't give Lifelink, it does "when enchanted creature deals damage, you gain that much life." Very similar but different. Lifelink is a state based effect which doesn't use the stack and is an ability which doesn't stack with itself. The second option uses the stack (so you can die if it's on the stack and you have 0 life), and stacks with Lifelink and other damage/lifegain options.
Thanks!
- ember hauler
- Posts: 79
- Joined: 14 Aug 2013, 08:13
- Has thanked: 27 times
- Been thanked: 14 times
Re: Adding new cards with Groovy
by melvin » 13 Jan 2014, 01:53
This line was in your original submission and is currently in the card script. Now that I think about it the "pos" hint should be removed, to make it the same as Spirit Link. The reason is that this card can also be used to disable the opponent's creature as it is the controller of the enchantment that gains life, unlike lifelink where the controller of the creature gains life.ember hauler wrote:Ok, thanks!
I guess the script for Spirit Loop which I submitted should be corrected again:
enchant=lifelink,pos creature
(as a hint for AI).
-
melvin - AI Programmer
- Posts: 1062
- Joined: 21 Mar 2010, 12:26
- Location: Singapore
- Has thanked: 36 times
- Been thanked: 459 times
Re: Adding new cards with Groovy
by hong yie » 13 Jan 2014, 09:00
wants to know the script of dark banishing before been simplified. i mean every line of code in it. or where i can look for it. thank's. 

-
hong yie - Programmer
- Posts: 216
- Joined: 10 Mar 2013, 06:44
- Location: Jakarta
- Has thanked: 75 times
- Been thanked: 9 times
Re: Adding new cards with Groovy
by melvin » 13 Jan 2014, 12:27
The earliest version is this one: https://code.google.com/p/magarena/sour ... 45ad469b55hong yie wrote:wants to know the script of dark banishing before been simplified. i mean every line of code in it. or where i can look for it. thank's.
If you're interested in what the groovy script looks like for such as effect, you could look at Death Mutation's script from https://code.google.com/p/magarena/sour ... ion.groovy
-
melvin - AI Programmer
- Posts: 1062
- Joined: 21 Mar 2010, 12:26
- Location: Singapore
- Has thanked: 36 times
- Been thanked: 459 times
Re: Adding new cards with Groovy
by ember hauler » 13 Jan 2014, 15:04
Please note that Spirit Loop can only enchant the creature you control, not opponent's creature.melvin wrote:Now that I think about it the "pos" hint should be removed, to make it the same as Spirit Link. The reason is that this card can also be used to disable the opponent's creature as it is the controller of the enchantment that gains life, unlike lifelink where the controller of the creature gains life.
- ember hauler
- Posts: 79
- Joined: 14 Aug 2013, 08:13
- Has thanked: 27 times
- Been thanked: 14 times
Re: Adding new cards with Groovy
by melvin » 14 Jan 2014, 02:31
Thanks for the reminder, I missed that. In that case the enchant line should be:ember hauler wrote:Please note that Spirit Loop can only enchant the creature you control, not opponent's creature.
- Code: Select all
enchant=lifelink,creature you control
-
melvin - AI Programmer
- Posts: 1062
- Joined: 21 Mar 2010, 12:26
- Location: Singapore
- Has thanked: 36 times
- Been thanked: 459 times
Who is online
Users browsing this forum: No registered users and 2 guests