Skip to content

Commit

Permalink
## 1.0.3
Browse files Browse the repository at this point in the history
- Fixed error calculating success and crit success percentages
- Will ignore characters with "minion" trait by default, can disable in settings.
- Added macro to delete all reroll data
  • Loading branch information
Joe T committed Dec 10, 2024
1 parent e763d1d commit 28c7637
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 35 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,13 @@ This macro will DELETE all re-roll data for selected token actor! If you want to
Manual command:
`deleteActorRollData();`

### Delete ALL Reroll Stats

This macro will DELETE ALL REROLL DATA FOR ALL ACTORS

If you want to just reset all stats to 0, then usee the Reset macro instead.

!!! CAN NOT BE UNDONE !!!

Manual command:
`deleteAllRerollStats();`
4 changes: 2 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "pf2e-reroll-stats",
"title": "PF2E ReRoll Stats",
"description": "Tracks rolls made with 'Reroll using Hero Point' and compares the results.",
"version": "1.0.2",
"version": "1.0.3",
"compatibility": {
"minimum": "12",
"verified": "12"
Expand Down Expand Up @@ -43,7 +43,7 @@
"system": ["pf2e"],
"url": "https://github.com/thejoester/pf2e-reroll-stats",
"manifest": "https://github.com/thejoester/pf2e-reroll-stats/releases/latest/download/module.json",
"download": "https://github.com/thejoester/pf2e-reroll-stats/releases/download/1.0.2/pf2e_reroll_stats.zip",
"download": "https://github.com/thejoester/pf2e-reroll-stats/releases/download/1.0.3/pf2e_reroll_stats.zip",
"readme": "https://github.com/thejoester/pf2e-reroll-stats/blob/master/README.md",
"changelog": "https://github.com/thejoester/pf2e-reroll-stats/blob/master/CHANGELOG.md",
"license": "https://github.com/thejoester/pf2e-reroll-stats/blob/master/LICENSE.txt",
Expand Down
Empty file.
Binary file added packs/reroll-stats-macros/000019.ldb
Binary file not shown.
2 changes: 1 addition & 1 deletion packs/reroll-stats-macros/CURRENT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MANIFEST-000011
MANIFEST-000013
37 changes: 30 additions & 7 deletions packs/reroll-stats-macros/LOG
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
2024/12/09-16:15:53.316407 7ac0f3400640 Recovering log #8
2024/12/09-16:15:53.320430 7ac0f3400640 Delete type=0 #3
2024/12/09-16:15:53.320498 7ac0f3400640 Delete type=3 #2
2024/12/09-16:15:53.320573 7ac0f3400640 Delete type=2 #5
2024/12/09-16:15:53.320644 7ac0f3400640 Delete type=0 #4
2024/12/09-16:15:53.320687 7ac0f3400640 Delete type=0 #8
2024/12/09-16:15:53.320731 7ac0f3400640 Delete type=3 #6
2024/12/09-16:58:29.438195 765090200640 Recovering log #12
2024/12/09-16:58:29.438292 765090200640 Level-0 table #14: started
2024/12/09-16:58:29.439986 765090200640 Level-0 table #14: 746 bytes OK
2024/12/09-16:58:29.444302 765090200640 Delete type=0 #4
2024/12/09-16:58:29.444378 765090200640 Delete type=2 #5
2024/12/09-16:58:29.444450 765090200640 Delete type=0 #3
2024/12/09-16:58:29.444493 765090200640 Delete type=3 #2
2024/12/09-16:58:29.444599 765090200640 Delete type=3 #11
2024/12/09-16:58:29.444674 765090200640 Delete type=3 #6
2024/12/09-16:58:29.444740 765090200640 Delete type=0 #12
2024/12/09-16:58:29.444805 765090200640 Delete type=0 #8
2024/12/09-21:01:00.713191 765084a00640 Level-0 table #17: started
2024/12/09-21:01:00.714299 765084a00640 Level-0 table #17: 1530 bytes OK
2024/12/09-21:01:00.715864 765084a00640 Delete type=0 #15
2024/12/09-21:01:00.716053 765084a00640 Manual compaction at level-0 from '!macros!CLaCFNuMjvIMQ8xs' @ 72057594037927935 : 1 .. '!macros!sds2cJpvPZE6tZz2' @ 0 : 0; will stop at '!macros!CLaCFNuMjvIMQ8xs' @ 15 : 1
2024/12/09-21:01:00.716059 765084a00640 Compacting 1@0 + 0@1 files
2024/12/09-21:01:00.717493 765084a00640 Generated table #18@0: 1 keys, 705 bytes
2024/12/09-21:01:00.717517 765084a00640 Compacted 1@0 + 0@1 files => 705 bytes
2024/12/09-21:01:00.718610 765084a00640 compacted to: files[ 0 2 1 0 0 0 0 ]
2024/12/09-21:01:00.718679 765084a00640 Delete type=2 #14
2024/12/09-21:01:00.722289 765084a00640 Manual compaction at level-0 from '!macros!CLaCFNuMjvIMQ8xs' @ 15 : 1 .. '!macros!sds2cJpvPZE6tZz2' @ 0 : 0; will stop at (end)
2024/12/09-21:01:00.723577 765084a00640 Manual compaction at level-1 from '!macros!CLaCFNuMjvIMQ8xs' @ 72057594037927935 : 1 .. '!macros!sds2cJpvPZE6tZz2' @ 0 : 0; will stop at '!macros!sds2cJpvPZE6tZz2' @ 18 : 1
2024/12/09-21:01:00.723585 765084a00640 Compacting 2@1 + 1@2 files
2024/12/09-21:01:00.725287 765084a00640 Generated table #19@1: 6 keys, 2007 bytes
2024/12/09-21:01:00.725313 765084a00640 Compacted 2@1 + 1@2 files => 2007 bytes
2024/12/09-21:01:00.726411 765084a00640 compacted to: files[ 0 0 1 0 0 0 0 ]
2024/12/09-21:01:00.726479 765084a00640 Delete type=2 #17
2024/12/09-21:01:00.726578 765084a00640 Delete type=2 #18
2024/12/09-21:01:00.726643 765084a00640 Delete type=2 #10
2024/12/09-21:01:00.730592 765084a00640 Manual compaction at level-1 from '!macros!sds2cJpvPZE6tZz2' @ 18 : 1 .. '!macros!sds2cJpvPZE6tZz2' @ 0 : 0; will stop at (end)
22 changes: 7 additions & 15 deletions packs/reroll-stats-macros/LOG.old
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
2024/12/07-06:12:32.742161 7ddd15600640 Recovering log #4
2024/12/07-06:12:32.746653 7ddd15600640 Delete type=3 #2
2024/12/07-06:12:32.746739 7ddd15600640 Delete type=0 #4
2024/12/07-06:45:12.346840 7ddd03000640 Level-0 table #9: started
2024/12/07-06:45:12.348811 7ddd03000640 Level-0 table #9: 2767 bytes OK
2024/12/07-06:45:12.350246 7ddd03000640 Delete type=0 #7
2024/12/07-06:45:12.356393 7ddd03000640 Manual compaction at level-0 from '!macros!Ebhm5Q11zYOnOoXF' @ 72057594037927935 : 1 .. '!macros!i8JWfo4X13n7SUbL' @ 0 : 0; will stop at (end)
2024/12/07-06:45:12.356898 7ddd03000640 Manual compaction at level-1 from '!macros!Ebhm5Q11zYOnOoXF' @ 72057594037927935 : 1 .. '!macros!i8JWfo4X13n7SUbL' @ 0 : 0; will stop at '!macros!i8JWfo4X13n7SUbL' @ 8 : 1
2024/12/07-06:45:12.356915 7ddd03000640 Compacting 1@1 + 1@2 files
2024/12/07-06:45:12.358954 7ddd03000640 Generated table #10@1: 4 keys, 1646 bytes
2024/12/07-06:45:12.358987 7ddd03000640 Compacted 1@1 + 1@2 files => 1646 bytes
2024/12/07-06:45:12.360289 7ddd03000640 compacted to: files[ 0 0 1 0 0 0 0 ]
2024/12/07-06:45:12.360410 7ddd03000640 Delete type=2 #5
2024/12/07-06:45:12.360556 7ddd03000640 Delete type=2 #9
2024/12/07-06:45:12.366653 7ddd03000640 Manual compaction at level-1 from '!macros!i8JWfo4X13n7SUbL' @ 8 : 1 .. '!macros!i8JWfo4X13n7SUbL' @ 0 : 0; will stop at (end)
2024/12/09-16:15:53.316407 7ac0f3400640 Recovering log #8
2024/12/09-16:15:53.320430 7ac0f3400640 Delete type=0 #3
2024/12/09-16:15:53.320498 7ac0f3400640 Delete type=3 #2
2024/12/09-16:15:53.320573 7ac0f3400640 Delete type=2 #5
2024/12/09-16:15:53.320644 7ac0f3400640 Delete type=0 #4
2024/12/09-16:15:53.320687 7ac0f3400640 Delete type=0 #8
2024/12/09-16:15:53.320731 7ac0f3400640 Delete type=3 #6
Binary file added packs/reroll-stats-macros/MANIFEST-000013
Binary file not shown.
125 changes: 115 additions & 10 deletions scripts/reroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,19 @@ Hooks.once("init", () => {
default: {},
});

// Register settings to ignore minions
game.settings.register(MODULE_NAME, "ignoreMinion", {
name: "Ignore Minions",
hint: "Ignore rolls from minions (companions, summons, etc).",
scope: "world",
config: true,
type: Boolean,
default: true,
});

// Register settings for persistent data
game.settings.register(MODULE_NAME, "debugEnabled", {
name: "Enable Debuging",
name: "Enable Debugging",
hint: "enables debugging in the console for troubleshooting purposes.",
scope: "world", // Saved at the world level
config: true, // Exposed in the settings menu
Expand All @@ -33,6 +43,7 @@ Hooks.once("init", () => {
});
const debugEnabled = game.settings.get(MODULE_NAME, "debugEnabled");
console.log(`%cPF2e ReRoll Stats || Debugging: ${debugEnabled}`, "color: orange; font-weight: bold;");

});

Hooks.once("ready", async () => {
Expand Down Expand Up @@ -82,6 +93,38 @@ function debugLog(logMsg, logType = "c", logLevel = "1") {
}
}

/**
Checks if an actor is valid for reroll tracking.
An actor is considered valid if it meets the following conditions:
1. The actor is of type 'character'.
2. Unless "Ignore Minions" is disabled in settings, ensure actor does not have the 'minion' trait in its list of traits.
@param {Object} actor - The actor object to check.
@returns {boolean} - Returns true if the actor is valid for reroll tracking, false otherwise.
*/
function isValidActorForRerollTracking(actor) {
// Check if the actor is a character
const isCharacter = actor.type === "character";

// Check if we are ignoring minions in settings
const ignoreMinion = game.settings.get(MODULE_NAME, "ignoreMinion");
if (!ignoreMinion) {
return isCharacter;
} else {

// Ensure the actor has traits and check if the 'minion' trait exists
const traits = actor.system.traits?.value || [];
debugLog(`Actor Traits: ${traits}`);

const hasMinionTrait = traits.includes("minion");
debugLog(`Has Minion Trait: ${hasMinionTrait}`);

// Return true if it's a character and not a minion
return isCharacter && !hasMinionTrait;
}
}

// Save rollDataByActor to settings
function saveRollData() {
// Only save data if the user is the GM
Expand Down Expand Up @@ -192,11 +235,16 @@ function displayActorStatsInChat() {
}

// Calculate success percentage based on reroll outcomes
const { rerollCount, betterCount, worseCount, sameCount } = actorData;
const successPercentage = rerollCount > 0
? ((betterCount / rerollCount) * 100).toFixed(2)
: "N/A";

const { rerollCount, betterCount, worseCount, sameCount, successCount, critSuccessCount } = actorData;

// Calculate the success percentage based on the successCount and rerollCount
const successPercentage = (
(actorData.successCount / actorData.rerollCount) * 100
).toFixed(2);
const critsuccessPercentage = (
(actorData.critSuccessCount / actorData.rerollCount) * 100
).toFixed(2);

// Prepare the chat message content
const messageContent = `
<h2>Reroll Stats for ${actorName}</h2>
Expand All @@ -205,6 +253,8 @@ function displayActorStatsInChat() {
<li><strong>Better Results:</strong> ${betterCount}</li>
<li><strong>Worse Results:</strong> ${worseCount}</li>
<li><strong>Same Results:</strong> ${sameCount}</li>
<li><strong>Reroll Sucess:</strong> ${successCount}</li>
<li><strong>Reroll Crit:</strong> ${critSuccessCount}</li>
<li><strong>Success Percentage:</strong> ${successPercentage}%</li>
<li><strong>Crit Success Percentage:</strong> ${successPercentage}%</li>
</ul>
Expand All @@ -231,12 +281,22 @@ async function compileActorStatsToJournal() {
let totalSameCount = 0;
let totalSuccessCount = 0;
let totalCritSuccessCount = 0;
let actorsuccessPercentage = 0;
let actorcritsuccessPercentage = 0;

// Compile individual actor stats
for (const [actorId, stats] of Object.entries(rollDataByActor)) {
const actor = game.actors.get(actorId);
if (!actor) continue;

// Calculate the success percentage based on the successCount and rerollCount
actorsuccessPercentage = (
(stats.successCount / stats.rerollCount) * 100
).toFixed(2);
actorcritsuccessPercentage = (
(stats.critSuccessCount / stats.rerollCount) * 100
).toFixed(2);

journalContent += `
<h2>${actor.name}</h2>
<ul>
Expand All @@ -246,6 +306,8 @@ async function compileActorStatsToJournal() {
<li><strong>Total Same Results:</strong> ${stats.sameCount || 0}</li>
<li><strong>Total Success Count:</strong> ${stats.successCount || 0}</li>
<li><strong>Total Critical Success Count:</strong> ${stats.critSuccessCount || 0}</li>
<li><strong>Success Percentage:</strong> ${actorsuccessPercentage}%</li>
<li><strong>Crit Success Percentage:</strong> ${actorcritsuccessPercentage}%</li>
</ul>
`;

Expand Down Expand Up @@ -381,7 +443,6 @@ function displayCombinedRerollStats() {
debugLog("Combined reroll stats calculated and displayed.");
}


// Function to delete all roll data for a selected token's actor
function deleteActorRollData() {
// Get the selected tokens
Expand Down Expand Up @@ -428,6 +489,50 @@ function deleteActorRollData() {
}
}

// Function to delete all reroll data - optional to delete journal also
function deleteAllRerollStats(deleteJournal = false) {
// Confirm before proceeding
new Dialog({
title: "Delete All Reroll Stats",
content: `
<p>Are you sure you want to delete all Hero Point reroll stats?</p>
${deleteJournal ? "<p>The associated journal entry will also be deleted.</p>" : ""}
`,
buttons: {
yes: {
icon: '<i class="fas fa-trash"></i>',
label: "Yes",
callback: async () => {
// Clear the roll data
rollDataByActor = {};
debugLog("All Hero Point reroll stats have been cleared.", "c", 2);

// Optionally delete the journal entry
if (deleteJournal) {
const journalName = "Reroll Stats";
const journalEntry = game.journal.getName(journalName);
if (journalEntry) {
await journalEntry.delete();
debugLog(`Journal entry "${journalName}" has been deleted.`, "c", 2);
} else {
debugLog(`Journal entry "${journalName}" not found.`, "c", 2);
}
}

// Notify the user
debugLog("All Hero Point reroll stats have been deleted.");
}
},
no: {
icon: '<i class="fas fa-times"></i>',
label: "No",
callback: () => debugLog("Delete action cancelled.")
}
},
default: "no"
}).render(true);
}


// Hook into chat messages
Hooks.on("createChatMessage", (message) => {
Expand All @@ -451,9 +556,9 @@ Hooks.on("createChatMessage", (message) => {
// Retrieve the actor object
const actor = game.actors.get(actorId);

// Ignore if the actor is not a PC
if (!actor || actor.type !== "character") {
debugLog(`Ignoring roll from non-Player Character actor: ${actor?.name || "Unknown"}`);
// Check if actor is valid character
if (!isValidActorForRerollTracking(actor)) {
debugLog(`Ignoring roll from non-Player Character or minion actor: ${actor?.name || "Unknown"}`,"c",2);
return;
}

Expand Down

0 comments on commit 28c7637

Please sign in to comment.