Implementing new Ability Factories and Card Support Code
As of right now, I've done all I could with the targeting overlay codebase and I can conclude that it's usable at its basic functional level at the moment (I'll return to it once I improve my Java2D skills), so I'm moving on to my next developer target - figuring out how the ability factories work and potentially implementing some new card-related code (most likely in the AF department) to support some of the legacy cards that are currently not yet supported.
This is a very difficult issue for me because, as I've said before, I'm not a great expert on rule interactions and I've never touched the ability factory code before.
As I was looking through the AFs that are getting refactored at the moment by Max Mtg, I've noticed several recurring methods that each ability factory has (or at least can have). I think I figured out what some of them do but the others remain a mystery for me. I'd be grateful if someone who is good with the AF code can clarify some key points of the ability factory implementation for me:
1) in forge.card.abilityfactory:
Am I correct that each new ability factory should now be registered in ApiType.java, in the ApiType enumeration? That, apparently, is where this code goes, but I'd like to make sure. Also, is anything else necessary to be done in the global Ability Factory code to add support for a new ability factory, or is registering it in ApiType enough?
2) in forge.card.abilityfactory.effects:
As far as I understand, the abilityfactory.effects package contains the implementation of the ability effects as such, regardless of how AI is able to interact with the ability etc. I believe that:
getStackDescription is used to build a string description of the ability as it appears in the stack window.
resolve is the implementation of the effect as such which defines what effect the ability has on the cards on the playfield (e.g. on its target etc.)
I noticed that some parameters are usually passed to various ability factory methods via a java.util.Map<String, String> - is there a list of possible parameters anywhere? Some of them have rather unintuitive names - some of them seem like they should make sense immediately, but after some thinking, for instance, I realize I have no idea what AllType or AllValid could be used for when passed to a resolve method of an AF. Also, where do the parameters come from? Are they defined in card scripts or something like that?
Also, I believe that the above-mentioned two methods (getStackDescription and resolve) are the only ones that are essential to be implemented for the AF effect, everything else that might be there are just support methods, right?
3) in forge.card.abilityfactory.ai:
There are several methods that need to be implemented here, some of which make sense to me and some of which are a mystery:
canPlayAI - used to test whether the AI can play the ability at the given moment and should return 'true' in situations when it can, right?
chkAIDrawback - no idea, honestly... I'd need some help on this one.
doTriggerAINoCost - I *think* this defines how the AI plays the effect (e.g. what it chooses as target etc.), but I'm not sure; moreover, the words "No Cost" in the method name baffle me, I'm not sure why it says "NoCost" and whether there's also a version "with cost".
What's even more puzzling is that chkAIDrawback sometimes just calls doTriggerAINoCost and doTriggerAINoCost sometimes just calls CanPlayAI, which is a bit confusing... not sure why that is.
Also, are there any other methods out there that I haven't yet noticed in the AI department and that may be implemented for the ability factory-related AI?
4) in ability factory code in general:
In parameter names and field names, I think "sa" refers to SpellAbility and "ab" refers to Ability, though sometimes the difference eludes me (does it mean that "ab" is for non-spell abilities only?..).
I'd welcome any help that any of you will be able to provide for me regarding the problems I've outlined above. I hope I'll be able to help out with AFs once I figure out how they work and what would be necessary to code them.
Thanks a lot in advance for your help!
- Agetian
This is a very difficult issue for me because, as I've said before, I'm not a great expert on rule interactions and I've never touched the ability factory code before.
As I was looking through the AFs that are getting refactored at the moment by Max Mtg, I've noticed several recurring methods that each ability factory has (or at least can have). I think I figured out what some of them do but the others remain a mystery for me. I'd be grateful if someone who is good with the AF code can clarify some key points of the ability factory implementation for me:
1) in forge.card.abilityfactory:
Am I correct that each new ability factory should now be registered in ApiType.java, in the ApiType enumeration? That, apparently, is where this code goes, but I'd like to make sure. Also, is anything else necessary to be done in the global Ability Factory code to add support for a new ability factory, or is registering it in ApiType enough?
2) in forge.card.abilityfactory.effects:
As far as I understand, the abilityfactory.effects package contains the implementation of the ability effects as such, regardless of how AI is able to interact with the ability etc. I believe that:
getStackDescription is used to build a string description of the ability as it appears in the stack window.
resolve is the implementation of the effect as such which defines what effect the ability has on the cards on the playfield (e.g. on its target etc.)
I noticed that some parameters are usually passed to various ability factory methods via a java.util.Map<String, String> - is there a list of possible parameters anywhere? Some of them have rather unintuitive names - some of them seem like they should make sense immediately, but after some thinking, for instance, I realize I have no idea what AllType or AllValid could be used for when passed to a resolve method of an AF. Also, where do the parameters come from? Are they defined in card scripts or something like that?
Also, I believe that the above-mentioned two methods (getStackDescription and resolve) are the only ones that are essential to be implemented for the AF effect, everything else that might be there are just support methods, right?
3) in forge.card.abilityfactory.ai:
There are several methods that need to be implemented here, some of which make sense to me and some of which are a mystery:
canPlayAI - used to test whether the AI can play the ability at the given moment and should return 'true' in situations when it can, right?
chkAIDrawback - no idea, honestly... I'd need some help on this one.
doTriggerAINoCost - I *think* this defines how the AI plays the effect (e.g. what it chooses as target etc.), but I'm not sure; moreover, the words "No Cost" in the method name baffle me, I'm not sure why it says "NoCost" and whether there's also a version "with cost".
What's even more puzzling is that chkAIDrawback sometimes just calls doTriggerAINoCost and doTriggerAINoCost sometimes just calls CanPlayAI, which is a bit confusing... not sure why that is.
Also, are there any other methods out there that I haven't yet noticed in the AI department and that may be implemented for the ability factory-related AI?
4) in ability factory code in general:
In parameter names and field names, I think "sa" refers to SpellAbility and "ab" refers to Ability, though sometimes the difference eludes me (does it mean that "ab" is for non-spell abilities only?..).
I'd welcome any help that any of you will be able to provide for me regarding the problems I've outlined above. I hope I'll be able to help out with AFs once I figure out how they work and what would be necessary to code them.
Thanks a lot in advance for your help!
- Agetian