Skip to content

Commit

Permalink
Adds Adjust Shield HP macro
Browse files Browse the repository at this point in the history
  • Loading branch information
JamzTheMan committed Dec 20, 2022
1 parent 682b0ae commit 46f86af
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packs/shared-macros.db
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@
{"name":"Process Persistent Damage","type":"script","author":"oiPWLVPNH7xQBULr","img":"systems/pf2e/icons/conditions/persistent-damage.webp","scope":"global","command":"PF2EPersistentDamage.processPersistentDamage(canvas.tokens.controlled);","folder":null,"sort":0,"flags":{"cf":{"id":"temp_w4f9l9idxk","path":"GM Macros","color":"#940000"}},"_id":"x84PaWKV26WQZcsz","ownership":{"default":0,"oiPWLVPNH7xQBULr":3},"_stats":{"systemId":"pf2e","systemVersion":"4.0.6","coreVersion":"10.285","createdTime":1663690776302,"modifiedTime":1663690776302,"lastModifiedBy":"bvlTPmzDPuQBXfIC"}}
{"name":"Export Compendium Mapping","type":"script","author":"oiPWLVPNH7xQBULr","img":"icons/svg/dice-target.svg","scope":"global","command":"// https://gitlab.com/-/snippets/2138719\n\nconst folderName = encodeURL(`${game.system.id}CompendiumMappingBackup`)\n\ntry {\n FilePicker.createDirectory('data', folderName, {});\n} catch (error) { return\n}\n\nui.notifications.info(\"Starting export, this may take a few moments.\")\n\nasync function exportMapping(gamePack){\n const pack = game.packs.get(gamePack);\n const actors = await pack.getDocuments();\n const mappedImages = actors.map(a => ({id: a.id, img: a.img, data: { token:{ img: a.data.token.img, randomImg: a.data.token.randomImg, scale: a.data.token.scale}}}));\n const fileName = encodeURI(`${gamePack}.json`);\n const file = new File([JSON.stringify(mappedImages, null, '')], fileName, { type: 'application/json'});\n await FilePicker.upload('data', folderName, file)\n}\n\nconst gamePacks = game.packs.filter(entry => entry.documentName === \"Actor\")\n\nfor (let pack of gamePacks) {\n let gamePack = pack.collection;\n\n await exportMapping(gamePack);\n}\n\nui.notifications.info(\"done\")","folder":null,"sort":0,"flags":{"advanced-macros":{"runAsGM":false},"cf":{"id":"temp_jgmri56d4gm","path":"System Macros","color":"#02ac24"}},"_id":"xEWrtwcCZEJ5Y3UH","ownership":{"default":0,"oiPWLVPNH7xQBULr":3},"_stats":{"systemId":"pf2e","systemVersion":"4.0.6","coreVersion":"10.285","createdTime":1663690776304,"modifiedTime":1663690776304,"lastModifiedBy":"bvlTPmzDPuQBXfIC"}}
{"name":"Reset Path","type":"script","author":"oiPWLVPNH7xQBULr","img":"icons/svg/dice-target.svg","scope":"global","command":"const combat = game.combats.active;\nconst combatant = combat.turns[combat.turn];\nconst flags = {trackedRound: 0, rulerState: null};\nimport(\"/modules/drag-ruler/src/socket.js\").then(module => module.updateCombatantDragRulerFlags(combat, combatant, flags));","folder":null,"sort":0,"flags":{"combat-utility-belt":{"macroTrigger":""},"furnace":{"runAsGM":false},"advanced-macros":{"runAsGM":false},"cf":{"id":"temp_5lpecs4iq07","path":"Under Construction","color":"#e68600"}},"_id":"yQjEBK2I3dFLwpfL","ownership":{"default":0,"oiPWLVPNH7xQBULr":3},"_stats":{"systemId":"pf2e","systemVersion":"4.0.6","coreVersion":"10.285","createdTime":1663690776305,"modifiedTime":1663690776305,"lastModifiedBy":"bvlTPmzDPuQBXfIC"}}
{"name":"Repair Targets Shield","type":"script","author":"oiPWLVPNH7xQBULr","img":"modules/Nerps-For-Foundry/images/rpg-icons/ResourcesAndCrafting/Tools/en_craft_31.webp","scope":"global","command":"const targets = game.user.targets;\nlet shieldActor = actor;\n\nif (targets.size > 0) {\n\tshieldActor = targets.first().actor;\n} else {\n\tshieldActor = actor;\n}\n\nif (!shieldActor) {\n\tui.notifications.warn(\"You must have an actor selected.\");\n} else {\n\tconst skillName = \"Craft\";\n\tconst skillKey = \"cra\";\n\tconst actionSlug = \"repair\"\n\tconst actionName = \"Repair\"\n\n\tconst modifiers = []\n\t// list custom modifiers for a single roll here\n\t// const modifiers = [new game.pf2e.Modifier('Repair Kit (Superb)', 1, 'item')];\n\n\tconst dcByLevel = [14, 15, 16, 18, 19, 20, 22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36, 38, 39, 40, 42, 44, 46, 48, 50];\n\tconst shieldEquipped = shieldActor.items.find(item => item.id == shieldActor.heldShield._id);\n\tconst DC = dcByLevel[shieldEquipped.level];\n\tconst skillRank = token.actor.system.skills[skillKey].rank\n\n const isReforgingShield = shieldEquipped.name == \"Reforging Shield\" ? true : false;\n let repairSuccessTotal = 5 + (CheckForCraftersEyePiece() ? (skillRank * 10) : (skillRank * 5));\n repairSuccessTotal = isReforgingShield ? repairSuccessTotal * 2: repairSuccessTotal;\n \t\n \tconst hasGreaterCraftersEyepiece = CheckForEquipment(\"crafters-eyepiece-greater\") ? ' (Greater)' : \"\";\n \tconst hasCraftersEyepiece = CheckForCraftersEyePiece() ? `<p><i>Crafter's Eyepiece${hasGreaterCraftersEyepiece}: +${skillRank * 5} HP included</i></p>` : \"\";\n \tconst hasReforgingShield = isReforgingShield ? `<p><i>Reforging Shield: double HP included</i></p>` : \"\";\n \t\n//\tif(shieldEquipped.name == \"Reforging Shield\") {\n//\t repairSuccessTotal = repairSuccessTotal * 2;\n//\t}\n \t\n \tconst shieldInfo = `${shieldEquipped.name}<br />Level: ${shieldEquipped.level}`;\n\n\tconst notes = [...token.actor.system.skills[skillKey].notes]; // add more notes if necessary\n\tconst options = token.actor.getRollOptions(['all', 'skill-check', skillName.toLowerCase()]);\n\toptions.push(`action:${actionSlug}`); // add more traits here in new lines\n\tgame.pf2e.Check.roll(\n\t\tnew game.pf2e.CheckModifier(\n\t\t\t`<span class=\"pf2-icon\">A</span> <b>${actionName}</b> - <p class=\"compact-text\">${skillName} Skill Check</p><p>${shieldInfo}</p><p class=\"compact-text\"><i>Repairs <b>${repairSuccessTotal} HP</b> on success, <b>${repairSuccessTotal * 2} HP</b> on Critical Success, and deals 2d6 damage on Critical Fail.</i></p>${hasCraftersEyepiece}${hasReforgingShield}`,\n\t\t\ttoken.actor.system.skills[skillKey], modifiers),\n\t\t{ actor: token.actor, type: 'skill-check', options, notes, dc: { value: DC } },\n\t\tevent\n\t\t, (Roll) => { repairShield(Roll, repairSuccessTotal, shieldEquipped); } // for callback\n\t);\n}\n\nfunction CheckForCraftersEyePiece() {\n\treturn CheckForEquipment(\"crafters-eyepiece\") || CheckForEquipment(\"crafters-eyepiece-greater\");\n}\n\nfunction CheckForEquipment(slug) {\n\tif (token.actor.items.find(\n\t\t(i) => i.system.slug === slug && i.type === 'equipment' && i.isInvested === true)) {\n\t\treturn true;\n\t}\n\treturn false;\n}\n\nasync function repairShield(RollResult, repairSuccessTotal, shieldEquipped) {\n\tlet damageDone = 0;\n\n\tif (RollResult.options.degreeOfSuccess == 0) {\n\t\tlet r = new Roll(\"2d6\");\n\t\tdamageDone = r.roll({ async: false }).total * -1;\n\t\tgame.dice3d.showForRoll(r);\n\t}\n\n\tconst hpRestored = RollResult.options.degreeOfSuccess > 0 ? (RollResult.options.degreeOfSuccess - 1) * repairSuccessTotal : damageDone;\n\tconst newShieldHp = Math.max(0, Math.min(shieldEquipped.system.hp.max, shieldEquipped.system.hp.value + hpRestored));\n\tconst shieldUpdate = { \"system.hp.value\": newShieldHp };\n\n\tawait shieldEquipped.update(shieldUpdate);\n}","folder":null,"sort":0,"flags":{"advanced-macros":{"runAsGM":false},"cf":{"id":"temp_qx20rfr41e","path":"PC Macros","color":"#0068b8"}},"_id":"rKUvXQS5vwnu9xmB","ownership":{"default":0,"oiPWLVPNH7xQBULr":3},"_stats":{"systemId":"pf2e","systemVersion":"4.5.1","coreVersion":"10.291","createdTime":1663690776298,"modifiedTime":1671572023425,"lastModifiedBy":"UuTSTLlcnPmW5OOr"}}
{"name":"Adjust Shield HP","type":"script","scope":"global","author":"UuTSTLlcnPmW5OOr","img":"icons/skills/melee/shield-damaged-broken-brown.webp","command":"const targets = game.user.targets;\nlet shieldActor = actor;\n\nif (targets.size > 0) {\n\tshieldActor = targets.first().actor;\n} else {\n\tshieldActor = actor;\n}\n\nif (!shieldActor) {\n\tui.notifications.warn(\"You must have an actor selected.\");\n} else {\n\tconst shieldEquipped = shieldActor.items.find(item => item.id == shieldActor.heldShield._id);\n\n\tconst isReforgingShield = shieldEquipped.name == \"Reforging Shield\" ? true : false;\n\tlet repairSuccessTotal = 22222;\n\tconst hasReforgingShield = isReforgingShield ? `<p><i>Reforging Shield: double HP included</i></p>` : \"\";\n\n\tconst shieldInfo = `${shieldEquipped.name}`;\n\n\tconst dialogContent = `Damage: <input id=\"damageId\" type=\"text\" autofocus />`;\n\n\tnew Dialog({\n\t\ttitle: `Adjust ${shieldEquipped.name} HP`,\n\t\tcontent: dialogContent,\n\t\tbuttons: {\n\t\t\tdoItButton: {\n\t\t\t\tlabel: \"Damage It!\",\n\t\t\t\tcallback: (html) => adjustShield(html, shieldEquipped),\n\t\t\t\ticon: `<i class=\"fas fa-check\"></i>`\n\t\t\t},\n\t\t\tcancelButton: {\n\t\t\t\tlabel: \"Cancel\",\n\t\t\t\ticon: `<i class=\"fas fa-cancel\"></i>`\n\t\t\t}\n\t\t},\n\t\tdefault: \"doItButton\"\n\t}).render(true);\n}\n\nasync function adjustShield(html, shieldEquipped) {\n\tconst damageDone = html.find(\"input#damageId\").val();\n\tconst newShieldHp = Math.max(0, shieldEquipped.system.hp.value - damageDone);\n\tconst shieldUpdate = { \"system.hp.value\": newShieldHp };\n\n\tawait shieldEquipped.update(shieldUpdate);\n\n\tui.notifications.info(`${shieldEquipped.name} now has ${newShieldHp} HP.`);\n}","ownership":{"default":2,"UuTSTLlcnPmW5OOr":3},"flags":{"core":{"sourceId":"Macro.pOrdjKw6Q946Zhjz"}},"_stats":{"systemId":"pf2e","systemVersion":"4.5.1","coreVersion":"10.291","createdTime":1671570854447,"modifiedTime":1671573116681,"lastModifiedBy":"UuTSTLlcnPmW5OOr"},"folder":null,"sort":0,"_id":"hyB0DNIsTCEC3G6s"}
{"name":"#[CF_tempEntity]","type":"chat","author":"oiPWLVPNH7xQBULr","img":"icons/svg/dice-target.svg","scope":"global","command":"","folder":null,"sort":0,"flags":{"cf":{"id":"temp_qx20rfr41e","path":"PC Macros","color":"#0068b8","name":"PC Macros","children":[],"folderPath":[],"fontColor":"#FFFFFF","icon":null,"sorting":"a","contents":["v5M5v55uHkYOEY1b","UpgJAXrxxI0jxmVW","80MTSdYXp9gNyh8R","iBFHsbO9koZQWVLJ","6AIWFBOQYpdrLqYR","6vaZrU3P6os1DLRJ","ouoOWgFlfpWmpkOl","rKUvXQS5vwnu9xmB","DVnriSL2cKJE7RHL","5f4TMts2kOCUYVvc","jHk5QZkxCETE3Df8","MclrLi2xwBkCaEGY","amP7mbLcThw8GA8V","hyB0DNIsTCEC3G6s"],"version":"2.5.3"}},"_id":"cSIwkCxnVUska1H1","ownership":{"default":0,"oiPWLVPNH7xQBULr":3},"_stats":{"systemId":"pf2e","systemVersion":"4.5.1","coreVersion":"10.291","createdTime":1663690776284,"modifiedTime":1671573300329,"lastModifiedBy":"UuTSTLlcnPmW5OOr"}}
{"name":"Adjust Shield HP","type":"script","scope":"global","author":"UuTSTLlcnPmW5OOr","img":"icons/skills/melee/shield-damaged-broken-brown.webp","command":"const targets = game.user.targets;\nlet shieldActor = actor;\n\nif (targets.size > 0) {\n\tshieldActor = targets.first().actor;\n} else {\n\tshieldActor = actor;\n}\n\nif (!shieldActor) {\n\tui.notifications.warn(\"You must have an actor selected.\");\n} else {\n\tconst shieldEquipped = shieldActor.items.find(item => item.id == shieldActor.heldShield._id);\n\n\tconst isReforgingShield = shieldEquipped.name == \"Reforging Shield\" ? true : false;\n\tlet repairSuccessTotal = 22222;\n\tconst hasReforgingShield = isReforgingShield ? `<p><i>Reforging Shield: double HP included</i></p>` : \"\";\n\n\tconst shieldInfo = `${shieldEquipped.name}`;\n\n\tconst dialogContent = `Damage: <input id=\"damageId\" type=\"text\" autofocus />`;\n\n\tnew Dialog({\n\t\ttitle: `Adjust ${shieldEquipped.name} HP`,\n\t\tcontent: dialogContent,\n\t\tbuttons: {\n\t\t\tdoItButton: {\n\t\t\t\tlabel: \"Damage It!\",\n\t\t\t\tcallback: (html) => adjustShield(html, shieldEquipped),\n\t\t\t\ticon: `<i class=\"fas fa-check\"></i>`\n\t\t\t},\n\t\t\tcancelButton: {\n\t\t\t\tlabel: \"Cancel\",\n\t\t\t\ticon: `<i class=\"fas fa-cancel\"></i>`\n\t\t\t}\n\t\t},\n\t\tdefault: \"doItButton\"\n\t}).render(true);\n}\n\nasync function adjustShield(html, shieldEquipped) {\n\tconst damageDone = html.find(\"input#damageId\").val();\n\tconst newShieldHp = Math.max(0, shieldEquipped.system.hp.value - damageDone);\n\tconst shieldUpdate = { \"system.hp.value\": newShieldHp };\n\n\tawait shieldEquipped.update(shieldUpdate);\n\n\tui.notifications.info(`${shieldEquipped.name} now has ${newShieldHp} HP.`);\n}","ownership":{"default":2,"UuTSTLlcnPmW5OOr":3},"flags":{"core":{"sourceId":"Macro.pOrdjKw6Q946Zhjz"},"cf":{"id":"temp_qx20rfr41e"}},"_stats":{"systemId":"pf2e","systemVersion":"4.5.1","coreVersion":"10.291","createdTime":1671570854447,"modifiedTime":1671573300329,"lastModifiedBy":"UuTSTLlcnPmW5OOr"},"folder":null,"sort":0,"_id":"hyB0DNIsTCEC3G6s"}

0 comments on commit 46f86af

Please sign in to comment.