{"id":16812824,"url":"https://github.com/seiyria/lootastic","last_synced_at":"2025-04-11T01:43:33.582Z","repository":{"id":66160036,"uuid":"94337713","full_name":"seiyria/lootastic","owner":"seiyria","description":"a loot rolling system","archived":false,"fork":false,"pushed_at":"2018-10-11T16:29:59.000Z","size":8,"stargazers_count":10,"open_issues_count":1,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-24T22:51:17.698Z","etag":null,"topics":["loot","loot-rolling","random-drops","rolling","rpg"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/seiyria.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-14T14:07:02.000Z","updated_at":"2021-05-21T14:00:30.000Z","dependencies_parsed_at":"2023-03-10T23:41:27.573Z","dependency_job_id":null,"html_url":"https://github.com/seiyria/lootastic","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seiyria%2Flootastic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seiyria%2Flootastic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seiyria%2Flootastic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seiyria%2Flootastic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/seiyria","download_url":"https://codeload.github.com/seiyria/lootastic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248208547,"owners_count":21065202,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["loot","loot-rolling","random-drops","rolling","rpg"],"created_at":"2024-10-13T10:23:33.647Z","updated_at":"2025-04-11T01:43:33.574Z","avatar_url":"https://github.com/seiyria.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lootastic\n\nA simple and flexible loot rolling system.\n\n## Install\n`npm i lootastic`\n\n## Usage\n\nYou can create a LootTable with:\n\n* a plain array (all item weights will be set to 1)\n* an array with objects formatted like `{ chance: X, result: \u003citem\u003e }`\n\nYou can also pass in a `rollModifier` into the options object to increase the weights of every item.\n\nExamples:\n\n```\n// plain initialization - all weights are 1\nlet lootTable = new LootTable(['sword', 'armor', 'potion', 'shield']);\n\n// weight initialization - swords are common, potions are not\nlet lootTable = new LootTable([\n    { chance: 1, result: 'potion' },\n    { chance: 5, result: 'armor' },\n    { chance: 10, result: 'shield' },\n    { chance: 20, result: 'sword' }\n]);\n\n// weight initialization with a rollModifier - each weight is 10 higher\n// a common use-case here is a \"luck bonus\" in item drops\nlet lootTable = new LootTable([\n    { chance: 1, result: 'potion' },\n    { chance: 5, result: 'armor' },\n    { chance: 10, result: 'shield' },\n    { chance: 20, result: 'sword', maxChance: 100 }, // always a 1/5 drop rate\n    { chance: -1, result: 'gold' } // always drops\n], { rollModifier: 10 });\n```\n\nYou can roll a table using one of 3 methods:\n\n* choose X items with replacement\n* choose X items without replacement\n* try to roll for each item in the table using a chance/X probability (where X would be something like 1/10000)\n\nExamples:\n```\nlet result = lootTable.chooseWithReplacement(1) // 1 random item + gold\nlet result = lootTable.chooseWithReplacement(5) // 5 random items + gold\n\nlet result = lootTable.chooseWithoutReplacement(1) // 1 random item + gold\nlet result = lootTable.chooseWithoutReplacement(4) // the whole table + gold\nlet result = lootTable.chooseWithoutReplacement(5) // error - not enough items to choose\n\nlet result = lootTable.tryToDropEachItem(1) // all items will drop + gold\nlet result = lootTable.tryToDropEachItem(10) // shield and sword will guaranteed drop + gold\nlet result = lootTable.tryToDropEachItem(100) // some items might drop + gold\n```\n\nIf you want to roll multiple loot tables at once, or the same loot table multiple times (suppose you have a monster drop table and a zone drop table), you can use the LootRoller class:\n\n```\nlet result = LootRoller.rollTables([\n\n    { table: lootTable, func: LootFunctions.WithoutReplacement, args: 1 }, // always picks 1 item (+ gold)\n    { table: lootTable, func: LootFunctions.EachItem, args: 1 }, // try to drop each item (+ gold)\n\n]); // 2 gold entries, 1 item, and maybe more depending on the EachItem roll\n```\n\n## Usage Notes\n\n* You can add a property `maxChance` to an item to customize `tryToDropForEachItem` when you don't want to scale item probabilities.\n* You can specify a weight of -1 to tell an item to always drop in addition to other random drops.\n* Use plain objects, not classes, since the data is cloned when rolling loot.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseiyria%2Flootastic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseiyria%2Flootastic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseiyria%2Flootastic/lists"}