summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
authorMischa Untaga <99098079+MischaU8@users.noreply.github.com>2023-10-10 12:27:23 +0200
committerMischa Untaga <99098079+MischaU8@users.noreply.github.com>2023-10-10 12:27:23 +0200
commit4edf378e51d8fc9a78a0032823566348f57b49aa (patch)
treeb7db98c7ea341b93fc71320c683e381cf3248858 /rules.js
parentdd5dbed61093bc9787b27a28913b9722808db9c6 (diff)
downloadalgeria-4edf378e51d8fc9a78a0032823566348f57b49aa.tar.gz
clamp
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js10
1 files changed, 5 insertions, 5 deletions
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) {