Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Average Hit Points calculating incorrectly #462 #464

Merged
merged 1 commit into from Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/cljc/orcpub/dice.cljc
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
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
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
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