~technomancy/tremendous-quest-iv

tremendous-quest-iv/item.fnl -rw-r--r-- 2.6 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
(local lume (require "polywell.lib.lume"))

(local max-length 35)

(fn maybe-choose [choices chance]
  (if (< (math.random) chance) (lume.randomchoice choices)))

(local modifiers
       {:weapon {:kinds ["iron" "two-handed" "steel" "golden" "bronze"]
                 :prefixes ["magic" "rusted" "blessed" "flaming" "poisoned"]
                 :suffixes ["+5 against undead" "of speed" "of the ancients"]}
        :armor {:kinds ["iron" "leather" "steel" "golden" "cloth"]
                :prefixes ["boosted" "tattered" "fashionable" "elusive"]
                :suffixes ["+3 against arrows" "of shadows" "of heroes"]}
        :item {:kinds ["sticky" "enchanted" "corrugated" "ethereal" "cryptic"
                       "mystical" "blood" "turbo" "strength" "golden"]
               :prefixes ["catastrophic" "legendary" "enormous" "screaming"
                          "dragonhair" "slippery"]
               :suffixes ["of scrying" "of immortality" "of the north"]}})

(local items
       [{:type :weapon :name "sword"}
        {:type :weapon :name "spear"}
        {:type :weapon :name "trident"}
        {:type :weapon :name "axe"}
        {:type :weapon :name "mace"}
        {:type :weapon :name "bow"}
        {:type :weapon :name "dagger"}
        {:type :weapon :name "staff"}
        {:type :armor :name "plate"}
        {:type :armor :name "gloves"}
        {:type :armor :name "helmet"}
        {:type :armor :name "boots"}
        {:type :armor :name "shield"}
        {:type :armor :name "robe"}
        {:type :item :name "potion"}
        {:type :item :name "scroll"}
        {:type :item :name "key"}
        {:type :item :name "crystal"}
        {:type :item :name "fruit"}
        {:type :item :name "book"}
        {:type :item :name "seed"}
        {:type :item :name "bag"}
        {:type :item :name "lute"}
        {:type :item :name "spatula"}
        {:type :item :name "stick"}])

(fn make [?type]
  (let [type (or ?type (lume.randomchoice [:weapon :armor :item :item]))
        {: type : name} (-> items
                            (lume.filter #(= type $1.type))
                            (lume.randomchoice))
        {: kinds : prefixes : suffixes} (. modifiers type)
        kind (lume.randomchoice kinds)
        prefix (or (maybe-choose prefixes 0.1) "")
        suffix (or (maybe-choose suffixes 0.1) "")
        item (-> "%s %s %s %s"
                 (: :format prefix kind name suffix)
                 (: :gsub "  +" " ")
                 (: :gsub "^ +" ""))]
    (if (< (# item) max-length)
        item
        (do (dbg :too-long-item item)
            (make type)))))

{: make}