Move spell function into separate module

This commit is contained in:
Blade Barringer
2015-09-23 12:53:43 -05:00
parent f3bfded624
commit 3578e05979
3 changed files with 15 additions and 36 deletions

View File

@@ -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;

View File

@@ -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);
});
};