From 4cc1ddcd185509080b4b3e15d1646567edd51c9d Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Mon, 15 Jun 2026 02:57:35 -0400 Subject: removed game speed for being broken and an antifeature anyway. added color support. --- internal/game/cmd_get.go | 55 ++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 23 deletions(-) (limited to 'internal/game/cmd_get.go') diff --git a/internal/game/cmd_get.go b/internal/game/cmd_get.go index 7ec183f..9591657 100644 --- a/internal/game/cmd_get.go +++ b/internal/game/cmd_get.go @@ -3,6 +3,7 @@ package game import ( "fmt" + "thirdcollapse/internal/color" "thirdcollapse/internal/net" "thirdcollapse/internal/player" ) @@ -10,6 +11,7 @@ import ( func (g *Game) doGet(sess *net.Session, input string) { p := sess.Player.(*player.Player) g.CancelAction(p) + mode := g.colorMode(sess) ground := g.World.GroundItems(p.RoomID) if len(ground) == 0 { sess.WriteLine("There's nothing on the ground to pick up.") @@ -85,7 +87,7 @@ func (g *Game) doGet(sess *net.Session, input string) { } slot.Quantity += qty g.AccountStore.SaveCharacter(p) - sess.WriteLine(fmt.Sprintf("You pick up %d x %s. (now %d)", qty, def.Name, slot.Quantity)) + sess.WriteLine(fmt.Sprintf("You pick up %d x %s. (now %d)", qty, color.Wrap(mode, "green", def.Name), slot.Quantity)) return } } @@ -101,9 +103,9 @@ func (g *Game) doGet(sess *net.Session, input string) { p.SetInvSlot(freeSlot, g.newInventorySlot(itemID, qty)) g.AccountStore.SaveCharacter(p) if qty == 1 { - sess.WriteLine(fmt.Sprintf("You pick up a %s.", def.Name)) + sess.WriteLine(fmt.Sprintf("You pick up a %s.", color.Wrap(mode, "green", def.Name))) } else { - sess.WriteLine(fmt.Sprintf("You pick up %d x %s.", qty, def.Name)) + sess.WriteLine(fmt.Sprintf("You pick up %d x %s.", qty, color.Wrap(mode, "green", def.Name))) } return } @@ -393,35 +395,42 @@ func (g *Game) pickupCredits(sess *net.Session, p *player.Player, itemID string) } } -func (g *Game) findGroundMatches(input string, roomID int) []itemMatch { - ground := g.World.GroundItems(roomID) +func (g *Game) collectMatches(input string, each func(func(itemID string, slot int) bool)) []itemMatch { var matches []itemMatch - for itemID := range ground { + each(func(itemID string, slot int) bool { def, err := g.ItemStore.Load(itemID) if err != nil { - continue + return true } if def.MatchesName(input) { - matches = append(matches, itemMatch{ID: itemID, Name: def.Name, Slot: -1}) + matches = append(matches, itemMatch{ID: itemID, Name: def.Name, Slot: slot}) } - } + return true + }) return matches } -func (g *Game) findInventoryMatches(input string, p *player.Player) []itemMatch { - var matches []itemMatch - for i := 0; i < 28; i++ { - slot := p.InvSlot(i) - if slot == nil { - continue - } - def, err := g.ItemStore.Load(slot.ItemID) - if err != nil { - continue +func (g *Game) findGroundMatches(input string, roomID int) []itemMatch { + ground := g.World.GroundItems(roomID) + return g.collectMatches(input, func(yield func(string, int) bool) { + for itemID := range ground { + if !yield(itemID, -1) { + return + } } - if def.MatchesName(input) { - matches = append(matches, itemMatch{ID: slot.ItemID, Name: def.Name, Slot: i}) + }) +} + +func (g *Game) findInventoryMatches(input string, p *player.Player) []itemMatch { + return g.collectMatches(input, func(yield func(string, int) bool) { + for i := 0; i < 28; i++ { + slot := p.InvSlot(i) + if slot == nil { + continue + } + if !yield(slot.ItemID, i) { + return + } } - } - return matches + }) } -- cgit v1.2.3