From 9666676766bf21364f4fc4d0d1d336e72f2a91b4 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Tue, 6 Oct 2026 12:57:23 -0400 Subject: refactor: split casino.go, dedup helpers, remove audit docs --- internal/game/cmd_trigger_utility.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'internal/game/cmd_trigger_utility.go') diff --git a/internal/game/cmd_trigger_utility.go b/internal/game/cmd_trigger_utility.go index fa81f23..6b502cf 100644 --- a/internal/game/cmd_trigger_utility.go +++ b/internal/game/cmd_trigger_utility.go @@ -2,6 +2,7 @@ package game import ( "fmt" + "sort" "strings" "thehouseoficarus/internal/item" @@ -118,8 +119,15 @@ func (g *Game) triggerEmGrab(sess *net.Session, p *player.Player, mod *ModDef, t // Reservation-aware: only items this player may take are considered, so // em grab cannot magnetize kill loot reserved for another player. groundItems := g.World.AccessibleGround(p.RoomID, p.Name) - var matchedID string + itemIDs := make([]string, 0, len(groundItems)) for itemID := range groundItems { + itemIDs = append(itemIDs, itemID) + } + // Map iteration is randomized; pick deterministically so `em grab ` + // always resolves the same matching stack. + sort.Strings(itemIDs) + var matchedID string + for _, itemID := range itemIDs { def, _ := g.ItemStore.Load(itemID) if def != nil && def.MatchesName(targetArg) { matchedID = itemID @@ -276,7 +284,12 @@ func (g *Game) triggerSuperheat(sess *net.Session, p *player.Player, mod *ModDef return } - consumeIngredients(c, p.CountItem, p.RemoveItem) + if !consumeIngredients(c, p.CountItem, p.RemoveItem) { + // planIngredients reserves stock across entries, so a weak pre-check + // (duplicate entries) can fail here. Abort without producing output. + sess.WriteLine("You don't have the required materials.") + return + } outputQty := c.OutputQty if outputQty <= 0 { @@ -381,7 +394,8 @@ func (g *Game) triggerPlankMake(sess *net.Session, p *player.Player, mod *ModDef return } - for logID, info := range logTypes { + for _, logID := range []string{"logs", "oak_logs", "teak_logs", "mahogany_logs"} { + info := logTypes[logID] qty := p.CountItem(logID) if qty == 0 { continue -- cgit v1.2.3