It is currently 26 Aug 2025, 20:50
   
Text Size

Bugs with X costs

Post MTG Forge Related Programming Questions Here

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

Bugs with X costs

Postby Sloth » 20 Apr 2013, 07:58

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?
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: Bugs with X costs

Postby Max mtg » 20 Apr 2013, 09:19

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");
Single class for single responsibility.
Max mtg
Programmer
 
Posts: 1997
Joined: 02 Jul 2011, 14:26
Has thanked: 173 times
Been thanked: 334 times

Re: Bugs with X costs

Postby Max mtg » 21 Apr 2013, 05:11

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.
Single class for single responsibility.
Max mtg
Programmer
 
Posts: 1997
Joined: 02 Jul 2011, 14:26
Has thanked: 173 times
Been thanked: 334 times

Re: Bugs with X costs

Postby Sloth » 21 Apr 2013, 06:57

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.
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: Bugs with X costs

Postby Max mtg » 21 Apr 2013, 07:54

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
Single class for single responsibility.
Max mtg
Programmer
 
Posts: 1997
Joined: 02 Jul 2011, 14:26
Has thanked: 173 times
Been thanked: 334 times

Re: Bugs with X costs

Postby Sloth » 21 Apr 2013, 08:15

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.
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: Bugs with X costs

Postby Max mtg » 21 Apr 2013, 08:25

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.
Single class for single responsibility.
Max mtg
Programmer
 
Posts: 1997
Joined: 02 Jul 2011, 14:26
Has thanked: 173 times
Been thanked: 334 times

Re: Bugs with X costs

Postby Max mtg » 21 Apr 2013, 08:37

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.
Single class for single responsibility.
Max mtg
Programmer
 
Posts: 1997
Joined: 02 Jul 2011, 14:26
Has thanked: 173 times
Been thanked: 334 times

Re: Bugs with X costs

Postby Sloth » 21 Apr 2013, 09:38

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.
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: Bugs with X costs

Postby Max mtg » 21 Apr 2013, 09:56

Ok, glad my assumption was wrong.

Let me commit the code quoted above anyway - maybe it'll be useful for some other cases.
Single class for single responsibility.
Max mtg
Programmer
 
Posts: 1997
Joined: 02 Jul 2011, 14:26
Has thanked: 173 times
Been thanked: 334 times

Re: Bugs with X costs

Postby friarsol » 21 Apr 2013, 12:53

(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.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 38 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 38 users online :: 0 registered, 0 hidden and 38 guests (based on users active over the past 10 minutes)
Most users ever online was 7303 on 15 Jul 2025, 20:46

Users browsing this forum: No registered users and 38 guests

Login Form