aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_trigger_utility.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-10-06 12:57:23 -0400
committerhistoria <[not public]>2026-10-06 12:57:23 -0400
commit9666676766bf21364f4fc4d0d1d336e72f2a91b4 (patch)
tree0cade34091d7602790dc38cd44053f0b74bbadf2 /internal/game/cmd_trigger_utility.go
parent4bc1daaf259e0c19c5fe4a12ec8bc7f6e5a735c1 (diff)
downloadthehouseoficarus-9666676766bf21364f4fc4d0d1d336e72f2a91b4.tar.gz
refactor: split casino.go, dedup helpers, remove audit docs
Diffstat (limited to 'internal/game/cmd_trigger_utility.go')
-rw-r--r--internal/game/cmd_trigger_utility.go20
1 files changed, 17 insertions, 3 deletions
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 <name>`
+ // 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