{"name":"Entanglement Generator","type":"script","author":"thWDvNEhl7M3mC2d","img":"icons/magic/nature/root-vines-entwined-leaves.webp","scope":"global","command":"const tableHeatA = 'Entanglements - Heat 0-3'; // Entanglements - Heat 0-3\nconst tableHeatB = 'Entanglements - Heat 4/5'; // Entanglements - Heat 4/5\nconst tableHeatC = 'Entanglements - Heat 6+'; // Entanglements - Heat 6+\nconst compendiumTables = 'Entanglements'; // Compendium name \nconst version = '1.2';\nmain();\n\n/*\nTODO\n- replace text by journal\n\nsource: https://raw.githubusercontent.com/brunocalado/mestre-digital/master/Foundry%20VTT/Macros/Forged%20in%20the%20Dark/bid-entanglement.js\ncontributors: brunocalado, LebombJames\nicon: icons/magic/nature/root-vines-entwined-leaves.webp\n*/\n \nasync function main() {\n \n playersNames = game.actors.contents.filter((t) => t.data.type === \"crew\").map((p=> p.data.name)); \n\n let playerNameList;\n\n playersNames.map((el) => { \n playerNameList += ``; \n }); \n \n new Dialog({\n title: `Entanglement - v${version}`,\n content: `\n
\n Whisper?\n
\n `,\n buttons: {\n roll: {\n label: \"Change\",\n callback: (html) => {\n createImageFolder(html);\n }\n }, \n cancel: {\n label: \"Cancel\"\n }\n }\n }).render(true)\n}\n\nasync function createImageFolder(html) {\n let playerName = html.find(\"#playerName\")[0].value;\n let whisper = html.find(\"#whisper\")[0].checked;\n\n let crew = game.actors.getName(playerName).data.data;\n let crewHeat = parseInt(crew.heat);\n let crewWanted = parseInt(crew.wanted);\n\n let entanglementToUse = '';\n\n switch (crewHeat) {\n case 0:\n case 1:\n case 2:\n case 3:\n entanglementToUse = await drawFromTable(tableHeatA, compendiumTables) \n break\n case 4:\n case 5:\n entanglementToUse = await drawFromTable(tableHeatB, compendiumTables) \n break\n case 6:\n case 7:\n case 8:\n case 9:\n entanglementToUse = await drawFromTable(tableHeatC, compendiumTables) \n }\n\n let rollFormula = `${crewWanted}d6`;\n if (rollFormula === \"0d6\") {\n rollFormula = \"2d6kl1\";\n }\n\n entanglementToUse.data.formula = rollFormula;\n \n if (whisper) {\n entanglementToUse.draw({rollMode: 'gmroll'});\n } else {\n entanglementToUse.draw();\n } \n}\n\nasync function drawFromTable(tableName, compendiumName) {\n let list_compendium = await game.packs.filter(p=>p.documentName=='RollTable'); \n let inside = await list_compendium.filter( p=>p.metadata.label==compendiumName )[0].getDocuments(); \n let table = await inside.filter( p=>p.data['name']==tableName )[0];\n \n if (!table) {\n ui.notifications.warn(`Table ${tableName} not found.`, {});\n return;\n }\n return await table;\n}","folder":null,"sort":0,"permission":{"default":0,"thWDvNEhl7M3mC2d":3},"flags":{"core":{"sourceId":"Macro.nlsTrxhKZxLIqHWD"}},"_id":"SbpxJdLv2Q1eTJhq"}