mirror of
https://github.com/Nighthawk42/roll20-character-sheets.git
synced 2026-08-30 03:40:32 +00:00
Fixed THAC0 and Total Weight
I fixed the problem with THAC0 exceeding 20 when showing the to hit for negative AC. It's now properly clamped to 20 as the maximum for the roll needed. Total weight was exceeding the three decimal places to show up to 8 places when there was only 3 decimal places being calculated.
This commit is contained in:
@@ -536,6 +536,7 @@
|
||||
</div>
|
||||
|
||||
<script type="text/worker">
|
||||
|
||||
on("clicked:core", function() {
|
||||
setAttrs({ sheetTab: "core" });
|
||||
});
|
||||
@@ -548,14 +549,17 @@ on("clicked:proficiencies", function() {
|
||||
setAttrs({ sheetTab: "proficiencies" });
|
||||
});
|
||||
|
||||
on("clicked:spells", function() {
|
||||
setAttrs({ sheetTab: "spells" });
|
||||
on("clicked:command", function() {
|
||||
setAttrs({ sheetTab: "command" });
|
||||
});
|
||||
|
||||
on("clicked:notes", function() {
|
||||
setAttrs({ sheetTab: "notes" });
|
||||
});
|
||||
|
||||
// ─────────────────────────────────────────────
|
||||
// Total Weight – Rounded to 2 decimal places
|
||||
// ─────────────────────────────────────────────
|
||||
const updateTotalWeight = function() {
|
||||
getSectionIDs("repeating_equipment", function(ids) {
|
||||
const fields = ids.map(function(id) {
|
||||
@@ -566,17 +570,81 @@ const updateTotalWeight = function() {
|
||||
let total = 0;
|
||||
|
||||
ids.forEach(function(id) {
|
||||
total += parseFloat(values["repeating_equipment_" + id + "_item_weight"]) || 0;
|
||||
const weight = parseFloat(values["repeating_equipment_" + id + "_item_weight"]) || 0;
|
||||
total += weight;
|
||||
});
|
||||
|
||||
// Round to 2 decimal places (clean display)
|
||||
const roundedTotal = total.toFixed(2);
|
||||
|
||||
setAttrs({
|
||||
total_weight: total
|
||||
total_weight: roundedTotal
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
on("sheet:opened", updateTotalWeight);
|
||||
// ─────────────────────────────────────────────
|
||||
// THAC0 Attack Table – Clamped for descending AC
|
||||
// ─────────────────────────────────────────────
|
||||
const updateAttackTable = function() {
|
||||
getAttrs(["attack_table_thaco"], function(values) {
|
||||
const thaco = parseInt(values.attack_table_thaco, 10);
|
||||
if (isNaN(thaco)) return;
|
||||
|
||||
const updates = {};
|
||||
|
||||
// Calculate needed roll: thaco - targetAC (descending AC)
|
||||
const needed = (ac) => thaco - ac;
|
||||
|
||||
// Display logic:
|
||||
// ≤ 0 → 1 (auto-hit except possible nat-1 fumble)
|
||||
// > 20 → 20 (nat 20 required)
|
||||
// 1–20 → exact number
|
||||
const display = (val) => {
|
||||
if (val <= 0) return 1;
|
||||
if (val > 20) return 20;
|
||||
return val;
|
||||
};
|
||||
|
||||
// Positive AC rows (AC 1 to 10)
|
||||
updates.to_hit_ac_1 = display(needed(1));
|
||||
updates.to_hit_ac_2 = display(needed(2));
|
||||
updates.to_hit_ac_3 = display(needed(3));
|
||||
updates.to_hit_ac_4 = display(needed(4));
|
||||
updates.to_hit_ac_5 = display(needed(5));
|
||||
updates.to_hit_ac_6 = display(needed(6));
|
||||
updates.to_hit_ac_7 = display(needed(7));
|
||||
updates.to_hit_ac_8 = display(needed(8));
|
||||
updates.to_hit_ac_9 = display(needed(9));
|
||||
updates.to_hit_ac_10 = display(needed(10));
|
||||
|
||||
// Negative AC rows (AC -1 to -10)
|
||||
updates.to_hit_ac_neg1 = display(needed(-1));
|
||||
updates.to_hit_ac_neg2 = display(needed(-2));
|
||||
updates.to_hit_ac_neg3 = display(needed(-3));
|
||||
updates.to_hit_ac_neg4 = display(needed(-4));
|
||||
updates.to_hit_ac_neg5 = display(needed(-5));
|
||||
updates.to_hit_ac_neg6 = display(needed(-6));
|
||||
updates.to_hit_ac_neg7 = display(needed(-7));
|
||||
updates.to_hit_ac_neg8 = display(needed(-8));
|
||||
updates.to_hit_ac_neg9 = display(needed(-9));
|
||||
updates.to_hit_ac_neg10 = display(needed(-10));
|
||||
|
||||
setAttrs(updates);
|
||||
});
|
||||
};
|
||||
|
||||
// ─────────────────────────────────────────────
|
||||
// Triggers
|
||||
// ─────────────────────────────────────────────
|
||||
on("sheet:opened", function() {
|
||||
updateTotalWeight();
|
||||
updateAttackTable();
|
||||
});
|
||||
|
||||
on("remove:repeating_equipment", updateTotalWeight);
|
||||
on("change:repeating_equipment", updateTotalWeight);
|
||||
on("change:attack_table_thaco", updateAttackTable);
|
||||
|
||||
</script>
|
||||
Reference in New Issue
Block a user