It is currently 26 Apr 2024, 16:42
   
Text Size

Adding new cards with Groovy

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

Re: Adding new cards with Groovy

Postby mike » 08 Aug 2013, 23:33

I'm trying to add Horizon Canopy but it seems something isn't working the way it's supposed to. When I play it as the first land I am able to immediately sacrifice it to draw a card. However, if another (untapped) land is in play the game requires me to tap that land to activate the Canopy's draw ability. It seems to canopy is considered a legal source for the 1 mana to activate it (which it should not be since it needs to be tapped). What's even stranger is that in this case it doesn't make me lose life so I assume the mana is never actually paid for the ability.

I'm working off of the Mind Stone script (which does not behave in the same broken way). Is this a bug or am I just missing something?

Here are the scripts.

Code: Select all
name=Horizon Canopy
url=(removed due to no url rule of forum)
image=(removed due to no url rule of forum)
value=36.99
rarity=R
type=Land
timing=land
ability=tap pain add mana {G} or {W}
requires_groovy_code
Code: Select all
 [
    new MagicPermanentActivation(
        [
          MagicConditionFactory.ManaCost("{1}")
        ],
        new MagicActivationHints(MagicTiming.Draw),
        "Draw"
    ) {

        @Override
        public MagicEvent[] getCostEvent(final MagicPermanent source) {
            return [
                new MagicTapEvent(source),
                new MagicSacrificeEvent(source),
                new MagicPayManaCostEvent(source,"{1}")
            ];
        }

        @Override
        public MagicEvent getPermanentEvent(final MagicPermanent source,final MagicPayedCost payedCost) {
            return new MagicEvent(
                source,
                this,
                "Draw a card."
            );
        }
        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
            game.doAction(new MagicDrawAction(event.getPlayer()));
        }
    }
]
User avatar
mike
Programmer
 
Posts: 128
Joined: 05 Jul 2013, 17:00
Has thanked: 0 time
Been thanked: 29 times

Re: Adding new cards with Groovy

Postby melvin » 09 Aug 2013, 00:59

The problem is because when checking if a costs can be paid, each cost is checked separately. i.e. Can we pay {1}? Yes. Can we tap this card? Yes!! But we actually can't both tap and pay {1} when this is the only card available.

The work around is to introduce an artificial condition like in Mind Stone (see below), so instead of checking if we can pay {1}, we check if we can pay {2}.

Code: Select all
new MagicPermanentActivation(
    [
        //Add one for the card itself
        MagicConditionFactory.ManaCost("{2}")
    ],
    new MagicActivationHints(MagicTiming.Draw),
    "Draw"
) {
...
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 mike » 09 Aug 2013, 08:15

I was wondering why it says 2 instead of 1 but somehow attributed it to Mind Stone's manacost. Layed out like this it makes perfect sense. Thx!

I'll be submitting the card through firemind.ch
User avatar
mike
Programmer
 
Posts: 128
Joined: 05 Jul 2013, 17:00
Has thanked: 0 time
Been thanked: 29 times

Re: Adding new cards with Groovy

Postby melvin » 09 Aug 2013, 09:12

mike wrote:I'll be submitting the card through firemind.ch
Thanks, just merged it. One suggestion regarding card submission through firemind.ch, it would be clearer if the commit is recorded using the user's username instead of as "Project Firemind". From the mercurial command line, one can specify the username to use with -u flag.

Here is something I just worked on today, Clone type effects. Only works in the current development version though as it requires some minor engine change.

Image
Magarena/scripts/Progenitor_Mimic.txt
Code: Select all
name=Progenitor Mimic
url=http://magiccards.info/dgm/en/92.html
image=http://magiccards.info/scans/en/dgm/92.jpg
value=3.717
rarity=M
type=Creature
subtype=Shapeshifter
cost={4}{G}{U}
pt=0/0
timing=main
requires_groovy_code
Magarena/scripts/Progenitor_Mimic.groovy
Code: Select all
def Duplicate = new MagicAtUpkeepTrigger() {
    @Override
    public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent,final MagicPlayer upkeepPlayer) {
        return permanent.isController(upkeepPlayer) && permanent.isNonToken() ?
            new MagicEvent(
                permanent,
                this,
                "PN puts a token onto the battlefield that's a copy of SN."
            ):
            MagicEvent.NONE;
    }

    @Override
    public void executeEvent(final MagicGame game, final MagicEvent event) {
        game.doAction(new MagicPlayTokenAction(
            event.getPlayer(),
            event.getPermanent().getCardDefinition()
        ));
    }
};

def GainTrig = new MagicStatic(MagicLayer.Ability) {
    @Override
    public void modAbilityFlags(final MagicPermanent source, final MagicPermanent permanent, final Set<MagicAbility> flags) {
        permanent.addTrigger(Duplicate);
    }
};

[
    new MagicSpellCardEvent() {
        @Override
        public MagicEvent getEvent(final MagicCardOnStack cardOnStack,final MagicPayedCost payedCost) {
            return new MagicEvent(
                cardOnStack,
                new MagicMayChoice(MagicTargetChoice.CREATURE),
                MagicCopyTargetPicker.create(),
                this,
                "Put SN onto the battlefield. You may\$ have SN enter the battlefield as a copy of any creature\$ on the battlefield, " +
                "except it gains \"At the beginning of your upkeep, if this creature isn't a token, put a token onto the battlefield that's a copy of this creature.\""
            );
        }

        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
            if (event.isYes()) {
                event.processTargetPermanent(game, {
                    final MagicPermanent chosen ->
                    final MagicPlayCardFromStackAction action = new MagicPlayCardFromStackAction(
                        event.getCardOnStack(),
                        chosen.getCardDefinition()
                    );
                    game.doAction(action);
                    final MagicPermanent perm = action.getPermanent();
                    game.doAction(new MagicAddStaticAction(perm, GainTrig));
                } as MagicPermanentAction);
            } else {
                game.doAction(new MagicPlayCardFromStackAction(
                    event.getCardOnStack()
                ));
            }
        }
    }
]
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 mike » 10 Aug 2013, 00:20

Code: Select all
One suggestion regarding card submission through firemind.ch, it would be clearer if the commit is recorded using the user's username instead of as "Project Firemind". From the mercurial command line, one can specify the username to use with -u flag.
Done.

Since I don't require authentication to submit cards though there might be a few submissions by "Guest". Just a heads up.
User avatar
mike
Programmer
 
Posts: 128
Joined: 05 Jul 2013, 17:00
Has thanked: 0 time
Been thanked: 29 times

Re: Adding new cards with Groovy

Postby melvin » 10 Aug 2013, 00:49

mike wrote:Done. Since I don't require authentication to submit cards though there might be a few submissions by "Guest". Just a heads up.
Wow, that's fast. Thanks!

Here is another Clone with a very flavorful ability.

Image

Magarena/scripts/Evil_Twin.txt
Code: Select all
name=Evil Twin
url=http://magiccards.info/isd/en/212.html
image=http://magiccards.info/scans/en/isd/212.jpg
value=3.717
rarity=R
type=Creature
subtype=Shapeshifter
cost={2}{U}{B}
pt=0/0
timing=main
requires_groovy_code
Magarena/scripts/Evil_Twin.groovy
Code: Select all
def DestroyTwin = new MagicPermanentActivation(
    new MagicActivationHints(MagicTiming.Removal),
    "Destroy"
) {
    @Override
    public MagicEvent[] getCostEvent(final MagicPermanent source) {
        return [
            new MagicPayManaCostEvent(source,"{U}{B}"),
            new MagicTapEvent(source)
        ];
    }
    @Override
    public MagicEvent getPermanentEvent(final MagicPermanent source,final MagicPayedCost payedCost) {
        final MagicTargetChoice targetChoice = new MagicTargetChoice(
            new MagicTargetFilter.NameTargetFilter(MagicTargetFilter.TARGET_CREATURE, source.getName()),
            true,
            MagicTargetHint.Negative,
            "target creature"
        );
        return new MagicEvent(
            source,
            targetChoice,
            new MagicDestroyTargetPicker(false),
            this,
            "Destroy target creature\$ with same name as this creature."
        );
    }
    @Override
    public void executeEvent(final MagicGame game, final MagicEvent event) {
        event.processTargetPermanent(game,new MagicPermanentAction() {
            public void doAction(final MagicPermanent permanent) {
                game.doAction(new MagicDestroyAction(permanent));
            }
        });
    }
};
   
def GainAct = new MagicStatic(MagicLayer.Ability) {
    @Override
    public void modAbilityFlags(final MagicPermanent source, final MagicPermanent permanent, final Set<MagicAbility> flags) {
        permanent.addActivation(DestroyTwin);
    }
};

[
    new MagicSpellCardEvent() {
        @Override
        public MagicEvent getEvent(final MagicCardOnStack cardOnStack,final MagicPayedCost payedCost) {
            return new MagicEvent(
                cardOnStack,
                new MagicMayChoice(MagicTargetChoice.CREATURE),
                MagicCopyTargetPicker.create(),
                this,
                "Put SN onto the battlefield. You may\$ have SN enter the battlefield as a copy of any creature\$ on the battlefield, " +
                "except it gains \"{U}{B}, {T}: Destroy target creature with the same name as this creature.\""
            );
        }

        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
            if (event.isYes()) {
                event.processTargetPermanent(game, {
                    final MagicPermanent chosen ->
                    final MagicPlayCardFromStackAction action = new MagicPlayCardFromStackAction(
                        event.getCardOnStack(),
                        chosen.getCardDefinition()
                    );
                    game.doAction(action);
                    game.doAction(new MagicAddStaticAction(
                        action.getPermanent(),
                        GainAct
                    ));
                } as MagicPermanentAction);
            } else {
                game.doAction(new MagicPlayCardFromStackAction(
                    event.getCardOnStack()
                ));
            }
        }
    }
]
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 mike » 10 Aug 2013, 11:28

Those Clones are pretty cool. Can't wait to build a deck around them.

I submitted a couple of M14 Slivers (together with the new filter that's necessary). I'm a little stuck on Manaweft Sliver / Gemhide Sliver now. Could someone please point me at a card with a similar "creatures get activated ability" effect? And/or how to add mana from groovy code?
User avatar
mike
Programmer
 
Posts: 128
Joined: 05 Jul 2013, 17:00
Has thanked: 0 time
Been thanked: 29 times

Re: Adding new cards with Groovy

Postby melvin » 10 Aug 2013, 11:42

mike wrote:I'm a little stuck on Manaweft Sliver / Gemhide Sliver now. Could someone please point me at a card with a similar "creatures get activated ability" effect? And/or how to add mana from groovy code?
Unfortunately gaining mana abilities is not supported by the engine, for now only certain keyword abilities, activated abilities, and triggered abilities can be gained.

What will be possible in the next release is Cipher, just got it to work a couple of minutes ago :)

Image

Magarena/scripts/Stolen_Identity.txt
Code: Select all
name=Stolen Identity
url=http://magiccards.info/gtc/en/53.html
image=http://magiccards.info/scans/en/gtc/53.jpg
value=4.638
rarity=R
type=Sorcery
cost={4}{U}{U}
timing=main
requires_groovy_code
Magarena/scripts/Stolen_Identity.groovy
Code: Select all
[
    new MagicSpellCardEvent() {
        @Override
        public MagicEvent getEvent(final MagicCardOnStack cardOnStack, final MagicPayedCost payedCost) {
            return new MagicEvent(
                cardOnStack,
                MagicTargetChoice.TARGET_ARTIFACT_OR_CREATURE,
                MagicCopyTargetPicker.create(),
                this,
                "Put a token onto the battlefield that's a copy of target artifact or creature\$. " +
                "Cipher."
            );
        }
        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
            event.processTargetPermanent(game,new MagicPermanentAction() {
                public void doAction(final MagicPermanent creature) {
                    final MagicPlayer player = event.getPlayer();
                    game.doAction(new MagicPlayCardAction(
                        MagicCard.createTokenCard(creature.getCardDefinition(), player),
                        player
                    ));
                    if (event.getCardOnStack().getCard().isToken() == false) {
                        // prevent auto move to graveyard
                        game.doAction(new MagicChangeCardDestinationAction(event.getCardOnStack(), MagicLocationType.Play));
                        game.addEvent(new MagicCipherEvent(event.getSource(), event.getPlayer()));
                    }
                }
            });
        }
    }
]
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 » 12 Aug 2013, 06:50

Image
Necrogen_Mists.txt
Code: Select all
name=Necrogen Mists
url=http://magiccards.info/mi/en/69.html
image=http://magiccards.info/scans/en/mi/69.jpg
value=3.667
rarity=R
type=Enchantment
cost={2}{B}
timing=enchantment
requires_groovy_code
Necrogen_Mists.groovy
Code: Select all
[
   new MagicAtUpkeepTrigger() {
        @Override
        public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicPlayer upkeepPlayer) {
         return new MagicEvent(
            permanent,
            upkeepPlayer,
            this,
            "PN discards a card."
         );
      }
        @Override
        public void executeEvent(final MagicGame game,final MagicEvent event) {
            final MagicPlayer player = event.getPlayer();
         game.addEvent(new MagicDiscardEvent(
            event.getSource(),
            event.getPlayer()
         ));
        }      
    }
]
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 » 12 Aug 2013, 08:40

Looks good, thanks hong yie, I've merged it into the main repo.

With http://firemind.ch launched, there is a new and better way to submit card scripts using http://www.firemind.ch/card_script_submissions/new This submission page integrates with our revision control software directly and reduces the work needed to merge new scripts. Do try it out for future script submissions.

For proper attribution, it is recommended to create an account on the site, otherwise the contribution will be listed as from "guest".
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 melvin » 12 Aug 2013, 13:34

Evoke will be supported in card scripts starting from Aug release :)

Image

Magarena/scripts/Mulldrifter.txt
Code: Select all
name=Mulldrifter
url=http://magiccards.info/lw/en/76.html
image=http://magiccards.info/scans/en/lw/76.jpg
value=3.717
rarity=C
type=Creature
subtype=Elemental
cost={4}{U}
pt=2/2
ability=flying,enters draw card 2,evoke {2}{U}
timing=main
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 » 14 Aug 2013, 08:25

Hello guys,

I'm trying to make my first card with Groovy script and need some help, please.
The card is Striking Sliver from Magic 2014 Core Set.

It's a sliver creature and it's only ability is "Sliver creatures you control have first strike".

This is my txt for it:
Code: Select all
name=Striking Sliver
url=*** had to remove this ***
image=*** had to remove this ***
value=3.087
rarity=C
type=Creature
subtype=Sliver
cost={R}
pt=1/1
timing=main
requires_groovy_code
I guess the card which is close to this one is Akroma's Memorial, so I looked at the Groovy script and changed it a bit:

Code: Select all
[
    new MagicStatic(
        MagicLayer.Ability,
        MagicTargetFilter.TARGET_CREATURE_YOU_CONTROL) {
        @Override
        public void modAbilityFlags(final MagicPermanent source,final MagicPermanent permanent,final Set<MagicAbility> flags) {
            flags.addAll(MagicAbility.of(
               MagicAbility.FirstStrike
           ));
        }
    }
]
Now I have to change MagicTargetFilter.TARGET_CREATURE_YOU_CONTROL to something which affects not all creatures, but slivers only.

How should I do that?

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 ember hauler » 14 Aug 2013, 08:35

Sorry guys, I'm dumb.
I guess I figured it out:

Code: Select all
[
    new MagicStatic(
            MagicLayer.Ability,
            MagicTargetFilter.TARGET_SLIVER) {
        @Override
        public void modAbilityFlags(final MagicPermanent source,final MagicPermanent permanent,final Set<MagicAbility> flags) {
            flags.add(MagicAbility.FirstStrike);
        }
    }
]
Right?
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 Aug 2013, 13:10

ember hauler wrote:Right?
Yes! Yours is the closest possible with Magarena 1.40 as it lacks the TARGET_SLIVER_YOU_CONTROL which we added for Magarena 1.41. Thanks for the new cards, I've merged it in https://code.google.com/p/magarena/sour ... e26280dc6d
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 » 14 Aug 2013, 22:58

Submitted "Spidersilk Armor" through "firemind.ch"

Spidersilk_Armor.txt
Code: Select all
name=Spidersilk Armor
url=http://magiccards.info/ddg/en/32.html
image=http://magiccards.info/scans/en/ddg/32.jpg
value=4.262
rarity=C
type=Enchantment
cost={2}{G}
static=player
timing=enchantment
requires_groovy_code
Spidersilk_Armor.groovy
Code: Select all
[
    new MagicStatic(
        MagicLayer.Ability,
        MagicTargetFilter.TARGET_CREATURE_YOU_CONTROL) {
        @Override
        public void modAbilityFlags(final MagicPermanent source,final MagicPermanent permanent,final Set<MagicAbility> flags) {
            flags.add(MagicAbility.Reach);
        }
      @Override
      public void modPowerToughness(final MagicPermanent source,final MagicPermanent permanent,final MagicPowerToughness pt) {
            pt.add(0,1);
        }
    }
]
i test this code, and the +1 toughness doesn't seems to work. ?
any clue?
Last edited by hong yie on 16 Aug 2013, 05:18, edited 1 time in total.
User avatar
hong yie
Programmer
 
Posts: 216
Joined: 10 Mar 2013, 06:44
Location: Jakarta
Has thanked: 75 times
Been thanked: 9 times

PreviousNext

Return to Magarena

Who is online

Users browsing this forum: No registered users and 57 guests


Who is online

In total there are 57 users online :: 0 registered, 0 hidden and 57 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 57 guests

Login Form