Page 11 of 28

Re: Adding new cards with Groovy

PostPosted: 06 Oct 2013, 05:55
by melvin
New in 1.43, MagicHeroicTrigger in groovy script.

Image

Magarena/scripts/Wingsteed_Rider.txt
Code: Select all
name=Wingsteed Rider
url=http://magiccards.info/ths/en/36.html
image=http://magiccards.info/scans/en/ths/36.jpg
value=3.729
rarity=C
type=Creature
subtype=Human,Knight
cost={1}{W}{W}
pt=2/2
ability=flying
timing=main
requires_groovy_code
Magarena/scripts/Wingsteed_Rider.groovy
Code: Select all
[
    new MagicHeroicTrigger() {
        @Override
        public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent,final MagicItemOnStack target) {
            return new MagicEvent(
                permanent,
                this,
                "Put a +1/+1 counter on SN."
            );
        }

        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
            game.doAction(new MagicChangeCountersAction(event.getPermanent(), MagicCounterType.PlusOne, 1, true))
        }
    }
]

Re: Adding new cards with Groovy

PostPosted: 06 Oct 2013, 05:56
by melvin
New in 1.43, 'monstrosity <n>' in ability property of card script

Image

Magarena/scripts/Nessian_Asp.txt
Code: Select all
name=Nessian Asp
url=http://magiccards.info/ths/en/164.html
image=http://magiccards.info/scans/en/ths/164.jpg
value=3.72
rarity=C
type=Creature
subtype=Snake
cost={4}{G}
ability=reach;monstrosity 4 {6}{G}
pt=4/5
timing=main

Re: Adding new cards with Groovy

PostPosted: 06 Oct 2013, 05:57
by melvin
New in 1.43, MagicWhenBecomesMonstrousTrigger in groovy script.

Image

Magarena/scripts/Arbor_Colossus.txt
Code: Select all
name=Arbor Colossus
url=http://magiccards.info/ths/en/150.html
image=http://magiccards.info/scans/en/ths/150.jpg
value=3.729
rarity=R
type=Creature
subtype=Giant
cost={2}{G}{G}{G}
pt=6/6
ability=reach;monstrosity 3 {3}{G}{G}{G}
timing=main
requires_groovy_code
Magarena/scripts/Arbor_Colossus.groovy
Code: Select all
[
    new MagicWhenBecomesMonstrousTrigger() {
        @Override
        public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent,final MagicChangeStateAction action) {
            return action.permanent == permanent ?
                new MagicEvent(
                    permanent,
                    new MagicTargetChoice("target creature with flying an opponent controls"),
                    new MagicDestroyTargetPicker(false),
                    this,
                    "Destroy target creature\$ with flying an opponent controls."
                ):
                MagicEvent.NONE;
        }

        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
            event.processTargetPermanent(game,new MagicPermanentAction() {
                public void doAction(final MagicPermanent creature) {
                    game.doAction(new MagicDestroyAction(creature));
                }
            });
        }
    }
]

Re: Adding new cards with Groovy

PostPosted: 06 Oct 2013, 05:58
by melvin
New in 1.43, 'bestow <mana cost>' in ability property of card script.

Image

Magarena/scripts/Cavern_Lampad.txt
Code: Select all
name=Cavern Lampad
url=http://magiccards.info/ths/en/81.html
image=http://magiccards.info/scans/en/ths/81.jpg
value=3.729
rarity=C
type=Enchantment,Creature
subtype=Nymph
cost={3}{B}
ability=intimidate;bestow {5}{B}
given_pt=2/2
given_ability=intimidate
pt=2/2
timing=main

Re: Adding new cards with Groovy

PostPosted: 06 Oct 2013, 09:07
by melvin
New in 1.43, getDevotion method on MagicPlayer in groovy script.

Image

Magarena/scripts/Purphoros__God_of_the_Forge.txt
Code: Select all
name=Purphoros, God of the Forge
url=http://magiccards.info/ths/en/135.html
image=http://magiccards.info/scans/en/ths/135.jpg
value=3.729
rarity=M
type=Legendary,Enchantment,Creature
subtype=God
cost={3}{R}
pt=6/5
ability=indestructible
timing=main
requires_groovy_code
Magarena/scripts/Purphoros__God_of_the_Forge.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.Red) < 5;
        }
    },
    new MagicWhenOtherComesIntoPlayTrigger() {
        @Override
        public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicPermanent otherPermanent) {
            return (otherPermanent != permanent &&
                    otherPermanent.isFriend(permanent) &&
                    otherPermanent.isCreature()) ?
                new MagicEvent(
                    permanent,
                    this,
                    "SN deals 2 damage to each opponent."
                ):
                MagicEvent.NONE;
        }
        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
            game.doAction(new MagicDealDamageAction(
                new MagicDamage(
                    event.getSource(),
                    event.getPlayer().getOpponent(),
                    2
                )
            ));
        }
    },
    new MagicPermanentActivation(
        new MagicActivationHints(MagicTiming.Pump),
        "Pump"
    ) {

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

        @Override
        public MagicEvent getPermanentEvent(final MagicPermanent source,final MagicPayedCost payedCost) {
            return new MagicEvent(
                source,
                this,
                "Creatures PN controls get +1/+0 until end of turn."
            );
        }

        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
            final Collection<MagicPermanent> targets = game.filterPermanents(
                event.getPlayer(),
                MagicTargetFilter.TARGET_CREATURE_YOU_CONTROL
            );
            for (final MagicPermanent creature : targets) {
                game.doAction(new MagicChangeTurnPTAction(creature,1,0));
            }
        }
    }
]

Re: Adding new cards with Groovy

PostPosted: 06 Oct 2013, 09:26
by melvin
Card scripters are encouraged to use the 1.43 release candidate to test out the new features, you can get it at http://melvinzh.sdf.org/Magarena-003fb4f955bc.exe (Windows users can launch the new version from this exe, Linux/Mac users will have to copy this over the existing Magarena.exe file so that the existing launcher scripts will work)

Re: Adding new cards with Groovy

PostPosted: 06 Oct 2013, 12:54
by jerichopumpkin
melvin wrote:Both are solved with conditions, which is passed as an array before the activation hint. i.e.

Code: Select all
 new MagicCardActivation(
        [TWO_OTHER_GREEN_CARDS_IN_HAND, MagicCondition.CARD_CONDITION]
        new MagicActivationHints(MagicTiming.Main),
        "Alt"
    ) {
...
To follow the card's regular casting restriction (sorcery during main), just use the built-in MagicCondition.CARD_CONDITION. Now that you mentioned it, all the alternate casting cost should include this, but so far we've only had instants so it didn't matter.

To prevent casting with a single green card, you need to define your own activation condition, define following at the start of the script
Code: Select all
    def TWO_OTHER_GREEN_CARDS_IN_HAND = new MagicCondition() {
        public boolean accept(final MagicSource source) {
           //source is the MagicCard
           //obtain MagicGame from source via source.getGame()
           //create a other card filter, same as one in the cost
           //use game.filterCards passing it the player and filter to get a list of other green cards
           //return true if player has at least two other green cards
        }
    };
Thank you, now it works fine! I've already submitted it with ProjectFiremind as always

Re: Adding new cards with Groovy

PostPosted: 14 Oct 2013, 18:18
by ember hauler
Trying to make Archangel of Thune:

Image

card:
Code: Select all
name=Archangel of Thune
url=http://magiccards.info/m14/en/5.html
image=http://magiccards.info/scans/en/m14/5.jpg
value=2.500
rarity=M
type=Creature
subtype=Angel
cost={3}{W}{W}
pt=3/4
timing=main
ability=flying;lifelink
requires_groovy_code
script:
Code: Select all
[
    new MagicWhenLifeIsGainedTrigger() {
        @Override
        public MagicEvent executeTrigger(
                final MagicGame game,
                final MagicPermanent permanent,
                final MagicPermanent otherPermanent) {
            return (otherPermanent.isCreature() &&
                    otherPermanent.isFriend(permanent)) ?
                new MagicEvent(
                    permanent,
                    this,
                    "PN puts a +1/+1 counter on " +
                    "each creature he or she controls."
                ) :
                MagicEvent.NONE;
        }

        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
            final Collection<MagicPermanent> targets = game.filterPermanents(
                event.getPlayer(),
                MagicTargetFilter.TARGET_CREATURE_YOU_CONTROL
            );
            for (final MagicPermanent target : targets) {
                game.doAction(new MagicChangeCountersAction(
                    target,
                    MagicCounterType.PlusOne,
                    1,
                    true
                ));
            }
        }
    }
]
error:
Code: Select all
Can't have an abstract method in a non-abstract class. The class 'Archangel_of_Thune$1' must be declared abstract or the method 'magic.model.event.MagicEvent executeTrigger(magic.model.MagicGame, magic.model.MagicPermanent, java.lang.Object)' must be implemented.
 @ line 2, column 40.
It seems that MagicWhenLifeIsGainedTrigger cannot be used this way, but why?

Thanks!

Re: Adding new cards with Groovy

PostPosted: 14 Oct 2013, 18:54
by ember hauler
Another problem is with Ashen Rider.

Image

the card:
Code: Select all
name=Ashen Rider
url=http://magiccards.info/ths/en/187.html
image=http://magiccards.info/scans/en/ths/187.jpg
value=2.500
rarity=M
type=Creature
subtype=Archon
cost={4}{W}{W}{B}{B}
pt=5/5
ability=flying;dies effect Exile target permanent.
timing=main
requires_groovy_code
the script:
Code: Select all
[
    new MagicWhenComesIntoPlayTrigger() {
        @Override
        public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent, final MagicPayedCost payedCost) {
            return new MagicEvent(
                permanent,
                MagicTargetChoice.TARGET_PERMANENT,
                MagicExileTargetPicker.create(),
                this,
                "Exile target permanent\$."
            );
        }
        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
            event.processTargetPermanent(game,new MagicPermanentAction() {
                public void doAction(final MagicPermanent permanent) {
                    game.doAction(new MagicRemoveFromPlayAction(permanent,MagicLocationType.Exile));
                }
            });
        }
    }
]
The problem is: the ability "dies effect Exile target permanent" seems to target only permanents the opponent control, but it has to target any permanent.

Re: Adding new cards with Groovy

PostPosted: 15 Oct 2013, 01:19
by melvin
ember hauler wrote:Trying to make Archangel of Thune
The issue is this line:
Code: Select all
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicPermanent otherPermanent) {
It should read:
Code: Select all
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicLifeChangeTriggerData lifeChange) {
The third parameter is information about the player whose life is changed and how much is changed by checking lifeChange.player and lifeChange.amount. See https://code.google.com/p/magarena/sour ... ond.groovy for an example.

ember hauler wrote:Another problem is with Ashen Rider. The problem is: the ability "dies effect Exile target permanent" seems to target only permanents the opponent control, but it has to target any permanent.
This is due to AI hinting, you can disable for your moves by unchecking "Remove unusual target choices" in the Preferences dialog.

Btw, do note that Ashen Rider has been submitted earlier, the enters trigger can also be described in the card script as "enters effect Exile target permanent." The full list of submitted cards for 1.43 can be viewed at https://code.google.com/p/magarena/wiki/UpcomingCards

Re: Adding new cards with Groovy

PostPosted: 15 Oct 2013, 05:41
by ember hauler
melvin wrote:
ember hauler wrote:Another problem is with Ashen Rider. The problem is: the ability "dies effect Exile target permanent" seems to target only permanents the opponent control, but it has to target any permanent.
This is due to AI hinting, you can disable for your moves by unchecking "Remove unusual target choices" in the Preferences dialog.
True. But the script for ETB exile target permament allows me to choose even my own permanents while "Remove unusual target choices" is still checked.

Re: Adding new cards with Groovy

PostPosted: 15 Oct 2013, 07:15
by melvin
ember hauler wrote:True. But the script for ETB exile target permament allows me to choose even my own permanents while "Remove unusual target choices" is still checked.
That is because the ETB script did not have a hint for the target as it uses MagicTargetChoice.TARGET_PERMANENT, the trigger generated by "enters effect Exile target permanent." uses MagicTargetChoice.NEG_TARGET_PERMANENT.

Re: Adding new cards with Groovy

PostPosted: 15 Oct 2013, 07:30
by ember hauler
melvin wrote:The third parameter is information about the player whose life is changed and how much is changed by checking lifeChange.player and lifeChange.amount. See https://code.google.com/p/magarena/sour ... ond.groovy for an example.
Thanks, it's working now, submitted thru Firemind.

Re: Adding new cards with Groovy

PostPosted: 15 Oct 2013, 07:35
by ember hauler
melvin wrote:
ember hauler wrote:True. But the script for ETB exile target permament allows me to choose even my own permanents while "Remove unusual target choices" is still checked.
That is because the ETB script did not have a hint for the target as it uses MagicTargetChoice.TARGET_PERMANENT, the trigger generated by "enters effect Exile target permanent." uses MagicTargetChoice.NEG_TARGET_PERMANENT.
So it's better to use NEG_TARGET_PERMANENT instead of TARGET_PERMANENT every time, right?

Re: Adding new cards with Groovy

PostPosted: 15 Oct 2013, 07:37
by melvin
ember hauler wrote:So it's better to use NEG_TARGET_PERMANENT instead of TARGET_PERMANENT every time, right?
Yes, it helps the AI to avoid making bad moves.