Skip to content

Commit

Permalink
Fixes Orcpub#462
Browse files Browse the repository at this point in the history
Made functions clearer what they do
  • Loading branch information
datdamnzotz committed Oct 12, 2020
1 parent b49b8fb commit 5023f61
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/cljc/orcpub/dice.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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+)?")
Expand Down
2 changes: 1 addition & 1 deletion src/cljc/orcpub/dnd/e5/options.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/cljs/orcpub/dnd/e5/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/cljs/orcpub/dnd/e5/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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))))]
Expand Down

0 comments on commit 5023f61

Please sign in to comment.