diff options
author | Mischa Untaga <99098079+MischaU8@users.noreply.github.com> | 2023-10-10 12:27:23 +0200 |
---|---|---|
committer | Mischa Untaga <99098079+MischaU8@users.noreply.github.com> | 2023-10-10 12:27:23 +0200 |
commit | 4edf378e51d8fc9a78a0032823566348f57b49aa (patch) | |
tree | b7db98c7ea341b93fc71320c683e381cf3248858 /rules.js | |
parent | dd5dbed61093bc9787b27a28913b9722808db9c6 (diff) | |
download | algeria-4edf378e51d8fc9a78a0032823566348f57b49aa.tar.gz |
clamp
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -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) { |