Adding new cards with Groovy
by ubeefx
Moderators: ubeefx, beholder, melvin, ShawnieBoy, Lodici, CCGHQ Admins
Re: Adding new cards with Groovy
by ShawnieBoy » 16 Feb 2014, 14:13
Nice work
I don't think there's templates on Firemind for Born of the Gods
I don't think there's templates on Firemind for Born of the Gods
-
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 melvin » 17 Feb 2014, 13:10
Magarena/scripts/Brimaz__King_of_Oreskos.txt
- Code: Select all
name=Brimaz, King of Oreskos
url=http://magiccards.info/bng/en/5.html
image=http://mtgimage.com/card/brimaz%2C%20king%20of%20oreskos.jpg
value=3.741
rarity=M
type=Legendary,Creature
subtype=Cat,Soldier
cost={1}{W}{W}
ability=vigilance
pt=3/4
timing=main
requires_groovy_code
- Code: Select all
[
new MagicWhenAttacksTrigger() {
@Override
public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent,final MagicPermanent attacker) {
return permanent == attacker ?
new MagicEvent(
permanent,
this,
"PN puts a 1/1 white Cat Soldier creature token with vigilance onto the battlefield attacking."
) :
MagicEvent.NONE;
}
@Override
public void executeEvent(final MagicGame game, final MagicEvent event) {
final MagicPlayer player=event.getPlayer();
game.doAction(new MagicPlayCardAction(
MagicCard.createTokenCard(
TokenCardDefinitions.get("1/1 white Cat Soldier creature token with vigilance"),
player
),
player,
[MagicPlayMod.ATTACKING]
));
}
},
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,
blocked,
this,
"PN puts a 1/1 white Cat Soldier creature token with vigilance onto the battlefield blocking RN."
):
MagicEvent.NONE;
}
@Override
public void executeEvent(final MagicGame game, final MagicEvent event) {
final MagicPlayer player=event.getPlayer();
final MagicPlayCardAction act = new MagicPlayCardAction(
MagicCard.createTokenCard(
TokenCardDefinitions.get("1/1 white Cat Soldier creature token with vigilance"),
player
),
player
);
game.doAction(act);
game.doAction(new MagicSetBlockerAction(event.getRefPermanent(), act.getPermanent()));
}
}
]
-
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 » 17 Feb 2014, 22:17
I've tried making Feast of Blood using MagicCardActivation conditions, and I must be doing something wrong as it is coming into play as a permanent, and not creating any effects:
- Code: Select all
name=Feast of Blood
url=http://magiccards.info/zen/en/88.html
image=http://mtgimage.com/card/feast%20of%20blood.jpg
value=4.013
rarity=U
type=Sorcery
cost={1}{B}
timing=main
requires_groovy_code
- Code: Select all
def TWO_OR_MORE_VAMPIRES_CONDITION = new MagicCondition() {
public boolean accept(final MagicSource source) {
return source.getController().getNrOfPermanents(MagicSubType.Vampire)>=2;
}
};
[
new MagicCardActivation(
[TWO_OR_MORE_VAMPIRES_CONDITION],
new MagicActivationHints(MagicTiming.Removal,true),
"Destroy"
) {
@Override
public Iterable<MagicEvent> getCostEvent(final MagicCard source) {
return source.getCostEvent();
}
@Override
public MagicEvent getEvent(final MagicCardOnStack cardOnStack, final MagicPayedCost payedCost) {
return new MagicEvent(
cardOnStack,
MagicTargetChoice.NEG_TARGET_CREATURE,
MagicDestroyTargetPicker.Destroy,
this,
"Destroy target creature\$. " +
"PN gains 4 life."
);
}
@Override
public void executeEvent(final MagicGame game, final MagicEvent event) {
event.processTargetPermanent(game, {
final MagicPermanent creature ->
game.doAction(new MagicDestroyAction(creature));
game.doAction(new MagicChangeLifeAction(event.getPlayer(),4));
});
}
}
]
-
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 melvin » 18 Feb 2014, 05:33
Currently there is no way to replace the default MagicCardActivation. I've just pushed a change that makes this possible in https://code.google.com/p/magarena/sour ... 1b865eec87
With this new method, the new MagicCardActivation should be written as follows:
The difference is the addition of the change method that calls the new setCardAct method. The getCostEvent method is redundant as it is the same as that provided by MagicCardActivation, I've removed it from the code below.
With this new method, the new MagicCardActivation should be written as follows:
The difference is the addition of the change method that calls the new setCardAct method. The getCostEvent method is redundant as it is the same as that provided by MagicCardActivation, I've removed it from the code below.
- Code: Select all
new MagicCardActivation(
[TWO_OR_MORE_VAMPIRES_CONDITION],
new MagicActivationHints(MagicTiming.Removal,true),
"Destroy"
) {
@Override
public void change(final MagicCardDefinition cdef) {
cdef.setCardAct(this);
}
@Override
public MagicEvent getEvent(final MagicCardOnStack cardOnStack, final MagicPayedCost payedCost) {
return new MagicEvent(
cardOnStack,
MagicTargetChoice.NEG_TARGET_CREATURE,
MagicDestroyTargetPicker.Destroy,
this,
"Destroy target creature\$. " +
"PN gains 4 life."
);
}
@Override
public void executeEvent(final MagicGame game, final MagicEvent event) {
event.processTargetPermanent(game, {
final MagicPermanent creature ->
game.doAction(new MagicDestroyAction(creature));
game.doAction(new MagicChangeLifeAction(event.getPlayer(),4));
});
}
}
]
-
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 » 18 Feb 2014, 05:44
That's great news! Thanks for that - Conditional spells ahoy
-
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 melvin » 18 Feb 2014, 05:52
Just found a bug, should add MagicCondition.CARD_CONDITION to the MagicCardActivation for Feast of Blood so that it follows the Sorcery type restriction
-
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 mike » 19 Feb 2014, 21:13
Sorry guys, just now gotten around to adding the BNG cards to firemind.chhong yie wrote:tried to submit this script to firemind.ch, but somehow this card is not recognized. i think this would be in Mike's Authority, maybe.
Anyway here it is
Re: Adding new cards with Groovy
by melvin » 25 Feb 2014, 05:24
Thanks, mikemike wrote:Sorry guys, just now gotten around to adding the BNG cards to firemind.ch
While watching the finals of PTBNG, I thought of a way we can encode phyrexian mana cards! Here is the first one.
Magarena/scripts/Mental_Misstep.txt
- Code: Select all
name=Mental Misstep
url=http://magiccards.info/nph/en/38.html
image=http://mtgimage.com/card/mental%20misstep.jpg
value=4.626
rarity=U
type=Instant
cost={U}
effect=Counter target spell with converted mana cost 1.
timing=counter
requires_groovy_code
- Code: Select all
[
new MagicCardActivation(
[MagicCondition.CARD_CONDITION],
new MagicActivationHints(MagicTiming.Counter,true),
"Pay 2 life"
) {
public Iterable<MagicEvent> getCostEvent(final MagicCard source) {
return [
new MagicPayLifeEvent(source, 2)
];
}
}
]
-
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 » 25 Feb 2014, 06:28
Nice - is it possible to add normal mana activations into the Alternate costs? For {RP} {RP}, Act of Aggression for example? (Well, several alternate costs: +2 life, +4 life)
-
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 melvin » 25 Feb 2014, 07:06
Sure, just add two MagicCardActivation with the respective costs.
For example,
For example,
- Code: Select all
return [
new MagicPayManaCostEvent(source,"{3}{R}")
new MagicPayLifeEvent(source, 2)
];
-
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 » 25 Feb 2014, 16:30
This is so cool
Hopefully there's a way to stitch this onto the MagicPayManaCostChoice and the MagicBuilderManaCost-type engine. I've had a look at the mana generation prompting but doesn't make a lot of sense to me. Would be good to have a choice prompt for Phyrexian mana while paying mana instead of when casting.
Choose a method to may {P/U}:
[{U}] [Pay 2 life]
then if the mana choice is chosen, it leads to the normal mana prompt:
Choose a mana source to pay
Otherwise the life is paid.
Hopefully there's a way to stitch this onto the MagicPayManaCostChoice and the MagicBuilderManaCost-type engine. I've had a look at the mana generation prompting but doesn't make a lot of sense to me. Would be good to have a choice prompt for Phyrexian mana while paying mana instead of when casting.
Choose a method to may {P/U}:
[{U}] [Pay 2 life]
then if the mana choice is chosen, it leads to the normal mana prompt:
Choose a mana source to pay
Otherwise the life is paid.
-
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 melvin » 26 Feb 2014, 01:51
Agree, originally I've been thinking along these lines, but the generation of different ways to pay mana for the AI is already quite complicated. Hacking it to tack on paying life would make it even more complex.
Hence the thought of using separate activation, which keeps it away from the core engine and can be done in the card itself using groovy code. Unless phyrexian mana becomes a regular thing (which I highly doubt since its flavor is tied to Phyrexia) it doesn't make sense to complicate the core to support it.
I'm looking at one more step to simplify it by providing syntax to specify alternative casting cost as a card ability. Then we can use our regular cost parsing to do the heavy lifting and do the work in the card script instead of in groovy code.
Hence the thought of using separate activation, which keeps it away from the core engine and can be done in the card itself using groovy code. Unless phyrexian mana becomes a regular thing (which I highly doubt since its flavor is tied to Phyrexia) it doesn't make sense to complicate the core to support it.
I'm looking at one more step to simplify it by providing syntax to specify alternative casting cost as a card ability. Then we can use our regular cost parsing to do the heavy lifting and do the work in the card script instead of in groovy code.
-
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 » 26 Feb 2014, 03:01
Cool - The only reason I wondered, is for permanents with activation costs using Phyrexian mana. We'll end up with having multiple activations with the same hint, as the hints on permanents relate to the effects, not how payment will be payed.
Insatiable Souleater, for example, would have ability hints of [Trample] [Trample] with no way to tell the difference.
Insatiable Souleater, for example, would have ability hints of [Trample] [Trample] with no way to tell the difference.
-
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 melvin » 26 Feb 2014, 03:15
We should give a different name to indicate payment of life, perhaps say "Phyrexian Trample". Not sure if it will fit on the dialog UI though.
-
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 » 26 Feb 2014, 16:07
As the UI buttons can accept the mana symbols - maybe a symbol to represent payment of life. So Birthing Pod would have hints of: [ :Search] [ {2Life} :Search] - Omitting the , and 'Sacrifice a creature' as they appear on both?
-
ShawnieBoy - Programmer
- Posts: 601
- Joined: 02 Apr 2012, 22:42
- Location: UK
- Has thanked: 80 times
- Been thanked: 50 times
Who is online
Users browsing this forum: No registered users and 17 guests