aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_drop.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_drop.go
parent06c02a697e5daf8832a462de5970dd4c0e13a02c (diff)
downloadthehouseoficarus-1b9e2da3b3c438d8dc53d3489725dd5ba0022777.tar.gz
feat: web client, get/drop updates and fixes
Diffstat (limited to 'internal/game/cmd_drop.go')
-rw-r--r--internal/game/cmd_drop.go163
1 files changed, 141 insertions, 22 deletions
diff --git a/internal/game/cmd_drop.go b/internal/game/cmd_drop.go
index 2f79a2f..cbe232d 100644
--- a/internal/game/cmd_drop.go
+++ b/internal/game/cmd_drop.go
@@ -8,24 +8,27 @@ import (
"thirdcollapse/internal/player"
)
-func (g *Game) doDrop(sess *net.Session, input string) {
+func (g *Game) doDropAll(sess *net.Session) {
p := sess.Player.(*player.Player)
+ g.CancelAction(p)
- if input == "all" {
- count := 0
- for _, slot := range p.Inventory {
- if slot != nil && slot.Quantity > 0 {
- count++
- }
+ count := 0
+ for _, slot := range p.Inventory {
+ if slot != nil && slot.Quantity > 0 {
+ count++
}
- if count == 0 {
- sess.WriteLine("You have nothing to drop.")
- return
- }
- sess.State = net.StateDropAllConfirm
- sess.WriteLine(fmt.Sprintf("\nDrop all %d items? [y/N]", count))
+ }
+ if count == 0 {
+ sess.WriteLine("You have nothing to drop.")
return
}
+ sess.State = net.StateDropAllConfirm
+ sess.WriteLine(fmt.Sprintf("\nDrop all %d items? [y/N]", count))
+}
+
+func (g *Game) doDropAllNamed(sess *net.Session, input string) {
+ p := sess.Player.(*player.Player)
+ g.CancelAction(p)
matches := g.findInventoryMatches(input, p)
if len(matches) == 0 {
@@ -43,25 +46,141 @@ func (g *Game) doDrop(sess *net.Session, input string) {
}
itemID := matches[0].ID
- slotIdx := matches[0].Slot
- slot := p.InvSlot(slotIdx)
def, _ := g.ItemStore.Load(itemID)
- qty := 1
name := itemID
if def != nil {
name = def.Name
}
- if slot.Quantity > qty {
- slot.Quantity -= qty
+ if def != nil && def.Stackable {
+ slot := p.InvSlot(matches[0].Slot)
+ qty := slot.Quantity
+ p.SetInvSlot(matches[0].Slot, nil)
+ g.World.AddGroundItem(p.RoomID, itemID, qty)
+ g.AccountStore.SaveCharacter(p)
+ if qty == 1 {
+ sess.WriteLine(fmt.Sprintf("You drop a %s.", name))
+ } else {
+ sess.WriteLine(fmt.Sprintf("You drop %d x %s.", qty, name))
+ }
+ return
+ }
+
+ total := 0
+ for _, match := range matches {
+ slot := p.InvSlot(match.Slot)
+ if slot == nil || slot.ItemID != itemID || slot.Quantity <= 0 {
+ continue
+ }
+ total += slot.Quantity
+ p.SetInvSlot(match.Slot, nil)
+ g.World.AddGroundItem(p.RoomID, itemID, slot.Quantity)
+ }
+ g.AccountStore.SaveCharacter(p)
+ if total == 1 {
+ sess.WriteLine(fmt.Sprintf("You drop a %s.", name))
} else {
- p.SetInvSlot(slotIdx, nil)
+ sess.WriteLine(fmt.Sprintf("You drop %d x %s.", total, name))
+ }
+}
+
+func (g *Game) doDrop(sess *net.Session, input string) {
+ p := sess.Player.(*player.Player)
+ g.CancelAction(p)
+
+ qty, itemName := parseQty(input)
+
+ matches := g.findInventoryMatches(itemName, p)
+ if len(matches) == 0 {
+ sess.WriteLine(fmt.Sprintf("You don't have any '%s'.", itemName))
+ return
+ }
+
+ 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
+ def, _ := g.ItemStore.Load(itemID)
+
+ name := itemID
+ if def != nil {
+ name = def.Name
+ }
+
+ if qty == 0 {
+ if def != nil && def.Stackable {
+ for i := 0; i < 28; i++ {
+ slot := p.InvSlot(i)
+ if slot != nil && slot.ItemID == itemID && slot.Quantity > 0 {
+ qty = slot.Quantity
+ break
+ }
+ }
+ } else {
+ qty = 1
+ }
}
- g.World.AddGroundItem(p.RoomID, itemID, qty)
+ if qty <= 0 {
+ sess.WriteLine(fmt.Sprintf("You don't have any %s.", name))
+ return
+ }
+
+ if def != nil && def.Stackable {
+ slot := p.InvSlot(matches[0].Slot)
+ if qty > slot.Quantity {
+ qty = slot.Quantity
+ }
+ if slot.Quantity > qty {
+ slot.Quantity -= qty
+ } else {
+ p.SetInvSlot(matches[0].Slot, nil)
+ }
+ g.World.AddGroundItem(p.RoomID, itemID, qty)
+ g.AccountStore.SaveCharacter(p)
+ if qty == 1 {
+ sess.WriteLine(fmt.Sprintf("You drop a %s.", name))
+ } else {
+ sess.WriteLine(fmt.Sprintf("You drop %d x %s.", qty, name))
+ }
+ return
+ }
+
+ remaining := qty
+ for _, match := range matches {
+ if remaining <= 0 {
+ break
+ }
+ slot := p.InvSlot(match.Slot)
+ if slot == nil || slot.ItemID != itemID || slot.Quantity <= 0 {
+ continue
+ }
+ take := 1
+ if slot.Quantity > take {
+ slot.Quantity -= take
+ } else {
+ p.SetInvSlot(match.Slot, nil)
+ }
+ g.World.AddGroundItem(p.RoomID, itemID, take)
+ remaining -= take
+ }
+
+ dropped := qty - remaining
g.AccountStore.SaveCharacter(p)
- sess.WriteLine(fmt.Sprintf("You drop a %s.", name))
+ if dropped == 0 {
+ sess.WriteLine(fmt.Sprintf("You don't have any %s.", name))
+ } else if dropped == 1 {
+ sess.WriteLine(fmt.Sprintf("You drop a %s.", name))
+ } else {
+ sess.WriteLine(fmt.Sprintf("You drop %d x %s.", dropped, name))
+ }
}
func (g *Game) handleDropAllConfirm(sess *net.Session, input string) {
@@ -71,6 +190,7 @@ func (g *Game) handleDropAllConfirm(sess *net.Session, input string) {
sess.Write("\r\n> ")
return
}
+ g.CancelAction(p)
input = strings.TrimSpace(strings.ToLower(input))
if input != "y" && input != "yes" {
@@ -103,7 +223,6 @@ func (g *Game) handleDropAllConfirm(sess *net.Session, input string) {
} else {
sess.Write(fmt.Sprintf("\nYou drop your "))
innerPickupReport(sess, dropped)
- sess.WriteLine(".")
}
sess.Write("\r\n> ")
}