blob: 4122e0ad1857a093879c58dad1676bfd17681d85 (
plain)
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
|
package game
import (
"fmt"
"strings"
"thehouseoficarus/internal/net"
)
func (g *Game) executeSearch(sess *net.Session, args []string, rawInput string) {
p := sess.Player
g.cancelAction(p)
if len(args) == 0 {
sess.WriteLine("Search what?")
} else {
g.doSearch(sess, strings.Join(args, " "))
}
}
func (g *Game) doSearch(sess *net.Session, input string) {
p := sess.Player
g.cancelAction(p)
lower := strings.ToLower(strings.TrimSpace(input))
if lower == "" {
sess.WriteLine("Search what?")
return
}
matches := g.findInventoryMatches(lower, p)
if len(matches) == 0 {
sess.WriteLine(fmt.Sprintf("You don't have any '%s' to search.", input))
return
}
unique := uniqueItemNames(matches)
if len(unique) > 1 {
g.showWhichOne(sess, matches)
return
}
itemID := matches[0].ID
slotIdx := matches[0].Slot
g.startSearch(sess, p, itemID, slotIdx)
}
|