diff options
Diffstat (limited to 'internal/behavior')
| -rw-r--r-- | internal/behavior/behavior.go | 5 | ||||
| -rw-r--r-- | internal/behavior/types.go | 28 |
2 files changed, 30 insertions, 3 deletions
diff --git a/internal/behavior/behavior.go b/internal/behavior/behavior.go index 57b2a7b..f81c73c 100644 --- a/internal/behavior/behavior.go +++ b/internal/behavior/behavior.go @@ -30,16 +30,17 @@ type TalkConfig struct { } type TalkNode struct { - Message string `yaml:"message"` + Message MessageList `yaml:"message"` Options []TalkOption `yaml:"options"` Action *NodeAction `yaml:"action"` + Next string `yaml:"next,omitempty"` } type TalkOption struct { Text string `yaml:"text"` Goto string `yaml:"goto"` - End bool `yaml:"end"` Condition *Condition `yaml:"condition"` + Action *NodeAction `yaml:"action,omitempty"` } type NodeAction struct { diff --git a/internal/behavior/types.go b/internal/behavior/types.go index 3c6e290..f8e65f7 100644 --- a/internal/behavior/types.go +++ b/internal/behavior/types.go @@ -1,6 +1,11 @@ package behavior -import "strings" +import ( + "math/rand" + "strings" + + "gopkg.in/yaml.v3" +) func WordPrefixMatch(input, name string) bool { inputWords := strings.Fields(strings.ToLower(input)) @@ -186,3 +191,24 @@ type DropEntry struct { type DropTableDef struct { Drops []DropEntry `yaml:"drops"` } + +type MessageList []string + +func (ml *MessageList) UnmarshalYAML(value *yaml.Node) error { + if value.Kind == yaml.ScalarNode { + var s string + if err := value.Decode(&s); err != nil { + return err + } + *ml = MessageList{s} + return nil + } + return value.Decode((*[]string)(ml)) +} + +func (ml MessageList) Pick() string { + if len(ml) == 0 { + return "" + } + return ml[rand.Intn(len(ml))] +} |
