rpglevel

A npm package for managing "Level" with "Exp" that is used by like RPG.

npm install rpglevel
10 downloads in the last week
20 downloads in the last month

rpglevel Build Status

A npm package for managing "Level" with "Exp" that is used by like RPG.

Download

Or, if you can use node.js:

$ npm install rpglevel

Supported browsers/node.js

  • IE10, IE9, IE8, IE7
  • Chrome
  • Firefox
  • Safari
  • Mobile Safari
  • PhantomJS
  • node.js >= 0.11.0

License

Public Domain

Usage

// v1.1.2 or later, global variable name is changed to `rpglevel` from `RPGLevel`.
var RPGLevel = rpglevel.RPGLevel;

// Or, if you want to use by node.js
//var RPGLevel = require('rpglevel').RPGLevel;

var lv = new RPGLevel();

//
// Define Exp-Table by formula.
//
//   Lv1 = 0
//   Lv2 = 4
//   Lv3 = 6  (Total = 10)
//   Lv4 = 8  (Total = 18)
//   Lv5 = 10 (Total = 28)
//
lv.defineExpTable(function(level){
  return level * 2;
}, {
  maxLevel: 5
});

// You got exps with 2 levels up.
lv.gainExp(10);

// Getable your level.
console.log(lv.getLevel());  // -> 3

// Getable more infos.
console.log(lv.getStatuses());  // -> { level:3, .. }

API Reference

RPGLevel Class

  • new RPGLevel()
  • VERSION = "X.X.X"
  • registerExpTablePreset(presetKey, argsForDefineExpTable...)
  • resetExpTablePresets()

RPGLevel Instance

  • defineExpTable(necessaryExps)
    • Set Exp-Table by delta exp list. For example, [0, 2, 4, 8] means what it needs total exps [Lv1=0, Lv2=2, Lv3=6, Lv4=14].
    • For that reason, list[0] is always to contain 0.
  • defineExpTable(formula, options={})
    • Set Exp-Table by formula that is for each levels.
    • Define a fomula like function(level){ return level * level; }.
    • Also, a fomula has helper data for calculation in second arg, it is usable as function(level, data){ .. }.
  • defineExpTable(presetKey)
    • You can use Exp-Table presets by assigning key.
    • You can assign a only one "wiz_like" key, now.
    • The "wiz_like" key loads Exp-Table like a famous RPG.
  • getMinLevel()
  • getMaxLevel()
  • getStartLevel()
  • getExp()
  • getTotalNecessaryExp(fromLevel, toLevel)
  • getNecessaryExpByLevel(level)
  • getMaxExp()
  • setExp(exp)
  • resetExp()
  • gainExp(exp)
    • That returns a object what includes informations about growths in this time.
    • The object is like this: { beforeLevel: 3, afterLevel: 5, levelDelta: 2, isLevelUp: true ... }.
  • drainExp(exp)
    • That reduces your exps.
  • gainLevel(levelUpCount)
  • drainLevel(levelDownCount)
  • getStatuses()
    • Returns your statuses about level and exps.
  • getLevel()
  • isMaxLevel()

Sorry, these are not enough. Please look a source code.

Development

Dependencies

  • node.js >= 0.11.0, e.g. brew install node
  • PhantomJS, e.g. brew install phantomjs
$ npm install -g grunt-cli testem

Deploy

$ git clone git@github.com:kjirou/npm-rpglevel.git
$ cd npm-rpglevel
$ npm install
$ grunt

Build commands

  • grunt builds all files for development on web.
  • grunt watch executes grunt each time at updating CoffeeScript files.
  • grunt release generates JavaScript files for release.

Testing

  • Open test/index.html
  • Execute testem or testem server, after that, open http://localhost:7357/
  • grunt test is CI test by PhantomJS only.
  • grunt test:xb is CI test by PhantomJS, Chrome, Firefox and Safari.
  • grunt test:node tests by node.js with building processes.
npm loves you