Node Gacha
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".
npm install gacha
Roguelike
Purpose: Given a listing of items (or enemies) with variable drop rates, determine the odds of them being dropped on a particular level.
Diagram
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
var gacha = ; // items must be an object where each property contains level, weight, and spread.var items = "101": "name": "Knife" "type": "weapon" "level": 1 "weight": 10 "spread": 1 "102": "name": "Sword" "type": "weapon" "level": 2 "weight": 10 "spread": 2 "103": "name": "Iron Buckler" "type": "shield" "level": 3 "weight": 30 "spread": 3 "104": "name": "Potion" "type": "heal" "level": 3 "weight": 10 "spread": 2 ; var equip = gacha; console; // Shown below // Which item should we spawn on level 3?var lvl3 = equip3;var strata = Math * lvl3total;var item = null; for var i = 0; i < lvl3stratalength; i++ if strata <= lvl3stratai var id = lvl3lookupi; item = itemsid; break; console;
equip
object
Resulting