From 5023f6131a9a17f6d4f8157d24c79df44ec0da34 Mon Sep 17 00:00:00 2001 From: DatDamnZotz Date: Mon, 12 Oct 2020 09:55:31 -0600 Subject: [PATCH] Fixes #462 Made functions clearer what they do --- src/cljc/orcpub/dice.cljc | 7 +++++-- src/cljc/orcpub/dnd/e5/options.cljc | 2 +- src/cljs/orcpub/dnd/e5/events.cljs | 2 +- src/cljs/orcpub/dnd/e5/views.cljs | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/cljc/orcpub/dice.cljc b/src/cljc/orcpub/dice.cljc index 20d341a31..ffd702c2b 100644 --- a/src/cljc/orcpub/dice.cljc +++ b/src/cljc/orcpub/dice.cljc @@ -19,10 +19,13 @@ (defn dice-string [die die-count modifier] (str die "d" die-count (common/mod-str modifier))) -(defn die-mean [die] +(defn die-mean-round-down [die] (int (Math/floor (/ (apply + (range 1 (inc die))) die)))) -(defn dice-mean [num sides modifier] +(defn die-mean-round-up [die] + (int (Math/ceil (/ (apply + (range 1 (inc die))) die)))) + +(defn dice-mean-round-down [num sides modifier] (int (Math/floor (+ modifier (* num (/ (apply + (range 1 (inc sides))) sides)))))) (def dice-regex #"(\d+)?d(\d+)\s?([+-])?\s?(\d+)?") diff --git a/src/cljc/orcpub/dnd/e5/options.cljc b/src/cljc/orcpub/dnd/e5/options.cljc index a867e3e97..594b8b050 100644 --- a/src/cljc/orcpub/dnd/e5/options.cljc +++ b/src/cljc/orcpub/dnd/e5/options.cljc @@ -2562,7 +2562,7 @@ ::t/help "This option rolls virtual dice for you and sets that value for this level's hit points. It could pay off with a high roll, but you might also roll a 1." ::t/modifiers [(modifiers/deferred-max-hit-points) (al-illegal-hit-points-mod "Rolling for hit points is not legal.")]} - (let [average (dice/die-mean die)] + (let [average (dice/die-mean-round-up die)] (t/option-cfg {:name "Average" :key :average diff --git a/src/cljs/orcpub/dnd/e5/events.cljs b/src/cljs/orcpub/dnd/e5/events.cljs index bcc9f13fc..65febb0f5 100644 --- a/src/cljs/orcpub/dnd/e5/events.cljs +++ b/src/cljs/orcpub/dnd/e5/events.cljs @@ -1134,7 +1134,7 @@ character (entity/get-entity-path built-template character path) {::entity/key :average - ::entity/value (dice/die-mean (-> levels class-kw :hit-die))})) + ::entity/value (dice/die-mean-round-up (-> levels class-kw :hit-die))})) (reg-event-db :set-hit-points-to-average diff --git a/src/cljs/orcpub/dnd/e5/views.cljs b/src/cljs/orcpub/dnd/e5/views.cljs index aee3b11af..ce052d895 100644 --- a/src/cljs/orcpub/dnd/e5/views.cljs +++ b/src/cljs/orcpub/dnd/e5/views.cljs @@ -1224,7 +1224,7 @@ (let [mean (or mean (if (and die die-count) - (dice/dice-mean + (dice/dice-mean-round-down die-count die (or modifier 0))))]