Adding new cards with Groovy
by ubeefx
Moderators: ubeefx, beholder, melvin, ShawnieBoy, Lodici, CCGHQ Admins
Re: Adding new cards with Groovy
by melvin » 06 Oct 2013, 05:55
New in 1.43, MagicHeroicTrigger in groovy script.

Magarena/scripts/Wingsteed_Rider.txt

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
- 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))
}
}
]
-
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
by melvin » 06 Oct 2013, 05:56
New in 1.43, 'monstrosity <n>' in ability property of card script

Magarena/scripts/Nessian_Asp.txt

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
-
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
by melvin » 06 Oct 2013, 05:57
New in 1.43, MagicWhenBecomesMonstrousTrigger in groovy script.

Magarena/scripts/Arbor_Colossus.txt

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
- 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));
}
});
}
}
]
-
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
by melvin » 06 Oct 2013, 05:58
New in 1.43, 'bestow <mana cost>' in ability property of card script.

Magarena/scripts/Cavern_Lampad.txt

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
-
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
by melvin » 06 Oct 2013, 09:07
New in 1.43, getDevotion method on MagicPlayer in groovy script.

Magarena/scripts/Purphoros__God_of_the_Forge.txt

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
- 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));
}
}
}
]
-
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
by melvin » 06 Oct 2013, 09:26
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)
-
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
by jerichopumpkin » 06 Oct 2013, 12:54
Thank you, now it works fine! I've already submitted it with ProjectFiremind as alwaysmelvin wrote:Both are solved with conditions, which is passed as an array before the activation hint. i.e.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.
- Code: Select all
new MagicCardActivation(
[TWO_OTHER_GREEN_CARDS_IN_HAND, MagicCondition.CARD_CONDITION]
new MagicActivationHints(MagicTiming.Main),
"Alt"
) {
...
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
}
};
- jerichopumpkin
- Posts: 212
- Joined: 12 Sep 2013, 11:21
- Has thanked: 19 times
- Been thanked: 13 times
Re: Adding new cards with Groovy
by ember hauler » 14 Oct 2013, 18:18
Trying to make Archangel of Thune:

card:
Thanks!

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
- 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
));
}
}
}
]
- 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.
Thanks!
- ember hauler
- Posts: 79
- Joined: 14 Aug 2013, 08:13
- Has thanked: 27 times
- Been thanked: 14 times
Re: Adding new cards with Groovy
by ember hauler » 14 Oct 2013, 18:54
Another problem is with Ashen Rider.

the card:

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
- 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));
}
});
}
}
]
- ember hauler
- Posts: 79
- Joined: 14 Aug 2013, 08:13
- Has thanked: 27 times
- Been thanked: 14 times
Re: Adding new cards with Groovy
by melvin » 15 Oct 2013, 01:19
The issue is this line:ember hauler wrote:Trying to make Archangel of Thune
- Code: Select all
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicPermanent otherPermanent) {
- Code: Select all
public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicLifeChangeTriggerData lifeChange) {
This is due to AI hinting, you can disable for your moves by unchecking "Remove unusual target choices" in the Preferences dialog.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.
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
-
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
by ember hauler » 15 Oct 2013, 05:41
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.melvin wrote:This is due to AI hinting, you can disable for your moves by unchecking "Remove unusual target choices" in the Preferences dialog.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.
- ember hauler
- Posts: 79
- Joined: 14 Aug 2013, 08:13
- Has thanked: 27 times
- Been thanked: 14 times
Re: Adding new cards with Groovy
by melvin » 15 Oct 2013, 07:15
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.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.
-
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
by ember hauler » 15 Oct 2013, 07:30
Thanks, it's working now, submitted thru Firemind.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.
- ember hauler
- Posts: 79
- Joined: 14 Aug 2013, 08:13
- Has thanked: 27 times
- Been thanked: 14 times
Re: Adding new cards with Groovy
by ember hauler » 15 Oct 2013, 07:35
So it's better to use NEG_TARGET_PERMANENT instead of TARGET_PERMANENT every time, right?melvin wrote: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.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.
- ember hauler
- Posts: 79
- Joined: 14 Aug 2013, 08:13
- Has thanked: 27 times
- Been thanked: 14 times
Re: Adding new cards with Groovy
by melvin » 15 Oct 2013, 07:37
Yes, it helps the AI to avoid making bad moves.ember hauler wrote:So it's better to use NEG_TARGET_PERMANENT instead of TARGET_PERMANENT every time, right?
-
melvin - AI Programmer
- Posts: 1062
- Joined: 21 Mar 2010, 12:26
- Location: Singapore
- Has thanked: 36 times
- Been thanked: 459 times
Who is online
Users browsing this forum: No registered users and 3 guests