It is currently 20 Apr 2024, 15:17
   
Text Size

Adding new cards with Groovy

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

Re: Adding new cards with Groovy

Postby ShawnieBoy » 16 Feb 2014, 14:13

Nice work :)

I don't think there's templates on Firemind for Born of the Gods
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 » 17 Feb 2014, 13:10

Image

Magarena/scripts/Brimaz__King_of_Oreskos.txt
Code: Select all
name=Brimaz, King of Oreskos
url=http://magiccards.info/bng/en/5.html
image=http://mtgimage.com/card/brimaz%2C%20king%20of%20oreskos.jpg
value=3.741
rarity=M
type=Legendary,Creature
subtype=Cat,Soldier
cost={1}{W}{W}
ability=vigilance
pt=3/4
timing=main
requires_groovy_code
Magarena/scripts/Brimaz__King_of_Oreskos.groovy
Code: Select all
[
    new MagicWhenAttacksTrigger() {
        @Override
        public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent,final MagicPermanent attacker) {
            return permanent == attacker ?
                new MagicEvent(
                    permanent,
                    this,
                    "PN puts a 1/1 white Cat Soldier creature token with vigilance onto the battlefield attacking."
                ) :
                MagicEvent.NONE;
        }
        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
            final MagicPlayer player=event.getPlayer();
            game.doAction(new MagicPlayCardAction(
                MagicCard.createTokenCard(
                    TokenCardDefinitions.get("1/1 white Cat Soldier creature token with vigilance"),
                    player
                ),
                player,
                [MagicPlayMod.ATTACKING]
            ));
        }
    },
    new MagicWhenBlocksTrigger() {
        @Override
        public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent,final MagicPermanent blocker) {
            final MagicPermanent blocked = permanent.getBlockedCreature();
            return (permanent == blocker && blocked.isValid()) ?
                new MagicEvent(
                    permanent,
                    blocked,
                    this,
                    "PN puts a 1/1 white Cat Soldier creature token with vigilance onto the battlefield blocking RN."
                ):
                MagicEvent.NONE;
        }
        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
            final MagicPlayer player=event.getPlayer();
            final MagicPlayCardAction act = new MagicPlayCardAction(
                MagicCard.createTokenCard(
                    TokenCardDefinitions.get("1/1 white Cat Soldier creature token with vigilance"),
                    player
                ),
                player
            );
            game.doAction(act);
            game.doAction(new MagicSetBlockerAction(event.getRefPermanent(), act.getPermanent()));
        }
    }
]
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 » 17 Feb 2014, 22:17

I've tried making Feast of Blood using MagicCardActivation conditions, and I must be doing something wrong as it is coming into play as a permanent, and not creating any effects:

Code: Select all
name=Feast of Blood
url=http://magiccards.info/zen/en/88.html
image=http://mtgimage.com/card/feast%20of%20blood.jpg
value=4.013
rarity=U
type=Sorcery
cost={1}{B}
timing=main
requires_groovy_code
Code: Select all
def TWO_OR_MORE_VAMPIRES_CONDITION = new MagicCondition() {
        public boolean accept(final MagicSource source) {
            return source.getController().getNrOfPermanents(MagicSubType.Vampire)>=2;
        }
    };

[
    new MagicCardActivation(
        [TWO_OR_MORE_VAMPIRES_CONDITION],
        new MagicActivationHints(MagicTiming.Removal,true),
        "Destroy"
        ) {
        @Override
        public Iterable<MagicEvent> getCostEvent(final MagicCard source) {
            return source.getCostEvent();
        }
        @Override
        public MagicEvent getEvent(final MagicCardOnStack cardOnStack, final MagicPayedCost payedCost) {
            return new MagicEvent(
                cardOnStack,
                MagicTargetChoice.NEG_TARGET_CREATURE,
                MagicDestroyTargetPicker.Destroy,
                this,
                "Destroy target creature\$. " +
                "PN gains 4 life."
            );
        }
        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
            event.processTargetPermanent(game, {
                final MagicPermanent creature ->
                game.doAction(new MagicDestroyAction(creature));
                game.doAction(new MagicChangeLifeAction(event.getPlayer(),4));
            });
        }
    }
]
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 » 18 Feb 2014, 05:33

Currently there is no way to replace the default MagicCardActivation. I've just pushed a change that makes this possible in https://code.google.com/p/magarena/sour ... 1b865eec87

With this new method, the new MagicCardActivation should be written as follows:
The difference is the addition of the change method that calls the new setCardAct method. The getCostEvent method is redundant as it is the same as that provided by MagicCardActivation, I've removed it from the code below.
Code: Select all
    new MagicCardActivation(
        [TWO_OR_MORE_VAMPIRES_CONDITION],
        new MagicActivationHints(MagicTiming.Removal,true),
        "Destroy"
    ) {
        @Override
        public void change(final MagicCardDefinition cdef) {
            cdef.setCardAct(this);
        }
        @Override
        public MagicEvent getEvent(final MagicCardOnStack cardOnStack, final MagicPayedCost payedCost) {
            return new MagicEvent(
                cardOnStack,
                MagicTargetChoice.NEG_TARGET_CREATURE,
                MagicDestroyTargetPicker.Destroy,
                this,
                "Destroy target creature\$. " +
                "PN gains 4 life."
            );
        }
        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
            event.processTargetPermanent(game, {
                final MagicPermanent creature ->
                game.doAction(new MagicDestroyAction(creature));
                game.doAction(new MagicChangeLifeAction(event.getPlayer(),4));
            });
        }
    }
]
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 » 18 Feb 2014, 05:44

That's great news! Thanks for that - Conditional spells ahoy ;)
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 » 18 Feb 2014, 05:52

Just found a bug, should add MagicCondition.CARD_CONDITION to the MagicCardActivation for Feast of Blood so that it follows the Sorcery type restriction
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 » 19 Feb 2014, 21:13

hong yie wrote:tried to submit this script to firemind.ch, but somehow this card is not recognized. i think this would be in Mike's Authority, maybe.
Anyway here it is
Sorry guys, just now gotten around to adding the BNG cards to 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 » 25 Feb 2014, 05:24

mike wrote:Sorry guys, just now gotten around to adding the BNG cards to firemind.ch
Thanks, mike :)

While watching the finals of PTBNG, I thought of a way we can encode phyrexian mana cards! Here is the first one.

Image

Magarena/scripts/Mental_Misstep.txt
Code: Select all
name=Mental Misstep
url=http://magiccards.info/nph/en/38.html
image=http://mtgimage.com/card/mental%20misstep.jpg
value=4.626
rarity=U
type=Instant
cost={U}
effect=Counter target spell with converted mana cost 1.
timing=counter
requires_groovy_code
Magarena/scripts/Mental_Misstep.groovy
Code: Select all
[
    new MagicCardActivation(
        [MagicCondition.CARD_CONDITION],
        new MagicActivationHints(MagicTiming.Counter,true),
        "Pay 2 life"
    ) {
        public Iterable<MagicEvent> getCostEvent(final MagicCard source) {
            return [
                new MagicPayLifeEvent(source, 2)
            ];
        }
    }
]
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 » 25 Feb 2014, 06:28

Nice - is it possible to add normal mana activations into the Alternate costs? For {3} {RP} {RP}, Act of Aggression for example? (Well, several alternate costs: {3} {R} +2 life, {3} +4 life)
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 » 25 Feb 2014, 07:06

Sure, just add two MagicCardActivation with the respective costs.

For example,
Code: Select all
return [         
   new MagicPayManaCostEvent(source,"{3}{R}")
   new MagicPayLifeEvent(source, 2)                                                                                                                                             
];
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 » 25 Feb 2014, 16:30

This is so cool :)

Hopefully there's a way to stitch this onto the MagicPayManaCostChoice and the MagicBuilderManaCost-type engine. I've had a look at the mana generation prompting but doesn't make a lot of sense to me. Would be good to have a choice prompt for Phyrexian mana while paying mana instead of when casting.

Choose a method to may {P/U}:
[{U}] [Pay 2 life]

then if the mana choice is chosen, it leads to the normal mana prompt:

Choose a mana source to pay {U}

Otherwise the life is paid.
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 » 26 Feb 2014, 01:51

Agree, originally I've been thinking along these lines, but the generation of different ways to pay mana for the AI is already quite complicated. Hacking it to tack on paying life would make it even more complex.

Hence the thought of using separate activation, which keeps it away from the core engine and can be done in the card itself using groovy code. Unless phyrexian mana becomes a regular thing (which I highly doubt since its flavor is tied to Phyrexia) it doesn't make sense to complicate the core to support it.

I'm looking at one more step to simplify it by providing syntax to specify alternative casting cost as a card ability. Then we can use our regular cost parsing to do the heavy lifting and do the work in the card script instead of in groovy code.
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 » 26 Feb 2014, 03:01

Cool - The only reason I wondered, is for permanents with activation costs using Phyrexian mana. We'll end up with having multiple activations with the same hint, as the hints on permanents relate to the effects, not how payment will be payed.

Insatiable Souleater, for example, would have ability hints of [Trample] [Trample] with no way to tell the difference.
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 » 26 Feb 2014, 03:15

We should give a different name to indicate payment of life, perhaps say "Phyrexian Trample". Not sure if it will fit on the dialog UI though.
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 » 26 Feb 2014, 16:07

As the UI buttons can accept the mana symbols - maybe a symbol to represent payment of life. So Birthing Pod would have hints of: [ {G} :Search] [ {2Life} :Search] - Omitting the {1}, {T} and 'Sacrifice a creature' as they appear on both?
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 17 guests


Who is online

In total there are 17 users online :: 0 registered, 0 hidden and 17 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 17 guests

Login Form