Skip to content

Quick Custom Card Variables

Alchyr edited this page Sep 19, 2023 · 14 revisions

In addition to the standard !D!, !B!, and !M!, BaseMod supports creating your own custom dynamic variables. BasicMod is set up to allow quick and easy creation of these variables without manually creating classes for them.

First, decide the name for the variable. For this example, "beep" will be used.

Defining and Using the Variable in Code

In the constructor of a card that extends BaseCard, you can use the setCustomVar method to set the base (and upgrade) amount for one of these variables.

    public ExampleCard() {
        super(ID, info);

        setDamage(DAMAGE); //Setting a normal variable
        setCustomVar("beep", 6, 3); //Setting a custom variable with a base value of 6, increased by 3 on upgrade
    }

To use the variable later, use customVar("beep") to get the value of the variable.

If you want your variable to have some special calculations applied to it, such as being increased by certain buffs, you can use the setVarCalculation method or the other overloads of setCustomVar.

If isMultiDamage is set to true, the variable will also be calculated for each individual enemy and stored in an array based on the enemy's index in the AbstractDungeon.getMonsters().monsters group, similar to multiDamage. This can be accessed using customVarMulti("variable key"). (Added September 19 2023, if using an earlier version you may not have this feature.)

        setCustomVar("beep", 6, 3); //Setting a custom variable with a base value of 6, increased by 3 on upgrade
        setVarCalculation("beep", (m, base)->{ //For the "beep" variable, given some monster target and the base value:
            if (m instanceof Byrd) {
                return base * 2; //Double it if targeting a Byrd
            }
            return base; //Otherwise, just the original value.
        });

        setCustomVar("damage2", VariableType.DAMAGE, 10, 5); //A variable that will be calculated as damage.
        //Options are DAMAGE, BLOCK, and MAGIC. This constructor is generally not useful for the MAGIC type as this just applies no calculation.
        //You can also add extra calculation to be done before and/or after the chosen calculation type, to mimic effects like Heavy Blade.

This will result in the value obtained using customVar("beep") being modified. For convenience, you can use the calculateVarAsDamage and calculateVarAsBlock methods to quickly have your variable be calculated like damage and block are. The only exception is that AOE damage isn't supported, as calculating AOE damage requires storing the result in an array. The variable works like magicNumber by default, not modified by anything.

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {
        addToBot(new DamageAction(m, new DamageInfo(p, damage, damageTypeForTurn), AbstractGameAction.AttackEffect.FIRE));
        //Using the custom variable
        addToBot(new DamageAction(m, new DamageInfo(p, customVar("beep"), DamageInfo.DamageType.HP_LOSS), AbstractGameAction.AttackEffect.NONE));
    }

Adding the Variable to Card Text

The variable is used in card text similarly to !D! or !M!; it will be an ID between exclamation points. The ID in this case will be the mod's ID and the name you chose.

  "${modID}:ExampleCard": {
    "NAME": "Why Byrd",
    "DESCRIPTION": "Deal !D! damage. NL Enemy loses !${modID}:beep! HP. Byrds lose twice as much."
  }

Clone this wiki locally