Page 1 of 1

Bugs with X costs

PostPosted: 20 Apr 2013, 07:58
by Sloth
Numerous bugs with X costs have arised, where the player doesn't get to pay for X (X is set to 0).

Warbreak Trumpeter (morph up)
Clan Defiance (Charm)
Engineered Explosives (?)

I made some attempts to fix them (but nothing seriously) and failed, but this should get fixed for the next beta. So any ideas?

Re: Bugs with X costs

PostPosted: 20 Apr 2013, 09:19
by Max mtg
Idea:
Code: Select all
Index: CostPartMana.java
===================================================================
--- CostPartMana.java   (revision 21085)
+++ CostPartMana.java   (working copy)
@@ -112,7 +112,8 @@
         ManaCostBeingPaid toPay = new ManaCostBeingPaid(getManaToPay(), restriction);
         
         boolean xWasBilled = false;
-        if (this.getAmountOfX() > 0 && !ability.getSVar("X").equals("Count$xPaid")) { // announce X will overwrite whatever was in card script
+        String xInCard = source.getSVar("X");
+        if (this.getAmountOfX() > 0 && !"Count$xPaid".equals(xInCard)) { // announce X will overwrite whatever was in card script
             // this currently only works for things about Targeted object
             int xCost = AbilityUtils.calculateAmount(source, "X", ability) * this.getAmountOfX();
             byte xColor = MagicColor.fromName(ability.hasParam("XColor") ? ability.getParam("XColor") : "1");

Re: Bugs with X costs

PostPosted: 21 Apr 2013, 05:11
by Max mtg
The patch worked for me, and noone has left any comment here, although they did have a chance to do so - ie Sloth and Sol both have been online since I posted the 'idea' patch.

Ok then, I'll commit.

Re: Bugs with X costs

PostPosted: 21 Apr 2013, 06:57
by Sloth
Max mtg wrote:The patch worked for me, and noone has left any comment here, although they did have a chance to do so - ie Sloth and Sol both have been online since I posted the 'idea' patch.

Ok then, I'll commit.
Warbreak Trumpeter and Clan Defiance work now, but Engineered Explosives still does not.

Re: Bugs with X costs

PostPosted: 21 Apr 2013, 07:54
by Max mtg
Sloth wrote:but Engineered Explosives still does not.
That's a scripting problem already.
To let human pay any X, the SVar:X needs to be Count$xPaid for cards that use X in cost and don't use announce (And I don't know how to turn on announce for SpellPermanents).
expression ValidCards$ Permanent.nonLand+cmcEQX also uses X, there is no code to use other variable here.

Solution? let there be EQY, EQZ and just any variable

Re: Bugs with X costs

PostPosted: 21 Apr 2013, 08:15
by Sloth
Max mtg wrote:That's a scripting problem already.
To let human pay any X, the SVar:X needs to be Count$xPaid for cards that use X in cost and don't use announce (And I don't know how to turn on announce for SpellPermanents).
expression ValidCards$ Permanent.nonLand+cmcEQX also uses X, there is no code to use other variable here.

Solution? let there be EQY, EQZ and just any variable
Yup that worked. Thanks Max.

Re: Bugs with X costs

PostPosted: 21 Apr 2013, 08:25
by Max mtg
That did work to pay an arbitrary X cost, but the card effect must be broken now (I didn't test it).

To enable other variables in 'EQ*' expression one needs to pay a visit to AbilityUtils:680.

Re: Bugs with X costs

PostPosted: 21 Apr 2013, 08:37
by Max mtg
Something like this:
Code: Select all
        String valid = type;
        int eqIndex = valid.indexOf("EQ");
        if (eqIndex >= 0) {
            char reference = valid.charAt(eqIndex + 2); // take whatever goes after EQ
            if( Character.isLetter(reference)) {
                String varName = valid.substring(eqIndex + 2, 1); // single-letter names, not sure how to learn variable name length
                valid = valid.replace(varName, Integer.toString(calculateAmount(source, varName, sa)));
            }
        }
Not commited yet. Will commit in some 20 hours if noone else does or any objections arise.

Re: Bugs with X costs

PostPosted: 21 Apr 2013, 09:38
by Sloth
Max mtg wrote:That did work to pay an arbitrary X cost, but the card effect must be broken now (I didn't test it).
No, it works correctly. hasProperty handles that.

Re: Bugs with X costs

PostPosted: 21 Apr 2013, 09:56
by Max mtg
Ok, glad my assumption was wrong.

Let me commit the code quoted above anyway - maybe it'll be useful for some other cases.

Re: Bugs with X costs

PostPosted: 21 Apr 2013, 12:53
by friarsol
(And I don't know how to turn on announce for SpellPermanents).
You could create a PermanentCreature (or noncreature as appropriate) to force Announce to be on in these circumstances.