It is currently 18 Jul 2025, 21:56
   
Text Size

Adding new cards with Groovy

Moderators: ubeefx, beholder, melvin, ShawnieBoy, Lodici, CCGHQ Admins

Re: Adding new cards with Groovy

Postby 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?

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
            ));
        }
    }
]
and the token bare-bones script

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}
Will also help for Miming Slime, Mystic Genesis, Ooze Flux, Ooze Garden and Slime Molding
User avatar
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

Postby 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> }))
User avatar
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

Postby 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()?
User avatar
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

Postby 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.
User avatar
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

Postby 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:

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.
Both given_ability= and enchant= are present.

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
Only enchant= is present.

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

Postby 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

Postby 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).
User avatar
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

Postby 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.
User avatar
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

Postby ember hauler » 12 Jan 2014, 20:22

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).
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).
ember hauler
 
Posts: 79
Joined: 14 Aug 2013, 08:13
Has thanked: 27 times
Been thanked: 14 times

Re: Adding new cards with Groovy

Postby ember hauler » 12 Jan 2014, 20:23

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.
Cool, it's good to know the difference.
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

Postby melvin » 13 Jan 2014, 01:53

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).
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.
User avatar
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

Postby 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. :)
User avatar
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

Postby melvin » 13 Jan 2014, 12:27

hong 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. :)
The earliest version is this one: https://code.google.com/p/magarena/sour ... 45ad469b55

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
User avatar
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

Postby ember hauler » 13 Jan 2014, 15:04

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.
Please note that Spirit Loop can only enchant the creature you control, not opponent's 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

Postby melvin » 14 Jan 2014, 02:31

ember hauler wrote:Please note that Spirit Loop can only enchant the creature you control, not opponent's creature.
Thanks for the reminder, I missed that. In that case the enchant line should be:
Code: Select all
enchant=lifelink,creature you control
Fixed in https://code.google.com/p/magarena/sour ... 09e4047b57
User avatar
melvin
AI Programmer
 
Posts: 1062
Joined: 21 Mar 2010, 12:26
Location: Singapore
Has thanked: 36 times
Been thanked: 459 times

PreviousNext

Return to Magarena

Who is online

Users browsing this forum: No registered users and 1 guest

Main Menu

User Menu

Our Partners


Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest (based on users active over the past 10 minutes)
Most users ever online was 7303 on 15 Jul 2025, 20:46

Users browsing this forum: No registered users and 1 guest

Login Form