diff options
| author | historia <[not public]> | 2026-06-12 18:59:22 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-06-12 18:59:22 -0400 |
| commit | f3a6ae488bbd2128af8356b0da016699c5abb70e (patch) | |
| tree | 76965c30baa5d6ab92d1fa9c371d7ca3f08349ba /internal/game/action_default_target.go | |
| parent | d6ab0e93a64525ce34f89e26d5272efbac513c32 (diff) | |
| download | thehouseoficarus-f3a6ae488bbd2128af8356b0da016699c5abb70e.tar.gz | |
feat: commands automatically target if unambiguous, depleted node improvements
Diffstat (limited to 'internal/game/action_default_target.go')
| -rw-r--r-- | internal/game/action_default_target.go | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/internal/game/action_default_target.go b/internal/game/action_default_target.go new file mode 100644 index 0000000..45060cc --- /dev/null +++ b/internal/game/action_default_target.go @@ -0,0 +1,79 @@ +package game + +import ( + "strings" +) + +func verbToSkill(verb string) string { + switch verb { + case "mine": + return "mining" + case "chop", "cut": + return "woodcutting" + case "fish": + return "fishing" + } + return "" +} + +func (g *Game) resolveDefaultTarget(roomID int, verb string) string { + skill := verbToSkill(verb) + if skill == "" { + return "" + } + + objStates := g.World.AllObjInstances(roomID) + + type candidate struct { + defID string + name string + } + var candidates []candidate + seen := make(map[string]bool) + + for _, st := range objStates { + if seen[st.DefID] { + continue + } + seen[st.DefID] = true + + objDef, err := g.ObjectStore.Load(st.DefID) + if err != nil || objDef.BehaviorID == "" { + continue + } + + bh, err := g.BehaviorStore.Load(objDef.BehaviorID) + if err != nil || bh.Type != "gather" { + continue + } + + cfg, err := g.BehaviorStore.LoadGather(objDef.BehaviorID) + if err != nil { + continue + } + + if strings.EqualFold(cfg.Skill, skill) { + candidates = append(candidates, candidate{defID: st.DefID, name: objDef.Name}) + } + } + + if len(candidates) == 1 { + return candidates[0].name + } + return "" +} + +func (g *Game) resolveDefaultMob(roomID int) string { + mobs := g.MobStore.MobsInRoom(roomID) + if len(mobs) == 0 { + return "" + } + + firstDef := mobs[0].DefID + for _, m := range mobs[1:] { + if m.DefID != firstDef { + return "" + } + } + return mobs[0].Name +} |
