aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_shop.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-25 19:37:20 -0400
committerhistoria <[not public]>2026-06-25 19:37:20 -0400
commitc55d0e4150b23f2c5c9f96bbc3d4dc2fc6dbaa36 (patch)
treed1c02acea2b4c8d0f672c1539cfdb373b6272ed0 /internal/game/cmd_shop.go
parent068ce514ea3eebdc42b595c631b4b00ce4594577 (diff)
downloadthehouseoficarus-c55d0e4150b23f2c5c9f96bbc3d4dc2fc6dbaa36.tar.gz
feat: yaml conversation trees more robust
Diffstat (limited to 'internal/game/cmd_shop.go')
-rw-r--r--internal/game/cmd_shop.go42
1 files changed, 25 insertions, 17 deletions
diff --git a/internal/game/cmd_shop.go b/internal/game/cmd_shop.go
index 51d0ab1..d1b0e9c 100644
--- a/internal/game/cmd_shop.go
+++ b/internal/game/cmd_shop.go
@@ -401,10 +401,8 @@ func (g *Game) leaveShop(sess *net.Session) {
g.writePrompt(sess)
return
}
- nodeKey := td.Node
- cfg := td.Cfg
- node, ok := cfg.Nodes[nodeKey]
+ node, ok := td.Cfg.Nodes[td.Node]
if !ok {
sess.State = net.StateGame
g.cancelAction(p)
@@ -412,20 +410,30 @@ func (g *Game) leaveShop(sess *net.Session) {
return
}
- sess.State = net.StateTalk
- visible := 0
- for _, opt := range node.Options {
- if opt.Condition != nil && !g.checkCondition(sess, opt.Condition) {
- continue
+ for {
+ visible := g.visibleOptions(sess, node.Options)
+ if len(visible) > 0 {
+ for i, opt := range visible {
+ sess.WriteLine(fmt.Sprintf(" %d. %s", i+1, opt.Text))
+ }
+ sess.State = net.StateTalk
+ sess.Write("\nChoice: ")
+ return
+ }
+
+ if node.Next != "" {
+ next, ok := td.Cfg.Nodes[node.Next]
+ if !ok {
+ break
+ }
+ td.Node = node.Next
+ node = next
+ } else {
+ break
}
- visible++
- sess.WriteLine(fmt.Sprintf(" %d. %s", visible, opt.Text))
- }
- if visible == 0 {
- sess.State = net.StateGame
- g.cancelAction(p)
- g.writePrompt(sess)
- return
}
- sess.Write("\nChoice: ")
+
+ sess.State = net.StateGame
+ g.cancelAction(p)
+ g.writePrompt(sess)
}