It is currently 05 Sep 2025, 02:07
   
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 Jul 2013, 05:55

this is my 1st attempt to try groovy code. i'm Trying to add this card.

name=Daunting Defender
url=http://magiccards.info/on/en/21.html
image=http://magiccards.info/scans/en/on/21.jpg
value=3.074
rarity=C
type=Creature
subtype=Human,Cleric
cost={4}{W}
pt=3/3
timing=fmain
requires_groovy_code



its "prevent 1 damage" ability is similar to "Hedron-Field Purists". in this script:

new MagicIfDamageWouldBeDealtTrigger(5) {
@Override
public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent,final MagicDamage damage) {
if (permanent.isFriend(damage.getTarget())) {
final int amountCounters = permanent.getCounters(MagicCounterType.Charge);
final int amountPrevented =
amountCounters >= 5 ? 2 :
amountCounters >= 1 ? 1 : 0
// Prevention effect.
damage.prevent(amountPrevented);
}
return MagicEvent.NONE;
}
}


i tried to add this groovy code:

Daunting_Defender.groovy
[
new MagicIfDamageWouldBeDealtTrigger(5) {
@Override
public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent,final MagicDamage damage) {
if (permanent.isFriend(damage.getTarget())) {
amountPrevented = 1
// Prevention effect.
damage.prevent(amountPrevented);
}
return MagicEvent.NONE;
}
}
]

it seems there has been error, magarena crash to desktop, when i start with this new card i just added. hope for enlightenment, thanks. :)
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 » 15 Jul 2013, 08:17

Hi hong yie, thanks for helping to add cards. When the program crashes, it will create a Magarena/crash.log file in the folder where you unzipped the program.

I tried your script and got the following in the crash.log
Code: Select all
/Magarena/scripts/Daunting_Defender.groovy: 6: [Static type checking] - The variable [amountPrevented] is undeclared.                                   
  @ line 6, column 13.                                                                                                                                                                         
                amountPrevented = 1     
The engine complains that the variable amountPrevented is not declared, there are two ways to fix this.
1. declare amountPrevented as follows
Code: Select all
final int amountPrevented = 1;
2. use a constant in the prevent method. Remove the amountPrevented line and change the next line to be
Code: Select all
damage.prevent(1);
To implement the card, the script should also check that the target of the damage is a Cleric creature. To do this you can modify the check as follows
Code: Select all
if (damage.getTarget().isCreature() && damage.getTarget().hasSubType(MagicSubType.Cleric) && permanent.isFriend(damage.getTarget())) {
...
Happy scripting :)
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 » 15 Jul 2013, 10:15

thank's for the enlightenment about the groovy code. :)
but i notice something else i need to ask:

new MagicIfDamageWouldBeDealtTrigger(5) {

the "5" in that function declaration, is that used as an input parameter or what?
i don't think i would make use of that "5" in this function. i just happened to get the code by copying from "Hedron_Field_Purists.groovy"

new MagicIfDamageWouldBeDealtTrigger(5) {
@Override
public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent,final MagicDamage damage) {
if (permanent.isFriend(damage.getTarget())) {
final int amountCounters = permanent.getCounters(MagicCounterType.Charge);
final int amountPrevented =
amountCounters >= 5 ? 2 :
amountCounters >= 1 ? 1 : 0
// Prevention effect.
damage.prevent(amountPrevented);
}
return MagicEvent.NONE;
}
}

it that "5" bring nothing good, i'll get rid of it. thanks. :)
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 » 15 Jul 2013, 12:18

Thanks for asking about that, the "5" is the priority of the effect, effect with smaller number occurs first. The reason we need the ordering is because there can be other damage modification effects in play. For example, Fire Servant's ability is at level 3 so they happen first. I think using numbers is not intuitive, in future versions we will change it to use a constant, eg MagicTrigger.DamagePrevention.
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 » 15 Jul 2013, 16:11

Image

daunting_Defender.txt
Code: Select all
name=Daunting Defender
url=http://magiccards.info/on/en/21.html
image=http://magiccards.info/scans/en/on/21.jpg
value=3.074
rarity=C
type=Creature
subtype=Human,Cleric
cost={4}{W}
pt=3/3
timing=fmain
requires_groovy_code
daunting_defender.groovy

Code: Select all
[
new MagicIfDamageWouldBeDealtTrigger(5) {
   @Override
   public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent,final MagicDamage damage) {
      if (damage.getTarget().isCreature() && damage.getTarget().hasSubType(MagicSubType.Cleric) && permanent.isFriend(damage.getTarget())) {
         // Prevention effect.
         damage.prevent(1);
      }
   return MagicEvent.NONE;
   }
}
]
tested, it worked. cleric Pestilence deck is coming up, in the next update.
enjoy. :)
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 » 15 Jul 2013, 16:35

trying to implement
"{B}, tap, Sacrifice a Cleric creature: Target player loses life equal to the sacrificed creature's power."
i've tried to search in magarena, found no card ever use such ability yet. if someone can provide me with a working groovy code for this. it will be wonderful progress in building this graceful cleric tribal deck. :)
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 Jul 2013, 03:08

Thanks for the new cards, I've just pushed it to the repo as https://code.google.com/p/magarena/sour ... 3ba08441cf It is nice to see someone else posting cards in this thread, that was one of my goals starting this :)

As for the ability you mentioned, you should look at the script for Brion Stoutarm.
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 » 16 Jul 2013, 05:29

As for the ability you mentioned, you should look at the script for Brion Stoutarm.
about this ability, it's different than what i need. cleric use "lost life", something that can't be prevented, and will surely kill a player even when that player have "worship" enchantment. i played a worship deck before, someone "killed" me with highway robber's lost life ability.
as i know, the "damage" mechanic should be as follow:
- pooling "prevent the next x damage(s) deal to target" effects.
- assign damage to target
- dealing damage to target
- dealing damage triggers damage prevention
- unprevented damages triggers lost life

thank's for the help, though. i will wait for further update, while trying to put more interesting things later. :)
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 Jul 2013, 05:44

You'll need to change the deal damage to lose life. The last part should be something like:
Code: Select all
@Override                                                                                                                                                                             
public void executeEvent(final MagicGame game, final MagicEvent event) {                                                                                                             
    event.processTargetPlayer(game,new MagicPlayerAction() {                                                                                                                         
        public void doAction(final MagicPlayer player) {                                                                                                                             
            final MagicPermanent sacrificed=event.getRefPermanent();                                                                                                                 
            game.doAction(new MagicChangeLifeAction(player, -sacrificed.getPower()));                                                                                                                         
        }                                                                                                                       
    });                                                                                                                                                                               
}   
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 » 16 Jul 2013, 08:16

i found
Code: Select all
MagicTargetChoice.SACRIFICE_GOBLIN
is that mean i can also use this code?
Code: Select all
MagicTargetChoice.SACRIFICE_CLERIC


or do i have to do more override ?
i don't mind if you would show me how to add this code, i might can make more code for other tribal, if necessary. i searched in "gatherer" site, found only 2 cards uses "sacrifice a cleric" cost. far less compared to "sacrifice a goblin".
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 » 17 Jul 2013, 05:40

Unfortunate the code for MagicTargetChoice.SACRIFICE_CLERIC does not exist as there is no other card that needs it. You'll need to write your own. Thanks to this discussion, I was able to find out about some engine limitations that makes it quite hard to write your own target choice. These have been fixed. To get these fixes, you need to use the current release candidate of 1.40 from https://buildhive.cloudbees.com/job/mel ... a-1.40.zip

Below is an example of writing SACRIFICE_CLERIC.

Image

Magarena/scripts/Cabal_Archon.txt
Code: Select all
name=Cabal Archon
url=http://magiccards.info/on/en/129.html
image=http://magiccards.info/scans/en/on/129.jpg
value=3.708
rarity=U
type=Creature
subtype=Human,Cleric
cost={2}{B}
pt=2/2
timing=main
requires_groovy_code
Magarena/scripts/Cabal_Archon.groovy
Code: Select all
[
    new MagicPermanentActivation(
        new MagicActivationHints(MagicTiming.Removal),
        "Life"
    ) {

        @Override
        public MagicEvent[] getCostEvent(final MagicPermanent source) {
            final MagicTargetChoice targetChoice = new MagicTargetChoice(
                MagicTargetFilter.Factory.tribal(MagicSubType.Cleric, MagicTargetFilter.Control.You),
                false,
                MagicTargetHint.None,
                "a Cleric to sacrifice"
            );
            return [
                new MagicPayManaCostEvent(source,"{B}"),
                new MagicSacrificePermanentEvent(source,targetChoice)
            ];
        }

        @Override
        public MagicEvent getPermanentEvent(final MagicPermanent source,final MagicPayedCost payedCost) {
            return new MagicEvent(
                source,
                MagicTargetChoice.NEG_TARGET_PLAYER,
                this,
                "Target player\$ loses 2 life and PN gains 2 life."
            );
        }

        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
            event.processTargetPlayer(game,new MagicPlayerAction() {
                public void doAction(final MagicPlayer player) {
                    game.doAction(new MagicChangeLifeAction(player, -2));
                    game.doAction(new MagicChangeLifeAction(event.getPlayer(), 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 hong yie » 17 Jul 2013, 06:38

thank's melvin,
u even include "cabal archon", that was in my next target list.
i will try to complete "starlit sanctum" that need this sacrifice ability.
... and some other interesting things coming up. :)
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 » 17 Jul 2013, 21:53

Image

blessed_orator.txt
Code: Select all
name=Blessed Orator
url=http://magiccards.info/9e/en/6.html
image=http://magiccards.info/scans/en/9e/6.jpg
value=2.662
rarity=U
type=Creature
subtype=Human,Cleric
cost={3}{W}
pt=1/4
static=all
timing=fmain
requires_groovy_code
blessed_orator.groovy
Code: Select all
[
    new MagicStatic(
        MagicLayer.ModPT,
        MagicTargetFilter.TARGET_CREATURE_YOU_CONTROL) {
        @Override
        public void modPowerToughness(final MagicPermanent source,final MagicPermanent permanent,final MagicPowerToughness pt) {
            pt.add(0,1);
        }
        @Override
        public boolean condition(final MagicGame game,final MagicPermanent source,final MagicPermanent target) {
            return source != target;
        }
    }
]
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 » 17 Jul 2013, 22:30

Image

doubtless_one.txt
Code: Select all
name=Doubtless One
url=http://magiccards.info/on/en/27.html
image=http://magiccards.info/scans/en/on/27.jpg
value=4.105
rarity=U
type=Creature
subtype=Cleric,Avatar
cost={3}{W}
ability=lifelink
timing=main
requires_groovy_code
doubtless_one.groovy
Code: Select all
[
    new MagicCDA() {
        @Override
        public void modPowerToughness(final MagicGame game,final MagicPlayer player,final MagicPowerToughness pt) {
            final int amount =
                player.getNrOfPermanentsWithSubType(MagicSubType.Cleric) +
                player.getOpponent().getNrOfPermanentsWithSubType(MagicSubType.Cleric);
            pt.set(amount,amount);
        }
    }
]
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 » 18 Jul 2013, 11:05

Thanks for both cards! Added in https://code.google.com/p/magarena/sour ... 94f14f663b and https://code.google.com/p/magarena/sour ... eea2284c29

The image for Doubtless One led me to double check all cards with "Whenever NAME deals damage, you gain that much life." There is another card like this, Mourning Thrull, that is also using lifelink. I've fixed them both to use a triggered ability that goes on the stack (unlike lifelink, which doesn't go on the stack).
User avatar
melvin
AI Programmer
 
Posts: 1062
Joined: 21 Mar 2010, 12:26
Location: Singapore
Has thanked: 36 times
Been thanked: 459 times

PreviousNext

Return to Magarena

Who is online

Users browsing this forum: No registered users and 7 guests

Main Menu

User Menu

Our Partners


Who is online

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

Login Form