Comparing version 0.0.2 to 0.1.0
{ | ||
"name": "gacha", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "Roguelike item drop distribution calculator", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# Node Gacha | ||
Given a database of items with variable drop rates, determine the odds of an item being dropped on a particular level. | ||
Node Gacha (named after the Japanese onomatopoeia for the sound made by toy machines) aims to be a module providing different methods for calculating randomness in games. | ||
Randomness can include everything from enemy encounters to item drop rates, particularly useful for RPG's and Roguelikes. | ||
Eventually we'll offer a few different systems, but for now we only support "roguelike". | ||
``` | ||
@@ -9,6 +12,16 @@ npm install gacha | ||
Eventually we'll offer a few systems of gacha. For now we only support "roguelike". | ||
## Roguelike | ||
## Roguelike Usage | ||
**Purpose:** Given a listing of items (or enemies) with variable drop rates, determine the odds of them being dropped on a particular level. | ||
### Diagram | ||
![Diagram](http://static.zyu.me/projects/node-gacha/roguelike-diagram.png) | ||
The above diagram gives a visualization of how Roguelike works. | ||
Each item has an ideal level (center of curve), a spread (the radius of the curve), and a weight (makes it taller). | ||
After passing data through the roguelike function, a list of probabilities of each item spawning is provided on a per-level basis. | ||
### Code Sample | ||
```javascript | ||
@@ -15,0 +28,0 @@ var gacha = require('gacha'); |
var roguelike = require('../lib/roguelike.js'); | ||
var assert = require('assert'); | ||
var sample_data = require('./data/sample-roguelike.json'); | ||
var small_data = require('./data/small-roguelike.json'); | ||
var data_complex = require('./fixtures/roguelike-complex.json'); | ||
var data_double = require('./fixtures/roguelike-double.json'); | ||
var data_single = require('./fixtures/roguelike-single.json'); | ||
describe('Roguelike', function() { | ||
it('works', function() { | ||
var result = roguelike(sample_data); | ||
console.log(result); | ||
describe('single item, level 5, spread 3', function() { | ||
var result; | ||
before(function() { | ||
result = roguelike(data_single); | ||
}); | ||
it('has expected levels', function() { | ||
assert.deepEqual(Object.keys(result), [ | ||
'2', '3', '4', '5', '6', '7', '8' | ||
]); | ||
}); | ||
it('is symmetrical', function() { | ||
assert.equal(result[2].total, result[8].total); | ||
assert.equal(result[3].total, result[7].total); | ||
assert.equal(result[4].total, result[6].total); | ||
}); | ||
it('is biggest in the center', function() { | ||
assert(result[5].total > result[4].total); | ||
assert(result[4].total > result[3].total); | ||
assert(result[3].total > result[2].total); | ||
}); | ||
}); | ||
it('works', function() { | ||
var result = roguelike(small_data); | ||
describe('double items with overlap', function() { | ||
var result; | ||
var random = Math.random() * result[3].total; | ||
before(function() { | ||
result = roguelike(data_double); | ||
}); | ||
for (var i = 0; i < result[3].strata.length; i++) { | ||
if (random < result[3].strata[i]) { | ||
var id = result[3].lookup[i]; | ||
console.log(id); | ||
break; | ||
it('has expected levels', function() { | ||
assert.deepEqual(Object.keys(result), [ | ||
'2', '3', '4', '5', '6', '7', '8', '9', '10', '11' | ||
]); | ||
}); | ||
it('has expected lookups', function() { | ||
assert.deepEqual(result[2].lookup, ['101']); | ||
for (var i = 3; i <= 8; i++) { | ||
assert.deepEqual(result[i].lookup, ['101', '102']); | ||
} | ||
} | ||
for (var j = 9; j <= 11; j++) { | ||
assert.deepEqual(result[j].lookup, ['102']); | ||
} | ||
}); | ||
}); | ||
describe('complex items', function() { | ||
var result; | ||
before(function() { | ||
result = roguelike(data_complex); | ||
}); | ||
it('has key gaps', function() { | ||
assert.deepEqual(Object.keys(result), [ | ||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '20' | ||
]); | ||
}); | ||
it('always has the same number of strata as lookup', function() { | ||
var levels = Object.keys(result); | ||
for (var index = 0; index < levels.length; index++) { | ||
var level_id = levels[index]; | ||
assert.equal(result[level_id].strata.length, result[level_id].lookup.length); | ||
} | ||
}); | ||
it('total is always equal to last strata', function() { | ||
var levels = Object.keys(result); | ||
for (var index = 0; index < levels.length; index++) { | ||
var level_id = levels[index]; | ||
var last_strata = result[level_id].strata[result[level_id].strata.length - 1]; | ||
assert.equal(result[level_id].total, last_strata); | ||
} | ||
}); | ||
it('strata are always ascending', function() { | ||
var levels = Object.keys(result); | ||
for (var index = 0; index < levels.length; index++) { | ||
var level = result[levels[index]]; | ||
for (var strata = 0; strata < level.strata.length - 1; strata++) { | ||
assert(level.strata[strata] < level.strata[strata + 1]); | ||
} | ||
} | ||
}); | ||
}); | ||
}); |
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
33360
13
209
107
3