mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-22 03:34:14 +00:00
Move spell function into separate module
This commit is contained in:
parent
f3bfded624
commit
3578e05979
3 changed files with 15 additions and 36 deletions
|
|
@ -1,7 +1,6 @@
|
|||
api = module.exports
|
||||
|
||||
_ = require 'lodash'
|
||||
moment = require 'moment'
|
||||
|
||||
t = require('../../dist/scripts/content/helpers').translator
|
||||
|
||||
|
|
@ -85,16 +84,6 @@ api.spells = require('../../dist/scripts/content/spells/index')
|
|||
|
||||
api.cardTypes = require('../../dist/scripts/content/card-types')
|
||||
|
||||
# Intercept all spells to reduce user.stats.mp after casting the spell
|
||||
_.each api.spells, (spellClass) ->
|
||||
_.each spellClass, (spell, key) ->
|
||||
spell.key = key
|
||||
_cast = spell.cast
|
||||
spell.cast = (user, target) ->
|
||||
#return if spell.target and spell.target != (if target.type then 'task' else 'user')
|
||||
_cast(user,target)
|
||||
user.stats.mp -= spell.mana
|
||||
|
||||
api.special = api.spells.special
|
||||
|
||||
###
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
};
|
||||
Loading…
Reference in a new issue