#Mana API

1 messages · Page 1 of 1 (latest)

distant tinsel
#

Is it possible to set the maximum amount of mana, and not the amount that is spent?

#
Mana
Getting and setting mana is very simple:

Copy
double mana = user.getMana();

// Check that the user has enough mana before removing it
if (mana >= 10.0) {
    user.setMana(mana - 10.0);
} else {
    // Handle not enough mana case
}

// Gets the user's max mana (determined by the Wisdom stat)
double maxMana = user.getMaxMana();
An easier way to consume mana for things like activating mana abilities or casting spells is using the consumeMana method. This returns true if the user has enough mana and mana was successfully removed, and false if mana could not be removed. It also automatically sends a "Not enough mana" message to the action bar.

Copy
if (user.consumeMana(15.0)) {
    // You have to send a success message yourself
    // Implement mana ability functionality here
}

I didn't find a way to do this according to the documentation

worldly matrix
#

Probably best to use a trait modifier for Traits.MAX_MANA