diff options
| author | historia <[not public]> | 2026-06-10 01:48:28 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-06-10 01:48:28 -0400 |
| commit | a226d72e51eecb768b13600303f73483118d9104 (patch) | |
| tree | 458d15ef049732c15dacc591a830d3beddbedfde /internal/game/cmd_drop.go | |
| parent | 6a0f3d7a252de4b1741cfe5e1c561412c602becc (diff) | |
| download | thehouseoficarus-a226d72e51eecb768b13600303f73483118d9104.tar.gz | |
feat: implemented janky object interaction model
Diffstat (limited to 'internal/game/cmd_drop.go')
| -rw-r--r-- | internal/game/cmd_drop.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/internal/game/cmd_drop.go b/internal/game/cmd_drop.go new file mode 100644 index 0000000..511688a --- /dev/null +++ b/internal/game/cmd_drop.go @@ -0,0 +1,48 @@ +package game + +import ( + "fmt" + + "thirdcollapse/internal/net" + "thirdcollapse/internal/player" +) + +func (g *Game) doDrop(sess *net.Session, input string) { + p := sess.Player.(*player.Player) + + matches := g.findInventoryMatches(input, p) + if len(matches) == 0 { + sess.WriteLine(fmt.Sprintf("You don't have any '%s'.", input)) + 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 + 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 + } else { + p.SetInvSlot(slotIdx, nil) + } + + g.World.AddGroundItem(p.RoomID, itemID, qty) + g.AccountStore.SaveCharacter(p) + sess.WriteLine(fmt.Sprintf("You drop a %s.", name)) +} |
