Adding new cards with Groovy
by ubeefx
Moderators: ubeefx, beholder, melvin, ShawnieBoy, Lodici, CCGHQ Admins
Re: Adding new cards with Groovy
by 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));
}
});
}
}
]
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.

-
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 » 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]
)
-
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 » 09 Jun 2014, 08:20
- Code: Select all
new MagicPlayCardAction(
card,
event.getPlayer(),
[MagicPlayMod.TAPPED]
)
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.

-
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 » 10 Jun 2014, 08:38
Sure, that will work.hong yie wrote:this function will work on "tapped" too?
- Code: Select all
new MagicPlayCardAction(
card,
event.getPlayer(),
[MagicPlayMod.TAPPED]
)
Like in "victimize"?
See the mini example belowhong 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.
- Code: Select all
final MagicCard card = player.getLibrary().getCardAtTop();
boolean isGoblinOrBlack = card.hasSubType(MagicSubType.Goblin) || card.hasColor(MagicColor.Black);
-
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 » 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.
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.
-
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 » 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?
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?
-
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 ShawnieBoy » 08 Jul 2014, 04:45
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.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?
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.
-
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
by 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.

Master_of_the_Feast.txt

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.
- 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));
}
}
]
-
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 » 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
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.
-
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 » 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
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.
-
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 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.
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.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.
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.
-
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
by hong yie » 16 Jul 2014, 07:50
here is my attempt to script Phyrexian Unlife
to trigger this code in MagicDealDamageAction.java any property / method i can use?
- 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;
}
}
]
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));
}
-
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 » 10 Aug 2014, 06:25
"damage is dealt to you as though its source had infect" can't be implemented in groovy code at the moment.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?
-
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 ShawnieBoy » 11 Aug 2014, 01:20
Maybe a replacement effect that adds poison counters using the .getDealtAmount() value in some way (But not actually doing any damage?!)melvin wrote:"damage is dealt to you as though its source had infect" can't be implemented in groovy code at the moment.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?
-
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
by 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
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.
- 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
))
});
}
}
]
-
hong yie - Programmer
- Posts: 216
- Joined: 10 Mar 2013, 06:44
- Location: Jakarta
- Has thanked: 75 times
- Been thanked: 9 times
Who is online
Users browsing this forum: No registered users and 12 guests