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
|
package game
import (
"strings"
"thehouseoficarus/internal/behavior"
"thehouseoficarus/internal/engine"
"thehouseoficarus/internal/item"
"thehouseoficarus/internal/net"
"thehouseoficarus/internal/player"
)
func (g *Game) executeClean(sess *net.Session, args []string, rawInput string) {
g.doClean(sess, strings.Join(args, " "))
}
func (g *Game) doClean(sess *net.Session, input string) {
p := sess.Player
if g.Combat.Get(p.Name) != nil {
sess.WriteLine("You can't do that during combat!")
return
}
items := g.CraftIndex.ByType("clean")
filter := strings.TrimSpace(input)
found := false
for _, item := range items {
if filter != "" && !matchesCleanFilter(item, filter) {
continue
}
if p.Level(player.Pharmacy) < item.FirstCraft().Level {
continue
}
if !craftHasAllItems(item.FirstCraft(), p.HasItem) {
continue
}
found = true
break
}
if !found {
hasHerbs := false
for _, item := range items {
if filter != "" && !matchesCleanFilter(item, filter) {
continue
}
if craftHasAllItems(item.FirstCraft(), p.HasItem) {
hasHerbs = true
break
}
}
if hasHerbs {
sess.WriteLine("You don't have the Pharmacy level to clean any of your herbs.")
} else {
sess.WriteLine("You don't have any herbs to clean.")
}
return
}
g.cancelBgAction(p)
p.BackgroundAction = &behavior.Action{
Type: "clean",
TargetID: "clean_herbs",
Data: &behavior.CleanData{
Phase: 0,
Filter: filter,
},
WaitLeft: engine.ToTicks(1),
}
g.broadcastAction(sess, "%s starts cleaning herbs.", p.Name)
sess.WriteLine("You begin cleaning herbs.")
}
func matchesCleanFilter(item *item.ItemDef, filter string) bool {
if len(item.Craft) > 0 && len(item.FirstCraft().Consume) > 0 && len(item.FirstCraft().Consume[0].Items) > 0 {
if strings.Contains(item.FirstCraft().Consume[0].Items[0], filter) {
return true
}
}
if strings.Contains(item.ID, filter) {
return true
}
return false
}
|