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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
package game
import (
"fmt"
"path/filepath"
"sort"
"strings"
"gopkg.in/yaml.v3"
"thehouseoficarus/internal/action"
"thehouseoficarus/internal/net"
"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
}
func findAllModMatches(input string) []*ModDef {
inputWords := strings.Fields(strings.ToLower(input))
if len(inputWords) == 0 {
return nil
}
var matches []*ModDef
for _, m := range AllMods {
lowerName := strings.ToLower(m.Name)
lowerID := strings.ToLower(m.ID)
allMatch := true
for _, word := range inputWords {
if !strings.Contains(lowerName, word) && !strings.Contains(lowerID, word) {
allMatch = false
break
}
}
if allMatch {
matches = append(matches, m)
}
}
return matches
}
func FindModForPlayer(input string, sciLevel int) *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
}
}
matches := findAllModMatches(input)
if len(matches) == 0 {
return nil
}
if len(matches) == 1 {
return matches[0]
}
sort.Slice(matches, func(i, j int) bool {
return matches[i].Level > matches[j].Level
})
for _, m := range matches {
if m.Level <= sciLevel {
return m
}
}
return matches[len(matches)-1]
}
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) providesJunk(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")
}
providesJunk := g.providesJunk(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) triggerModReward(sess *net.Session, p *player.Player, mod *ModDef, multiplier float64, extraGains ...xpGain) int {
g.consumeJunkCost(p, mod)
sciXP := int(float64(mod.BaseXP) * multiplier)
if sciXP < 1 {
sciXP = 1
}
g.awardSkillXP(sess, p, player.Science, sciXP)
for _, gain := range extraGains {
g.awardSkillXP(sess, p, player.SkillName(gain.Skill), gain.XP)
}
g.AccountStore.SaveCharacter(p)
if p.OptionBool("xp_drops") {
parts := []string{fmt.Sprintf("+%dxp %s", sciXP, player.SkillAbbr[player.Science])}
for _, gain := range extraGains {
parts = append(parts, fmt.Sprintf("+%dxp %s", gain.XP, player.SkillAbbr[player.SkillName(gain.Skill)]))
}
sess.WriteLine(g.colorize(sess, "xp", "("+strings.Join(parts, ", ")+")"))
}
return sciXP
}
func (g *Game) junkCostString(p *player.Player, mod *ModDef) string {
cost := g.effectiveJunkCost(p, mod)
delete(cost, "scrap")
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) totalScienceAttack(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
}
|