diff options
| author | historia <[not public]> | 2026-10-06 12:57:23 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-10-06 12:57:23 -0400 |
| commit | 9666676766bf21364f4fc4d0d1d336e72f2a91b4 (patch) | |
| tree | 0cade34091d7602790dc38cd44053f0b74bbadf2 /internal/game/cmd_hide.go | |
| parent | 4bc1daaf259e0c19c5fe4a12ec8bc7f6e5a735c1 (diff) | |
| download | thehouseoficarus-9666676766bf21364f4fc4d0d1d336e72f2a91b4.tar.gz | |
refactor: split casino.go, dedup helpers, remove audit docs
Diffstat (limited to 'internal/game/cmd_hide.go')
| -rw-r--r-- | internal/game/cmd_hide.go | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/internal/game/cmd_hide.go b/internal/game/cmd_hide.go index b5d38fe..59ddf9e 100644 --- a/internal/game/cmd_hide.go +++ b/internal/game/cmd_hide.go @@ -2,6 +2,7 @@ package game import ( "fmt" + "strconv" "strings" "thehouseoficarus/internal/net" @@ -26,13 +27,29 @@ func (g *Game) executeHide(sess *net.Session, args []string, rawInput string) { target = strings.Join(args[1:], " ") } - instances := g.World.FindObjInstances(p.RoomID, target) + // The disambiguation prompt prints "N.name", so accept the same "N." + // selector every sibling verb supports (act.go, look_target.go). + instanceIdx := -1 + searchName := strings.ToLower(target) + if dotPos := strings.Index(searchName, "."); dotPos > 0 { + if n, err := strconv.Atoi(searchName[:dotPos]); err == nil && n > 0 { + instanceIdx = n - 1 + searchName = searchName[dotPos+1:] + } + } + + instances := g.World.FindObjInstances(p.RoomID, searchName) if len(instances) == 0 { sess.WriteLine("You don't see that here.") return } - if len(instances) > 1 && objectInstancesNeedDisambiguation(instances) { + if instanceIdx >= 0 && instanceIdx >= len(instances) { + sess.WriteLine("You don't see that here.") + return + } + + if instanceIdx < 0 && len(instances) > 1 && objectInstancesNeedDisambiguation(instances) { sess.WriteLines( "That's ambiguous, which one?", formatObjInstanceChoices(instances), @@ -40,14 +57,19 @@ func (g *Game) executeHide(sess *net.Session, args []string, rawInput string) { return } - objDef, err := g.ObjectStore.Load(instances[0].DefID) + chosen := instances[0] + if instanceIdx >= 0 { + chosen = instances[instanceIdx] + } + + objDef, err := g.ObjectStore.Load(chosen.DefID) if err != nil || !objDef.IsSafespot() { sess.WriteLine("You can't hide behind that.") return } cfg := objDef.Safespot - st := g.World.GetObjState(p.RoomID, objDef.ID, instances[0].Index) + st := g.World.GetObjState(p.RoomID, objDef.ID, chosen.Index) if st == nil { sess.WriteLine("You can't hide behind that.") return @@ -56,7 +78,7 @@ func (g *Game) executeHide(sess *net.Session, args []string, rawInput string) { existingSS, alreadyHiding := g.safespot.Get(p.Name) if alreadyHiding && existingSS.Active { - if existingSS.ObjectDefID == objDef.ID && existingSS.ObjectIndex == instances[0].Index { + if existingSS.ObjectDefID == objDef.ID && existingSS.ObjectIndex == chosen.Index { if existingSS.HideCountdown > 0 { sess.WriteLine("You're already moving into position there.") } else { |
