1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
package game
// Regression: credit pickups must never destroy value at the economy cap.
// Only the balance headroom below casino.MaxCredits may be removed from the
// ground; the remainder stays there. The previous code removed the whole
// ground stack and then let grantCredits clamp the excess away.
import (
"strings"
"testing"
"thehouseoficarus/internal/casino"
"thehouseoficarus/internal/net"
)
func TestPickupCreditsAtCapLeavesRemainderOnGround(t *testing.T) {
h := newHarness(t)
h.seedAccount("alice")
p := h.seedCharacter("alice", "alice")
h.g.RunOnOwner(func() {
p.Credits = casino.MaxCredits - 5
h.g.World.AddGroundItem(p.RoomID, "credits", 20)
sess := &net.Session{Conn: newChanConn(), Player: p}
sess.SetState(net.StateGame)
h.g.pickupCredits(sess, p, "credits")
if p.Credits != casino.MaxCredits {
t.Errorf("balance = %d, want the cap %d", p.Credits, casino.MaxCredits)
}
if got := h.g.World.GroundItems(p.RoomID)["credits"]; got != 15 {
t.Errorf("ground credits = %d, want 15 left behind", got)
}
})
}
func TestPickupCreditsAtCapDestroysNothing(t *testing.T) {
h := newHarness(t)
h.seedAccount("alice")
p := h.seedCharacter("alice", "alice")
h.g.RunOnOwner(func() {
p.Credits = casino.MaxCredits
h.g.World.AddGroundItem(p.RoomID, "credits", 20)
sess := &net.Session{Conn: newChanConn(), Player: p}
sess.SetState(net.StateGame)
h.g.pickupCredits(sess, p, "credits")
if p.Credits != casino.MaxCredits {
t.Errorf("balance = %d, want the cap %d", p.Credits, casino.MaxCredits)
}
if got := h.g.World.GroundItems(p.RoomID)["credits"]; got != 20 {
t.Errorf("ground credits = %d, want the full stack to survive", got)
}
if out := string(sess.Conn.(*chanConn).Bytes()); !strings.Contains(out, "can't hold any more credits") {
t.Errorf("expected a cap message, got %q", out)
}
})
}
func TestGetAllCreditsAtCapLeavesRemainderOnGround(t *testing.T) {
h := newHarness(t)
h.seedAccount("alice")
p := h.seedCharacter("alice", "alice")
h.g.RunOnOwner(func() {
p.Credits = casino.MaxCredits - 5
h.g.World.AddGroundItem(p.RoomID, "credits", 20)
sess := &net.Session{Conn: newChanConn(), Player: p}
sess.SetState(net.StateGame)
h.g.doGetAll(sess)
if p.Credits != casino.MaxCredits {
t.Errorf("balance = %d, want the cap %d", p.Credits, casino.MaxCredits)
}
if got := h.g.World.GroundItems(p.RoomID)["credits"]; got != 15 {
t.Errorf("ground credits = %d, want 15 left behind", got)
}
})
}
func TestGetAllCreditsAtCapReportsShortfall(t *testing.T) {
h := newHarness(t)
h.seedAccount("alice")
p := h.seedCharacter("alice", "alice")
h.g.RunOnOwner(func() {
p.Credits = casino.MaxCredits
h.g.World.AddGroundItem(p.RoomID, "credits", 20)
sess := &net.Session{Conn: newChanConn(), Player: p}
sess.SetState(net.StateGame)
h.g.doGetAll(sess)
if got := h.g.World.GroundItems(p.RoomID)["credits"]; got != 20 {
t.Errorf("ground credits = %d, want the full stack to survive", got)
}
out := string(sess.Conn.(*chanConn).Bytes())
if !strings.Contains(out, "can't hold any more credits") {
t.Errorf("expected a cap message, got %q", out)
}
if strings.Contains(out, "inventory is full") {
t.Errorf("cap shortfall misreported as a full inventory: %q", out)
}
})
}
|