aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_search.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/cmd_search.go')
-rw-r--r--internal/game/cmd_search.go68
1 files changed, 10 insertions, 58 deletions
diff --git a/internal/game/cmd_search.go b/internal/game/cmd_search.go
index 341685e..d9a5b1e 100644
--- a/internal/game/cmd_search.go
+++ b/internal/game/cmd_search.go
@@ -10,6 +10,7 @@ import (
func (g *Game) doSearch(sess *net.Session, input string) {
p := sess.Player.(*player.Player)
+ g.CancelAction(p)
lower := strings.ToLower(strings.TrimSpace(input))
if lower == "" {
@@ -23,65 +24,16 @@ func (g *Game) doSearch(sess *net.Session, input string) {
return
}
- itemID := matches[0].ID
- slotIdx := matches[0].Slot
-
- if itemID != "birds_nest" {
- sess.WriteLine(fmt.Sprintf("You can't search %s.", matches[0].Name))
- return
- }
-
- slot := p.InvSlot(slotIdx)
- if slot == nil || slot.ItemID != "birds_nest" {
- return
- }
-
- if slot.Quantity > 1 {
- slot.Quantity--
- } else {
- p.SetInvSlot(slotIdx, nil)
- }
-
- dt, err := g.BehaviorStore.LoadDropTable("birds_nest_drop")
- if err != nil || len(dt.Drops) == 0 {
- sess.WriteLine("You search the bird's nest but find nothing.")
- g.AccountStore.SaveCharacter(p)
- return
- }
-
- drop := g.BehaviorStore.ResolveDrop(dt.Drops)
- if drop == nil {
- sess.WriteLine("You search the bird's nest but find nothing.")
- g.AccountStore.SaveCharacter(p)
- return
- }
-
- qty := drop.Quantity
- if qty <= 0 {
- qty = 1
- }
-
- if drop.ItemID == "credits" {
- p.Credits += qty
- sess.WriteLine(fmt.Sprintf("You search the bird's nest and find %d credits.", qty))
- } else {
- freeSlot := p.FirstFreeSlot()
- if freeSlot == -1 {
- g.World.AddGroundItem(p.RoomID, drop.ItemID, qty)
- name := drop.ItemID
- if def, err := g.ItemStore.Load(drop.ItemID); err == nil {
- name = def.Name
- }
- sess.WriteLine(fmt.Sprintf("You search the bird's nest and find %s. It falls to the ground.", name))
- } else {
- p.SetInvSlot(freeSlot, &player.InventorySlot{ItemID: drop.ItemID, Quantity: qty})
- name := drop.ItemID
- if def, err := g.ItemStore.Load(drop.ItemID); err == nil {
- name = def.Name
- }
- sess.WriteLine(fmt.Sprintf("You search the bird's nest and find %s.", name))
+ unique := uniqueItemNames(matches)
+ if len(unique) > 1 {
+ sess.WriteLine("Which one?")
+ for _, name := range unique {
+ sess.WriteLine(fmt.Sprintf(" - %s", name))
}
+ return
}
- g.AccountStore.SaveCharacter(p)
+ itemID := matches[0].ID
+ slotIdx := matches[0].Slot
+ g.startSearch(sess, p, itemID, slotIdx)
}