diff options
| author | historia <[not public]> | 2026-10-05 19:30:49 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-10-05 19:30:49 -0400 |
| commit | a5447965e7808d656a5e5d9326a9ca0231148f85 (patch) | |
| tree | 618d46ccf2119658d0a6cc9e7b7a27fd75c0fee0 /internal/game | |
| parent | 1091d0fae96d152c11aec1bb2dd949f51ed5aa1e (diff) | |
| download | thehouseoficarus-a5447965e7808d656a5e5d9326a9ca0231148f85.tar.gz | |
feat: sym-link containment, batch count prompt for crafting
Diffstat (limited to 'internal/game')
| -rw-r--r-- | internal/game/correct_audit_fixes_test.go | 40 | ||||
| -rw-r--r-- | internal/game/production_menu.go | 12 |
2 files changed, 52 insertions, 0 deletions
diff --git a/internal/game/correct_audit_fixes_test.go b/internal/game/correct_audit_fixes_test.go index 6177eac..c32b1e5 100644 --- a/internal/game/correct_audit_fixes_test.go +++ b/internal/game/correct_audit_fixes_test.go @@ -1,6 +1,7 @@ package game import ( + "path/filepath" "testing" "thehouseoficarus/internal/behavior" @@ -126,6 +127,45 @@ func TestUsableCraftIndexSelectsSatisfiedRecipe(t *testing.T) { } } +// End-to-end gather: the missing coverage the audit called out. Start a mine +// action on a seeded rock with a pickaxe and tick it to a drop. +func TestGatherYieldsDrop(t *testing.T) { + h := newHarness(t) + h.seedAccount("alice") + p := h.seedCharacter("alice", "alice") + writeSeedFile(t, filepath.Join(h.dir, "objects", "copper_rock.yaml"), + []byte("id: copper_rock\nname: copper rock\ngather:\n skill: mining\n tools: [pickaxe]\n success: {base: 1, cap: 1}\n gather_message: You mine the rock.\n drops:\n - item_id: copper_ore\n weight: 100\n")) + writeSeedFile(t, filepath.Join(h.dir, "items", "pickaxe.yaml"), + []byte("id: pickaxe\nname: pickaxe\ntool:\n type: pickaxe\n speed: 1\n")) + writeSeedFile(t, filepath.Join(h.dir, "items", "copper_ore.yaml"), + []byte("id: copper_ore\nname: copper ore\nstackable: true\n")) + sess := &net.Session{Conn: newChanConn(), Player: p} + sess.SetState(net.StateGame) + h.g.RunOnOwner(func() { + h.g.ItemStore.Reload(h.dir) + h.g.ObjectStore.Reload(h.dir) + h.g.World.EnsureObjectStates(1, []string{"copper_rock"}) + p.SetInvSlot(0, &player.InventorySlot{ItemID: "pickaxe", Quantity: 1}) + obj, _, err := h.g.resolveObjectDef(1, "copper_rock") + if err != nil { + t.Fatalf("resolve object: %v", err) + } + st := h.g.World.GetObjState(1, "copper_rock", 0) + if st == nil { + t.Fatal("no object state after EnsureObjectStates") + } + h.g.startGather(sess, p, obj, st) + if p.Action == nil { + t.Fatalf("gather action did not start: %s", sess.Conn.(*chanConn).Bytes()) + } + h.g.advanceGather(sess, p) // step 0: announce + h.g.advanceGather(sess, p) // step 1: resolve the drop + if got := p.CountItem("copper_ore"); got == 0 { + t.Fatalf("gather yielded no ore (output: %s)", sess.Conn.(*chanConn).Bytes()) + } + }) +} + func TestPlayerDataFileNameCanonicalizesPrefixes(t *testing.T) { for _, in := range []string{ "players/characters/alice.yaml", diff --git a/internal/game/production_menu.go b/internal/game/production_menu.go index 5d712da..ad44853 100644 --- a/internal/game/production_menu.go +++ b/internal/game/production_menu.go @@ -290,6 +290,18 @@ func itemIDs(defs []*item.ItemDef) []string { func (g *Game) promptHowMany(sess *net.Session, itemID string) { sess.PendingItemID = itemID sess.SetState(net.StateHowMany) + yield := 1 + if item := g.loadCraftItem(itemID); item != nil { + if c := g.usableCraft(sess.Player, item); c != nil && c.OutputQty > 0 { + yield = c.OutputQty + } + } + // The count is batches, not units: say so and show the per-batch yield so + // "15" cannot silently mean 225 arrow shafts. + if yield > 1 { + sess.Write(fmt.Sprintf("How many batches (each makes %d, return for all)?: ", yield)) + return + } sess.Write("How many (return for all)?: ") } |
