Adding new cards with Groovy
by ubeefx
Moderators: ubeefx, beholder, melvin, ShawnieBoy, Lodici, CCGHQ Admins
Re: Adding new cards with Groovy
by hong yie » 25 Aug 2013, 10:29
how to apply script for
"search your library ...then put into hand" instead of onto battlefield?
"search your library ...then put into hand" instead of onto battlefield?
-
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
by melvin » 25 Aug 2013, 10:51
Typically those require a "reveal" action which is not yet implemented.
-
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 » 25 Aug 2013, 12:28

Magarena/scripts/Path_to_Exile.txt
- Code: Select all
name=Path to Exile
url=http://magiccards.info/mma/en/25.html
image=http://magiccards.info/scans/en/mma/25.jpg
removal=5
rarity=U
type=Instant
cost={W}
timing=removal
requires_groovy_code
- Code: Select all
[
new MagicSpellCardEvent() {
@Override
public MagicEvent getEvent(final MagicCardOnStack cardOnStack, final MagicPayedCost payedCost) {
return new MagicEvent(
cardOnStack,
MagicTargetChoice.NEG_TARGET_CREATURE,
MagicExileTargetPicker.create(),
this,
"Exile target creature\$. " +
"Its controller may search his or her library for a basic land card, put that card onto the battlefield tapped, then shuffle his or her library."
);
}
@Override
public void executeEvent(final MagicGame game, final MagicEvent event) {
event.processTargetPermanent(game,new MagicPermanentAction() {
public void doAction(final MagicPermanent creature) {
game.doAction(new MagicRemoveFromPlayAction(creature,MagicLocationType.Exile));
game.addEvent(new MagicSearchOntoBattlefieldEvent(
event.getSource(),
creature.getController(),
new MagicMayChoice(
"Search for a basic land card?",
MagicTargetChoice.BASIC_LAND_CARD_FROM_LIBRARY
),
MagicPlayMod.TAPPED
));
}
});
}
}
]
-
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 hong yie » 25 Aug 2013, 14:07
Need some testing...

Perilous_Forays.txt

Perilous_Forays.txt
- Code: Select all
name=Perilous Forays
url=http://magiccards.info/rav/en/176.html
image=http://magiccards.info/scans/en/rav/176.jpg
value=3.731
rarity=U
type=Enchantment
cost={3}{G}{G}
timing=enchantment
requires_groovy_code
- Code: Select all
[
new MagicPermanentActivation(
new MagicActivationHints(MagicTiming.Removal),
"Damage"
) {
@Override
public MagicEvent[] getCostEvent(final MagicPermanent source) {
return [
new MagicPayManaCostTapEvent("{1}"),
new MagicSacrificePermanentEvent(
source,
MagicTargetChoice.SACRIFICE_CREATURE
)
];
}
@Override
public MagicEvent getPermanentEvent(final MagicPermanent source, final MagicPayedCost payedCost) {
return new MagicEvent(
permanent,
this,
"PN searches his or her library for a basic land card and put that card onto the battlefield tapped. Then shuffle PN's library."
);
}
@Override
public void executeEvent(final MagicGame game, final MagicEvent event) {
game.addEvent(new MagicEvent(
event.getSource(),
MagicTargetChoice.BASIC_LAND_CARD_FROM_LIBRARY,
{
final MagicGame G, final MagicEvent E ->
E.processTargetCard(G, {
final MagicCard card ->
G.doAction(new MagicRemoveCardAction(card,MagicLocationType.OwnersLibrary));
G.doAction(new MagicPlayCardAction(card,event.getPlayer(),MagicPlayMod.TAPPED));
G.doAction(new MagicShuffleLibraryAction(event.getPlayer()));
} as MagicCardAction);
} as MagicEventAction,
"Selected basic land card\$."
));
}
}
]
-
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
by ember hauler » 25 Aug 2013, 19:56
Oh, yes!melvin wrote:Library search!
You made my day, man.
Keep up the good work!

- 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 » 26 Aug 2013, 13:52
Thanks for the encouragement!ember hauler wrote:Oh, yes!
You made my day, man.
Keep up the good work!

Magarena/scripts/Young_Pyromancer.txt
- Code: Select all
name=Young Pyromancer
url=http://magiccards.info/m14/en/163.html
image=http://magiccards.info/scans/en/m14/163.jpg
value=3.717
rarity=U
type=Creature
subtype=Human,Shaman
cost={1}{R}
pt=2/1
timing=main
requires_groovy_code
- Code: Select all
[
new MagicWhenOtherSpellIsCastTrigger() {
@Override
public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent,final MagicCardOnStack cardOnStack) {
return cardOnStack.isFriend(permanent) && cardOnStack.isInstantOrSorcery() ?
new MagicEvent(
permanent,
this,
"PN puts a 1/1 red Elemental creature token onto the battlefield."
) :
MagicEvent.NONE;
}
@Override
public void executeEvent(final MagicGame game, final MagicEvent event) {
game.doAction(new MagicPlayTokenAction(
event.getPlayer(),
TokenCardDefinitions.get("R Elemental")
));
}
}
]
-
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 hong yie » 26 Aug 2013, 16:32

Darksteel_Colossus.txt
- Code: Select all
name=Darksteel Colossus
url=http://magiccards.info/m10/en/208.html
image=http://magiccards.info/scans/en/m10/208.jpg
value=4.604
ability=trample,indestructible,graveyard to library
rarity=M
type=Artifact,Creature
subtype=Golem
cost={11}
pt=11/11
timing=main

- Code: Select all
name=Blightsteel Colossus
url=http://magiccards.info/mbs/en/99.html
image=http://magiccards.info/scans/en/mbs/99.jpg
value=4.055
ability=trample,infect,indestructible,graveyard to library
rarity=M
type=Artifact,Creature
subtype=Golem
cost={12}
pt=11/11
timing=main

Progenitus.txt
- Code: Select all
name=Progenitus
url=http://magiccards.info/mma/en/182.html
image=http://magiccards.info/scans/en/mma/182.jpg
value=4.315
rarity=M
type=Legendary,Creature
subtype=Hydra,Avatar
cost={W}{W}{U}{U}{B}{B}{R}{R}{G}{G}
pt=10/10
ability=unblockable,shroud,graveyard to library
timing=main
requires_groovy_code
- Code: Select all
[
new MagicIfDamageWouldBeDealtTrigger(MagicTrigger.PREVENT_DAMAGE) {
@Override
public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent,final MagicDamage damage) {
if (damage.getTarget()==permanent) {
damage.prevent();
}
return MagicEvent.NONE;
}
}
]
-
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
by melvin » 28 Aug 2013, 08:16
Now that I think about it again, we should just go ahead and have some cards with this effect but leave out the reveal part for now. Seems to be not so easy to track revealed cards for the purpose of the AI, will need more time to iron it out.hong yie wrote:how to apply script for
"search your library ...then put into hand" instead of onto battlefield?
Here is something I put together to test this effect, uses a new event MagicSearchIntoHandEvent

Magarena/scripts/Sylvan_Scrying.txt
- Code: Select all
name=Sylvan Scrying
url=http://magiccards.info/10e/en/302.html
image=http://magiccards.info/scans/en/10e/302.jpg
value=4.638
rarity=U
type=Sorcery
cost={1}{G}
timing=main
requires_groovy_code
- Code: Select all
[
new MagicSpellCardEvent() {
@Override
public MagicEvent getEvent(final MagicCardOnStack cardOnStack,final MagicPayedCost payedCost) {
return new MagicEvent(
cardOnStack,
this,
"PN searches his or her library for a land card, reveal it, and put it into his or her hand. Then shuffle PN's library."
);
}
@Override
public void executeEvent(final MagicGame game, final MagicEvent event) {
game.addEvent(new MagicSearchIntoHandEvent(
event,
MagicTargetChoice.LAND_CARD_FROM_LIBRARY
));
}
}
]
-
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 hong yie » 28 Aug 2013, 22:48

Civic_Wayfinder.txt
- Code: Select all
name=Civic Wayfinder
url=http://magiccards.info/dpa/en/56.html
image=http://magiccards.info/scans/en/dpa/56.jpg
value=3.524
rarity=C
type=Creature
subtype=Elf,Warrior,Druid
cost={2}{G}
pt=2/2
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,
this,
"PN searches his or her library for a land card, reveal it, and put it into his or her hand. Then shuffle PN's library."
);
}
@Override
public void executeEvent(final MagicGame game, final MagicEvent event) {
game.addEvent(new MagicSearchIntoHandEvent(
event,
MagicTargetChoice.BASIC_LAND_CARD_FROM_LIBRARY
));
}
}
]

Borderland_Ranger.txt
- Code: Select all
name=Borderland Ranger
url=http://magiccards.info/avr/en/169.html
image=http://magiccards.info/scans/en/avr/169.jpg
value=3.593
rarity=C
type=Creature
subtype=Human,Scout
cost={2}{G}
pt=2/2
timing=main
requires_groovy_code=Civic Wayfinder

Primeval_Titan.txt
- Code: Select all
name=Primeval Titan
url=http://magiccards.info/m12/en/188.html
image=http://magiccards.info/scans/en/m12/188.jpg
value=4.416
ability=trample
rarity=M
type=Creature
subtype=Giant
cost={4}{G}{G}
pt=6/6
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,
this,
"PN may search his or her library for up to two basic land cards and put them onto the battlefield tapped, then shuffle his or her library."
);
}
@Override
public void executeEvent(final MagicGame game, final MagicEvent event) {
game.addEvent(new MagicSearchOntoBattlefieldEvent(
event,
new MagicMayChoice(
"Search for a basic land card?",
MagicTargetChoice.BASIC_LAND_CARD_FROM_LIBRARY
),
MagicPlayMod.TAPPED
));
game.addEvent(new MagicSearchOntoBattlefieldEvent(
event,
new MagicMayChoice(
"Search for a basic land card?",
MagicTargetChoice.BASIC_LAND_CARD_FROM_LIBRARY
),
MagicPlayMod.TAPPED
));
}
},
new MagicWhenAttacksTrigger() {
@Override
public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent,final MagicPermanent creature) {
return (permanent == creature) ?
new MagicEvent(
permanent,
this,
"PN may search his or her library for up to two basic land cards and put them onto the battlefield tapped, then shuffle his or her library."
):
MagicEvent.NONE;
}
@Override
public void executeEvent(final MagicGame game, final MagicEvent event) {
game.addEvent(new MagicSearchOntoBattlefieldEvent(
event,
new MagicMayChoice(
"Search for a basic land card?",
MagicTargetChoice.BASIC_LAND_CARD_FROM_LIBRARY
),
MagicPlayMod.TAPPED
));
game.addEvent(new MagicSearchOntoBattlefieldEvent(
event,
new MagicMayChoice(
"Search for a basic land card?",
MagicTargetChoice.BASIC_LAND_CARD_FROM_LIBRARY
),
MagicPlayMod.TAPPED
));
}
}
]
-
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
by melvin » 29 Aug 2013, 01:42
@hong yie: Looks good! Don't forget to submit on http://www.firemind.ch/card_script_submissions/new
-
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 hong yie » 29 Aug 2013, 15:13

Thorn_Elemental.txt
- Code: Select all
name=Thorn Elemental
url=http://magiccards.info/8e/en/283.html
image=http://magiccards.info/scans/en/8e/283.jpg
value=4.487
rarity=R
type=Creature
subtype=Elemental
cost={5}{G}{G}
pt=7/7
timing=main
requires_groovy_code
- Code: Select all
[
new MagicWhenBecomesBlockedTrigger() {
@Override
public MagicEvent executeTrigger(
final MagicGame game,
final MagicPermanent permanent,
final MagicPermanent attacker) {
return (permanent == attacker) ?
new MagicEvent(
permanent,
new MagicMayChoice(),
this,
"PN may\$ have SN deal its combat damage " +
"to defending player as though it weren't blocked."
):
MagicEvent.NONE;
}
@Override
public void executeEvent(final MagicGame game, final MagicEvent event) {
if (event.isYes()) {
final MagicPermanent permanent = event.getPermanent();
final MagicDamage damage = MagicDamage.Combat(
permanent,
event.getPlayer().getOpponent(),
permanent.getPower()
);
game.doAction(new MagicDealDamageAction(damage));
game.doAction(MagicChangeStateAction.Set(
permanent,
MagicPermanentState.NoCombatDamage
));
}
}
}
]

Pestilence_Demon.txt
- Code: Select all
name=Pestilence Demon
url=http://magiccards.info/roe/en/124.html
image=http://magiccards.info/scans/en/roe/124.jpg
value=4.387
rarity=R
type=Creature
subtype=Demon
cost={5}{B}{B}{B}
pt=7/6
ability=flying
timing=main
requires_groovy_code
- Code: Select all
[
new MagicPermanentActivation(
new MagicActivationHints(MagicTiming.None),"Damage"
) {
@Override
public MagicEvent[] getCostEvent(final MagicPermanent source) {
return [
new MagicPayManaCostEvent(source,"{B}")
];
}
@Override
public MagicEvent getPermanentEvent(final MagicPermanent source,final MagicPayedCost payedCost) {
return new MagicEvent(
source,
this,
"SN deals 1 damage to all creatures and players."
);
}
@Override
public void executeEvent(final MagicGame game, final MagicEvent event) {
final Collection<MagicPermanent> targets =
game.filterPermanents(event.getPlayer(),MagicTargetFilter.TARGET_CREATURE);
for (final MagicPermanent target : targets) {
final MagicDamage damage=new MagicDamage(event.getSource(),target,1);
game.doAction(new MagicDealDamageAction(damage));
}
for (final MagicPlayer player : game.getPlayers()) {
final MagicDamage damage=new MagicDamage(event.getSource(),player,1);
game.doAction(new MagicDealDamageAction(damage));
}
}
}
]
-
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
by hong yie » 29 Aug 2013, 15:58

Vinelasher_Kudzu.txt
- Code: Select all
name=Vinelasher Kudzu
url=http://magiccards.info/rav/en/189.html
image=http://magiccards.info/scans/en/rav/189.jpg
value=4.470
rarity=R
type=Creature
subtype=Plant
cost={1}{G}
pt=1/1
timing=main
requires_groovy_code
- Code: Select all
[
new MagicLandfallTrigger() {
@Override
public MagicEvent getEvent(final MagicPermanent permanent) {
return new MagicEvent(
permanent,
this,
"PN 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
));
}
}
]
-
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
by melvin » 30 Aug 2013, 01:03
Thanks! I've merged them in from firemind.
Thorn Elemental's groovy script looks the same as Rhox, in that case it is better to refer to Rhox's script in Thorn Elemental's card script like so to reduce duplication.
Thorn Elemental's groovy script looks the same as Rhox, in that case it is better to refer to Rhox's script in Thorn Elemental's card script like so to reduce duplication.
- Code: Select all
name=Thorn Elemental
url=http://magiccards.info/8e/en/283.html
image=http://magiccards.info/scans/en/8e/283.jpg
value=4.487
rarity=R
type=Creature
subtype=Elemental
cost={5}{G}{G}
pt=7/7
timing=main
requires_groovy_code=Rhox
-
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 » 01 Sep 2013, 05:30
Note the use of lord effect in ability property of card script.

Magarena/scripts/Balthor_the_Stout.txt

Magarena/scripts/Balthor_the_Stout.txt
- Code: Select all
name=Balthor the Stout
url=http://magiccards.info/tr/en/91.html
image=http://magiccards.info/scans/en/tr/91.jpg
value=4.238
rarity=R
type=Legendary,Creature
subtype=Dwarf,Barbarian
cost={1}{R}{R}
pt=2/2
ability=lord other barbarian creatures get +1/+1
static=all
timing=main
requires_groovy_code
- Code: Select all
[
new MagicPermanentActivation(
new MagicActivationHints(MagicTiming.Pump),
"Pump"
) {
@Override
public Iterable<MagicEvent> getCostEvent(final MagicPermanent source) {
return [new MagicPayManaCostEvent(source,"{R}")];
}
@Override
public MagicEvent getPermanentEvent(final MagicPermanent source,final MagicPayedCost payedCost) {
final MagicTargetChoice targetChoice = new MagicTargetChoice(
new MagicOtherPermanentTargetFilter(
MagicTargetFilter.TARGET_BARBARIAN,
source
),
true,
MagicTargetHint.Positive,
"another target Barbarian"
);
return new MagicEvent(
source,
targetChoice,
MagicPumpTargetPicker.create(),
this,
"Another target Barbarian creature\$ gets +1/+0 until end of turn."
);
}
@Override
public void executeEvent(final MagicGame game, final MagicEvent event) {
event.processTargetPermanent(game,new MagicPermanentAction() {
public void doAction(final MagicPermanent creature) {
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
Who is online
Users browsing this forum: No registered users and 13 guests