Skip to content

Commit

Permalink
Make Add XP compatible with WFRP4e v8
Browse files Browse the repository at this point in the history
  • Loading branch information
Jagusti committed Sep 8, 2024
1 parent 631a8a2 commit 8e51e78
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. The format
## Unreleased
See [Issue Backlog](../../issues) and [Roadmap](../../milestones).
* *Fixed* end of round operations happening at the end every combat turn. Lose Momentum is no longer triggered after each character turn. [[#275](https://github.com/Jagusti/fvtt-wfrp4e-gmtoolkit/issues/275)]
* *Added* WFRP4e v8 compatibility for Add XP macro. This is a **breaking** change.

## [Version 7.1.1](https://github.com/Jagusti/fvtt-wfrp4e-gmtoolkit/releases/tag/v7.1.1) (2024-08-12)
* *Fixed* Maintenance utility not loading when (RollTable) content version flag is missing
Expand Down
6 changes: 3 additions & 3 deletions scripts/macros/add-xp.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function updateXP (awardees, XP, reason) {
const newXPCurrent = Math.max(XPCurrent + XP, 0)

// Update token actor or actor
pc?.actor ? pc.actor.awardExp(XP, reason) : pc.awardExp(XP, reason)
pc?.actor ? pc.actor.system.awardExp(XP, reason) : pc.system.awardExp(XP, reason)

// Build report message
chatContent += game.i18n.format("GMTOOLKIT.AddXP.Success", { recipient, XPTotal, newXPTotal, XPCurrent, newXPCurrent } )
Expand All @@ -108,8 +108,8 @@ function updateXP (awardees, XP, reason) {

/* ==========
* MACRO: Add XP
* VERSION: 6.1.0
* UPDATED: 2022-10-23
* VERSION: 8.0.0
* UPDATED: 2024-09-08
* DESCRIPTION: Adds a set amount of XP to all or targeted player character(s). Adds XP update note to the chat log.
* TIP: Characters must have a player assigned (if default group is 'party') or be player-owned (if default group is 'company').
* TIP: Default XP amount and reason can be preset in module settings, along with option to bypass prompt for XP amount each time.
Expand Down
10 changes: 5 additions & 5 deletions src/packs/gm-toolkit-macros/Add_XP_rzKeTLKp0bOp5SK9.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"author": "k5y1jEYMBqd9uLUx",
"img": "modules/wfrp4e-gm-toolkit/assets/icons/add-xp.svg",
"scope": "global",
"command": "addXP()\n\nasync function addXP () {\n\n // Setup: determine group of actors to be awarded experience\n let awardees = []\n if (game.user.targets.size < 1) {\n // (1) all assigned player characters\n awardees = game.gmtoolkit.utility\n .getGroup(game.settings.get(\"wfrp4e-gm-toolkit\", \"defaultPartySessionTurnover\"))\n .filter(g => g.type === \"character\")\n } else {\n // (2) all targeted tokens of awardee selection\n awardees = game.gmtoolkit.utility\n .getGroup(game.settings.get(\"wfrp4e-gm-toolkit\", \"defaultPartySessionTurnover\"), { interaction: \"targeted\" })\n .filter(g => g.type === \"character\")\n }\n\n // Setup: exit with notice if there are no player-assigned characters\n if (awardees.length < 1) return ui.notifications.error(game.i18n.localize(\"GMTOOLKIT.Token.TargetPCs\"), {})\n\n // Get session ID/date, default XP award and default reason\n const XP = Number(game.settings.get(\"wfrp4e-gm-toolkit\", \"addXPDefaultAmount\"))\n let reason = (game.settings.get(\"wfrp4e-gm-toolkit\", \"addXPDefaultReason\") === \"null\")\n ? \"\"\n : game.settings.get(\"wfrp4e-gm-toolkit\", \"addXPDefaultReason\")\n if (reason) {\n reason = game.settings.get(\"wfrp4e-gm-toolkit\", \"addXPDefaultReason\")\n const session = game.gmtoolkit.utility.getSession()\n reason = (session.date)\n ? reason.replace(\"(%date%)\", `(${session.date})`)\n : reason.replace(\" (%date%)\", \"\")\n reason = (session.id !== \"null\" )\n ? reason.replace(\"%session%\", session.id)\n : reason = reason.replace(\"%session%\", \"\")\n }\n\n // Prompt for XP if option is set\n if (game.settings.get(\"wfrp4e-gm-toolkit\", \"addXPPrompt\")) {\n let awardeeList = \"<ul>\"\n awardees.forEach(pc => {\n awardeeList += `<li>${pc?.actor?.name || pc.name}</li>`\n })\n awardeeList += \"</ul>\"\n const dialog = new Dialog({\n title: game.i18n.localize(\"GMTOOLKIT.Dialog.AddXP.Title\"),\n content: `<form>\n <p>${game.i18n.format(\"GMTOOLKIT.Dialog.AddXP.Recipients\", { recipients: awardeeList })}</p>\n <div class=\"form-group\">\n <label>${game.i18n.localize(\"GMTOOLKIT.Dialog.AddXP.Prompt\")}</label> \n <input type=\"text\" id=\"add-xp\" name=\"add-xp\" value=\"${XP}\" />\n </div>\n <div class=\"form-group\">\n <label>${game.i18n.localize(\"GMTOOLKIT.Dialog.AddXP.Reason\")}</label> \n <input type=\"text\" id=\"xp-reason\" name=\"xp-reason\" value=\"${reason}\" />\n </div>\n </form>`,\n buttons: {\n yes: {\n icon: \"<i class='fas fa-check'></i>\",\n label: game.i18n.localize(\"GMTOOLKIT.Dialog.Apply\"),\n callback: html => {\n const XP = Math.round(html.find(\"#add-xp\").val())\n if (isNaN(XP)) return ui.notifications.error(game.i18n.localize(\"GMTOOLKIT.Dialog.AddXP.InvalidXP\"))\n const reason = html.find(\"#xp-reason\").val()\n updateXP(awardees, XP, reason)\n }\n },\n no: {\n icon: \"<i class='fas fa-times'></i>\",\n label: game.i18n.localize(\"GMTOOLKIT.Dialog.Cancel\")\n }\n },\n default: \"yes\"\n }).render(true)\n } else {\n updateXP(awardees, XP, reason)\n }\n\n} // END: addXP\n\nfunction updateXP (awardees, XP, reason) {\n let chatContent = \"\"\n\n // Cycle through player characters, gathering experience change data for report message\n awardees.forEach(pc => {\n const recipient = pc?.actor?.name || pc.name\n const XPTotal = pc?.details?.experience?.total\n const newXPTotal = Math.max(XPTotal + XP, 0)\n const XPCurrent = pc?.details?.experience?.current || 0\n const newXPCurrent = Math.max(XPCurrent + XP, 0)\n\n // Update token actor or actor\n pc?.actor ? pc.actor.awardExp(XP, reason) : pc.awardExp(XP, reason)\n\n // Build report message\n chatContent += game.i18n.format(\"GMTOOLKIT.AddXP.Success\", { recipient, XPTotal, newXPTotal, XPCurrent, newXPCurrent } )\n }) // End cycle\n\n // confirm changes made in whisper to GM\n const chatData = game.wfrp4e.utility.chatDataSetup(chatContent, \"gmroll\", false)\n chatData.flavor = game.i18n.format(\"GMTOOLKIT.AddXP.Flavor\", { XP, reason })\n ChatMessage.create(chatData, {})\n console.log(chatContent)\n\n} // END: updateXP\n\n\n/* ==========\n * MACRO: Add XP\n * VERSION: 6.1.0\n * UPDATED: 2022-10-23\n * DESCRIPTION: Adds a set amount of XP to all or targeted player character(s). Adds XP update note to the chat log.\n * TIP: Characters must have a player assigned (if default group is 'party') or be player-owned (if default group is 'company').\n * TIP: Default XP amount and reason can be preset in module settings, along with option to bypass prompt for XP amount each time.\n * TIP: Non-whole numbers are rounded off. Negative numbers are subtracted.\n ========== */",
"command": "addXP()\n\nasync function addXP () {\n\n // Setup: determine group of actors to be awarded experience\n let awardees = []\n if (game.user.targets.size < 1) {\n // (1) all assigned player characters\n awardees = game.gmtoolkit.utility\n .getGroup(game.settings.get(\"wfrp4e-gm-toolkit\", \"defaultPartySessionTurnover\"))\n .filter(g => g.type === \"character\")\n } else {\n // (2) all targeted tokens of awardee selection\n awardees = game.gmtoolkit.utility\n .getGroup(game.settings.get(\"wfrp4e-gm-toolkit\", \"defaultPartySessionTurnover\"), { interaction: \"targeted\" })\n .filter(g => g.type === \"character\")\n }\n\n // Setup: exit with notice if there are no player-assigned characters\n if (awardees.length < 1) return ui.notifications.error(game.i18n.localize(\"GMTOOLKIT.Token.TargetPCs\"), {})\n\n // Get session ID/date, default XP award and default reason\n const XP = Number(game.settings.get(\"wfrp4e-gm-toolkit\", \"addXPDefaultAmount\"))\n let reason = (game.settings.get(\"wfrp4e-gm-toolkit\", \"addXPDefaultReason\") === \"null\")\n ? \"\"\n : game.settings.get(\"wfrp4e-gm-toolkit\", \"addXPDefaultReason\")\n if (reason) {\n reason = game.settings.get(\"wfrp4e-gm-toolkit\", \"addXPDefaultReason\")\n const session = game.gmtoolkit.utility.getSession()\n reason = (session.date)\n ? reason.replace(\"(%date%)\", `(${session.date})`)\n : reason.replace(\" (%date%)\", \"\")\n reason = (session.id !== \"null\" )\n ? reason.replace(\"%session%\", session.id)\n : reason = reason.replace(\"%session%\", \"\")\n }\n\n // Prompt for XP if option is set\n if (game.settings.get(\"wfrp4e-gm-toolkit\", \"addXPPrompt\")) {\n let awardeeList = \"<ul>\"\n awardees.forEach(pc => {\n awardeeList += `<li>${pc?.actor?.name || pc.name}</li>`\n })\n awardeeList += \"</ul>\"\n const dialog = new Dialog({\n title: game.i18n.localize(\"GMTOOLKIT.Dialog.AddXP.Title\"),\n content: `<form>\n <p>${game.i18n.format(\"GMTOOLKIT.Dialog.AddXP.Recipients\", { recipients: awardeeList })}</p>\n <div class=\"form-group\">\n <label>${game.i18n.localize(\"GMTOOLKIT.Dialog.AddXP.Prompt\")}</label> \n <input type=\"text\" id=\"add-xp\" name=\"add-xp\" value=\"${XP}\" />\n </div>\n <div class=\"form-group\">\n <label>${game.i18n.localize(\"GMTOOLKIT.Dialog.AddXP.Reason\")}</label> \n <input type=\"text\" id=\"xp-reason\" name=\"xp-reason\" value=\"${reason}\" />\n </div>\n </form>`,\n buttons: {\n yes: {\n icon: \"<i class='fas fa-check'></i>\",\n label: game.i18n.localize(\"GMTOOLKIT.Dialog.Apply\"),\n callback: html => {\n const XP = Math.round(html.find(\"#add-xp\").val())\n if (isNaN(XP)) return ui.notifications.error(game.i18n.localize(\"GMTOOLKIT.Dialog.AddXP.InvalidXP\"))\n const reason = html.find(\"#xp-reason\").val()\n updateXP(awardees, XP, reason)\n }\n },\n no: {\n icon: \"<i class='fas fa-times'></i>\",\n label: game.i18n.localize(\"GMTOOLKIT.Dialog.Cancel\")\n }\n },\n default: \"yes\"\n }).render(true)\n } else {\n updateXP(awardees, XP, reason)\n }\n\n} // END: addXP\n\nfunction updateXP (awardees, XP, reason) {\n let chatContent = \"\"\n\n // Cycle through player characters, gathering experience change data for report message\n awardees.forEach(pc => {\n const recipient = pc?.actor?.name || pc.name\n const XPTotal = pc?.details?.experience?.total\n const newXPTotal = Math.max(XPTotal + XP, 0)\n const XPCurrent = pc?.details?.experience?.current || 0\n const newXPCurrent = Math.max(XPCurrent + XP, 0)\n\n // Update token actor or actor\n pc?.actor ? pc.actor.system.awardExp(XP, reason) : pc.system.awardExp(XP, reason)\n\n // Build report message\n chatContent += game.i18n.format(\"GMTOOLKIT.AddXP.Success\", { recipient, XPTotal, newXPTotal, XPCurrent, newXPCurrent } )\n }) // End cycle\n\n // confirm changes made in whisper to GM\n const chatData = game.wfrp4e.utility.chatDataSetup(chatContent, \"gmroll\", false)\n chatData.flavor = game.i18n.format(\"GMTOOLKIT.AddXP.Flavor\", { XP, reason })\n ChatMessage.create(chatData, {})\n console.log(chatContent)\n\n} // END: updateXP\n\n\n/* ==========\n * MACRO: Add XP\n * VERSION: 8.0.0\n * UPDATED: 2024-09-08\n * DESCRIPTION: Adds a set amount of XP to all or targeted player character(s). Adds XP update note to the chat log.\n * TIP: Characters must have a player assigned (if default group is 'party') or be player-owned (if default group is 'company').\n * TIP: Default XP amount and reason can be preset in module settings, along with option to bypass prompt for XP amount each time.\n * TIP: Non-whole numbers are rounded off. Negative numbers are subtracted.\n ========== */",
"folder": null,
"sort": 0,
"flags": {
"wfrp4e-gm-toolkit": {
"version": "6.1.0"
"version": "8.0.0"
}
},
"ownership": {
Expand All @@ -19,10 +19,10 @@
"_stats": {
"systemId": "wfrp4e",
"systemVersion": "6.1.4",
"coreVersion": "12.329",
"coreVersion": "12.331",
"createdTime": null,
"modifiedTime": 1666489057871,
"lastModifiedBy": "Yz8naH0UqWS3uLwh",
"modifiedTime": 1725793063938,
"lastModifiedBy": "Pt7qzajGGC2jofTq",
"compendiumSource": null,
"duplicateSource": null
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"sourceId": "Macro.issAGdpFxchQw2zp"
},
"wfrp4e-gm-toolkit": {
"version": "7.1.0"
"version": "0.9.5"
}
},
"ownership": {
Expand Down
21 changes: 8 additions & 13 deletions src/packs/gm-toolkit-tables/Dark_Whispers_9rXQv4uJcQoLBitt.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"_id": "9rXQv4uJcQoLBitt",
"name": "Dark Whispers",
"img": "modules/wfrp4e-gm-toolkit/assets/icons/dark-whispers.svg",
"description": "Generic Dark Whispers that are used as placeholder prompts by the Send Dark Whispers macro.",
"description": "<p>Generic Dark Whispers that are used as placeholder prompts by the Send Dark Whispers macro.</p>",
"results": [
{
"_id": "g9rsj2kp26oh6r3z",
Expand Down Expand Up @@ -166,22 +166,17 @@
},
"flags": {
"wfrp4e": {
"key": "darkwhispers"
},
"wfrp4e-gm-toolkit": {
"version": "0.9.2"
},
"core": {
"sourceId": "RollTable.9rXQv4uJcQoLBitt"
"key": "darkwhispers",
"column": ""
}
},
"_stats": {
"coreVersion": "12.329",
"systemId": null,
"systemVersion": null,
"coreVersion": "12.330",
"systemId": "wfrp4e",
"systemVersion": "7.2.4",
"createdTime": null,
"modifiedTime": null,
"lastModifiedBy": null,
"modifiedTime": 1723425266787,
"lastModifiedBy": "Pt7qzajGGC2jofTq",
"compendiumSource": null,
"duplicateSource": null
},
Expand Down

0 comments on commit 8e51e78

Please sign in to comment.