Implementing new Ability Factories and Card Support Code
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Agetian, friarsol, Blacksmith, KrazyTheFox, CCGHQ Admins
Re: Implementing new Ability Factories and Card Support Code
by friarsol » 30 Nov 2012, 17:19
Ahhh this is the issue where we need to use a popup for sacrificing as opposed to letting a user click on the battlefield, since the function isn't waiting for the input to finish. I'm not sure separating will really help, it's more about making sure the function waits until the input from the user is finished (or there's a callback implemented).Agetian wrote:Right, it's already passed completely to payCostDuringAbilityResolve, the problems start inside payCostDuringAbilityResolve when, closer to the end of it, certain calls are executed outside of the chain because they require input on behalf of the user and, as such, happen "delayed"... So, that's where the change must be made, but I'm afraid I can't quite grasp the essence of the change yet (at least outside of what I've outlined above). :\
- friarsol
- Global Moderator
- Posts: 7593
- Joined: 15 May 2010, 04:20
- Has thanked: 243 times
- Been thanked: 965 times
Re: Implementing new Ability Factories and Card Support Code
by Agetian » 30 Nov 2012, 17:54
So, in that case, maybe I can start by switching that call to a multiple-choose input box which would fire "immediately" as opposed to the delayed input select on the field?
- Agetian
- Agetian
- Agetian
- Programmer
- Posts: 3490
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
Re: Implementing new Ability Factories and Card Support Code
by Sloth » 30 Nov 2012, 18:32
Yes that would work. It's a little bit less user friendly, but it's easy to change. Take a look at the sacrificeHuman function in the SacrificeEffect class. It does exactly what you want.Agetian wrote:So, in that case, maybe I can start by switching that call to a multiple-choose input box which would fire "immediately" as opposed to the delayed input select on the field?
-

Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: Implementing new Ability Factories and Card Support Code
by Agetian » 30 Nov 2012, 18:36
Awesome, I'll get down to that tomorrow! Thanks for help!
- Agetian
- Agetian
- Agetian
- Programmer
- Posts: 3490
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
Re: Implementing new Ability Factories and Card Support Code
by Agetian » 01 Dec 2012, 12:18
Ok, I converted the Sacrifice cost to a selection menu and that part works perfectly well, but that alone is apparently not enough, because Propaganda itself also requires a cost that needs an input too (which is the payment of mana). That one, however, can't simply be replaced by a selection menu because that requires mandatory input from the user (that is, tapping lands). What, do you think, can be done here? Would something like this be viable:
Pass the parts of the cost to the constructors of InputPayManaCostAbility, InputPayDiscardCost etc., so that if it's not null, the next ability will be processed from the inside, and if it's null, then nothing will happen? It seems viable at first, but I don't understand one thing: by the time the payCostDuringAbilityResolve method gets to the input-based actions, there's only one of them remaining (and if there's more than one, an exception is thrown). How's it even possible to get two input-based actions to show up at that point so that they can be chained together in this or another way?
P.S. I double-checked it with some debug code and, indeed, only one ability ends up being sent to payCostDuringAbilityResolve if, let's say, I try swordshine's Leviathan card in play - only the "Sacrifice Two Islands" cost ever makes it into the method, the Propaganda mana cost doesn't even show up in cost parts.
Thanks in advance for your further suggestions.
- Agetian
Pass the parts of the cost to the constructors of InputPayManaCostAbility, InputPayDiscardCost etc., so that if it's not null, the next ability will be processed from the inside, and if it's null, then nothing will happen? It seems viable at first, but I don't understand one thing: by the time the payCostDuringAbilityResolve method gets to the input-based actions, there's only one of them remaining (and if there's more than one, an exception is thrown). How's it even possible to get two input-based actions to show up at that point so that they can be chained together in this or another way?
P.S. I double-checked it with some debug code and, indeed, only one ability ends up being sent to payCostDuringAbilityResolve if, let's say, I try swordshine's Leviathan card in play - only the "Sacrifice Two Islands" cost ever makes it into the method, the Propaganda mana cost doesn't even show up in cost parts.
Thanks in advance for your further suggestions.
- Agetian
- Agetian
- Programmer
- Posts: 3490
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
Re: Implementing new Ability Factories and Card Support Code
by Agetian » 01 Dec 2012, 12:37
Ok, nevermind my last post, I got it to work, my code needed some minor tweaking... as far as I can see, currently it looks fine, at least the Sacrifice cost can now be coupled with something else. I'll keep testing and will keep you posted. 
- Agetian
- Agetian
- Agetian
- Programmer
- Posts: 3490
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
Re: Implementing new Ability Factories and Card Support Code
by Agetian » 01 Dec 2012, 13:06
OK, I tested all four cards by swordshine that require to sacrifice lands for compatibility with Propaganda, both when I play them and when the AI plays them, and they seem to work fine both ways. Committing to SVN. Please test because I'm afraid that I could have inadvertently broken something in the Sacrifice mechanism.
- Agetian
- Agetian
- Agetian
- Programmer
- Posts: 3490
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
Re: Implementing new Ability Factories and Card Support Code
by Agetian » 02 Dec 2012, 05:32
I noticed that Leviathan and Exalted Dragon were flagged RemAIDeck, are you sure that the AI can't handle them? During my tests the AI used them pretty well, both with and without Propaganda, and the usage seemed intelligent enough, though I certainly haven't tested enough to be absolutely sure... I'm not sure if maybe the AI will just completely ruin its mana base using them whether it makes sense to attack with them or not, but it seems like the AI was conscious enough about deciding whether to attack with Leviathan or not (at least so it seemed at first glance xD).
P.S. On the other hand, something probably has to be done with Crypt Rats AI or it should be flagged RemAIDeck, someone reported that the AI doesn't obey mana color restriction, I tried to look into that but I couldn't find the place I'd need to change to add that restriction to the AI...
- Agetian
P.S. On the other hand, something probably has to be done with Crypt Rats AI or it should be flagged RemAIDeck, someone reported that the AI doesn't obey mana color restriction, I tried to look into that but I couldn't find the place I'd need to change to add that restriction to the AI...
- Agetian
- Agetian
- Programmer
- Posts: 3490
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
Re: Implementing new Ability Factories and Card Support Code
by Sloth » 02 Dec 2012, 07:39
Sometimes the AI makes attacks that are nearly useless, sacrificing a land in doing so can lead the AI to ruining its board position for nothing.Agetian wrote:I noticed that Leviathan and Exalted Dragon were flagged RemAIDeck, are you sure that the AI can't handle them? During my tests the AI used them pretty well, both with and without Propaganda, and the usage seemed intelligent enough, though I certainly haven't tested enough to be absolutely sure... I'm not sure if maybe the AI will just completely ruin its mana base using them whether it makes sense to attack with them or not, but it seems like the AI was conscious enough about deciding whether to attack with Leviathan or not (at least so it seemed at first glance xD).
The X to pay is set in the canPlay functions in the respective AbilityFactories. For example in DamageAllAi:Agetian wrote:P.S. On the other hand, something probably has to be done with Crypt Rats AI or it should be flagged RemAIDeck, someone reported that the AI doesn't obey mana color restriction, I tried to look into that but I couldn't find the place I'd need to change to add that restriction to the AI...
- Code: Select all
if (damage.equals("X") && sa.getSVar(damage).equals("Count$xPaid")) {
// Set PayX here to maximum value.
dmg = ComputerUtil.determineLeftoverMana(sa, ai);
source.setSVar("PayX", Integer.toString(dmg));
}
-

Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: Implementing new Ability Factories and Card Support Code
by Agetian » 02 Dec 2012, 09:44
OK I'll take a look at that function and will try to update it! Thanks, Sloth!
- Agetian
- Agetian
- Agetian
- Programmer
- Posts: 3490
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
Re: Implementing new Ability Factories and Card Support Code
by Agetian » 15 Dec 2012, 13:29
I added the support code for Last Rites to AF Discard (the ability to discard any number of cards via a two-panel interface similar to AF Reveal) and implemented Last Rites itself. However, since I'm not very good at coding cards, can someone please go over the implementation and take a look if everything is fine? It seems to work as intended, at least so it looks to me.
In particular, I'm not sure if for "any number" (of cards to discard), 0 cards is a valid choice (I think yes, cause MTG rules say that 0 is a valid choice for any number), and if 0 is chosen (no cards are discarded), the opponent still reveals his hand (currently, in my implementation he does).
Also, there's no AI support for this at the moment. I tested what the AI would do with Last Rites and it would use it as a typical "discard one card, then choose one card in human's hand and make him discard it" card. I'm not sure how to extend this functionality to make the AI play it correctly and more or less intelligently, if anyone is willing to take a look at that I'd be grateful.
- Agetian
In particular, I'm not sure if for "any number" (of cards to discard), 0 cards is a valid choice (I think yes, cause MTG rules say that 0 is a valid choice for any number), and if 0 is chosen (no cards are discarded), the opponent still reveals his hand (currently, in my implementation he does).
Also, there's no AI support for this at the moment. I tested what the AI would do with Last Rites and it would use it as a typical "discard one card, then choose one card in human's hand and make him discard it" card. I'm not sure how to extend this functionality to make the AI play it correctly and more or less intelligently, if anyone is willing to take a look at that I'd be grateful.
- Agetian
- Agetian
- Programmer
- Posts: 3490
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
Re: Implementing new Ability Factories and Card Support Code
by Agetian » 17 Dec 2012, 06:12
My next card support code project might be Split Cards. I've been reading up a bit on the rules for those cards and I have a few questions about the potential implementation:
- Since split cards have two costs, how should the deck editor treat them as far as CMC goes? E.g. when a card like that goes to deck, and, let's say, if the mana costs of two sides are 1 and 4, respectively, does the deck editor show it as a CMC 1 card going into deck, a CMC 4 card going into deck, or both of those? :\ (I mean in statistics).
- The same question is valid for colors in the deck editor - should the deck editor treat them as multicolored cards if each side has its own color?
- As far as rendering the mana cost goes, would it be OK to display it like <first card cost>/<second card cost>?
- As far as naming the card goes, we can use either a slash (/) or a double slash (//) notation. The card picture renderer will then, if it encounters a card named like that, convert the name to the appropriate full card picture name (e.g. NightDay.full.jpg, or whatever it's named, I'll look it up) and then load it.
Also, it is very important for me to understand where we stand at the moment. Let's say, if I were to come up with a mock script for the future "Night // Day" card implementation, what exactly could I do already? For example:
- Would it be possible, in principle, to code a card that would have two different effects with two different mana costs? As far as I know, Forge currently doesn't support the fact that each side has its own color, but outside of that issue, is that doable using, for instance, the flip card mechanism (for one and the same color)?
- Is it a good idea to base the Split card implementation on the existing Flip card implementation? That implementation has two alternate card scripts in one, I can see, which may be a good starting point for a similar implementation for the Split cards.
- How should we go about the fact that the card has two CMCs (one per side) and should yield two results to whichever effect is asking it for CMC? In Comprehensive Rules, it is said that the card can return two answers to the query (1, and 4 - if two sides have CMCs 1 and 4, respectively). What should I look into in order to extend the functionality in this respect?
- Is there anything else you believe I need to be aware of in order to implement this?
Thanks in advance for your help.
- Agetian
- Since split cards have two costs, how should the deck editor treat them as far as CMC goes? E.g. when a card like that goes to deck, and, let's say, if the mana costs of two sides are 1 and 4, respectively, does the deck editor show it as a CMC 1 card going into deck, a CMC 4 card going into deck, or both of those? :\ (I mean in statistics).
- The same question is valid for colors in the deck editor - should the deck editor treat them as multicolored cards if each side has its own color?
- As far as rendering the mana cost goes, would it be OK to display it like <first card cost>/<second card cost>?
- As far as naming the card goes, we can use either a slash (/) or a double slash (//) notation. The card picture renderer will then, if it encounters a card named like that, convert the name to the appropriate full card picture name (e.g. NightDay.full.jpg, or whatever it's named, I'll look it up) and then load it.
Also, it is very important for me to understand where we stand at the moment. Let's say, if I were to come up with a mock script for the future "Night // Day" card implementation, what exactly could I do already? For example:
- Would it be possible, in principle, to code a card that would have two different effects with two different mana costs? As far as I know, Forge currently doesn't support the fact that each side has its own color, but outside of that issue, is that doable using, for instance, the flip card mechanism (for one and the same color)?
- Is it a good idea to base the Split card implementation on the existing Flip card implementation? That implementation has two alternate card scripts in one, I can see, which may be a good starting point for a similar implementation for the Split cards.
- How should we go about the fact that the card has two CMCs (one per side) and should yield two results to whichever effect is asking it for CMC? In Comprehensive Rules, it is said that the card can return two answers to the query (1, and 4 - if two sides have CMCs 1 and 4, respectively). What should I look into in order to extend the functionality in this respect?
- Is there anything else you believe I need to be aware of in order to implement this?
Thanks in advance for your help.
- Agetian
- Agetian
- Programmer
- Posts: 3490
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
Re: Implementing new Ability Factories and Card Support Code
by krevett » 17 Dec 2012, 08:20
For cmc of split cards, I'll give you two famous examples for effects asking for cmc:
1) counterbalance: if you reveal a split card with cmc 1 and 4, you'll be able to counter spells with cmc 1 or 4 but not 5
2) dark confidant: if you reveal a split card with converted mana cost 1 and 4, you'll take 1 and 4 damage (5 in total
)
For color I think they're treated as multicolored except on the stack where they get the color of the side you play (I know that you can remove a Fire/Ice from the game to pay alternate cost of Force of Will for exammple)
I've tried to implement a "fake" Fire/Ice by myself (because I needed it for a deck) but they're still many issues:
The card has only one color
The card cmc is 2 (for counterbalance purpose
) but you'll take only 2 for revealing it with dark confidant (instead of 4)
Here's the code
Name:Fire/Ice
ManaCost:1 UR
Types:Instant
Text:
A:SP$ Effect | Cost$ 1 R | SP$ DealDamage | ValidTgts$ Creature,Player,Planeswalker | TgtPrompt$ Select target creature, player or planeswalker (1) | NumDmg$ 1 | SubAbility$ DBDamage2 | SpellDescription$ Fire deals 2 damage divided as you choose among one or two target creatures and/or players.
SVar:DBDamage2:DB$DealDamage | Cost$ 0 | ValidTgts$ Creature,Player,Planeswalker | TgtPrompt$ Select target creature, player or planeswalker (2) | NumDmg$ 1
A:SP$ Effect | Cost$ 1 U | SP$ Tap | ValidTgts$ Permanent | TgtPrompt$ Select target permanent | SubAbility$ DBDraw | SpellDescription$ Tap target permanent. Draw a card.
SVar:DBDraw:DB$Draw | Cost$ 0 | NumCards$ 1
K:CARDNAME is blue.
SVar:RemAIDeck:True
SVar:Rarity:Uncommon
SVar:Picture:http://www.wizards.com/global/images/magic/general/fire_ice.jpg
SetInfo:APC|Uncommon|http://magiccards.info/scans/en/ap/128.jpg
Oracle: Fire deals 2 damage divided as you choose among one or two target creatures and/or players.|| Tap target permanent. Draw a card.
End
As I said in another post I'm not a coder I've just opened your work in cardfolder and go from there to build me a temporary "almost working" version of Fire/Ice, waiting for people like you to implement the true feature
The picture is named FireIce.full and works correctly!
That's all I can do to try to help you a bit! Good luck.
1) counterbalance: if you reveal a split card with cmc 1 and 4, you'll be able to counter spells with cmc 1 or 4 but not 5
2) dark confidant: if you reveal a split card with converted mana cost 1 and 4, you'll take 1 and 4 damage (5 in total
For color I think they're treated as multicolored except on the stack where they get the color of the side you play (I know that you can remove a Fire/Ice from the game to pay alternate cost of Force of Will for exammple)
I've tried to implement a "fake" Fire/Ice by myself (because I needed it for a deck) but they're still many issues:
The card has only one color
The card cmc is 2 (for counterbalance purpose
Here's the code
Name:Fire/Ice
ManaCost:1 UR
Types:Instant
Text:
A:SP$ Effect | Cost$ 1 R | SP$ DealDamage | ValidTgts$ Creature,Player,Planeswalker | TgtPrompt$ Select target creature, player or planeswalker (1) | NumDmg$ 1 | SubAbility$ DBDamage2 | SpellDescription$ Fire deals 2 damage divided as you choose among one or two target creatures and/or players.
SVar:DBDamage2:DB$DealDamage | Cost$ 0 | ValidTgts$ Creature,Player,Planeswalker | TgtPrompt$ Select target creature, player or planeswalker (2) | NumDmg$ 1
A:SP$ Effect | Cost$ 1 U | SP$ Tap | ValidTgts$ Permanent | TgtPrompt$ Select target permanent | SubAbility$ DBDraw | SpellDescription$ Tap target permanent. Draw a card.
SVar:DBDraw:DB$Draw | Cost$ 0 | NumCards$ 1
K:CARDNAME is blue.
SVar:RemAIDeck:True
SVar:Rarity:Uncommon
SVar:Picture:http://www.wizards.com/global/images/magic/general/fire_ice.jpg
SetInfo:APC|Uncommon|http://magiccards.info/scans/en/ap/128.jpg
Oracle: Fire deals 2 damage divided as you choose among one or two target creatures and/or players.|| Tap target permanent. Draw a card.
End
As I said in another post I'm not a coder I've just opened your work in cardfolder and go from there to build me a temporary "almost working" version of Fire/Ice, waiting for people like you to implement the true feature
The picture is named FireIce.full and works correctly!
That's all I can do to try to help you a bit! Good luck.
- krevett
- Posts: 109
- Joined: 21 Feb 2012, 22:24
- Location: France
- Has thanked: 18 times
- Been thanked: 9 times
Re: Implementing new Ability Factories and Card Support Code
by Agetian » 17 Dec 2012, 08:34
Nice, thank you very much for your assistance, it is indeed very helpful! I'll keep you posted on my progress!
- Agetian
- Agetian
- Agetian
- Programmer
- Posts: 3490
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
Re: Implementing new Ability Factories and Card Support Code
by Sloth » 17 Dec 2012, 08:47
Whatever.Agetian wrote:- Since split cards have two costs, how should the deck editor treat them as far as CMC goes? E.g. when a card like that goes to deck, and, let's say, if the mana costs of two sides are 1 and 4, respectively, does the deck editor show it as a CMC 1 card going into deck, a CMC 4 card going into deck, or both of those? :\ (I mean in statistics).
Yes.Agetian wrote:- The same question is valid for colors in the deck editor - should the deck editor treat them as multicolored cards if each side has its own color?
Yes (whatever).Agetian wrote:- As far as rendering the mana cost goes, would it be OK to display it like <first card cost>/<second card cost>?
Whatever.Agetian wrote:- As far as naming the card goes, we can use either a slash (/) or a double slash (//) notation. The card picture renderer will then, if it encounters a card named like that, convert the name to the appropriate full card picture name (e.g. NightDay.full.jpg, or whatever it's named, I'll look it up) and then load it.
I wouldn't use the flip card mechanism here. A custom parameter like "SplitCard" in the spellabilities should be enough. When this parameter is present the color and cmc for the spell on the stack is taken directly from the Cost parameter (and not from the card).Agetian wrote:- Would it be possible, in principle, to code a card that would have two different effects with two different mana costs? As far as I know, Forge currently doesn't support the fact that each side has its own color, but outside of that issue, is that doable using, for instance, the flip card mechanism (for one and the same color)?
This is the only real problem and there is no easy solution. We have to create a distinction where none was before, which means lots of code and script changes.krevett wrote:For cmc of split cards, I'll give you two famous examples for effects asking for cmc:
1) counterbalance: if you reveal a split card with cmc 1 and 4, you'll be able to counter spells with cmc 1 or 4 but not 5
2) dark confidant: if you reveal a split card with converted mana cost 1 and 4, you'll take 1 and 4 damage
-

Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Who is online
Users browsing this forum: No registered users and 16 guests