aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_search.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-11 04:46:27 -0400
committerhistoria <[not public]>2026-06-11 08:58:37 +0000
commit1b9e2da3b3c438d8dc53d3489725dd5ba0022777 (patch)
tree62264f24420bf4cfaa734942c65cc8dd45ba3d3b /internal/game/cmd_search.go
parent06c02a697e5daf8832a462de5970dd4c0e13a02c (diff)
downloadthehouseoficarus-1b9e2da3b3c438d8dc53d3489725dd5ba0022777.tar.gz
feat: web client, get/drop updates and fixes
Diffstat (limited to 'internal/game/cmd_search.go')
-rw-r--r--internal/game/cmd_search.go87
1 files changed, 87 insertions, 0 deletions
diff --git a/internal/game/cmd_search.go b/internal/game/cmd_search.go
new file mode 100644
index 0000000..341685e
--- /dev/null
+++ b/internal/game/cmd_search.go
@@ -0,0 +1,87 @@
+package game
+
+import (
+ "fmt"
+ "strings"
+
+ "thirdcollapse/internal/net"
+ "thirdcollapse/internal/player"
+)
+
+func (g *Game) doSearch(sess *net.Session, input string) {
+ p := sess.Player.(*player.Player)
+
+ 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
+ }
+
+ 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))
+ }
+ }
+
+ g.AccountStore.SaveCharacter(p)
+}