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

Adding new cards with Groovy

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

Re: Adding new cards with Groovy

Postby hong yie » 15 Jan 2014, 02:48

i've just posted a script for elderscale wurm.
then i notice, a tigger i haven't encountered before
"As long as you have 7 or more life, ..." that means we have to know the life before damage was dealt right? the script i posted to firemind.ch haven't include this trigger check.
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 » 16 Jan 2014, 08:54

I added in the "as long as" clause by only giving Elderscale Wurm the ability if its controller's life is 7 or more, see https://code.google.com/p/magarena/sour ... c6f8c1c46b
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 » 18 Jan 2014, 00:34

trying to script this ability:
"Reveal the top five cards of your library. Put all creature cards revealed this way into your hand and the rest on the bottom of your library"

how to access the top card of library? need to check the card's type first.
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 ShawnieBoy » 19 Jan 2014, 01:44

Currently unable to 'reveal' cards from anywhere.

But not to sound like a grump - player.getLibrary().getCardAtTop() will do the job
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 hong yie » 20 Jan 2014, 21:32

this planeswalker script just missing script for 1st skill. trying to complete script for this skill "Reveal the top five cards of your library. Put all creature cards revealed this way into your hand and the rest on the bottom of your library" :)


Garruk__Caller_of_Beasts.groovy
Code: Select all
[
    new MagicPlaneswalkerActivation(1) {
        @Override
        public MagicEvent getPermanentEvent(final MagicPermanent source,final MagicPayedCost payedCost) {
        }
        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
        }
    },
    new MagicPlaneswalkerActivation(-3) {
        @Override
        public MagicEvent getPermanentEvent(final MagicPermanent source,final MagicPayedCost payedCost) {
             return new MagicEvent(
                this,
                MagicTargetChoice.TARGET_GREEN_CREATURE_CARD_FROM_HAND,
                MagicGraveyardTargetPicker.PutOntoBattlefield,
                this,
                "Put a green creature card\$ from your hand onto the battlefield."
            );
       }
        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
            event.processTargetCard(game, {
                final MagicCard card ->
                game.doAction(new MagicRemoveCardAction(card,MagicLocationType.OwnersHand));
                game.doAction(new MagicPlayCardAction(card,event.getPlayer()));
            });      
        }
    },
    new MagicPlaneswalkerActivation(-7) {
        @Override
        public MagicEvent getPermanentEvent(final MagicPermanent source,final MagicPayedCost payedCost) {
            return new MagicEvent(
                source,
                this,
                "PN gets an emblem with \"Whenever you cast a creature spell, you may search your library for a creature card, put it onto the battlefield, then shuffle your library.\""
            );
        }
        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
            final MagicPlayer you = outerEvent.getPlayer();
            outerGame.doAction(new MagicAddTriggerAction(
            new MagicWhenOtherSpellIsCastTrigger() {
               @Override
               public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicCardOnStack cardOnStack) {
                  return (cardOnStack.isFriend(permanent) && cardOnStack.hasType(MagicType.Creature)) ?
                     new MagicEvent(
                        source,
                        this,
                        "PN searches his or her library for creature card and puts that card onto the battlefield. Then shuffle PN's library."
                  ):
                  MagicEvent.NONE;
               }
               @Override
               public void executeEvent(final MagicGame game, final MagicEvent event) {
                  game.addEvent(new MagicSearchOntoBattlefieldEvent(
                     event,
                     MagicTargetChoice.CREATURE_CARD_FROM_LIBRARY
                  ));
               }
            }
            ));      
        }
    }
]
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 » 21 Jan 2014, 06:18

hong yie wrote:this planeswalker script just missing script for 1st skill. trying to complete script for this skill "Reveal the top five cards of your library. Put all creature cards revealed this way into your hand and the rest on the bottom of your library" :)
Thanks for the initial script. I've implemented the first ability and fix some bugs in https://code.google.com/p/magarena/sour ... b5d0284393

Image

Magarena/scripts/Garruk__Caller_of_Beasts.txt
Code: Select all
name=Garruk, Caller of Beasts
url=http://magiccards.info/m14/en/172.html
image=http://mtgimage.com/card/garruk%2C%20caller%20of%20beasts.jpg
value=3.906
rarity=M
type=Planeswalker
subtype=Garruk
cost={4}{G}{G}
ability=enters with counter charge 4
timing=main
requires_groovy_code
Magarena/scripts/Garruk__Caller_of_Beasts.groovy
Code: Select all
[
    new MagicPlaneswalkerActivation(1) {
        @Override
        public MagicEvent getPermanentEvent(final MagicPermanent source,final MagicPayedCost payedCost) {
            return new MagicEvent(
                source,
                this,
                "Reveal the top five cards of your library. Put all creature cards revealed this way into your hand and the rest on the bottom of your library in any order."
            );
        }
        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
            final MagicCardList library = event.getPlayer().getLibrary();
            for (int i = 0; i < 5 && library.isEmpty() == false; i++) {
                final MagicCard top = library.getCardAtTop();
                game.doAction(new MagicRemoveCardAction(
                    top,
                    MagicLocationType.OwnersLibrary
                ));
                game.doAction(new MagicMoveCardAction(
                    top,
                    MagicLocationType.OwnersLibrary,
                    top.hasType(MagicType.Creature) ?
                      MagicLocationType.OwnersHand :
                      MagicLocationType.BottomOfOwnersLibrary
                ));
            }
        }
    },
    new MagicPlaneswalkerActivation(-3) {
        @Override
        public MagicEvent getPermanentEvent(final MagicPermanent source,final MagicPayedCost payedCost) {
             return new MagicEvent(
                source,
                MagicTargetChoice.TARGET_GREEN_CREATURE_CARD_FROM_HAND,
                MagicGraveyardTargetPicker.PutOntoBattlefield,
                this,
                "PN puts a green creature card\$ from his or her hand onto the battlefield."
            );
       }
        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
            event.processTargetCard(game, {
                final MagicCard card ->
                game.doAction(new MagicRemoveCardAction(card,MagicLocationType.OwnersHand));
                game.doAction(new MagicPlayCardAction(card,event.getPlayer()));
            });
        }
    },
    new MagicPlaneswalkerActivation(-7) {
        @Override
        public MagicEvent getPermanentEvent(final MagicPermanent source,final MagicPayedCost payedCost) {
            return new MagicEvent(
                source,
                this,
                "PN gets an emblem with \"Whenever you cast a creature spell, you may search your library for a creature card, put it onto the battlefield, then shuffle your library.\""
            );
        }
        @Override
        public void executeEvent(final MagicGame outerGame, final MagicEvent outerEvent) {
            final MagicPlayer you = outerEvent.getPlayer();
            outerGame.doAction(new MagicAddTriggerAction(
                new MagicWhenOtherSpellIsCastTrigger() {
                    @Override
                    public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicCardOnStack cardOnStack) {
                        return (cardOnStack.isFriend(permanent) && cardOnStack.hasType(MagicType.Creature)) ?
                            new MagicEvent(
                                permanent,
                                this,
                                "PN searches his or her library for creature card and puts that card onto the battlefield. Then shuffle PN's library."
                            ):
                            MagicEvent.NONE;
                    }
                    @Override
                    public void executeEvent(final MagicGame game, final MagicEvent event) {
                        game.addEvent(new MagicSearchOntoBattlefieldEvent(
                            event,
                            MagicTargetChoice.CREATURE_CARD_FROM_LIBRARY
                        ));
                    }
                }
            ));
        }
    }
]
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 » 21 Jan 2014, 19:57

Is there a way to make the 'revealed' cards appear in the game log, (Will class them as being revealed) - and also to allow the cards to be placed on the bottom of your library in any order - a kind-of pseudo-zone containing the top cards of library, with a choice "Choose a card to put on the bottom of your library"

May be a bit much - but will make it function more like the real card.

I'm really hoping that it will be possible to do the 'reveal cards' cards, as it will enable a lot of them :D
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 hong yie » 22 Jan 2014, 07:13

how to script garruk's horde?
the top card of library is playable as in player's hand. maybe the top card can be moved to other window to enable clicking, to be played as other cards in hand?
Maybe "Lodici" knows better how to handle this? :)
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 » 22 Jan 2014, 12:19

ShawnieBoy wrote:Is there a way to make the 'revealed' cards appear in the game log, (Will class them as being revealed) - and also to allow the cards to be placed on the bottom of your library in any order - a kind-of pseudo-zone containing the top cards of library, with a choice "Choose a card to put on the bottom of your library"
Yes, it is possible to reveal them in the log, but it will be unfair to the AI as it currently doesn't make use of information about revealed cards. Ordering of cards is intentionally not supported due to the large number of choices involved (five cards has 120 possible orderings) which will reduce how far the AI can look ahead, this is also why we only support "scry 1".


hong yie wrote:how to script garruk's horde?
the top card of library is playable as in player's hand. maybe the top card can be moved to other window to enable clicking, to be played as other cards in hand?
Maybe "Lodici" knows better how to handle this? :)
Garruk's Horde is not scriptable. Creating the way for the player to interact with the card is only one of the issues, the AI also needs to consider this additional card when deciding what spells to cast.
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 » 26 Jan 2014, 02:20

Image

Magarena/scripts/Erebos__God_of_the_Dead.txt
Code: Select all
name=Erebos, God of the Dead
url=http://magiccards.info/ths/en/85.html
image=http://mtgimage.com/card/erebos%2C%20god%20of%20the%20dead.jpg
value=3.708
rarity=M
type=Legendary,Enchantment,Creature
subtype=God
cost={3}{B}
pt=5/7
ability=indestructible;\
        pay {1}{B}, Pay 2 life: PN draws a card.
timing=main
requires_groovy_code
Magarena/scripts/Erebos__God_of_the_Dead.groovy
Code: Select all
[
    new MagicStatic(MagicLayer.Type) {
        @Override
        public int getTypeFlags(final MagicPermanent permanent,final int flags) {
            return flags & ~MagicType.Creature.getMask();
        }
        @Override
        public void modSubTypeFlags(final MagicPermanent permanent,final Set<MagicSubType> flags) {
            flags.remove(MagicSubType.God);
        }
        @Override
        public boolean condition(final MagicGame game,final MagicPermanent source,final MagicPermanent target) {
            return source.getController().getDevotion(MagicColor.Black) < 5;
        }
    },
    new MagicIfLifeWouldChangeTrigger() {
        @Override
        public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent,final MagicChangeLifeAction act) {
            if (permanent.isOpponent(act.getPlayer()) && act.getLifeChange() > 0) {
                act.setLifeChange(0);
            }
            return MagicEvent.NONE;
        }
    }
]
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 » 06 Feb 2014, 17:07

Using permanent.addAbility(<ability>) instead of flags.add(<ability>) to add abilities. Should spells like Turn to Frog still be removing flags instead of removing abilities?
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 » 07 Feb 2014, 01:48

ShawnieBoy wrote:Using permanent.addAbility(<ability>) instead of flags.add(<ability>) to add abilities. Should spells like Turn to Frog still be removing flags instead of removing abilities?
Good point, we need to add support for removing abilities with implementation like we have for adding. Thanks for the reminder. Currently, removal only works for "built-in" abilities.
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 » 08 Feb 2014, 01:29

Been banging my head against Erratic Portal for a while now, seems so simple, but every angle I've tried breaks it :(

This is as close as I have been able to get, although the owner of Erratic Portal ends up paying the optional mana cost if the opponent chooses to pay it. (It's all about how I can get a ManaCost event source on the opponent)

Script:
Code: Select all
name=Erratic Portal
url=http://magiccards.info/ex/en/132.html
image=http://mtgimage.com/card/erratic%20portal.jpg
value=4.212
rarity=R
type=Artifact
cost={4}
timing=artifact
requires_groovy_code
Groovy:
Code: Select all
def action = {
    final MagicGame game, final MagicEvent event ->
    if (event.isYes()) {
        game.addEvent(new MagicPayManaCostEvent(event.getSource(), "{1}"));
    } else {
        game.addEvent(new MagicBouncePermanentEvent(event.getSource(), event.getRefPermanent()));
    }
}

[
    new MagicPermanentActivation(
        new MagicActivationHints(MagicTiming.Removal),
        "Bounce"
    ) {

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

        @Override
        public MagicEvent getPermanentEvent(final MagicPermanent source, final MagicPayedCost payedCost) {
            return new MagicEvent(
                source,
                MagicTargetChoice.TARGET_CREATURE,
                MagicBounceTargetPicker.create(),
                this,
                "Return target creature\$ to its owner's hand unless its controller pays {1}."
            );
        }

        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
            event.processTargetPermanent(game, {
                final MagicPermanent permanent ->
                game.addEvent(new MagicEvent(
                    event.getSource(),
                    permanent.getController(),
                    new MagicMayChoice(),
                    permanent,
                    action,
                    "PN may\$ pay {1}."
                ));
            });
        }
    }
]
Any insight appreciated
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 » 08 Feb 2014, 02:44

You can combine the MayChoice and ManaCostChoice together, see Goblin_Dirigible.groovy, then in action just bounce the permanent if event.isNo().
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 » 08 Feb 2014, 04:24

Hmm, I've tried that, but the computer has a habit of selecting 'Yes' but then not paying the mana.
User avatar
ShawnieBoy
Programmer
 
Posts: 601
Joined: 02 Apr 2012, 22:42
Location: UK
Has thanked: 80 times
Been thanked: 50 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