Programming a card
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
Programming a card
by cyclope » 28 Sep 2009, 18:19
Hello , i'm french and i'm very interested in your mtg forge game.
I want to add to the cards the enchant "armadillo cloak" but i don't know the java language...
so , after looking at card factory , i tried to write the code for this card...
Is my code correct or no ? could anyone help me?
//*************** START *********** START **************************
if(cardName.equals("Armadillo Cloak"))
{
final SpellAbility spell = new Spell(card)
{
private static final long serialVersionUID = 4227124619270545652L;
public boolean canPlayAI()
{
CardList list = new CardList(AllZone.Computer_Play.getCards());
list = list.getType("Creature");
if(list.isEmpty())
return false;
//else
CardListUtil.sortAttack(list);
CardListUtil.sortFlying(list);
setTargetCard(list.get(0));
return true;
}//canPlayAI()
public void resolve()
{
PlayerZone play = AllZone.getZone(Constant.Zone.Play, card.getController());
play.add(card);
Card c = getTargetCard();
if(AllZone.GameAction.isCardInPlay(c) && CardFactoryUtil.canTarget(card, c) )
{
card.enchantCard(c);
System.out.println("Enchanted: " +getTargetCard());
}
}//resolve()
};//SpellAbility
card.clearSpellAbility();
card.addSpellAbility(spell);
Command onEnchant = new Command()
{
public void execute()
{
if (card.isEnchanting())
{
Card crd = card.getEnchanting().get(0);
crd.addExtrinsicKeyword("Trample");
crd.addExtrinsicKeyword("Lifelink");
crd.addSemiPermanentAttackBoost(2);
crd.addSemiPermanentDefenseBoost(2);
}
}//execute()
};//Command
Command onUnEnchant = new Command()
{
public void execute()
{
if (card.isEnchanting())
{
Card crd = card.getEnchanting().get(0);
crd.removeExtrinsicKeyword("Trample");
crd.removeExtrinsicKeyword("Lifelink");
crd.addSemiPermanentAttackBoost(-2);
crd.addSemiPermanentDefenseBoost(-2);
}
}//execute()
};//Command
Command onLeavesPlay = new Command()
{
public void execute()
{
if (card.isEnchanting())
{
Card crd = card.getEnchanting().get(0);
card.unEnchantCard(crd);
}
}
};
card.setEnchant(onEnchant);
card.setUnEnchant(onUnEnchant);
card.setLeavesPlay(onLeavesPlay);
spell.setBeforePayMana(CardFactoryUtil.input_targetCreature(spell));
}//*************** END ************ END **************************
I want to add to the cards the enchant "armadillo cloak" but i don't know the java language...
so , after looking at card factory , i tried to write the code for this card...
Is my code correct or no ? could anyone help me?
//*************** START *********** START **************************
if(cardName.equals("Armadillo Cloak"))
{
final SpellAbility spell = new Spell(card)
{
private static final long serialVersionUID = 4227124619270545652L;
public boolean canPlayAI()
{
CardList list = new CardList(AllZone.Computer_Play.getCards());
list = list.getType("Creature");
if(list.isEmpty())
return false;
//else
CardListUtil.sortAttack(list);
CardListUtil.sortFlying(list);
setTargetCard(list.get(0));
return true;
}//canPlayAI()
public void resolve()
{
PlayerZone play = AllZone.getZone(Constant.Zone.Play, card.getController());
play.add(card);
Card c = getTargetCard();
if(AllZone.GameAction.isCardInPlay(c) && CardFactoryUtil.canTarget(card, c) )
{
card.enchantCard(c);
System.out.println("Enchanted: " +getTargetCard());
}
}//resolve()
};//SpellAbility
card.clearSpellAbility();
card.addSpellAbility(spell);
Command onEnchant = new Command()
{
public void execute()
{
if (card.isEnchanting())
{
Card crd = card.getEnchanting().get(0);
crd.addExtrinsicKeyword("Trample");
crd.addExtrinsicKeyword("Lifelink");
crd.addSemiPermanentAttackBoost(2);
crd.addSemiPermanentDefenseBoost(2);
}
}//execute()
};//Command
Command onUnEnchant = new Command()
{
public void execute()
{
if (card.isEnchanting())
{
Card crd = card.getEnchanting().get(0);
crd.removeExtrinsicKeyword("Trample");
crd.removeExtrinsicKeyword("Lifelink");
crd.addSemiPermanentAttackBoost(-2);
crd.addSemiPermanentDefenseBoost(-2);
}
}//execute()
};//Command
Command onLeavesPlay = new Command()
{
public void execute()
{
if (card.isEnchanting())
{
Card crd = card.getEnchanting().get(0);
card.unEnchantCard(crd);
}
}
};
card.setEnchant(onEnchant);
card.setUnEnchant(onUnEnchant);
card.setLeavesPlay(onLeavesPlay);
spell.setBeforePayMana(CardFactoryUtil.input_targetCreature(spell));
}//*************** END ************ END **************************
- cyclope
- Posts: 69
- Joined: 28 Sep 2009, 18:08
- Has thanked: 0 time
- Been thanked: 0 time
Re: Programming a card
by DennisBergkamp » 28 Sep 2009, 20:45
Hello and welcome to the forums!
Yep, it looks like this code should work just fine. I'll add it it in!
Yep, it looks like this code should work just fine. I'll add it it in!
-
DennisBergkamp - AI Programmer
- Posts: 2602
- Joined: 09 Sep 2008, 15:46
- Has thanked: 0 time
- Been thanked: 0 time
Re: Programming a card
by DennisBergkamp » 28 Sep 2009, 20:58
By the way, does anyone know if there's some reason Armadillo Cloak's text is:
"Enchant creature
Enchanted creature gets +2/+2 and has trample.
Whenever enchanted creature deals damage, you gain that much life."
Instead of :
"Enchant creature
Enchanted creature gets +2/+2 and has trample and lifelink."
???
"Enchant creature
Enchanted creature gets +2/+2 and has trample.
Whenever enchanted creature deals damage, you gain that much life."
Instead of :
"Enchant creature
Enchanted creature gets +2/+2 and has trample and lifelink."

-
DennisBergkamp - AI Programmer
- Posts: 2602
- Joined: 09 Sep 2008, 15:46
- Has thanked: 0 time
- Been thanked: 0 time
Re: Programming a card
by silly freak » 28 Sep 2009, 21:01
it's the same as with Spirit Link 
hint: it wouldn't matter if the card had "enchant creature you control"

hint: it wouldn't matter if the card had "enchant creature you control"
___
where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
- silly freak
- DEVELOPER
- Posts: 598
- Joined: 26 Mar 2009, 07:18
- Location: Vienna, Austria
- Has thanked: 93 times
- Been thanked: 25 times
Re: Programming a card
by DennisBergkamp » 28 Sep 2009, 21:03
Ahhh, that's right, I forgot about that 
Which, I guess wouldn't make this a 100% correct implementation of this card (controller of the creature will gain the life).

Which, I guess wouldn't make this a 100% correct implementation of this card (controller of the creature will gain the life).
-
DennisBergkamp - AI Programmer
- Posts: 2602
- Joined: 09 Sep 2008, 15:46
- Has thanked: 0 time
- Been thanked: 0 time
Re: Programming a card
by Rob Cashwalker » 29 Sep 2009, 03:25
With the recent changing of lifelink, they decided to revert many Oracle rules text to the original wording to preserve their functionality.
The Force will be with you, Always.
-
Rob Cashwalker - Programmer
- Posts: 2167
- Joined: 09 Sep 2008, 15:09
- Location: New York
- Has thanked: 5 times
- Been thanked: 40 times
Re: Programming a card
by Marek14 » 29 Sep 2009, 05:27
Yes, but NOT Armadillo Cloak. That was never in Oracle with lifelink.Rob Cashwalker wrote:With the recent changing of lifelink, they decided to revert many Oracle rules text to the original wording to preserve their functionality.
Speaking of lifelink, could it be added according to M10 rules now (simultaneous with damage, non-stacking)? The old code, of course, is still useful for older cards.
Re: Programming a card
by DennisBergkamp » 29 Sep 2009, 06:37
Hmm, I don't think lifelink "stacks" anymore in forge (I mean yes, it still does get put on the stack, but multiple instances will not do anything).
I'll see if I can change it according to the M10 rules. I guess this means it doesn't show up on the stack at all? And the lifegain happens exactly when damage happens?
I'll see if I can change it according to the M10 rules. I guess this means it doesn't show up on the stack at all? And the lifegain happens exactly when damage happens?
-
DennisBergkamp - AI Programmer
- Posts: 2602
- Joined: 09 Sep 2008, 15:46
- Has thanked: 0 time
- Been thanked: 0 time
Re: Programming a card
by silly freak » 29 Sep 2009, 08:28
yes, that's it like. btw, is there already wither in forge? don't remember at all... if so, that would be the same
___
where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
- silly freak
- DEVELOPER
- Posts: 598
- Joined: 26 Mar 2009, 07:18
- Location: Vienna, Austria
- Has thanked: 93 times
- Been thanked: 25 times
Re: Programming a card
by Marek14 » 29 Sep 2009, 09:28
Wither is there, but remember that you can have wither+lifelink (so the code mustn't be mutually exclusive).silly freak wrote:yes, that's it like. btw, is there already wither in forge? don't remember at all... if so, that would be the same
Looking through the Visual Spoiler, there's not too many unimplementable cards in Zendikar. I think that the landfall cards, in particular, will make the random decks better.
I was wondering about Rite of Replication - how does Forge show token copies of cards now? I came with an idea of having a generic "token copy" image and overlay the card image with it. Perhaps a big red stamp reading "FAKE"?

Re: Programming a card
by Rob Cashwalker » 29 Sep 2009, 14:49
A copy of a card is just that, a copy. The only part of the rules that care about it being a token would be if something referenced a "non-token". Otherwise, they are supposed to be exact copies, card image and all. Sure, there could be some sort of marker to indicate it's a token, but I think "FAKE" isn't it.
The Force will be with you, Always.
-
Rob Cashwalker - Programmer
- Posts: 2167
- Joined: 09 Sep 2008, 15:09
- Location: New York
- Has thanked: 5 times
- Been thanked: 40 times
Re: Programming a card
by silly freak » 29 Sep 2009, 15:33
IMO FAKE is great. probably depends on display size...
___
where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
- silly freak
- DEVELOPER
- Posts: 598
- Joined: 26 Mar 2009, 07:18
- Location: Vienna, Austria
- Has thanked: 93 times
- Been thanked: 25 times
Re: Programming a card
by cyclope » 29 Sep 2009, 18:51
So , my code would be correct if it was "lifelink" but this don't have "lifelink"... so I can't had it to the implemented cards...
- cyclope
- Posts: 69
- Joined: 28 Sep 2009, 18:08
- Has thanked: 0 time
- Been thanked: 0 time
Re: Programming a card
by DennisBergkamp » 29 Sep 2009, 19:52
No, unless a lot of people object, I'll add it in...
There are only two cases in which it would be incorrect:
- If you cast this on a creature an opponent controls (99 out of a 100 times you wouldn't do this).
- If the enchanted creature gets stolen somehow (Control Magic, ...).
For now, I'll add it in... I will try and fix the small issues it has at some point in the future (in which case Spirit Link could be added too).
There are only two cases in which it would be incorrect:
- If you cast this on a creature an opponent controls (99 out of a 100 times you wouldn't do this).
- If the enchanted creature gets stolen somehow (Control Magic, ...).
For now, I'll add it in... I will try and fix the small issues it has at some point in the future (in which case Spirit Link could be added too).
-
DennisBergkamp - AI Programmer
- Posts: 2602
- Joined: 09 Sep 2008, 15:46
- Has thanked: 0 time
- Been thanked: 0 time
Re: Programming a card
by silly freak » 30 Sep 2009, 08:06
and a third case: two spirit links. this is still a triggered ability, which means it does stack
magic has more twists than one can think of ^^
magic has more twists than one can think of ^^
___
where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
- silly freak
- DEVELOPER
- Posts: 598
- Joined: 26 Mar 2009, 07:18
- Location: Vienna, Austria
- Has thanked: 93 times
- Been thanked: 25 times
Who is online
Users browsing this forum: No registered users and 54 guests