It is currently 29 Oct 2025, 12:27
   
Text Size

AF Charm only works for spells

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Agetian, friarsol, Blacksmith, KrazyTheFox, CCGHQ Admins

AF Charm only works for spells

Postby Sloth » 22 Nov 2011, 11:18

Jeff has encountered some problems when scriptig Ulasht, the Hate Seed, but they are general problems with AF charm. Example:

When Skinshifter 's ability is activated for the second time, the choice of the first activation is shown as a fourth choice. If the ability is activated a third time you can chose the first choice and second choice combined (and selecting it will cause an infinite loop).

Other cards that suffer from this: Energy Chamber, Relic Bind and Varchild's War-Riders.

When looking at this code it becomes clear that the abilities are massively modified whenever they are activated (even when the payment is canceled):
setupCharmSAs | Open
Code: Select all
public static void setupCharmSAs(final SpellAbility sa) {
        // make Charm choices
        if (sa.isCharm()) {
            final ArrayList<SpellAbility> choices = new ArrayList<SpellAbility>();
            choices.addAll(sa.getCharmChoices());
            for (int i = 0; i < choices.size(); i++) {
                if (!sa.canPlay()) {
                    choices.remove(sa);
                }
            }
            for (int i = 0; i < sa.getCharmNumber(); i++) {
                Object o;
                if (i < sa.getMinCharmNumber()) {
                    o = GuiUtils.getChoice("Choose a mode", choices.toArray());
                } else {
                    o = GuiUtils.getChoiceOptional("Choose a mode", choices.toArray());
                }
                if (null == o) {
                    break;
                }
                final AbilitySub chosen = (AbilitySub) o;
                sa.addCharmChoice(chosen);
                choices.remove(chosen);

                // walk down the SpellAbility tree and add to the child
                // Ability_Sub
                SpellAbility child = sa;
                while (child.getSubAbility() != null) {
                    child = child.getSubAbility();
                }
                child.setSubAbility(chosen);
                if (chosen.getActivatingPlayer() == null) {
                    chosen.setActivatingPlayer(child.getActivatingPlayer());
                }
                chosen.setParent(child);
            }
        }
    }
Some code has to be added at the start, that reverts the last setup (and maybe it's better to store the whole choice in a different way).
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: AF Charm only works for spells

Postby Sloth » 14 Jan 2012, 07:13

Here are some more bugs with AF Charm:

gos wrote:I cast Naya Charm off of cascade (Bloodbraid Elf). I did not get to choose a mode, and it had no effect on resolving.
gos wrote:If you choose the 2 options for a Command spell, and then cancel when you are prompted to pay the mana, the next time you try to cast the Command, the options are a strange amalgamation of the various choices, and it causes an error. Tested with Cryptic Command and Incendiary Command.
Accountancy wrote:If I use Snapcaster Mage to give Cryptic Command flashback and then cast it using flashback, I get 6 choices of mode, two of which are the choices I made for the first casting, then if I select one of the choices I made the first time, forge becomes unresponsive, however, if I choose new choices, then it will perform ALL the modes.
For example, I tap my opponents creatures and draw a card, then flash it back with the intent to counter a spell and draw a card, it will crash.
If I instead choose to counter a spell and return a permanent the second time, then it will also tap the creatures and draw a card.
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 13 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 13 users online :: 0 registered, 0 hidden and 13 guests (based on users active over the past 10 minutes)
Most users ever online was 9298 on 10 Oct 2025, 12:54

Users browsing this forum: No registered users and 13 guests

Login Form