lootgen-mayank 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,314 +1,117 @@
1
1
  # LootGen
2
2
 
3
- LootGen is a small, dependency-free Node.js package for creating randomized RPG loot and rewards. Generate weapons, armor, potions, accessories, collectibles, chest contents, boss rewards, and custom-table drops. Configure rarity, levels, luck, enchantments, gold, and reproducible seeded randomness.
3
+ LootGen makes random items and rewards for RPG games. It works in Node.js and
4
+ does not need any extra packages.
4
5
 
5
- ## Features
6
+ ## Install
6
7
 
7
- - Five built-in item categories with useful stats, values, names, and descriptions.
8
- - Common, Rare, Epic, and Legendary rarities with configurable weights.
9
- - Optional elemental and magical enchantments.
10
- - Item level scaling for stats and value.
11
- - Configurable luck that improves higher-rarity odds and is capped at `1`.
12
- - Gold, chest, and boss reward generation.
13
- - Weighted custom loot tables with per-entry drop chances.
14
- - Reproducible output with a numeric or string seed.
15
- - CommonJS API and no runtime dependencies.
8
+ npm install lootgen-mayank
16
9
 
17
- ## Requirements and installation
10
+ ## Use
18
11
 
19
- LootGen requires Node.js 18 or newer.
12
+ const LootGenerator = require('lootgen-mayank');
20
13
 
21
- ```sh
22
- npm install lootgen
23
- ```
14
+ const loot = new LootGenerator().generateLoot();
15
+ console.log(loot);
24
16
 
25
- ## Quick start
17
+ Items have a name, type, rarity, level, value, stats, enchantment, and
18
+ description. The available types are `Weapon`, `Armor`, `Potion`, `Accessory`,
19
+ and `Miscellaneous`.
26
20
 
27
- ```js
28
- const LootGenerator = require('lootgen');
21
+ You can set options when making a generator:
29
22
 
30
- const loot = new LootGenerator().generateLoot();
31
- console.log(loot);
32
- ```
23
+ const generator = new LootGenerator({
24
+ seed: 'game-1',
25
+ level: 5,
26
+ luck: 0.2
27
+ });
33
28
 
34
- A generated item has this shape:
29
+ console.log(generator.generateWeapon());
30
+ console.log(generator.generateGold());
35
31
 
36
- ```js
37
- {
38
- name: 'Fire Iron Sword',
39
- type: 'Weapon',
40
- rarity: 'Rare',
41
- level: 1,
42
- value: 34,
43
- stats: { damage: 12, speed: 0.9 },
44
- enchantment: 'Fire',
45
- description: 'A dependable blade with a well-balanced edge.'
46
- }
47
- ```
32
+ Using the same seed and making the same calls gives the same results. Without
33
+ a seed, generation uses regular random values.
48
34
 
49
- The name and numbers above illustrate the format; actual results are randomized.
50
- `enchantment` is `null` when the item is not enchanted.
35
+ ## Options
51
36
 
52
- ## Configuration
53
-
54
- Pass an optional object to `new LootGenerator(options)`:
55
-
56
- | Option | Default | Description |
37
+ | Option | Default | What it does |
57
38
  | --- | --- | --- |
58
- | `seed` | No seed | A finite number or string used for repeatable pseudo-random results. |
59
- | `level` | `1` | Default item level, an integer from `1` to `1000`. |
60
- | `luck` | `0` | Rarity luck modifier from `0` to `1`, inclusive. |
61
- | `rarityWeights` | `{ Common: 60, Rare: 25, Epic: 10, Legendary: 5 }` | Non-negative rarity weights; at least one must be positive. |
62
- | `enchantmentChance` | `0.15` | Chance from `0` to `1` for an eligible item to have an enchantment. |
63
- | `gold` | `{ min: 5, max: 25 }` | Default gold range. Both ends are inclusive non-negative integers. |
64
-
65
- ```js
66
- const LootGenerator = require('lootgen');
67
-
68
- const generator = new LootGenerator({
69
- seed: 'dungeon-entrance',
70
- level: 10,
71
- luck: 0.2,
72
- enchantmentChance: 0.3,
73
- rarityWeights: { Common: 50, Rare: 30, Epic: 15, Legendary: 5 },
74
- gold: { min: 10, max: 40 }
75
- });
76
- ```
77
-
78
- Rarity weights are relative, not percentages that must add up to 100. For the
79
- defaults, all weights total 100 and correspond to 60%, 25%, 10%, and 5%.
80
- For custom weights, a rarity's chance is its weight divided by the sum of all
81
- weights (before the luck modifier).
82
-
83
- ## Public API
84
-
85
- ### `new LootGenerator(options)`
86
-
87
- Creates a generator. Each instance has its own random sequence, configuration,
88
- and optional seed. Invalid configuration throws a `TypeError` or `RangeError`
89
- with a message that identifies the problem.
90
-
91
- ### `generateLoot(options)`
92
-
93
- Generates an item chosen from the five item categories. Optional fields:
94
-
95
- - `type`: `Weapon`, `Armor`, `Potion`, `Accessory`, or `Miscellaneous`.
96
- - `level`: item level for this call.
97
- - `rarity`: exact rarity to generate.
98
- - `minimumRarity`: rarity floor for the random rarity roll.
99
- - `luck`, `rarityWeights`, `enchantmentChance`: per-call overrides.
100
- - `table`: a custom table from `createLootTable`; a miss caused by `dropChance`
101
- falls back to a normal generated item.
102
-
103
- ### `generateWeapon(options)`, `generateArmor(options)`, `generatePotion(options)`
104
-
105
- Generate a specific item type. These accept the same rarity, level, luck, and
106
- enchantment options as `generateLoot`, except `type` is selected for you.
107
-
108
- Weapons include `damage` and `speed`; armor has `defense` and `durability`;
109
- potions include `healing`; accessories receive one randomized bonus stat.
110
- Miscellaneous items are collectibles. Enchantments are generated for weapons,
111
- armor, potions, and accessories, but not collectibles. Stats and value scale
112
- with level and rarity.
113
-
114
- ### `generateGold(options)`
115
-
116
- Returns an integer amount. An optional `{ min, max }` overrides the configured
117
- gold range for the call; bounds are inclusive.
118
-
119
- ### `generateMultiple(count, options)`
120
-
121
- Returns an array with `count` generated items. `count` must be an integer from
122
- `0` to `10000`; generation options match `generateLoot`.
123
-
124
- ### `generateChest(options)`
125
-
126
- Returns `{ items, gold }`. Defaults to 2–5 items and no gold. Supported options:
127
-
128
- - `minItems`, `maxItems`: inclusive item-count bounds (integers from `0` to `1000`).
129
- - `guaranteedRarity`: minimum rarity for the first item, when any is generated.
130
- - `table`: custom table to draw chest items from. Entries that miss their
131
- `dropChance` are omitted, so the returned item count can be lower than the
132
- selected count.
133
- - `gold`: `true` to use the configured gold range, `{ min, max }` for a custom
134
- range, or `false`/omitted for no gold.
135
- - `goldRange`: an optional range used with `gold: true`.
136
- - `level`, `luck`, `rarityWeights`, `enchantmentChance`, `minimumRarity`.
137
-
138
- ### `generateBossLoot(options)`
139
-
140
- Returns `{ items, gold }`. Defaults to three items, at least Rare for the first
141
- item, a boss-weighted rarity distribution (`20/40/25/15`), and 50 bonus gold.
142
- Options:
143
-
144
- - `itemCount`: integer from `1` to `1000`.
145
- - `guaranteedRarity`: minimum rarity for the first reward; defaults to `Rare`.
146
- - `table`: custom table from which rewards are drawn.
147
- - `rarityWeights`: override the boss-specific default weights.
148
- - `bonusGold`: non-negative integer added to a random gold amount.
149
- - `goldRange`: optional `{ min, max }` for the random portion of gold.
150
- - `level`, `luck`, `enchantmentChance`, `minimumRarity`.
151
-
152
- A custom table item without a rarity receives the guaranteed rarity for the
153
- first reward; a lower rarity is raised to that floor. A table drop miss falls
154
- back to a generated item so the boss reward count stays complete.
155
-
156
- ### `createLootTable(items)`
157
-
158
- Validates and returns a custom loot table. Each entry is either an item object
159
- with optional `weight` and `dropChance` properties, or an object of this form:
160
-
161
- ```js
162
- {
163
- item: { name: 'Moonstone', type: 'Accessory', rarity: 'Epic', value: 120 },
164
- weight: 2,
165
- dropChance: 0.75
166
- }
167
- ```
168
-
169
- `weight` defaults to `1` and must be a non-negative finite number.
170
- `dropChance` defaults to `1` and must be between `0` and `1`. At least one
171
- entry must have positive weight. The table is copied when
172
- created, so later changes to the input item objects do not alter it.
173
-
174
- ### `generateFromTable(table)`
175
-
176
- Selects one item according to its table weight, then checks that entry's
177
- `dropChance`. Returns a copied item or `null` if it does not drop.
178
-
179
- ### `setLuck(value)`, `setLevel(value)`, `setRarityWeights(weights)`
180
-
181
- Update the generator's defaults and return the generator to allow chaining.
182
- `setLuck` accepts values from `0` to `1`; `setLevel` accepts integer levels
183
- from `1` to `1000`; `setRarityWeights` uses the same validation as the
184
- constructor.
185
-
186
- ### Exported constants
187
-
188
- The package's default CommonJS export is the `LootGenerator` class. These
189
- named properties are also available:
190
-
191
- ```js
192
- const LootGenerator = require('lootgen');
193
- const { RARITIES, DEFAULT_RARITY_WEIGHTS, ENCHANTMENTS } = LootGenerator;
194
- ```
195
-
196
- `LootGenerator.LootGenerator` is an alias for the class itself.
197
-
198
- ## Luck and rarity
199
-
200
- Luck is bounded from `0` (no change) to `1` (maximum supported effect). Each
201
- rarity's base weight is multiplied by `1 + luck * rarityIndex`, where Common
202
- has index 0 and Legendary has index 3. The resulting weights are normalized
203
- for the final selection. Luck tilts odds toward higher rarities without
204
- guaranteeing a particular rarity. Set a `minimumRarity` or use a
205
- `guaranteedRarity` option when a floor is needed.
206
-
207
- ## Seeded randomness
208
-
209
- Using the same seed and the same sequence of calls/configuration produces the
210
- same results. String and finite-number seeds are supported:
211
-
212
- ```js
213
- const first = new LootGenerator({ seed: 'test-run', level: 4 });
214
- const second = new LootGenerator({ seed: 'test-run', level: 4 });
215
-
216
- console.log(first.generateLoot()); // Same result as the next line
217
- console.log(second.generateLoot());
218
- ```
219
-
220
- Each generator advances its own random sequence. Calls that consume random
221
- values (including gold and table rolls) affect subsequent results.
39
+ | `seed` | None | A string or finite number for repeatable results. |
40
+ | `level` | `1` | Default item level, from 1 to 1000. |
41
+ | `luck` | `0` | Shifts rarity rolls toward better items, from 0 to 1. |
42
+ | `rarityWeights` | Common 60, Rare 25, Epic 10, Legendary 5 | Sets the relative chance of each rarity. |
43
+ | `enchantmentChance` | `0.15` | Chance of an enchantment, from 0 to 1. |
44
+ | `gold` | `{ min: 5, max: 25 }` | Default gold range. |
45
+
46
+ Rarity weights do not have to add up to 100. At least one weight must be
47
+ greater than zero.
48
+
49
+ ## Main methods
50
+
51
+ - `generateLoot(options)` makes a random item. Options can include `type`,
52
+ `level`, `rarity`, `minimumRarity`, `luck`, `rarityWeights`, and
53
+ `enchantmentChance`. It can also use a custom `table`.
54
+ - `generateWeapon(options)`, `generateArmor(options)`, and
55
+ `generatePotion(options)` make a specific type of item.
56
+ - `generateMultiple(count, options)` makes an array of items.
57
+ - `generateGold({ min, max })` returns a random whole number of gold. The
58
+ range can be set on the generator or for one call.
59
+ - `generateChest(options)` returns an object with `items` and `gold`. It makes
60
+ 2 to 5 items by default. Set `minItems` and `maxItems` to change the count.
61
+ Use `guaranteedRarity` to set a rarity floor for the first item, or set
62
+ `gold` to `true` or to a `{ min, max }` range to add gold.
63
+ `goldRange` sets the range used when `gold` is `true`. A custom `table` can
64
+ be used for the items.
65
+ - `generateBossLoot(options)` returns `items` and `gold`. By default it makes
66
+ three items, gives the first item at least Rare rarity, and adds 50 bonus
67
+ gold. You can set `itemCount`, `guaranteedRarity`, `bonusGold`, `goldRange`,
68
+ `rarityWeights`, and a custom `table`.
69
+ - `setLuck(value)`, `setLevel(value)`, and `setRarityWeights(weights)` change
70
+ the generator's defaults. Each method returns the generator.
71
+
72
+ Chest and boss generation also accept `minimumRarity`, `level`, `luck`, and
73
+ `enchantmentChance`.
222
74
 
223
75
  ## Custom loot tables
224
76
 
225
- Tables are useful for enemy-specific drops, chest contents, or boss rewards.
226
- Weights decide which entry is selected; `dropChance` is checked after the
227
- selection:
228
-
229
- ```js
230
- const generator = new LootGenerator({ seed: 'crypt-guard' });
231
- const guardDrops = generator.createLootTable([
232
- {
233
- item: { name: 'Rusty Spear', type: 'Weapon', rarity: 'Common', value: 8 },
234
- weight: 8
235
- },
236
- {
237
- item: { name: 'Guard Insignia', type: 'Accessory', rarity: 'Rare', value: 45 },
238
- weight: 2,
239
- dropChance: 0.6
240
- }
241
- ]);
242
-
243
- const drop = generator.generateFromTable(guardDrops);
244
- if (drop) console.log(`The guard dropped ${drop.name}.`);
245
- ```
246
-
247
- Use the same table with a chest or boss:
248
-
249
- ```js
250
- const chest = generator.generateChest({
251
- table: guardDrops,
252
- minItems: 2,
253
- maxItems: 4,
254
- guaranteedRarity: 'Rare',
255
- gold: { min: 10, max: 35 }
256
- });
257
-
258
- const boss = generator.generateBossLoot({
259
- table: guardDrops,
260
- itemCount: 2,
261
- guaranteedRarity: 'Epic',
262
- bonusGold: 150
263
- });
264
- ```
265
-
266
- ## Level scaling and item stats
267
-
268
- Set a default level in the constructor, use `setLevel`, or override `level`
269
- per generation call. Levels must be integers from 1 to 1000. Stats and value
270
- increase with level; higher rarity also increases stats and value. The
271
- particular stat values are randomized within each item's ranges. Levels are
272
- intended as a simple game-friendly scale, not a balance system for a specific
273
- game.
274
-
275
- ## Error handling
276
-
277
- Invalid options fail explicitly instead of silently generating a fallback:
278
- expected object types use `TypeError`; out-of-range values and unsupported
279
- rarities/types use `RangeError`. Examples include negative gold, invalid
280
- weights, invalid levels, and a chest maximum below its minimum. Validate
281
- user-supplied configuration at the point where it enters your application.
282
-
283
- ## Examples
77
+ Make a table with `createLootTable`, then use it with `generateFromTable`,
78
+ `generateLoot`, `generateChest`, or `generateBossLoot`.
284
79
 
285
- Runnable scripts are provided in [`examples/`](./examples/):
80
+ const table = generator.createLootTable([
81
+ {
82
+ item: { name: 'Copper Key', type: 'Miscellaneous', rarity: 'Common' },
83
+ weight: 3
84
+ },
85
+ {
86
+ item: { name: 'Silver Key', type: 'Miscellaneous', rarity: 'Rare' },
87
+ weight: 1,
88
+ dropChance: 0.5
89
+ }
90
+ ]);
286
91
 
287
- - `basic.js` — create and print an item.
288
- - `custom-config.js` — configure seed, level, luck, rarity, and enchantments.
289
- - `chest.js` — create a chest with guaranteed rarity and gold.
290
- - `boss.js` — define a custom boss table and reward.
92
+ console.log(generator.generateFromTable(table));
291
93
 
292
- After installing the package, run an example with Node.js, such as:
94
+ Each entry needs an item. `weight` defaults to `1`; `dropChance` also defaults
95
+ to `1` and must be from 0 to 1. A table roll can return `null` if the selected
96
+ item does not drop. When a table is used for a chest, missed drops are left
97
+ out. For boss loot and `generateLoot`, a miss uses a regular generated item
98
+ instead.
293
99
 
294
- ```sh
295
- node examples/chest.js
296
- ```
100
+ ## Examples and tests
297
101
 
298
- ## Tests
102
+ The `examples` folder has short scripts for basic loot, custom settings,
103
+ chests, and boss rewards. Run one from the package folder, for example:
299
104
 
300
- LootGen uses Node.js built-in test tools and has no test dependencies:
105
+ node examples/chest.js
301
106
 
302
- ```sh
303
- npm test
304
- ```
107
+ Run the tests with:
305
108
 
306
- ## Contributing
109
+ npm test
307
110
 
308
- Bug reports and improvements are welcome. Please keep changes focused, add
309
- tests for behavior changes, and ensure `npm test` passes before submitting
310
- your contribution.
111
+ ## Exports
311
112
 
312
- ## License
113
+ The package exports the `LootGenerator` class. It also exposes `RARITIES`,
114
+ `DEFAULT_RARITY_WEIGHTS`, and `ENCHANTMENTS` as properties on the class.
313
115
 
314
- LootGen is released under the [MIT License](./LICENSE).
116
+ const LootGenerator = require('lootgen-mayank');
117
+ const { RARITIES, ENCHANTMENTS } = LootGenerator;
package/examples/basic.js CHANGED
@@ -4,4 +4,3 @@ const LootGenerator = require('..');
4
4
 
5
5
  const loot = new LootGenerator().generateLoot();
6
6
  console.log(`${loot.rarity} ${loot.name} (value: ${loot.value} gold)`);
7
- console.log(loot);
package/lib/items.js CHANGED
@@ -5,31 +5,31 @@ const { randomInt } = require('./utils');
5
5
 
6
6
  const CATALOG = Object.freeze({
7
7
  Weapon: [
8
- ['Iron Sword', 'A dependable blade with a well-balanced edge.'],
9
- ['Hunter Bow', 'A light bow made for careful, distant shots.'],
10
- ['Warhammer', 'A heavy hammer built to break stubborn defenses.'],
11
- ['Moonlit Dagger', 'A narrow dagger that catches the light strangely.']
8
+ ['Iron Sword', 'A sword made of iron.'],
9
+ ['Bow', 'A bow for ranged attacks.'],
10
+ ['Warhammer', 'A heavy hammer.'],
11
+ ['Dagger', 'A small dagger.']
12
12
  ],
13
13
  Armor: [
14
- ['Travel-worn Cuirass', 'Layered protection suited to a long journey.'],
15
- ['Oakguard Shield', 'A sturdy shield reinforced with dark iron.'],
16
- ['Sentinel Helm', 'A close-fitting helm with a clear field of view.'],
17
- ['Scale Vest', 'Overlapping scales offer flexible protection.']
14
+ ['Chest Armor', 'Armor that protects the chest.'],
15
+ ['Shield', 'A shield made from wood and iron.'],
16
+ ['Helmet', 'A metal helmet.'],
17
+ ['Scale Armor', 'Armor made from metal scales.']
18
18
  ],
19
19
  Potion: [
20
- ['Healing Draught', 'A restorative potion with a bright herbal scent.'],
21
- ['Crimson Tonic', 'A warm, peppery mixture that mends wounds.'],
22
- ['Wellspring Elixir', 'A clear elixir that glows faintly when shaken.']
20
+ ['Healing Potion', 'A potion that restores health.'],
21
+ ['Health Potion', 'A potion that helps heal injuries.'],
22
+ ['Strong Healing Potion', 'A stronger healing potion.']
23
23
  ],
24
24
  Accessory: [
25
- ['Wayfinder Ring', 'A simple ring engraved with a tiny compass rose.'],
26
- ['Warden Pendant', 'A polished pendant that feels warm to the touch.'],
27
- ['Traveler’s Charm', 'A braided charm said to steady a weary traveler.']
25
+ ['Ring', 'A ring with a compass design.'],
26
+ ['Pendant', 'A simple pendant.'],
27
+ ['Charm', 'A small braided charm.']
28
28
  ],
29
29
  Miscellaneous: [
30
- ['Ancient Coin', 'A curious coin bearing an unfamiliar crest.'],
31
- ['Sealed Map', 'A weathered map marked with a faded trail.'],
32
- ['Runed Trinket', 'A small keepsake etched with unreadable runes.']
30
+ ['Old Coin', 'An old coin with a crest.'],
31
+ ['Map', 'A map with a marked trail.'],
32
+ ['Rune Trinket', 'A small trinket with runes.']
33
33
  ]
34
34
  });
35
35
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "lootgen-mayank",
3
- "version": "1.0.0",
4
- "description": "A customizable, seeded loot and reward generator for RPGs and games.",
3
+ "version": "1.0.1",
4
+ "description": "A random RPG loot generator for Node.js.",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
7
7
  "scripts": {