aboutsummaryrefslogtreecommitdiff
path: root/internal/game/action_default_target.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/action_default_target.go')
-rw-r--r--internal/game/action_default_target.go79
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
+}