aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_get.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-15 02:57:35 -0400
committerhistoria <[not public]>2026-06-15 02:58:50 -0400
commit4cc1ddcd185509080b4b3e15d1646567edd51c9d (patch)
tree2a564846ad4fd159a2d7e55451bfa9569fe8c0b8 /internal/game/cmd_get.go
parent445c4612cc5cf2c226f85894b6ad1e2419a374e2 (diff)
downloadthehouseoficarus-4cc1ddcd185509080b4b3e15d1646567edd51c9d.tar.gz
removed game speed for being broken and an antifeature anyway. added color support.
Diffstat (limited to 'internal/game/cmd_get.go')
-rw-r--r--internal/game/cmd_get.go55
1 files changed, 32 insertions, 23 deletions
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
+ })
}