Skip to content

Commit

Permalink
Various new modules and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyVadala committed May 28, 2020
1 parent c039672 commit ad575db
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 35 deletions.
20 changes: 9 additions & 11 deletions packs/macros-actor.db

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packs/macros-item.db
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{"_id":"D38Cw70PsNaaQicv","name":"Tool Proficiency","permission":{"default":0,"y5gmtwxmW3A5ZuOP":3},"type":"script","flags":{},"scope":"global","command":"/**\n * Grab a list of tools in the selected player's inventory, then all the user to make a roll on the tool.\n * Will take into consideration if the player is proficient in using the tool.\n */\n\n// get the first entry from the array of currently selected tokens. Works best/exclusively with one selected token\nconst target = canvas.tokens.controlled[0].actor;\n// get the abilities of the selected token for ease of access later\nconst { abilities } = target.data.data;\n// Only items set as \"tools\" will be included!\n// get all held and equipped Tools/Kits/Supplies. Might want to replace with /[tT]ools|[kK]it|[sS]upplies|[sS]et$/ if gaming sets should be included\nconst toolsInInventory = target.items.filter( item => item.name.match(/[tT]ools|[kK]it|[sS]upplies$/) && item.data.data.hasOwnProperty(\"proficient\"));\n// const toolProficiencies = target.data.data.traits.toolProf; // Tools have proficiency mod in the object under <item>.data.data.proficient. \nlet tool = undefined;\n\n// Choose ability mod dialog\nconst abilityDialog = (async () => {\n let template = `\n <div>\n <div class=\"form-group\">\n <label>Choose ability</label>\n <select id=\"selectedAbility\">`\n for (let ability in abilities) {\n switch (ability) {\n case \"str\":\n abilities[ability].name = \"Strength\"\n break;\n case \"dex\":\n abilities[ability].name = \"Dexterity\"\n break;\n case \"con\":\n abilities[ability].name = \"Constitution\"\n break;\n case \"int\":\n abilities[ability].name = \"Intelligence\"\n break;\n case \"wis\":\n abilities[ability].name = \"Wisdom\"\n break;\n case \"cha\":\n abilities[ability].name = \"Charisma\"\n break;\n default:\n console.log(\"something went wrong\");\n }\n template += `<option value=\"${ability}\">${abilities[ability].name} (${abilities[ability].value})</option>`;\n }\n template += `</select>\n </div>\n </div>`\n\n\n new Dialog({\n title: tool.name,\n content: template,\n buttons: {\n ok: {\n icon: '<i class=\"fas fa-check\"></i>',\n label: \"OK\",\n callback: async (html) => {\n const selection = html.find(\"#selectedAbility\")[0].value;\n console.log(tool, target);\n let prof = tool.data.data.proficient * target.data.data.attributes.prof; // target might be half or doubly proficient. This will make sure it is accounted for\n\n let messageContent = `${target.name} rolled a <b>[[1d20+${abilities[selection].mod}(${abilities[selection].name})+${prof}(Proficiency)]]</b> for the ${tool.name} check.<br>`;\n let chatData = {\n user: game.user.id,\n speaker: ChatMessage.getSpeaker(),\n content: messageContent,\n // uncomment the line below to always whisper the roll to the GM\n // whisper: game.users.entities.filter(u => u.isGM).map(u => u._id)\n };\n ChatMessage.create(chatData, {});\n }\n },\n cancel: {\n icon: '<i class=\"fas fa-times\"></i>',\n label: 'Cancel'\n }\n },\n default: \"cancel\"\n }).render(true);\n})\n\n// Choose tool dialog\nif (toolsInInventory.length) {\n (async () => {\n let template = `\n <div>\n <div class=\"form-group\">\n <label>Choose a tool</label>\n <select id=\"selectedTool\">`\n toolsInInventory.forEach( tempTool => { \n template += `<option value=\"${tempTool.name}\">${tempTool.name}</option>`;\n });\n template += `</select>\n </div>\n </div>`;\n\n new Dialog({\n title: 'Which tool?',\n content: template,\n buttons: {\n ok: {\n icon: '<i class=\"fas fa-check\"></i>',\n label: \"OK\",\n callback: async (html) => {\n let selection = html.find(\"#selectedTool\")[0].value;\n tool = toolsInInventory.find( item => item.name === selection )\n abilityDialog();\n }\n },\n cancel: {\n icon: '<i class=\"fas fa-times\"></i>',\n label: 'Cancel'\n }\n },\n default: \"cancel\"\n }).render(true);\n })() \n}\n\nelse {\n new Dialog({\n title: 'No Tools!',\n content: '<p>You don\\'t seem to have any tool with you.</p>',\n buttons: {\n ok: {\n icon: '<i class=\"fas fa-check\"></i>',\n label: \"OK\"\n }\n },\n default: \"ok\"\n }).render(true);\n}","author":"y5gmtwxmW3A5ZuOP","img":"icons/svg/dice-target.svg","actorIds":[]}
{"_id":"JGpakxFCcEhZGIVZ","name":"Foundry Item Permission","permission":{"default":0,"y5gmtwxmW3A5ZuOP":3},"type":"script","flags":{},"scope":"global","command":"const form = `\n <div style=\"display: inline-block; width: 100px\">Folder:</div>\n <input type=\"string\" id=\"folderName\">\n <br />\n\n <div style=\"display: inline-block; width: 100px\">Permission:</div>\n <select id=\"desiredPermission\" />\n <option value=\"0\">None</option>\n <option value=\"1\">Limited</option>\n <option value=\"2\">Observer</option>\n <option value=\"3\">Owner</option>\n </select>\n <br />\n\n <label>\n \t<input type=\"checkbox\" id=\"recurse\" checked/>\n Recurse into subfolders\n\t</label>\n`;\n\nconst dialog = new Dialog({\n title: \"Set desired permission\",\n content: form,\n buttons: {\n use: {\n label: \"Apply permissions\",\n callback: applyPermissions\n }\n }\n}).render(true);\n\nfunction applyPermissions(html) {\n const folderName = html.find(`input#folderName`)[0].value;\n const permission = html.find(`select#desiredPermission`)[0].value;\n const recurse = html.find(`input#recurse`)[0].checked;\n \n const folders = game.folders.filter(f => f.name === folderName);\n if (folders.length === 0) {\n ui.notifications.error(`Your world does not have any folders named '${folderName}'.`);\n }\n else if(folders.length > 1) {\n ui.notifications.error(`Your world has more than one folder named ${folderName}`) \n }\n else {\n repermission(folders[0], permission, recurse);\n ui.notifications.notify(`Desired permissions were set successfully for '${folderName}'.`);\n }\n}\n\nfunction repermission(currentFolder, desiredPermission, recurse) {\n console.debug(\"Repermissioning: \", currentFolder.name);\n \n if (currentFolder.content) {\n currentFolder.content.map(item => {\n let newPermissions = duplicate(item.data.permission);\n newPermissions.default = desiredPermission;\n console.debug(\" Item:\", item.data.name);\n item.update({ permission: newPermissions });\n });\n }\n\n if (currentFolder.children && recurse) {\n currentFolder.children.map(({ data }) => {\n repermission(\n game.folders.entities.filter(f => f.data._id == data._id)[0],\n desiredPermission,\n recurse);\n });\n }\n}\n","author":"y5gmtwxmW3A5ZuOP","img":"icons/svg/dice-target.svg","actorIds":[]}
{"_id":"D38Cw70PsNaaQicv","name":"Tool Proficiency","permission":{"default":0,"y5gmtwxmW3A5ZuOP":3},"type":"script","flags":{},"scope":"global","command":"/**\n * Grab a list of tools in the selected player's inventory, then all the user to make a roll on the tool.\n * Will take into consideration if the player is proficient in using the tool.\n */\n\n// get the first entry from the array of currently selected tokens. Works best/exclusively with one selected token\nconst target = canvas.tokens.controlled[0].actor;\n// get the abilities of the selected token for ease of access later\nconst { abilities } = target.data.data;\n// Only items set as \"tools\" will be included!\n// get all held and equipped Tools/Kits/Supplies. Might want to replace with /[tT]ools|[kK]it|[sS]upplies|[sS]et$/ if gaming sets should be included\nconst toolsInInventory = target.items.filter( item => item.name.match(/[tT]ools|[kK]it|[sS]upplies$/) && item.data.data.hasOwnProperty(\"proficient\"));\n// const toolProficiencies = target.data.data.traits.toolProf; // Tools have proficiency mod in the object under <item>.data.data.proficient. \nlet tool = undefined;\n\n// Choose ability mod dialog\nconst abilityDialog = (async () => {\n let template = `\n <div>\n <div class=\"form-group\">\n <label>Choose ability</label>\n <select id=\"selectedAbility\">`\n for (let ability in abilities) {\n switch (ability) {\n case \"str\":\n abilities[ability].name = \"Strength\"\n break;\n case \"dex\":\n abilities[ability].name = \"Dexterity\"\n break;\n case \"con\":\n abilities[ability].name = \"Constitution\"\n break;\n case \"int\":\n abilities[ability].name = \"Intelligence\"\n break;\n case \"wis\":\n abilities[ability].name = \"Wisdom\"\n break;\n case \"cha\":\n abilities[ability].name = \"Charisma\"\n break;\n default:\n console.log(\"something went wrong\");\n }\n template += `<option value=\"${ability}\">${abilities[ability].name} (${abilities[ability].value})</option>`;\n }\n template += `</select>\n </div>\n </div>`\n\n\n new Dialog({\n title: tool.name,\n content: template,\n buttons: {\n ok: {\n icon: '<i class=\"fas fa-check\"></i>',\n label: \"OK\",\n callback: async (html) => {\n const selection = html.find(\"#selectedAbility\")[0].value;\n console.log(tool, target);\n let prof = tool.data.data.proficient * target.data.data.attributes.prof; // target might be half or doubly proficient. This will make sure it is accounted for\n\n let messageContent = `${target.name} rolled a <b>[[1d20+${abilities[selection].mod}(${abilities[selection].name})+${prof}(Proficiency)]]</b> for the ${tool.name} check.<br>`;\n let chatData = {\n user: game.user.id,\n speaker: ChatMessage.getSpeaker(),\n content: messageContent,\n // uncomment the line below to always whisper the roll to the GM\n // whisper: game.users.entities.filter(u => u.isGM).map(u => u._id)\n };\n ChatMessage.create(chatData, {});\n }\n },\n cancel: {\n icon: '<i class=\"fas fa-times\"></i>',\n label: 'Cancel'\n }\n },\n default: \"cancel\"\n }).render(true);\n})\n\n// Choose tool dialog\nif (toolsInInventory.length) {\n (async () => {\n let template = `\n <div>\n <div class=\"form-group\">\n <label>Choose a tool</label>\n <select id=\"selectedTool\">`\n toolsInInventory.forEach( tempTool => { \n template += `<option value=\"${tempTool.name}\">${tempTool.name}</option>`;\n });\n template += `</select>\n </div>\n </div>`;\n\n new Dialog({\n title: 'Which tool?',\n content: template,\n buttons: {\n ok: {\n icon: '<i class=\"fas fa-check\"></i>',\n label: \"OK\",\n callback: async (html) => {\n let selection = html.find(\"#selectedTool\")[0].value;\n tool = toolsInInventory.find( item => item.name === selection )\n abilityDialog();\n }\n },\n cancel: {\n icon: '<i class=\"fas fa-times\"></i>',\n label: 'Cancel'\n }\n },\n default: \"cancel\"\n }).render(true);\n })() \n}\n\nelse {\n new Dialog({\n title: 'No Tools!',\n content: '<p>You don\\'t seem to have any tool with you.</p>',\n buttons: {\n ok: {\n icon: '<i class=\"fas fa-check\"></i>',\n label: \"OK\"\n }\n },\n default: \"ok\"\n }).render(true);\n}\n","author":"y5gmtwxmW3A5ZuOP","img":"icons/svg/dice-target.svg","actorIds":[]}
{"_id":"mFFE3IauEDuuY3pQ","name":"Equip Unequip Shield","permission":{"default":0,"y5gmtwxmW3A5ZuOP":3},"type":"script","flags":{},"scope":"global","command":"/**\n * Equips or unequips an item named 'Shield'. Then updates the character's AC.\n * Author: ^ and stick#0520\n */\n\nlet charData = game.user.character;\nlet shield = charData.items.find(i => i.name == 'Shield');\n\nif (shield != null)\n{\n let item = game.user.character.getOwnedItem(shield._id);\n let attr = \"data.equipped\";\n item.update({[attr]: !getProperty(item.data, attr)});\n\n if (getProperty(item.data, attr)) {\n charData.update({\"data.attributes.ac.value\": charData.data.data.attributes.ac.value-2});\n } else {\n charData.update({\"data.attributes.ac.value\": charData.data.data.attributes.ac.value+2});\n }\n}\n","author":"y5gmtwxmW3A5ZuOP","img":"icons/svg/dice-target.svg","actorIds":[]}
Loading

0 comments on commit ad575db

Please sign in to comment.