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
|
package game
import (
"fmt"
"strings"
"thehouseoficarus/internal/action"
"thehouseoficarus/internal/combat"
"thehouseoficarus/internal/engine"
"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 combat.GetCombat(p.Name) != nil {
sess.WriteLine("You can't do that during combat!")
return
}
allRecipes, err := g.RecipeStore.LoadAll()
if err != nil {
sess.WriteLine("Error loading recipes.")
return
}
filter := strings.TrimSpace(input)
found := false
for _, r := range allRecipes {
if r.Type != "clean" {
continue
}
if filter != "" && !matchesCleanFilter(r, filter) {
continue
}
if p.Level(player.Pharmacy) < r.Level {
continue
}
if !r.HasAllItems(p.HasItem) {
continue
}
found = true
break
}
if !found {
sess.WriteLine("You don't have any herbs to clean.")
return
}
g.cancelBackgroundAction(p)
p.BackgroundAction = &action.Action{
Type: "clean",
TargetID: "clean_herbs",
Data: map[string]any{
"phase": 0,
"filter": filter,
},
WaitLeft: engine.ToTicks(1),
}
p.BackgroundActionState = &ActionState{Type: ActionCleaning}
if g.Hub != nil {
for _, other := range g.Hub.PlayersInRoom(p.RoomID) {
if other != sess && other.Player != nil {
other.WriteLine(g.colorize(other, "broadcast", fmt.Sprintf("\n%s starts cleaning herbs.", p.Name)))
}
}
}
sess.WriteLine("\nYou begin cleaning herbs.")
}
func matchesCleanFilter(r action.RecipeDef, filter string) bool {
if len(r.Consume) > 0 && len(r.Consume[0].Items) > 0 {
if strings.Contains(r.Consume[0].Items[0], filter) {
return true
}
}
if strings.Contains(r.Output, filter) {
return true
}
return false
}
|