UX S4: magic-item polish — slot fixes, swap-back, shop & sheet truth-up

B4: Slot classifier no longer treats "Springing" / "Snaring" / "Devouring"
as ring matches; tokenises by word boundary instead of raw substring.
Adds DnDSlotCloak so cloaks/capes/mantles/wings stop evicting body armor
from the chest slot. Regenerated magic_items_srd_data.go: boots_of_*,
gloves_of_missile_snaring, bag_of_devouring, talismans, and 6 cloaks all
land in the right slot.

R4: equipMagicItem swap-back returns the prior occupant at full Value
instead of half — swapping a curio shouldn't tax it.

R5: Attunement count is recomputed *after* the swap-back so freeing the
prior occupant's bond opens the slot for the incoming item.

R1: Inventory tags magic_item rows with 🔮 + rarity label and prints a
single equip-magic footer when any are present.

R6: Sheet's Magic Items block marks unbonded items as **(inactive)**
with the reason (cap full vs unbonded), so over-cap items aren't silent.

R7: New activeMagicItemsLine surfaces a one-shot "your curios stir: …"
at combat-start in both the dungeon path and !fight, mirroring the way
class passives are surfaced.

R8/R9: dropMagicItemLoot pretty-prints rarity, drops "wondrous", calls
attunement "needs bonding", appends "auto-uses in combat" for
potions/scrolls, and routes persistence errors to slog instead of
leaking %v into chat.

R2/R3: Curios shelf now shows "Very Rare" not "very_rare", drops the
bare "wondrous" word (the effect line carries it), renders the codified
magicItemEffectSummary above the SRD desc, and ends with a one-line
plain-language "what is bonding" footnote.

R10: Curios stock day flips at 06:00 UTC instead of midnight so EU
players don't see a fresh shelf at 1 a.m. mid-session.

R11: Curios buy resolver disambiguates fuzzy matches — typing "ring"
when several rings are on the shelf lists candidates instead of
silently selling the first.

P1: Greeting grid pairs Curios with an Exit chip so the 2-column
emoji layout doesn't dangle.

P2: Equip-magic empty state trimmed to one line.

P4 (back-from-curios reprompt) deferred — the existing back-flow is
correct, just verbose; not worth the surface-area expansion this
session.

Tests: word-boundary classifier, cloak/chest coexistence, full-value
swap-back. go test ./... + go vet clean.
This commit is contained in:
prosolis
2026-05-14 22:37:38 -07:00
committed by prosolis
parent 8ee170bb9b
commit c2fdc63b51
11 changed files with 349 additions and 70 deletions

View File

@@ -153,6 +153,105 @@ func TestMagicItemSellTyping(t *testing.T) {
}
}
// TestSlotClassifierWordBoundaries — sanity-check the post-classifier dump:
// boots/gloves/bags must not have leaked into the ring slot via raw substring
// matching on "Springing", "Snaring", "Devouring".
func TestSlotClassifierWordBoundaries(t *testing.T) {
cases := map[string]DnDSlot{
"boots_of_striding_and_springing": DnDSlotFeet,
"gloves_of_missile_snaring": DnDSlotHands,
"bag_of_devouring": "", // unslotted carry item
}
for id, want := range cases {
mi, ok := magicItemRegistry[id]
if !ok {
t.Fatalf("registry missing %s", id)
}
if mi.Slot != want {
t.Errorf("%s slot = %q, want %q", id, mi.Slot, want)
}
}
}
// TestCloakSlotCoexistsWithChest — the new cloak slot lets a Cloak of
// Elvenkind sit alongside (not on top of) Mithral Plate.
func TestCloakSlotCoexistsWithChest(t *testing.T) {
cloak, ok := magicItemRegistry["cloak_of_elvenkind"]
if !ok {
t.Fatal("registry missing cloak_of_elvenkind")
}
if cloak.Slot != DnDSlotCloak {
t.Errorf("cloak_of_elvenkind slot = %q, want %q", cloak.Slot, DnDSlotCloak)
}
armor, ok := magicItemRegistry["mithral_armor"]
if !ok {
t.Fatal("registry missing mithral_armor")
}
if armor.Slot != DnDSlotChest {
t.Errorf("mithral_armor slot = %q, want %q", armor.Slot, DnDSlotChest)
}
if cloak.Slot == armor.Slot {
t.Errorf("cloak and chest armor share slot %q — they will evict each other", cloak.Slot)
}
}
// TestSwapBackReturnsFullValue — equipping over a slot must return the prior
// occupant at full registry value, not halved. Plays the equip flow against
// the real DB so the AdvItem written back is what the player will see.
func TestSwapBackReturnsFullValue(t *testing.T) {
dir := t.TempDir()
db.Close()
if err := db.Init(dir); err != nil {
t.Fatal(err)
}
t.Cleanup(db.Close)
user := id.UserID("@swap:test.invalid")
// Find any two distinct items that share a slot — we're testing the
// swap-back math, not the attunement state.
bySlot := map[DnDSlot][]MagicItem{}
for _, mi := range magicItemRegistry {
if mi.Slot == "" || mi.Value == 0 {
continue
}
bySlot[mi.Slot] = append(bySlot[mi.Slot], mi)
}
var a, b MagicItem
for _, items := range bySlot {
if len(items) >= 2 {
a, b = items[0], items[1]
break
}
}
if a.ID == "" {
t.Skip("registry has no slot with two items")
}
// Pre-occupy the slot with `a`, then drop `b` into inventory and equip it.
if err := equipMagicItem(user, a.Slot, a.ID, false); err != nil {
t.Fatalf("seed equip: %v", err)
}
bInv := magicItemSell(b)
bInv.SkillSource = "magic_item:" + b.ID
if err := addAdvInventoryItem(user, bInv); err != nil {
t.Fatalf("seed inv: %v", err)
}
// Reach into the equip resolver via its public DB seam: replicate the
// swap-back that resolveMagicEquipReply performs.
equipped, err := loadEquippedMagicItems(user)
if err != nil {
t.Fatal(err)
}
prev := equipped[b.Slot]
back := magicItemSell(prev.Item)
back.SkillSource = "magic_item:" + prev.Item.ID
if int64(prev.Item.Value) != back.Value {
t.Errorf("swap-back value = %d, want full %d", back.Value, prev.Item.Value)
}
}
// TestEquippedMagicItemRoundTrip exercises the DB persistence layer: equip,
// load, attunement counting, unequip.
func TestEquippedMagicItemRoundTrip(t *testing.T) {