It is currently 02 Sep 2025, 17:40
   
Text Size

Adding new cards with Groovy

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

Re: Adding new cards with Groovy

Postby hong yie » 03 Jun 2014, 05:37

Code: Select all
[
    new MagicPermanentActivation(
        new MagicActivationHints(MagicTiming.Token),
        "Put"
    ) {
        @Override
        public Iterable getCostEvent(final MagicPermanent source) {
            return [
                new MagicPayManaCostEvent(source,"{R}")
            ];
        }

        @Override
        public MagicEvent getPermanentEvent(final MagicPermanent source, final MagicPayedCost payedCost) {
            return new MagicEvent(
                source,
                MagicTargetChoice.CREATURE_CARD_FROM_HAND,
                MagicGraveyardTargetPicker.PutOntoBattlefield,
                this,
                "PN puts a creature card\$ from his or her hand onto the battlefield."
            );
        }

        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
            event.processTargetCard(game,new MagicCardAction() {
                public void doAction(final MagicCard card) {
                    game.doAction(new MagicRemoveCardAction(card,MagicLocationType.OwnersHand));
                    game.doAction(new MagicPlayCardAction(card,event.getPlayer()));               
                }
            public void doAction(final MagicPermanent creature) {
               game.doAction(new MagicGainAbilityAction(creature, MagicAbility.Haste));
               game.doAction(new MagicAddTriggerAction(creature, MagicAtEndOfTurnTrigger.Sacrifice));
            }
            });
        }
    }
]
i tried to script "sneak attack".
when i test this code. the first part, may put a creature card into play works, but the next creature permanent gains haste & sacrifice doesn't. i know this is due to different object from a creature card --> creature permanent. how should i script this? thanx a lot lot for the help. :)
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 » 03 Jun 2014, 06:25

MagicPlayCardAction allows you to modify the permanent by specifying it in the constructor.

Code: Select all
new MagicPlayCardAction(
  card,
  event.getPlayer(),
  [MagicPlayMod.HASTE, MagicPlayMod.SACRIFICE_AT_END_OF_TURN]
)
See release/Magarena/scripts/Splinter_Twin.groovy for an example.
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 » 09 Jun 2014, 08:20

Code: Select all
new MagicPlayCardAction(
  card,
  event.getPlayer(),
  [MagicPlayMod.TAPPED]
)
this function will work on "tapped" too?
Like in "victimize"?

And one more thing, can i get a creature type or color of a top card on the library?
thank's for these. :)
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 » 10 Jun 2014, 08:38

hong yie wrote:
Code: Select all
new MagicPlayCardAction(
  card,
  event.getPlayer(),
  [MagicPlayMod.TAPPED]
)
this function will work on "tapped" too?
Like in "victimize"?
Sure, that will work.

hong yie wrote:And one more thing, can i get a creature type or color of a top card on the library?
thank's for these. :)
See the mini example below
Code: Select all
final MagicCard card = player.getLibrary().getCardAtTop();
boolean isGoblinOrBlack = card.hasSubType(MagicSubType.Goblin) || card.hasColor(MagicColor.Black);
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 » 10 Jun 2014, 11:14

actually, i'm trying to script "Descendants' Path"
i hope to get the creature type string, then use it to count number of creature with that certain string. wrong approach? :)

anyway, at the mean time, i will continue to other card.
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 hong yie » 08 Jul 2014, 04:05

when i read Liliana's Specter's script
i found this phrase:

permanent.getOpponent()

as far as i know, this is not equal to "each opponents", since it only contain 1 player.
is there a plan to upgrade this phrase to support multiple instance of opponents later? should i script something that contain "each opponents" with this phrase?
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 » 08 Jul 2014, 04:45

hong yie wrote:when i read Liliana's Specter's script
i found this phrase:

permanent.getOpponent()

as far as i know, this is not equal to "each opponents", since it only contain 1 player.
is there a plan to upgrade this phrase to support multiple instance of opponents later? should i script something that contain "each opponents" with this phrase?
I tend to try and take into account the possibility of multiple opponents in the future, depending on how easy it is to cram them in! It wouldn't be too difficult to add a .getOpponents() or .getAllOpponents() (Whichever is clearer). Although for..each loops to affect multiple targets still doesn't quite apply effects simultaneously.

At the moment there's only ever one opponent, so only having one is ok. The only thing to bear in mind is that "Each opponent" and "Target opponent" are different if you only have one opponent. "Each opponent" doesn't target, so can affect opponents with hexproof or shroud, whereas "Target opponent" can't.
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 » 08 Jul 2014, 04:50

tried to submit this to firemind.ch, i receive error. maybe not listed yet, anyway i'll put it here.

Image

Master_of_the_Feast.txt
Code: Select all
name=Master_of_the_Feast
image=http://magiccards.info/scans/en/jou/75.jpg
value=3.824
rarity=R
type=Enchantment,Creature
subtype=Demon
cost={1}{B}{B}
pt=5/5
ability=flying
timing=main
requires_groovy_code
oracle=Flying. At the beginning of your upkeep, each opponent draws a card.
Master_of_the_Feast.groovy
Code: Select all
[
   new MagicAtUpkeepTrigger() {
        @Override
        public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicPlayer upkeepPlayer) {
         return permanent.isController(upkeepPlayer) ?      
                new MagicEvent(
                    permanent,
                    permanent.getOpponent(),
               this,
                    "each opponent draws a card."
                ) :
                MagicEvent.NONE;
        }
        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
         final MagicPlayer player=event.getPlayer();
         game.doAction(new MagicDrawAction(player));
        }
    }
]
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 » 08 Jul 2014, 05:15

Thanks, added in https://code.google.com/p/magarena/sour ... 67b393a05b

The groovy code can be replaced by card script
Code: Select all
ability=Flying;\
        At the beginning of your upkeep, each opponent draws a card.
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 » 08 Jul 2014, 05:31

Fixed card script:
1. replace groovy code with card script
2. remove underscores in card name
3. retrieve image from mtgimage.com
Code: Select all
name=Master of the Feast
image=http://mtgimage.com/card/master%5Fof%5Fthe%5Ffeast.jpg
value=3.824
rarity=R
type=Enchantment,Creature
subtype=Demon
cost={1}{B}{B}
pt=5/5
ability=Flying;\
        At the beginning of your upkeep, each opponent draws a card.
timing=main
oracle=Flying. At the beginning of your upkeep, each opponent draws a card.
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 Jul 2014, 13:17

hong yie wrote:tried to submit this to firemind.ch, i receive error. maybe not listed yet, anyway i'll put it here.

Master_of_the_Feast.txt
Code: Select all
name=Master_of_the_Feast
image=http://magiccards.info/scans/en/jou/75.jpg
value=3.824
rarity=R
type=Enchantment,Creature
subtype=Demon
cost={1}{B}{B}
pt=5/5
ability=flying
timing=main
requires_groovy_code
oracle=Flying. At the beginning of your upkeep, each opponent draws a card.
melvin wrote:
Code: Select all
name=Master of the Feast
image=http://mtgimage.com/card/master%5Fof%5Fthe%5Ffeast.jpg
value=3.824
rarity=R
type=Enchantment,Creature
subtype=Demon
cost={1}{B}{B}
pt=5/5
ability=Flying;\
        At the beginning of your upkeep, each opponent draws a card.
timing=main
oracle=Flying. At the beginning of your upkeep, each opponent draws a card.
Project Firemind hasn't been updated in a long time, I'm wondering what's going on with it. It's using version 1.48 which was released in March, so is about 1,000 cards short of the current release.

This file already exists in Magarena\scripts_missing - Just needs to be moved to Magarena\scripts.

scripts_missing should really be the first place to go to get the card script.
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 » 16 Jul 2014, 07:50

here is my attempt to script Phyrexian Unlife
Code: Select all
[
    new MagicIfPlayerWouldLoseTrigger() {
        @Override
        public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent,final MagicLoseGameAction loseAct) {
            if (permanent.isController(loseAct.getPlayer())) && (loseAct.getPlayer().getLife()<=0){
                loseAct.setPlayer(MagicPlayer.NONE);
            }
            return MagicEvent.NONE;
        }
    },
    new MagicIfDamageWouldBeDealtTrigger(MagicTrigger.REPLACE_DAMAGE) {
        @Override
        public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent,final MagicDamage damage) {
            if (permanent.isController(damage.getTarget())) {
                // Replacement effect. Generates no event or action.
            }
            return MagicEvent.NONE;
        }
    }
]
i'm trying to add "infect" to the damage before being dealt.
to trigger this code in MagicDealDamageAction.java any property / method i can use?
Code: Select all
        if (target.isPlayer()) {
            final MagicPlayer targetPlayer = (MagicPlayer)target;
            if (source.hasAbility(MagicAbility.Infect)) {
                game.doAction(new MagicChangePoisonAction(targetPlayer,dealtAmount));
            } else {
                game.doAction(new MagicChangeLifeAction(targetPlayer,-dealtAmount));
            }
            game.doAction(new MagicChangePlayerStateAction(targetPlayer,MagicPlayerState.WasDealtDamage));
        }
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 » 10 Aug 2014, 06:25

hong yie wrote:i'm trying to add "infect" to the damage before being dealt.
to trigger this code in MagicDealDamageAction.java any property / method i can use?
"damage is dealt to you as though its source had infect" can't be implemented in groovy code at the moment.
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 » 11 Aug 2014, 01:20

melvin wrote:
hong yie wrote:i'm trying to add "infect" to the damage before being dealt.
to trigger this code in MagicDealDamageAction.java any property / method i can use?
"damage is dealt to you as though its source had infect" can't be implemented in groovy code at the moment.
Maybe a replacement effect that adds poison counters using the .getDealtAmount() value in some way (But not actually doing any damage?!)
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 » 16 Sep 2014, 03:39

Tested this script. tried submit this script to firemind.ch "Already taken", but can't find it in the newest source.

wall_of_junk.txt
Code: Select all
name=Wall of Junk
image=http://mtgimage.com/card/wall%20of%20junk.jpg
value=2.500
rarity=U
type=Artifact,Creature
subtype=Wall
cost={2}
pt=0/7
ability=defender
timing=artifact
requires_groovy_code
oracle=Defender.Whenever Wall of Junk blocks, return it to its owner's hand at end of combat.
wall_of_junk.groovy
Code: Select all
[
    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,
               blocker,
               this,
                    "Return Wall of Junk to its owner's hand at end of combat."
                ):
                MagicEvent.NONE;
        }
        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
            event.processRefPermanent(game, {
                game.doAction(new MagicAddTriggerAction(
                    it,
                    MagicAtEndOfCombatTrigger.Return
                ))
            });
        }
    }
]
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 12 guests

Main Menu

User Menu

Our Partners


Who is online

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

Login Form