From feac5e881faad4bb9f737d9cc829ef9785ae8c4a Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sun, 6 Jan 2019 10:34:49 +0000 Subject: factor out `org-d20--d20-plus' Signed-off-by: Sean Whitton --- org-d20.el | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'org-d20.el') diff --git a/org-d20.el b/org-d20.el index 863b8c9..0af6ef7 100644 --- a/org-d20.el +++ b/org-d20.el @@ -229,10 +229,7 @@ the best N of them, e.g., 4d6k3." ;; In 5e, all monsters of the same kind have the same ;; initiative (let ((init (int-to-string - (cdr (org-d20--roll - (concat - "1d20" - (org-d20--num-to-term init-input)))))) + (org-d20--d20-plus (string-to-number init-input)))) (monsters-left num-input)) (while (>= monsters-left 1) (let ((hp (int-to-string (cdr (org-d20--roll hd-input))))) @@ -363,10 +360,7 @@ the best N of them, e.g., 4d6k3." (org-table-goto-line (1+ (org-table-current-line))) (org-table-goto-line (1+ (org-table-current-line))) (let ((init (int-to-string - (cdr (org-d20--roll - (concat - "1d20" - (org-d20--num-to-term init-input)))))) + (org-d20--d20-plus (string-to-number init-input)))) (monsters-left num-input)) (while (>= monsters-left 1) ;; Open a new row and then immediately move it downwards @@ -449,5 +443,9 @@ the best N of them, e.g., 4d6k3." (forward-char -2) (skip-chars-backward " ")) +;; Roll a d20, adding or subtracting a modifier +(defun org-d20--d20-plus (&optional mod) + (+ 1 mod (random 20))) + (provide 'org-d20) ;;; org-d20.el ends here -- cgit v1.2.3