aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_drop.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/cmd_drop.go')
-rw-r--r--internal/game/cmd_drop.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/internal/game/cmd_drop.go b/internal/game/cmd_drop.go
index 511688a..2f79a2f 100644
--- a/internal/game/cmd_drop.go
+++ b/internal/game/cmd_drop.go
@@ -2,6 +2,7 @@ package game
import (
"fmt"
+ "strings"
"thirdcollapse/internal/net"
"thirdcollapse/internal/player"
@@ -10,6 +11,22 @@ import (
func (g *Game) doDrop(sess *net.Session, input string) {
p := sess.Player.(*player.Player)
+ if input == "all" {
+ 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))
+ return
+ }
+
matches := g.findInventoryMatches(input, p)
if len(matches) == 0 {
sess.WriteLine(fmt.Sprintf("You don't have any '%s'.", input))
@@ -46,3 +63,47 @@ func (g *Game) doDrop(sess *net.Session, input string) {
g.AccountStore.SaveCharacter(p)
sess.WriteLine(fmt.Sprintf("You drop a %s.", name))
}
+
+func (g *Game) handleDropAllConfirm(sess *net.Session, input string) {
+ p, ok := sess.Player.(*player.Player)
+ if !ok {
+ sess.State = net.StateGame
+ sess.Write("\r\n> ")
+ return
+ }
+
+ input = strings.TrimSpace(strings.ToLower(input))
+ if input != "y" && input != "yes" {
+ sess.State = net.StateGame
+ sess.Write("\r\n> ")
+ return
+ }
+
+ var dropped []string
+ for i := 0; i < 28; i++ {
+ slot := p.InvSlot(i)
+ if slot == nil || slot.Quantity <= 0 {
+ continue
+ }
+ g.World.AddGroundItem(p.RoomID, slot.ItemID, slot.Quantity)
+ def, _ := g.ItemStore.Load(slot.ItemID)
+ name := slot.ItemID
+ if def != nil {
+ name = def.Name
+ }
+ dropped = append(dropped, name)
+ p.SetInvSlot(i, nil)
+ }
+
+ g.AccountStore.SaveCharacter(p)
+ sess.State = net.StateGame
+
+ if len(dropped) == 0 {
+ sess.WriteLine("\nYou have nothing to drop.")
+ } else {
+ sess.Write(fmt.Sprintf("\nYou drop your "))
+ innerPickupReport(sess, dropped)
+ sess.WriteLine(".")
+ }
+ sess.Write("\r\n> ")
+}