From 0b27c2c69e1f335b5865ac8b829e92fce541f44e Mon Sep 17 00:00:00 2001 From: kandashi Date: Tue, 29 Jun 2021 02:25:11 +0100 Subject: [PATCH] first --- README.md | 76 ++++------------ module.json | 69 +++++--------- packs/races | 9 ++ scripts/Randomizer.js | 204 ++++++++++++++++++++++++++++++++++++++++++ scripts/lib/lib.js | 0 scripts/module.js | 7 -- 6 files changed, 253 insertions(+), 112 deletions(-) create mode 100644 packs/races create mode 100644 scripts/Randomizer.js delete mode 100644 scripts/lib/lib.js delete mode 100644 scripts/module.js diff --git a/README.md b/README.md index 68bc579..b409a98 100644 --- a/README.md +++ b/README.md @@ -1,71 +1,31 @@ ![](https://img.shields.io/badge/Foundry-v0.8.6-informational) - - - +![Latest Release Download Count](https://img.shields.io/github/downloads/kandashi/randomizer-npc/repo>/latest/module.zip) +![Forge Installs](https://img.shields.io/badge/dynamic/json?label=Forge%20Installs&query=package.installs&suffix=%25&url=https%3A%2F%2Fforge-vtt.com%2Fapi%2Fbazaar%2Fpackage%2Frandomizer-npc&colorB=4aa94a) - - - +# Randomizer NPC +This allows for your unlinked tokens to be that little extra bit different. Randomize available weapons, spells, hp and ability scores; all by just dropping a token onto the canvas. -# How to use this Template to create a versioned Release +## HP -1. Open your repository's releases page. +Auto rolls for a tokens HP (does not send chat message) -![Where to click to open repository releases.](https://user-images.githubusercontent.com/7644614/93409301-9fd25080-f864-11ea-9e0c-bdd09e4418e4.png) +## Ability Scores -2. Click "Draft a new release" +Rolls a user defined formula to apply to each ability score (default of +1d4-2) -![Draft a new release button.](https://user-images.githubusercontent.com/7644614/93409364-c1333c80-f864-11ea-89f1-abfcb18a8d9f.png) +## Randomize Weapons -3. Fill out the release version as the tag name. +Reduces the weapons on the Actor down to a specified amount by either melee/ranged weapons +Configure this level within the Special Traits menu of the *Original Actor* -If you want to add details at this stage you can, or you can always come back later and edit them. +## Randomize Spells -![Release Creation Form](https://user-images.githubusercontent.com/7644614/93409543-225b1000-f865-11ea-9a19-f1906a724421.png) +Reduces the spells on the actor down to a specified amount by spell level. +Configure this level within the Special Traits menu of the *Original Actor*. The value should be numbers split by `;` increasing in spell level from cantrip to 9th level +`4;3;2;2;1` would result in 4 cantrips, 3 first level, 2 second and third level and 1 fourth level on the unlinked token. -4. Hit submit. +## Randomize Race -5. Wait a few minutes. - -A Github Action will run to populate the `module.json` and `module.zip` with the correct urls that you can then use to distribute this release. You can check on its status in the "Actions" tab. - -![Actions Tab](https://user-images.githubusercontent.com/7644614/93409820-c1800780-f865-11ea-8c6b-c3792e35e0c8.png) - -6. Grab the module.json url from the release's details page. - -![image](https://user-images.githubusercontent.com/7644614/93409960-10c63800-f866-11ea-83f6-270cc5d10b71.png) - -This `module.json` will only ever point at this release's `module.zip`, making it useful for sharing a specific version for compatibility purposes. - -7. You can use the url `https://github.com///releases/latest/download/module.json` to refer to the manifest. - -This is the url you want to use to install the module typically, as it will get updated automatically. - -# How to List Your Releases on Package Admin - -To request a package listing for your first release, go to the [Package Submission Form](https://foundryvtt.com/packages/submit) (accessible via a link at the bottom of the "[Systems and Modules](https://foundryvtt.com/packages/)" page on the Foundry website). - -Fill in the form. "Package Name" must match the name in the module manifest. Package Title will be the display name for the package. Package URL should be your repo URL. -![image](https://user-images.githubusercontent.com/36359784/120664263-b49e5500-c482-11eb-9126-af7006389903.png) - - -One of the Foundry staff will typically get back to you with an approval or any further questions within a few days, and give you access to the package admin pages. - -Once you have access to the [module admin page](https://foundryvtt.com/admin/packages/package/), you can release a new version by going into the page for your module, scrolling to the bottom, and filling in a new Package Version. - -When listing a new version, Version should be the version number you set above, and the Manifest URL should be the manifest __for that specific version__ (do not use /latest/ here). -![image](https://user-images.githubusercontent.com/36359784/120664346-c4b63480-c482-11eb-9d8b-731b50d70939.png) - -> ### :warning: Important :warning: -> -> It is very important that you use the specific release manifest url, and not the `/latest` url here. For more details about why this is important and how Foundry Installs/Updates packages, read [this wiki article](https://foundryvtt.wiki/en/development/guides/releases-and-history). - -Clicking "Save" in the bottom right will save the new version, which means that anyone installing your module from within Foundry will get that version, and a post will be generated in the #release-announcements channel on the official Foundry VTT Discord. - - -# FoundryVTT Module - -Does something, probably - -## Changelog +Adds a item from a compendium of `races` to determine token race. The bundled compendium comes with Active Effects for the race traits, I suggest reducing the randomization slightly to offset these bonuses (1d3-2 perhaps) +Configure this within the Special Traits menu of the *Original Actor* \ No newline at end of file diff --git a/module.json b/module.json index 6b4c9fd..92f7404 100644 --- a/module.json +++ b/module.json @@ -1,48 +1,23 @@ { - "name": "module", - "title": "New Module", - "description": "", - "version": "This is auto replaced", - "library": "false", - "manifestPlusVersion": "1.0.0", - "minimumCoreVersion": "0.7.9", - "compatibleCoreVersion": "0.7.9", - "authors": [ - { - "name": "The League of Extraordinary FVTT Developers", - "url": "https://github.com/League-of-Foundry-Developers", - "discord": "discordID#0001" - } - ], - "dependencies": [ - - ], - "conflicts": [ - - ], - "esmodules": [ - "/scripts/module.js" - ], - "scripts": [ - "/scripts/lib/lib.js" - ], - "styles": [ - "/styles/module.css" - ], - "languages": [ - { - "lang": "en", - "name": "English", - "path": "languages/en.json" - } - ], - "url": "This is auto replaced", - "manifest": "This is auto replaced", - "download": "This is auto replaced", - "media": [ - { - "type": "icon", - "url": "https://avatars2.githubusercontent.com/u/71292812?s=400&u=ccdb4eeb7abf551ca8f314e5a9bfd0479a4d3d41&v=4" - } - ] -} + "name": "randomizer-npc", + "title": "Randomizer NPC", + "description": "A simple module to automatically randomize low level NPC stats", + "author": "Kandashi", + "version": "0.0.1", + "minimumCoreVersion": "0.7.5", + "compatibleCoreVersion": "0.7.7", + "system": "dnd5e", + "scripts": [ + "scripts/randomizer.js" + ], + "packs": [ + { + "name": "Randomizer Races", + "label": "Randomizer Races", + "path": "packs/races", + "entity": "Item", + "module": "randomizer-npc", + "private": false + } + ] +} \ No newline at end of file diff --git a/packs/races b/packs/races new file mode 100644 index 0000000..10bd80f --- /dev/null +++ b/packs/races @@ -0,0 +1,9 @@ +{"name":"Human","type":"feat","img":"icons/svg/item-bag.svg","data":{"description":{"value":"","chat":"","unidentified":""},"source":"","activation":{"type":"","cost":0,"condition":""},"duration":{"value":null,"units":""},"target":{"value":null,"width":null,"units":"","type":""},"range":{"value":null,"long":null,"units":""},"uses":{"value":0,"max":0,"per":null},"consume":{"type":"","target":null,"amount":null},"ability":null,"actionType":"","attackBonus":0,"chatFlavor":"","critical":null,"damage":{"parts":[],"versatile":""},"formula":"","save":{"ability":"","dc":null,"scaling":"spell"},"requirements":"","recharge":{"value":null,"charged":false}},"effects":[{"_id":"mQMQEaNbVtVXbfL2","changes":[{"key":"data.abilities.str.value","mode":2,"value":"+1"},{"key":"data.abilities.con.value","mode":2,"value":"+1"},{"key":"data.abilities.dex.value","mode":2,"value":"+1"},{"key":"data.abilities.cha.value","mode":2,"value":"+1"},{"key":"data.abilities.int.value","mode":2,"value":"+1"},{"key":"data.abilities.wis.value","mode":2,"value":"+1"}],"disabled":false,"duration":{"startTime":null},"icon":"icons/svg/aura.svg","label":"Race: Human","origin":"Item.5uMGq7lafSWnwyR5","transfer":true,"flags":{},"tint":null}],"folder":null,"sort":0,"permission":{"default":0,"E4BVikjIkVl2lL2j":3},"flags":{},"_id":"Fa7Lyf99O7XxrKzW"} +{"name":"Hill Dwarf","type":"feat","img":"icons/svg/item-bag.svg","data":{"description":{"value":"","chat":"","unidentified":""},"source":"","activation":{"type":"","cost":0,"condition":""},"duration":{"value":null,"units":""},"target":{"value":null,"width":null,"units":"","type":""},"range":{"value":null,"long":null,"units":""},"uses":{"value":0,"max":0,"per":null},"consume":{"type":"","target":null,"amount":null},"ability":null,"actionType":"","attackBonus":0,"chatFlavor":"","critical":null,"damage":{"parts":[],"versatile":""},"formula":"","save":{"ability":"","dc":null,"scaling":"spell"},"requirements":"","recharge":{"value":null,"charged":false}},"effects":[{"_id":"mQMQEaNbVtVXbfL2","changes":[{"key":"data.abilities.con.value","mode":2,"value":"+2"},{"key":"data.attributes.movement.walk","mode":2,"value":"-5"},{"key":"data.abilities.wis.value","mode":2,"value":"+1"}],"disabled":false,"duration":{"startTime":null},"icon":"icons/svg/aura.svg","label":"Race: Dwarf","origin":"Item.5uMGq7lafSWnwyR5","transfer":true,"flags":{},"tint":null}],"folder":null,"sort":0,"permission":{"default":0,"E4BVikjIkVl2lL2j":3},"flags":{},"_id":"746D4A3SCcVRpXI0"} +{"name":"High Elf","type":"feat","img":"icons/svg/item-bag.svg","data":{"description":{"value":"","chat":"","unidentified":""},"source":"","activation":{"type":"","cost":0,"condition":""},"duration":{"value":null,"units":""},"target":{"value":null,"width":null,"units":"","type":""},"range":{"value":null,"long":null,"units":""},"uses":{"value":0,"max":0,"per":null},"consume":{"type":"","target":null,"amount":null},"ability":null,"actionType":"","attackBonus":0,"chatFlavor":"","critical":null,"damage":{"parts":[],"versatile":""},"formula":"","save":{"ability":"","dc":null,"scaling":"spell"},"requirements":"","recharge":{"value":null,"charged":false}},"effects":[{"_id":"mQMQEaNbVtVXbfL2","changes":[{"key":"data.abilities.dex.value","mode":2,"value":"+2"},{"key":"data.abilities.int.value","mode":2,"value":"+1"}],"disabled":false,"duration":{"startTime":null},"icon":"icons/svg/aura.svg","label":"Race: Elf","origin":"Item.5uMGq7lafSWnwyR5","transfer":true,"flags":{},"tint":null}],"folder":null,"sort":0,"permission":{"default":0,"E4BVikjIkVl2lL2j":3},"flags":{},"_id":"UvcH6M1fSXNQCx14"} +{"name":"Lightfoot Halfling","type":"feat","img":"icons/svg/item-bag.svg","data":{"description":{"value":"","chat":"","unidentified":""},"source":"","activation":{"type":"","cost":0,"condition":""},"duration":{"value":null,"units":""},"target":{"value":null,"width":null,"units":"","type":""},"range":{"value":null,"long":null,"units":""},"uses":{"value":0,"max":0,"per":null},"consume":{"type":"","target":null,"amount":null},"ability":null,"actionType":"","attackBonus":0,"chatFlavor":"","critical":null,"damage":{"parts":[],"versatile":""},"formula":"","save":{"ability":"","dc":null,"scaling":"spell"},"requirements":"","recharge":{"value":null,"charged":false}},"effects":[{"_id":"mQMQEaNbVtVXbfL2","changes":[{"key":"data.abilities.dex.value","mode":2,"value":"+2"},{"key":"data.abilities.cha.value","mode":2,"value":"+1"},{"key":"data.attributes.movement.walk","mode":2,"value":"-5"}],"disabled":false,"duration":{"startTime":null},"icon":"icons/svg/aura.svg","label":"Race: Halfling","origin":"Item.5uMGq7lafSWnwyR5","transfer":true,"flags":{},"tint":null}],"folder":null,"sort":0,"permission":{"default":0,"E4BVikjIkVl2lL2j":3},"flags":{},"_id":"8kJGJhGg8aW4sFkj"} +{"name":"Dragonborn","type":"feat","img":"icons/svg/item-bag.svg","data":{"description":{"value":"","chat":"","unidentified":""},"source":"","activation":{"type":"","cost":0,"condition":""},"duration":{"value":null,"units":""},"target":{"value":null,"width":null,"units":"","type":""},"range":{"value":null,"long":null,"units":""},"uses":{"value":0,"max":0,"per":null},"consume":{"type":"","target":null,"amount":null},"ability":null,"actionType":"","attackBonus":0,"chatFlavor":"","critical":null,"damage":{"parts":[],"versatile":""},"formula":"","save":{"ability":"","dc":null,"scaling":"spell"},"requirements":"","recharge":{"value":null,"charged":false}},"effects":[{"_id":"mQMQEaNbVtVXbfL2","changes":[{"key":"data.abilities.str.value","mode":2,"value":"+2"},{"key":"data.abilities.cha.value","mode":2,"value":"+1"}],"disabled":false,"duration":{"startTime":null},"icon":"icons/svg/aura.svg","label":"Race: Dragonborn","origin":"Item.5uMGq7lafSWnwyR5","transfer":true,"flags":{},"tint":null}],"folder":null,"sort":0,"permission":{"default":0,"E4BVikjIkVl2lL2j":3},"flags":{},"_id":"KYNNgt2R5QIrmLWw"} +{"name":"Rock Gnome","type":"feat","img":"icons/svg/item-bag.svg","data":{"description":{"value":"","chat":"","unidentified":""},"source":"","activation":{"type":"","cost":0,"condition":""},"duration":{"value":null,"units":""},"target":{"value":null,"width":null,"units":"","type":""},"range":{"value":null,"long":null,"units":""},"uses":{"value":0,"max":0,"per":null},"consume":{"type":"","target":null,"amount":null},"ability":null,"actionType":"","attackBonus":0,"chatFlavor":"","critical":null,"damage":{"parts":[],"versatile":""},"formula":"","save":{"ability":"","dc":null,"scaling":"spell"},"requirements":"","recharge":{"value":null,"charged":false}},"effects":[{"_id":"mQMQEaNbVtVXbfL2","changes":[{"key":"data.abilities.con.value","mode":2,"value":"+1"},{"key":"data.abilities.int.value","mode":2,"value":"+2"},{"key":"data.attributes.movement.walk","mode":2,"value":"-5"}],"disabled":false,"duration":{"startTime":null},"icon":"icons/svg/aura.svg","label":"Race: Gnome","origin":"Item.5uMGq7lafSWnwyR5","transfer":true,"flags":{},"tint":null}],"folder":null,"sort":0,"permission":{"default":0,"E4BVikjIkVl2lL2j":3},"flags":{},"_id":"wqb8XHzjY8yVMSSm"} +{"name":"half-Elf","type":"feat","img":"icons/svg/item-bag.svg","data":{"description":{"value":"","chat":"","unidentified":""},"source":"","activation":{"type":"","cost":0,"condition":""},"duration":{"value":null,"units":""},"target":{"value":null,"width":null,"units":"","type":""},"range":{"value":null,"long":null,"units":""},"uses":{"value":0,"max":0,"per":null},"consume":{"type":"","target":null,"amount":null},"ability":null,"actionType":"","attackBonus":0,"chatFlavor":"","critical":null,"damage":{"parts":[],"versatile":""},"formula":"","save":{"ability":"","dc":null,"scaling":"spell"},"requirements":"","recharge":{"value":null,"charged":false}},"effects":[{"_id":"mQMQEaNbVtVXbfL2","changes":[{"key":"data.abilities.cha.value","mode":2,"value":"+1"},{"key":"data.abilities.int.value","mode":2,"value":"+2"},{"key":"data.abilities.str.value","mode":2,"value":"+1"}],"disabled":false,"duration":{"startTime":null},"icon":"icons/svg/aura.svg","label":"Race: Half-Elf","origin":"Item.5uMGq7lafSWnwyR5","transfer":true,"flags":{},"tint":null}],"folder":null,"sort":0,"permission":{"default":0,"E4BVikjIkVl2lL2j":3},"flags":{},"_id":"vNQTJBzsJmi1NEeB"} +{"name":"Half-Orc","type":"feat","img":"icons/svg/item-bag.svg","data":{"description":{"value":"","chat":"","unidentified":""},"source":"","activation":{"type":"","cost":0,"condition":""},"duration":{"value":null,"units":""},"target":{"value":null,"width":null,"units":"","type":""},"range":{"value":null,"long":null,"units":""},"uses":{"value":0,"max":0,"per":null},"consume":{"type":"","target":null,"amount":null},"ability":null,"actionType":"","attackBonus":0,"chatFlavor":"","critical":null,"damage":{"parts":[],"versatile":""},"formula":"","save":{"ability":"","dc":null,"scaling":"spell"},"requirements":"","recharge":{"value":null,"charged":false}},"effects":[{"_id":"mQMQEaNbVtVXbfL2","changes":[{"key":"data.abilities.con.value","mode":2,"value":"+1"},{"key":"data.abilities.str.value","mode":2,"value":"+2"}],"disabled":false,"duration":{"startTime":null},"icon":"icons/svg/aura.svg","label":"Race: Half-Orc","origin":"Item.5uMGq7lafSWnwyR5","transfer":true,"flags":{},"tint":null}],"folder":null,"sort":0,"permission":{"default":0,"E4BVikjIkVl2lL2j":3},"flags":{},"_id":"Bom45YP1AKea98ab"} +{"name":"Tiefling","type":"feat","img":"icons/svg/item-bag.svg","data":{"description":{"value":"","chat":"","unidentified":""},"source":"","activation":{"type":"","cost":0,"condition":""},"duration":{"value":null,"units":""},"target":{"value":null,"width":null,"units":"","type":""},"range":{"value":null,"long":null,"units":""},"uses":{"value":0,"max":0,"per":null},"consume":{"type":"","target":null,"amount":null},"ability":null,"actionType":"","attackBonus":0,"chatFlavor":"","critical":null,"damage":{"parts":[],"versatile":""},"formula":"","save":{"ability":"","dc":null,"scaling":"spell"},"requirements":"","recharge":{"value":null,"charged":false}},"effects":[{"_id":"mQMQEaNbVtVXbfL2","changes":[{"key":"data.abilities.cha.value","mode":2,"value":"+2"},{"key":"data.abilities.int.value","mode":2,"value":"+1"}],"disabled":false,"duration":{"startTime":null},"icon":"icons/svg/aura.svg","label":"Race: Tiefling","origin":"Item.5uMGq7lafSWnwyR5","transfer":true,"flags":{},"tint":null}],"folder":null,"sort":0,"permission":{"default":0,"E4BVikjIkVl2lL2j":3},"flags":{},"_id":"qm3am4UFCSjOqqqO"} diff --git a/scripts/Randomizer.js b/scripts/Randomizer.js new file mode 100644 index 0000000..b0d91f4 --- /dev/null +++ b/scripts/Randomizer.js @@ -0,0 +1,204 @@ +Hooks.on('init', () => { + + /** name of the table on which to roll if a surge occurs */ + game.settings.register("randomizer-npc", "namelist", { + name: "Randomizer names", + hint: "Names of actors to randomize, seperate with ; ", + scope: "world", + config: true, + default: "", + type: String, + }); + + game.settings.register("randomizer-npc", "hpRoll", { + name: "Randomizer HP", + hint: "Auto roll HP for new tokens", + scope: "world", + config: true, + default: false, + type: Boolean, + }) + + game.settings.register("randomizer-npc", "randomizeWeapons", { + name: "Randomizer Weapons", + hint: "Auto reduce tokens weapons to specified values", + scope: "world", + config: true, + default: false, + type: Boolean, + }) + + game.settings.register("randomizer-npc", "randomizeRace", { + name: "Randomizer Race", + hint: "Auto apply Racial Feature from compendium", + scope: "world", + config: true, + default: false, + type: Boolean, + }) + + game.settings.register("randomizer-npc", "raceCompendium", { + name: "Race Pack name", + hint: "Name of the compendium to draw race items from", + scope: "world", + config: true, + default: "", + type: String, + }) + + game.settings.register("randomizer-npc", "crRangeEnable", { + name: 'Enable CR randomization', + hint: 'Enables randomization for any create of CR equal or lower than the set value', + scope: 'world', + type: Boolean, + default: false, + config: true, + }); + + game.settings.register('randomizer-npc', 'crRange', { + name: 'CR range for randomization', + hint: 'What level of CR creature should be randomized, numeric. Use 0.25 for 1/4', + scope: 'world', + config: true, + default: 0, + type: Number, + }); + + game.settings.register("randomizer-npc", "randomizer", { + name: "Ability Randomizer Value", + hint: "Calculation of randomization. This is the calculation applied to every stat of a randomized creature", + scope: "world", + config: true, + default: "+1d4-2", + type: String, + }); + +}) + +Hooks.on("init", () => { + CONFIG.DND5E.characterFlags.randomizerMelee = { + hint: "Number of melee weapons to keep on randomization", + name: "NPC melee weapons", + section: "Randomization", + type: Number + } + CONFIG.DND5E.characterFlags.randomizerRanged = { + hint: "Number of ranged weapons to keep on randomization", + name: "NPC ranged weapons", + section: "Randomization", + type: Number + } + CONFIG.DND5E.characterFlags.randomizerSpellProg = { + hint: "Number of spells of each level should be randomized, split by ';'", + name: "NPC Spells per Level", + section: "Randomization", + type: String + } + CONFIG.DND5E.characterFlags.randomizerRace = { + hint: "Randomly assign a race item", + name: "Randomize Race", + section: "Randomization", + type: Boolean + } + +}) + +function Randomize(randomization, token) { + let newData = { + "data": { + "abilities": { + "cha": { + "value": token.actor.data.data.abilities.cha.value + new Roll(randomization).roll().total + }, + "con": { + "value": token.actor.data.data.abilities.con.value + new Roll(randomization).roll().total + }, + "dex": { + "value": token.actor.data.data.abilities.dex.value + new Roll(randomization).roll().total + }, + "int": { + "value": token.actor.data.data.abilities.int.value + new Roll(randomization).roll().total + }, + "str": { + "value": token.actor.data.data.abilities.str.value + new Roll(randomization).roll().total + }, + "wis": { + "value": token.actor.data.data.abilities.wis.value + new Roll(randomization).roll().total + } + } + } + + } + token.update({ "actorData": newData }) +} + +Hooks.on("createToken", async (tokenData, options, id) => { + if(tokenData.isLinked) return; + let token = canvas.tokens.get(tokenData._id); + let nameList = game.settings.get("randomizer-npc", "namelist").split(";"); + let randomization = game.settings.get('randomizer-npc', 'randomizer'); + + if ((game.settings.get('randomizer-npc', 'crRangeEnable') == true)) { + let crRange = game.settings.get('randomizer-npc', 'crRange') + if (token.actor.data.data.details.cr <= crRange) { + Randomize(randomization, token) + } + } + else if (nameList.includes(tokenData.name)) { + Randomize(randomization, token) + } + + if (game.settings.get("randomizer-npc", "hpRoll")) { + const formula = token.actor.data.data.attributes.hp.formula; + if (!formula) return; + const hp = new Roll(formula).roll().total; + AudioHelper.play({ src: CONFIG.sounds.dice }); + await token.actor.update({ "data.attributes.hp.value": hp, "data.attributes.hp.max": hp }); + } + + if (game.settings.get("randomizer-npc", "randomizeWeapons")) { + let { randomizerMelee, randomizerRanged, randomizerSpellProg } = token.actor.data.flags.dnd5e + let meleeWeapons = token.actor.items.filter(i => i.data.data.actionType === "mwak") + let rangedWeapons = token.actor.items.filter(i => i.data.data.actionType === "rwak") + let spells = token.actor.items.filter(i => i.data.type === "spell") + let deletedMelee = !!randomizerMelee ? await restrictWeapons(meleeWeapons, randomizerMelee) : [] + let deletedRanged = !!randomizerRanged ? await restrictWeapons(rangedWeapons, randomizerRanged) : [] + let deletedSpells = !!randomizerSpellProg ? await restrictSpells(spells, randomizerSpellProg) : [] + let update = deletedMelee.concat(deletedRanged, deletedSpells) + if (update.length > 0) { + await token.actor.deleteEmbeddedDocuments("Item", update) + } + } + + if(game.settings.get("randomizer-npc", "randomizeRace")){ + let userPackName = game.settings.get("randomizer-npc", "raceCompendium") + let pack = !!userPackName ? game.packs.find( i => i.metadata.name === userPackName) : game.packs.find( i => i.metadata.name === "Randomizer Races") + let index = Math.floor(Math.random() * pack.index.size | 0) + let race = await pack.getDocument(pack.index.contents[index]._id) + await token.actor.createEmbeddedDocuments("Item", [race.data]) + } + +}) + +async function restrictSpells(spells, prog) { + prog = prog.split(";") + // "3,2,1,0,0,0,0,0" + let spellArray = [] + for (let l = 0; l < 10; l++) { + let leveled = spells.filter(i => i.data.data.level === l) + let filtered = await restrictWeapons(leveled, prog[l]) + spellArray = spellArray.concat(filtered) + } + return spellArray +} + +async function restrictWeapons(weapons, value) { + if (typeof value === "string") value = parseInt(value) + let ids = [] + for (var i = 1; i <= weapons.length - value; i) { + let index = Math.floor(Math.random() * weapons.length | 0) + ids.push(weapons[index].id) + weapons.splice(index, 1) + } + return ids +} \ No newline at end of file diff --git a/scripts/lib/lib.js b/scripts/lib/lib.js deleted file mode 100644 index e69de29..0000000 diff --git a/scripts/module.js b/scripts/module.js deleted file mode 100644 index 222aea5..0000000 --- a/scripts/module.js +++ /dev/null @@ -1,7 +0,0 @@ -Hooks.once('init', async function() { - -}); - -Hooks.once('ready', async function() { - -});