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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
package game
import (
"fmt"
"path/filepath"
"sort"
"strings"
"gopkg.in/yaml.v3"
"thehouseoficarus/internal/action"
"thehouseoficarus/internal/object"
"thehouseoficarus/internal/player"
)
type ModCategory string
const (
ModCombat ModCategory = "combat"
ModUtility ModCategory = "utility"
ModEnchant ModCategory = "enchant"
ModProcessing ModCategory = "processing"
ModTransport ModCategory = "transport"
)
type ModDef struct {
ID string `yaml:"id"`
Name string `yaml:"name"`
Level int `yaml:"level"`
MaxHit int `yaml:"max_hit"`
BaseXP int `yaml:"base_xp"`
JunkCost map[string]int `yaml:"junk_cost"`
Category ModCategory `yaml:"category"`
Element string `yaml:"element"`
Destination int `yaml:"destination"`
}
var AllMods []*ModDef
var modByID map[string]*ModDef
func (g *Game) LoadMods() error {
dir := filepath.Join(g.DataDir, "modules")
AllMods = nil
modByID = make(map[string]*ModDef)
action.WalkYAMLDir(dir, func(path, id string, data []byte) error {
var m ModDef
if err := yaml.Unmarshal(data, &m); err != nil {
return nil
}
AllMods = append(AllMods, &m)
return nil
})
modByID = make(map[string]*ModDef, len(AllMods))
for _, m := range AllMods {
modByID[m.ID] = m
}
return nil
}
func GetMod(id string) *ModDef {
return modByID[id]
}
func FindMod(input string) *ModDef {
if m, ok := modByID[input]; ok {
return m
}
lower := strings.ToLower(strings.ReplaceAll(input, " ", "_"))
for _, m := range AllMods {
if strings.HasPrefix(m.ID, lower) {
return m
}
}
lowerSpace := strings.ToLower(input)
for _, m := range AllMods {
if strings.HasPrefix(strings.ToLower(m.Name), lowerSpace) {
return m
}
}
return nil
}
type chipEntry struct {
Input string
Output string
Qty int
}
var enchantMap = map[string]map[string]string{
"enchant_1": {
"sapphire_ring": "ring_of_recoil",
"sapphire_necklace": "necklace_of_passage",
"sapphire_bracelet": "bracelet_of_clay",
},
"enchant_2": {
"emerald_ring": "ring_of_dueling",
"emerald_necklace": "binding_necklace",
"emerald_bracelet": "bracelet_of_slaughter",
},
"enchant_3": {
"ruby_ring": "ring_of_forging",
"ruby_necklace": "digsite_pendant",
"ruby_bracelet": "inoculation_bracelet",
},
"enchant_4": {
"diamond_ring": "ring_of_life",
"diamond_necklace": "phoenix_necklace",
"diamond_bracelet": "abyssal_bracelet",
},
}
var chipMap = map[string]chipEntry{
"chip_sapphire": {"sapphire_bolts", "sapphire_bolts_e", 10},
"chip_emerald": {"emerald_bolts", "emerald_bolts_e", 10},
"chip_ruby": {"ruby_bolts", "ruby_bolts_e", 10},
"chip_diamond": {"diamond_bolts", "diamond_bolts_e", 10},
}
func (g *Game) hasDeckEquipped(p *player.Player) bool {
itemID, ok := p.Equipment[object.SlotMainHand]
if !ok {
return false
}
def, err := g.ItemStore.Load(itemID)
if err != nil {
return false
}
return def.WeaponType == object.WeaponScience
}
func (g *Game) equippedProvidesJunk(p *player.Player) string {
itemID, ok := p.Equipment[object.SlotMainHand]
if !ok {
return ""
}
def, err := g.ItemStore.Load(itemID)
if err != nil {
return ""
}
return def.ProvidesJunk
}
func (g *Game) effectiveJunkCost(p *player.Player, mod *ModDef) map[string]int {
cost := make(map[string]int)
for k, v := range mod.JunkCost {
cost[k] = v
}
hasDeck := g.hasDeckEquipped(p)
if hasDeck {
delete(cost, "scrap_metal")
}
providesJunk := g.equippedProvidesJunk(p)
if providesJunk != "" {
delete(cost, providesJunk)
}
return cost
}
func (g *Game) hasJunkCost(p *player.Player, mod *ModDef) bool {
cost := g.effectiveJunkCost(p, mod)
for itemID, qty := range cost {
if p.CountItem(itemID) < qty {
return false
}
}
return true
}
func (g *Game) consumeJunkCost(p *player.Player, mod *ModDef) bool {
cost := g.effectiveJunkCost(p, mod)
for itemID, qty := range cost {
if !p.RemoveItem(itemID, qty) {
return false
}
}
g.AccountStore.SaveCharacter(p)
return true
}
func (g *Game) junkCostString(p *player.Player, mod *ModDef) string {
cost := g.effectiveJunkCost(p, mod)
delete(cost, "scrap_metal")
if len(cost) == 0 {
return "free"
}
var parts []string
for itemID, qty := range cost {
def, _ := g.ItemStore.Load(itemID)
name := itemID
if def != nil {
name = def.Name
}
name = strings.TrimSuffix(name, "junk")
if qty > 1 {
parts = append(parts, fmt.Sprintf("%d %s", qty, name))
} else {
parts = append(parts, name)
}
}
sort.Strings(parts)
return strings.Join(parts, ", ")
}
func (g *Game) totalEquipScienceAttack(p *player.Player) int {
total := 0
for _, itemID := range p.Equipment {
def, err := g.ItemStore.Load(itemID)
if err == nil {
total += def.Stats.ScienceAttack
}
}
return total
}
|