mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 23:27:26 +01:00
Move spell function into separate module
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import {each} from 'lodash';
|
||||
|
||||
import wizard from './wizard';
|
||||
import warrior from './warrior';
|
||||
import healer from './healer';
|
||||
@@ -33,4 +35,17 @@ var spells = {
|
||||
special: special,
|
||||
};
|
||||
|
||||
// Intercept all spells to reduce user.stats.mp after casting the spell
|
||||
each(spells, (spellClass) => {
|
||||
each(spellClass, (spell, key) => {
|
||||
spell.key = key;
|
||||
|
||||
let _cast = spell.cast;
|
||||
spell.cast = (user, target) => {
|
||||
_cast(user, target);
|
||||
return user.stats.mp -= spell.mana;
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
export default spells;
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
import {each, defaults} from 'lodash';
|
||||
import capitalize from 'lodash.capitalize';
|
||||
import {translator as t} from '../helpers';
|
||||
|
||||
export function diminishingReturns(bonus, max, halfway=max/2) {
|
||||
return max * (bonus / (bonus + halfway));
|
||||
};
|
||||
|
||||
export function calculateBonus(value, stat, crit=1, stat_scale=0.5) {
|
||||
return (value < 0 ? 1 : value + 1) + (stat * stat_scale * crit);
|
||||
};
|
||||
|
||||
export function setSpellDefaults (className, spells) {
|
||||
let capitalClassName = capitalize(className);
|
||||
|
||||
each(spells, (spell, key) => {
|
||||
let capitalSpellKey = capitalize(key);
|
||||
let spellDefaults = {
|
||||
text: t(`spell${capitalClassName}${capitalSpellKey}Text`),
|
||||
notes: t(`spell${capitalClassName}${capitalSpellKey}Notes`),
|
||||
};
|
||||
|
||||
defaults(spell, spellDefaults);
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user