Storing and Retrieving Filters
Posted: 11 Sep 2016, 06:28
Being able to store and retrieve filters seems like an idea that might be useful. I don't currently know of any way to store a filter and retrieve it later, perhaps by another card. For instance, protection filters. So, I made a set of functions that can manage this. It's only VERY basically tested, so far, but it did work for the extremely simple filter "creature".
"CW_Filter_" is prefixed on the function name.
The filter (usually preceding the function) is moved into its first parameter.
The normal parameters are placed inside braces.
The idea here is that the "filter" return here is actually a rather complex table. The table contains two parts: indices, filter. This inner filter is the normal filter you'd get from ClearFilter(). Indices normally contains just the global index (but in a table) where this complex filter's instruction table is stored. Whenever you call "add", it appends a new entry to the table consisting of the function ("Add" in this case) and the parameters. The table for "creature" ends up looking like this: {"Add", {FE_TYPE, OP_IS, CARD_TYPE_CREATURE}}.
Non-human artifact would look like this:
{"Add", {FE_SUBTYPE, OP_NOT, CARD_TYPE_HUMAN}}
{"Add", {FE_TYPE, OP_IS, CARD_TYPE_ARTIFACT}}
It can also manage SetZone, AddSubFilter_Or/And, and SetFilterType, all using the same logic.
So, "Target red instant or sorcery card in your graveyard" would end up like this:
Using these functions, it would be really easy to convert a card with protection to a card with an exposed protection filter. This would allow other cards to check if a given card falls within that protection. It would be a pretty big undertaking (there are about 250 cards with protection), but it would be a really simple edit to make to them.
This would allow cards like Avalanche Tusker and anything else that requires knowing if Card A could target/block Card B, like Mirrorwing Dragon (we can already load the TargetDefinition).
I think Monday I'll test the functions thoroughly and if they hold up, I'll see about getting the protection cards converted over. In the meantime, if anyone has thoughts on this, let me know.
http://pastebin.com/7GBuq0y7
- Code: Select all
<RESOLUTION_TIME_ACTION>
local oFilter = CW_Filter_ClearFilter()
CW_Filter_Add(oFilter, {FE_TYPE, OP_IS, CARD_TYPE_CREATURE})
EffectDC():Set_Int(0, CW_Filter_GetGlobalIndex(SmartFilter))
EffectController():ChooseItem("CHOOSE", EffectDC():Make_Targets(1))
</RESOLUTION_TIME_ACTION>
<RESOLUTION_TIME_ACTION>
local oFilter = CW_Filter_GetStoredFilter(EffectDC():Get_Int(0)) -- Technically, the variable is unnecessary.
EffectController():ChooseItem("CHOOSE_AGAIN", EffectDC():Make_Targets(2))
</RESOLUTION_TIME_ACTION>
"CW_Filter_" is prefixed on the function name.
The filter (usually preceding the function) is moved into its first parameter.
The normal parameters are placed inside braces.
The idea here is that the "filter" return here is actually a rather complex table. The table contains two parts: indices, filter. This inner filter is the normal filter you'd get from ClearFilter(). Indices normally contains just the global index (but in a table) where this complex filter's instruction table is stored. Whenever you call "add", it appends a new entry to the table consisting of the function ("Add" in this case) and the parameters. The table for "creature" ends up looking like this: {"Add", {FE_TYPE, OP_IS, CARD_TYPE_CREATURE}}.
Non-human artifact would look like this:
{"Add", {FE_SUBTYPE, OP_NOT, CARD_TYPE_HUMAN}}
{"Add", {FE_TYPE, OP_IS, CARD_TYPE_ARTIFACT}}
It can also manage SetZone, AddSubFilter_Or/And, and SetFilterType, all using the same logic.
So, "Target red instant or sorcery card in your graveyard" would end up like this:
- Code: Select all
{"SetZone", {ZONE_GRAVEYARD, EffectController()}}
{"Add", {FE_COLOUR, OP_IS, COLOUR_RED}}
{"AddSubFilter_Or", {
{"Add", {FE_TYPE, OP_IS, CARD_TYPE_INSTANT}}
{"Add", {FE_TYPE, OP_IS, CARD_TYPE_SORCERY}}
}
Using these functions, it would be really easy to convert a card with protection to a card with an exposed protection filter. This would allow other cards to check if a given card falls within that protection. It would be a pretty big undertaking (there are about 250 cards with protection), but it would be a really simple edit to make to them.
This would allow cards like Avalanche Tusker and anything else that requires knowing if Card A could target/block Card B, like Mirrorwing Dragon (we can already load the TargetDefinition).
I think Monday I'll test the functions thoroughly and if they hold up, I'll see about getting the protection cards converted over. In the meantime, if anyone has thoughts on this, let me know.
http://pastebin.com/7GBuq0y7