aboutsummaryrefslogtreecommitdiff
path: root/internal/player
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-10-05 17:05:14 -0400
committerhistoria <[not public]>2026-10-05 17:05:14 -0400
commite42952469dadfb3535633c66c881050ac128703c (patch)
treea78f7396b72cdbd6fa4f6c454c830f40cf2ad0cb /internal/player
parent90ad8c0c33b519d5830c69d4128bdc984b5e9de8 (diff)
downloadthehouseoficarus-e42952469dadfb3535633c66c881050ac128703c.tar.gz
fix: gather verbs, walk oom, admin path bypass, roulette refund
Diffstat (limited to 'internal/player')
-rw-r--r--internal/player/hardening_removeitem_test.go14
-rw-r--r--internal/player/player.go7
-rw-r--r--internal/player/xp.go2
-rw-r--r--internal/player/xp_test.go15
4 files changed, 36 insertions, 2 deletions
diff --git a/internal/player/hardening_removeitem_test.go b/internal/player/hardening_removeitem_test.go
index 5cb1e4c..b891d4e 100644
--- a/internal/player/hardening_removeitem_test.go
+++ b/internal/player/hardening_removeitem_test.go
@@ -21,3 +21,17 @@ func TestRemoveItemRejectsNonPositive(t *testing.T) {
t.Fatalf("stack mutated by a zero removal: %+v", slot)
}
}
+
+// Regression: RemoveItem used to drain every stack and only then return false,
+// so a caller that rolled back on failure lost the items anyway.
+func TestRemoveItemIsAllOrNothing(t *testing.T) {
+ p := New("alice")
+ p.SetInvSlot(0, &InventorySlot{ItemID: "coin", Quantity: 2})
+ p.SetInvSlot(1, &InventorySlot{ItemID: "coin", Quantity: 3})
+ if p.RemoveItem("coin", 10) {
+ t.Fatal("removal of more than held reported success")
+ }
+ if got := p.CountItem("coin"); got != 5 {
+ t.Fatalf("failed removal drained stacks: count = %d, want 5", got)
+ }
+}
diff --git a/internal/player/player.go b/internal/player/player.go
index aad0b8e..92b017a 100644
--- a/internal/player/player.go
+++ b/internal/player/player.go
@@ -205,7 +205,7 @@ type Player struct {
Options map[string]any `yaml:"-"`
Flags map[string]any `yaml:"flags"`
PendingSequence *PendingSequence `yaml:"pending_sequence,omitempty"`
- RegenerateTick int
+ RegenerateTick int `yaml:"-"`
AmmoQty int `yaml:"ammo_qty,omitempty"`
Action *behavior.Action `yaml:"-"`
BackgroundAction *behavior.Action `yaml:"-"`
@@ -525,6 +525,11 @@ func (p *Player) RemoveItem(itemID string, qty int) bool {
if qty <= 0 {
return false
}
+ // All-or-nothing: a caller that rolls back on false must not find the
+ // inventory already drained. Check the total first, then remove.
+ if p.CountItem(itemID) < qty {
+ return false
+ }
remaining := qty
for i, slot := range p.Inventory {
if slot == nil || slot.ItemID != itemID {
diff --git a/internal/player/xp.go b/internal/player/xp.go
index ef59a25..13d5416 100644
--- a/internal/player/xp.go
+++ b/internal/player/xp.go
@@ -1,6 +1,6 @@
package player
-var XPTable = [100]int{
+var XPTable = [99]int{
0, 83, 174, 276, 388, 512, 650, 801, 969, 1154,
1358, 1584, 1833, 2107, 2411, 2746, 3115, 3523, 3973, 4470,
5018, 5624, 6291, 7028, 7842, 8740, 9730, 10824, 12031, 13363,
diff --git a/internal/player/xp_test.go b/internal/player/xp_test.go
new file mode 100644
index 0000000..fc0eeb4
--- /dev/null
+++ b/internal/player/xp_test.go
@@ -0,0 +1,15 @@
+package player
+
+import "testing"
+
+// Regression: XPTable was declared [100]int with 99 initializers, so index 99
+// silently read as 0 ("level 100 costs 0 XP"). The array is now sized so an
+// out-of-range index is a compile error.
+func TestXPTableBounds(t *testing.T) {
+ if len(XPTable) != 99 {
+ t.Fatalf("len(XPTable) = %d, want 99", len(XPTable))
+ }
+ if XPTable[98] != 13034431 {
+ t.Fatalf("XPTable[98] = %d, want 13034431", XPTable[98])
+ }
+}