-
Notifications
You must be signed in to change notification settings - Fork 36
Quick Custom Card Variables
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.
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.
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.
});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));
}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."
}