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
|
package game
import (
"fmt"
"strings"
"thehouseoficarus/internal/net"
"thehouseoficarus/internal/player"
)
func (g *Game) triggerEnchant(sess *net.Session, p *player.Player, mod *ModDef, targetArg string) {
if chipInfo, ok := chipMap[mod.ID]; ok {
g.triggerChipBolts(sess, p, mod, chipInfo)
return
}
enchants, ok := enchantMap[mod.ID]
if !ok {
sess.WriteLine("That enchantment has no known recipes.")
return
}
if targetArg == "" {
sess.WriteLine(fmt.Sprintf("Enchant what? Use: trigger %s <jewelry item>", strings.ReplaceAll(mod.ID, "_", " ")))
return
}
slot, inv := g.findInventoryItem(p, targetArg)
if slot < 0 {
sess.WriteLine("You don't have that item.")
return
}
outputID, ok := enchants[inv.ItemID]
if !ok {
sess.WriteLine("You can't enchant that with this mod.")
return
}
if p.Action != nil {
g.cancelAction(p)
}
inputID := inv.ItemID
inv.ItemID = outputID
g.triggerModReward(sess, p, mod, 1.0)
outputDef, _ := g.ItemStore.Load(outputID)
outputName := outputID
if outputDef != nil {
outputName = outputDef.Name
}
inputDef, _ := g.ItemStore.Load(inputID)
inputName := inputID
if inputDef != nil {
inputName = inputDef.Name
}
sess.WriteLine(fmt.Sprintf("You enchant the %s and it becomes a %s!", g.itemColorize(sess, inputDef, inputName), g.itemColorize(sess, outputDef, outputName)))
}
func (g *Game) triggerChipBolts(sess *net.Session, p *player.Player, mod *ModDef, chip chipEntry) {
count := p.CountItem(chip.Input)
if count < chip.Qty {
inputDef, _ := g.ItemStore.Load(chip.Input)
name := chip.Input
if inputDef != nil {
name = inputDef.Name
}
sess.WriteLine(fmt.Sprintf("You need at least %d %s.", chip.Qty, name))
return
}
if p.Action != nil {
g.cancelAction(p)
}
p.RemoveItem(chip.Input, chip.Qty)
placed := false
for i := 0; i < 28; i++ {
slot := p.InvSlot(i)
if slot != nil && slot.ItemID == chip.Output {
slot.Quantity += chip.Qty
placed = true
break
}
}
if !placed {
freeSlot := p.FirstFreeSlot()
p.SetInvSlot(freeSlot, &player.InventorySlot{ItemID: chip.Output, Quantity: chip.Qty})
}
g.triggerModReward(sess, p, mod, 1.0)
inputDef, _ := g.ItemStore.Load(chip.Input)
name := chip.Input
if inputDef != nil {
name = inputDef.Name
}
sess.WriteLine(fmt.Sprintf("You chip %d %s with arcane circuitry.", chip.Qty, g.itemColorize(sess, inputDef, name)))
}
|