summaryrefslogtreecommitdiff
path: root/src/wasp-user-stats.el
blob: 74c320aae8325df60d24eaab334d7606bd0c6753 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
;;; wasp-user-stats --- User data: statistics -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:

(require 'dash)
(require 's)
(require 'ht)
(require 'wasp-user)

(defvar w/user-faction-exemptions
  (list
   "LCOLONQ"
   "MODCLONK"
   "fn_lumi"))

(defun w/user-initial-faction (user)
  "Determine the initial faction for USER."
  (unless (-contains? w/user-faction-exemptions user)
    (let* ((factions '(nate lever tony)))
      (nth (random (length factions)) factions))))
(defun w/user-ensure-faction ()
  "Ensure that the current user has a faction assigned."
  (let ((cur (alist-get :faction w/user-current)))
    (unless cur
      (setf (alist-get :faction w/user-current)
        (w/user-initial-faction w/user-current-name)))))

(defconst w/user-elements
  '(("fire" "🔥" "red")
    ("water" "🌊" "blue")
    ("wind" "🍃️" "green")
    ("earth" "🪨" "brown")
    ("lightning" "⚡" "yellow")
    ("heart" "🩷" "pink")))
(defun w/user-initial-element ()
  "Determine the initial faction for USER."
  (let* ((factions w/user-elements))
    (car (nth (random (length factions)) factions))))
(defun w/user-ensure-element ()
  "Ensure that the current user has a faction assigned."
  (let ((cur (alist-get :element w/user-current)))
    (unless cur
      (setf (alist-get :element w/user-current)
        (w/user-initial-element)))))

(defun w/user-faction-total (faction)
  "Compute the boost totals for FACTION."
  (-sum
    (-non-nil
      (--map
        (alist-get :boost it)
        (--filter
          (and (listp it) (eq faction (alist-get :faction it)))
          (ht-values w/user-cache))))))
(defun w/user-faction-totals ()
  "Compute the boost totals for each FACTION."
  (list
    (w/user-faction-total 'nate)
    (w/user-faction-total 'tony)
    (w/user-faction-total 'lever)))

(defun w/user-ensure-name ()
  "Ensure that the current user has a name assigned."
  (let ((cur (alist-get :name w/user-current)))
    (unless cur
      (setf (alist-get :name w/user-current) w/user-current-name))))

(defun w/user-stats-update ()
  "Ensure that the current user has all stats."
  (w/user-ensure-name)
  (w/user-ensure-faction)
  (w/user-ensure-element))

(defun w/user-stats-update-color (color)
  "Ensure that COLOR is set for the current user."
  (setf (alist-get :color w/user-current) color))

(provide 'wasp-user-stats)
;;; wasp-user-stats.el ends here