From 4edf378e51d8fc9a78a0032823566348f57b49aa Mon Sep 17 00:00:00 2001 From: Mischa Untaga <99098079+MischaU8@users.noreply.github.com> Date: Tue, 10 Oct 2023 12:27:23 +0200 Subject: clamp --- rules.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'rules.js') diff --git a/rules.js b/rules.js index 91bc798..88967a7 100644 --- a/rules.js +++ b/rules.js @@ -3532,10 +3532,7 @@ const MST = [0, 0, 1, 1, 1, 2, 2, 3, 4, 5] const MST_EFFECT = ['+', '+', '+', '', '', '', '', '@', '@', '@'] function roll_mst(drm) { - let roll = roll_1d6(drm) - if (roll < -1) roll = -1 - if (roll > 8) roll = 8 - + let roll = clamp(roll_1d6(drm), -1, 8) let result = MST[roll + 1] let effect = MST_EFFECT[roll + 1] let effect_str = '' @@ -3566,7 +3563,6 @@ function combat_result(firepower, die) { return COMBAT_RESULT_TABLE[k][1][die - 1] } - function roll_crt(firepower) { let roll = roll_1d6(0) let result = combat_result(firepower, roll) @@ -3575,6 +3571,10 @@ function roll_crt(firepower) { return result } +function clamp(x, min, max) { + return Math.min(Math.max(x, min), max) +} + // Array remove and insert (faster than splice) function array_remove(array, index) { -- cgit v1.2.3