aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_get.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_get.go
parent06c02a697e5daf8832a462de5970dd4c0e13a02c (diff)
downloadthehouseoficarus-1b9e2da3b3c438d8dc53d3489725dd5ba0022777.tar.gz
feat: web client, get/drop updates and fixes
Diffstat (limited to 'internal/game/cmd_get.go')
-rw-r--r--internal/game/cmd_get.go222
1 files changed, 199 insertions, 23 deletions
diff --git a/internal/game/cmd_get.go b/internal/game/cmd_get.go
index bce8ddc..70b458e 100644
--- a/internal/game/cmd_get.go
+++ b/internal/game/cmd_get.go
@@ -9,15 +9,18 @@ import (
func (g *Game) doGet(sess *net.Session, input string) {
p := sess.Player.(*player.Player)
+ g.CancelAction(p)
ground := g.World.GroundItems(p.RoomID)
if len(ground) == 0 {
sess.WriteLine("There's nothing on the ground to pick up.")
return
}
- matches := g.findGroundMatches(input, p.RoomID)
+ qty, itemName := parseQty(input)
+
+ matches := g.findGroundMatches(itemName, p.RoomID)
if len(matches) == 0 {
- sess.WriteLine(fmt.Sprintf("There's no '%s' here.", input))
+ sess.WriteLine(fmt.Sprintf("There's no '%s' here.", itemName))
return
}
@@ -41,18 +44,29 @@ func (g *Game) doGet(sess *net.Session, input string) {
def, _ := g.ItemStore.Load(itemID)
- freeSlot := p.FirstFreeSlot()
- if freeSlot == -1 {
- sess.WriteLine("Your inventory is full.")
+ available := 0
+ if gqty, ok := ground[itemID]; ok {
+ available = gqty
+ }
+ if available <= 0 {
+ sess.WriteLine("There's none of that here.")
return
}
- qty := 1
- if def != nil && def.Stackable {
- ground := g.World.GroundItems(p.RoomID)
- if gqty, ok := ground[itemID]; ok && gqty > 0 {
- qty = gqty
+ if qty == 0 {
+ if def != nil && def.Stackable {
+ qty = available
+ } else {
+ qty = 1
}
+ } else if qty > available {
+ qty = available
+ }
+
+ freeSlot := p.FirstFreeSlot()
+ if freeSlot == -1 {
+ sess.WriteLine("Your inventory is full.")
+ return
}
if def != nil && def.Stackable {
@@ -67,29 +81,191 @@ func (g *Game) doGet(sess *net.Session, input string) {
_ = removed
slot.Quantity += qty
g.AccountStore.SaveCharacter(p)
- sess.WriteLine(fmt.Sprintf("You pick up a %s. (now %d)", def.Name, slot.Quantity))
+ sess.WriteLine(fmt.Sprintf("You pick up %d x %s. (now %d)", qty, def.Name, slot.Quantity))
return
}
}
+ freeSlot = p.FirstFreeSlot()
+ if freeSlot == -1 {
+ sess.WriteLine("Your inventory is full.")
+ return
+ }
+ removed, ok := g.World.RemoveReservedGroundItem(p.RoomID, itemID, qty, p.Name)
+ if !ok {
+ sess.WriteLine("That's not yours!")
+ return
+ }
+ _ = removed
+ p.SetInvSlot(freeSlot, &player.InventorySlot{ItemID: itemID, Quantity: qty})
+ g.AccountStore.SaveCharacter(p)
+ if qty == 1 {
+ sess.WriteLine(fmt.Sprintf("You pick up a %s.", def.Name))
+ } else {
+ sess.WriteLine(fmt.Sprintf("You pick up %d x %s.", qty, def.Name))
+ }
+ return
}
- removed, ok := g.World.RemoveReservedGroundItem(p.RoomID, itemID, qty, p.Name)
- if !ok {
- sess.WriteLine("That's not yours!")
- return
+ picked := 0
+ for picked < qty {
+ fs := p.FirstFreeSlot()
+ if fs == -1 {
+ break
+ }
+ removed, ok := g.World.RemoveReservedGroundItem(p.RoomID, itemID, 1, p.Name)
+ if !ok {
+ break
+ }
+ _ = removed
+ p.SetInvSlot(fs, &player.InventorySlot{ItemID: itemID, Quantity: 1})
+ picked++
}
- _ = removed
- p.SetInvSlot(freeSlot, &player.InventorySlot{ItemID: itemID, Quantity: qty})
+
g.AccountStore.SaveCharacter(p)
+ if picked == 0 {
+ sess.WriteLine("Your inventory is full.")
+ } else if picked == 1 {
+ name := itemID
+ if def != nil {
+ name = def.Name
+ }
+ sess.WriteLine(fmt.Sprintf("You pick up a %s.", name))
+ } else {
+ name := itemID
+ if def != nil {
+ name = def.Name
+ }
+ sess.WriteLine(fmt.Sprintf("You pick up %d x %s.", picked, name))
+ }
+}
+
+func (g *Game) doGetAllNamed(sess *net.Session, input string) {
+ p := sess.Player.(*player.Player)
+ g.CancelAction(p)
+ ground := g.World.GroundItems(p.RoomID)
+ if len(ground) == 0 {
+ sess.WriteLine("There's nothing on the ground to pick up.")
+ return
+ }
+
+ matches := g.findGroundMatches(input, p.RoomID)
+ if len(matches) == 0 {
+ sess.WriteLine(fmt.Sprintf("There's no '%s' here.", input))
+ return
+ }
+
+ if len(matches) > 1 {
+ unique := uniqueItemNames(matches)
+ if len(unique) > 1 {
+ sess.WriteLine("Which one?")
+ for _, name := range unique {
+ sess.WriteLine(fmt.Sprintf(" - %s", name))
+ }
+ return
+ }
+ }
+
+ itemID := matches[0].ID
+
+ if itemID == "credits" {
+ g.pickupCredits(sess, p, itemID)
+ return
+ }
+
+ def, _ := g.ItemStore.Load(itemID)
+
+ available := 0
+ if gqty, ok := ground[itemID]; ok {
+ available = gqty
+ }
+ if available <= 0 {
+ sess.WriteLine("There's none of that here.")
+ return
+ }
+
+ wanted := available
+ if def != nil && !def.Stackable {
+ free := p.FreeSlots()
+ if wanted > free {
+ wanted = free
+ }
+ }
+
+ if wanted <= 0 {
+ sess.WriteLine("Your inventory is full.")
+ return
+ }
+
name := itemID
if def != nil {
name = def.Name
}
- sess.WriteLine(fmt.Sprintf("You pick up a %s.", name))
+
+ if def != nil && def.Stackable {
+ for i := 0; i < 28; i++ {
+ slot := p.InvSlot(i)
+ if slot != nil && slot.ItemID == itemID {
+ removed, ok := g.World.RemoveReservedGroundItem(p.RoomID, itemID, wanted, p.Name)
+ if !ok {
+ sess.WriteLine("That's not yours!")
+ return
+ }
+ slot.Quantity += removed
+ g.AccountStore.SaveCharacter(p)
+ sess.WriteLine(fmt.Sprintf("You pick up %d x %s. (now %d)", removed, name, slot.Quantity))
+ return
+ }
+ }
+ freeSlot := p.FirstFreeSlot()
+ if freeSlot == -1 {
+ sess.WriteLine("Your inventory is full.")
+ return
+ }
+ removed, ok := g.World.RemoveReservedGroundItem(p.RoomID, itemID, wanted, p.Name)
+ if !ok {
+ sess.WriteLine("That's not yours!")
+ return
+ }
+ p.SetInvSlot(freeSlot, &player.InventorySlot{ItemID: itemID, Quantity: removed})
+ g.AccountStore.SaveCharacter(p)
+ if removed == 1 {
+ sess.WriteLine(fmt.Sprintf("You pick up a %s.", name))
+ } else {
+ sess.WriteLine(fmt.Sprintf("You pick up %d x %s.", removed, name))
+ }
+ return
+ }
+
+ picked := 0
+ for picked < wanted {
+ fs := p.FirstFreeSlot()
+ if fs == -1 {
+ break
+ }
+ _, ok := g.World.RemoveReservedGroundItem(p.RoomID, itemID, 1, p.Name)
+ if !ok {
+ break
+ }
+ p.SetInvSlot(fs, &player.InventorySlot{ItemID: itemID, Quantity: 1})
+ picked++
+ }
+
+ g.AccountStore.SaveCharacter(p)
+ if picked == 0 {
+ sess.WriteLine("Your inventory is full.")
+ } else if picked == 1 {
+ sess.WriteLine(fmt.Sprintf("You pick up a %s.", name))
+ } else {
+ sess.WriteLine(fmt.Sprintf("You pick up %d x %s.", picked, name))
+ }
+ if picked < available {
+ sess.WriteLine(fmt.Sprintf("You're only able to take %d x %s!", picked, name))
+ }
}
func (g *Game) doGetAll(sess *net.Session) {
p := sess.Player.(*player.Player)
+ g.CancelAction(p)
ground := g.World.GroundItems(p.RoomID)
if len(ground) == 0 {
sess.WriteLine("There's nothing on the ground to pick up.")
@@ -141,10 +317,10 @@ func (g *Game) doGetAll(sess *net.Session) {
freeSlot := p.FirstFreeSlot()
if freeSlot == -1 {
if len(picked) > 0 {
- sess.WriteLine("Inventory full. Picked up so far:")
+ sess.WriteLine("You can't hold everything but you picked up:")
innerPickupReport(sess, picked)
} else {
- sess.WriteLine("Your inventory is full.")
+ sess.WriteLine("Your inventory is full!")
}
g.AccountStore.SaveCharacter(p)
return
@@ -165,10 +341,10 @@ func (g *Game) doGetAll(sess *net.Session) {
freeSlot := p.FirstFreeSlot()
if freeSlot == -1 {
if len(picked) > 0 {
- sess.WriteLine("Inventory full. Picked up so far:")
+ sess.WriteLine("You can't hold everything but you picked up:")
innerPickupReport(sess, picked)
} else {
- sess.WriteLine("Your inventory is full.")
+ sess.WriteLine("Your inventory is full!")
}
g.AccountStore.SaveCharacter(p)
return
@@ -194,7 +370,7 @@ func (g *Game) doGetAll(sess *net.Session) {
if len(picked) == 0 {
sess.WriteLine("Your inventory is full.")
} else {
- sess.Write("You pick up: ")
+ sess.Write("You picked up: ")
innerPickupReport(sess, picked)
}
}