~technomancy/tremendous-quest-iv

tremendous-quest-iv/barks.fnl -rw-r--r-- 4.9 KiB
a3c24536Phil Hagelberg Bump to Fennel 0.9.1; fix some bugs. 5 months ago
                                                                                
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
(local lume (require :polywell.lib.lume))
(local fennelview (require :polywell.lib.fennelview))
(local personalities (require :personalities))
(local moods (require :moods))

(fn bark-conds [...]
  (let [fns [...]]
    (fn [char]
      (lume.all fns #($ char)))))

(fn bark-cond [raw-bark-cond]
  (match (type raw-bark-cond)
    :function raw-bark-cond
    :table (bark-conds (unpack raw-bark-cond))))

(fn create-bark [bark]
  (let [bark-table
        (match (type bark)
          :string {:msg bark :rarity 0 :cond #true}
          :table (lume.merge {:msg "" :rarity 0 :cond #true} bark))]
    (lume.merge bark-table {:cond (bark-cond bark-table.cond)})))

(fn create-barks [...]
  (let [raw-barks [...]]
    (lume.map raw-barks create-bark)))

(local p {:not {}})
(each [_ pers (ipairs personalities)]
  (tset p pers #(= pers $.ai.personality))
  (tset p.not pers #(not ((. p pers) $))))

(local m {:not {}})
(each [_ mood (ipairs moods.moods)]
  (tset m mood #(= mood (moods.mood-name $.ai.mood)))
  (tset m.not mood #(not ((. m mood) $))))

(local mean-or-foul #(or (p.mean $) (m.foul $)))

;; also not mean
(local upbeat-or-happy
  #(or (and (not (p.mean $)) (m.happy $))
       (and (p.upbeat $) (m.not.foul $))))

(local teammate #(and $.team? (not= $.name :-=lordMoredire=-)))

(local barks
  (create-barks
   "..."
   "I wonder..."
   {:msg "hmm..." :cond m.neutral}
   {:msg "*whistle*" :cond m.happy}
   {:msg "hehehehe" :cond [p.mean m.not.foul]}
   {:msg "see ya losers!" :cond [p.mean m.not.foul] :rarity 25}
   {:msg "get on my level!" :cond [p.mean m.not.foul] :rarity 25}
   {:msg "later n00bs" :cond [p.mean m.not.foul] :rarity 50}
   {:msg "You cheated!" :cond [p.mean m.foul]}
   {:msg "Ugh..." :cond m.foul}
   {:msg "laaaaaaaag" :cond m.foul}
   {:msg "This sucks." :cond #(or (m.foul $) (p.grumpy $))}
   {:msg "why isn't this game fun?" :cond m.foul}
   {:msg "I hate this game!" :cond [p.mean m.foul]}
   {:msg "what's the point of all this?" :cond #(or (m.foul $) (p.grumpy $))}

   {:msg "I'm stuck!" :cond #(= (-?> $ (. :ai ) (. :task) (. :name)) :stuck)
    :rarity -2000}

   {:msg "Nothing can get me down!" :cond [p.upbeat m.happy]}

   {:msg "let's do this!" :cond upbeat-or-happy}
   {:msg "i'm excited!" :cond upbeat-or-happy}
   {:msg "feeling good today":cond upbeat-or-happy}
   {:msg "this is usually so fun..." :cond [p.upbeat m.foul]}
   {:msg "i feel frustrated" :cond [p.upbeat m.foul]}
   {:msg "maybe I'll start a new character" :cond [p.upbeat m.foul]}

   {:msg "i'm made of raisins" :cond p.quirky}
   {:msg "uwu" :cond p.quirky :rarity 100}
   {:msg "*holds up spork*" :cond p.quirky :rarity 500}
   {:msg "*happy sounds*" :cond [p.quirky m.happy]}

   {:msg "zzz..." :cond p.sleepy}
   {:msg "*yawn*" :cond p.sleepy}
   {:msg "i'm tired..." :cond #(or (p.sleepy $) (and (p.quiet $) (not (m.happy $))))}
   {:msg "ah, this is relaxing" :cond [p.sleepy m.happy]}
   {:msg "i'm drinking tea!" :cond p.sleepy}
   {:msg "i am exhausted" :cond [p.sleepy #(or (m.neutral $) (m.foul $))]}

   {:msg "let's do this" :cond p.friendly}
   {:msg "i think we can do it!" :cond p.friendly}
   {:msg "why are people on here so mean?" :cond p.friendly}
   {:msg "hi!" :cond p.friendly}
   {:msg "i want to join a guild..." :cond p.friendly :rarity 200}
   {:msg "never pet a burning dog" :cond p.friendly :rarity 250}

   {:msg "*heavy sigh*" :cond #(or (p.grumpy $) (m.foul $))}
   {:msg "fiddlesticks!" :cond p.grumpy}
   {:msg "ah, humbug" :cond p.grumpy :rarity 100}
   {:msg "*grumpy muttering*" :cond p.grumpy}

   {:msg "Hey teammate!" :cond teammate}
   {:msg "how's it going?" :cond teammate}
   ))

(fn get-potential-barks [char] (lume.filter barks #($.cond char)))
(fn rarity->weight [rarity] (- 1000 rarity))
(fn get-weighted-barks [barks]
  (let [ret []]
    (each [_ bark (ipairs barks)]
      (tset ret bark (rarity->weight bark.rarity)))
    ret))

(fn choose-bark [char]
  (lume.weightedchoice (get-weighted-barks (get-potential-barks char))))

(fn bark [char bark-msg-arg]
  (let [bark-msg (or bark-msg-arg (. (choose-bark char) :msg))]
    (dbg :barking char.name bark-msg)
    (set char.ai.bark bark-msg)
    (set char.ai.bark-timer 2.5)))

(fn bark-teammate [char]
  (let [bark-msg (match char.name
                   :anya "hey teammate! how goes?"
                   :jek "do you have a sec?"
                   :octo "what are you doing?"
                   :-=lordMoredire=- "hey! underling!")]
    (set char.ai.bark bark-msg)
    (set char.ai.bark-timer 2.5)))

(fn run-barks [dt char]
  (if (and char.team? (not char.talked-to?))
      (bark-teammate char)

      (and char.ai.bark-timer (> char.ai.bark-timer 0))
      (set char.ai.bark-timer (- char.ai.bark-timer dt))

      (and char.ai.bark-timer (<= char.ai.bark-timer 0))
      (do (set char.ai.bark nil) (set char.ai.bark-timer nil))

      (not char.ai.bark-timer)
      (when (= (math.floor (lume.random 1 2000)) 1) (bark char))))

{:run run-barks : bark}