aboutsummaryrefslogtreecommitdiff
path: root/internal/game/credits_pickup_test.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-09-16 14:09:22 -0400
committerhistoria <[not public]>2026-09-16 14:09:22 -0400
commit2f34e75f27e5f99cfc1c5f8eaf6ab4ff2fddb1d9 (patch)
treec50388fe639286bda1b1999ca6c2c972d03eb3a5 /internal/game/credits_pickup_test.go
parentc054b27f628f23fecc505b9e09e78721738f3c4e (diff)
downloadthehouseoficarus-2f34e75f27e5f99cfc1c5f8eaf6ab4ff2fddb1d9.tar.gz
fix: reserved-loot pickup, credit pickup, payout recovery, and slot stake/bonus shutdown handling
Diffstat (limited to 'internal/game/credits_pickup_test.go')
-rw-r--r--internal/game/credits_pickup_test.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/internal/game/credits_pickup_test.go b/internal/game/credits_pickup_test.go
new file mode 100644
index 0000000..61509e4
--- /dev/null
+++ b/internal/game/credits_pickup_test.go
@@ -0,0 +1,44 @@
+package game
+
+import (
+ "testing"
+
+ "thehouseoficarus/internal/net"
+)
+
+// TestPickupCreditsSentinelQuantity: credit pickups request a sentinel
+// quantity far above any possible ground stock. RemoveReservedItem is
+// all-or-nothing and rejects such a request; the pickup must use capped
+// removal so picking up 10 credits succeeds instead of answering
+// "That's not yours!".
+func TestPickupCreditsSentinelQuantity(t *testing.T) {
+ h := newHarness(t)
+ h.seedAccount("alice", "pw", false)
+ p := h.seedCharacter("alice", "alice")
+ h.g.RunOnOwner(func() {
+ p.Credits = 100
+ h.g.World.AddGroundItem(p.RoomID, "credits", 10)
+ sess := &net.Session{Player: p, Conn: newChanConn()}
+ h.g.pickupCredits(sess, p, "credits")
+ if p.Credits != 110 {
+ t.Errorf("credits after pickup = %d, want 110 (output: %s)", p.Credits, sess.Conn.(*chanConn).Bytes())
+ }
+ })
+}
+
+// TestGetAllPicksUpCreditsWithSentinelQuantity: the same sentinel rule for
+// the "get all" path.
+func TestGetAllPicksUpCreditsWithSentinelQuantity(t *testing.T) {
+ h := newHarness(t)
+ h.seedAccount("alice", "pw", false)
+ p := h.seedCharacter("alice", "alice")
+ h.g.RunOnOwner(func() {
+ p.Credits = 0
+ h.g.World.AddGroundItem(p.RoomID, "credits", 10)
+ sess := &net.Session{Player: p, Conn: newChanConn()}
+ h.g.doGetAll(sess)
+ if p.Credits != 10 {
+ t.Errorf("credits after get-all = %d, want 10 (output: %s)", p.Credits, sess.Conn.(*chanConn).Bytes())
+ }
+ })
+}