aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_option.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-11 20:41:06 -0400
committerhistoria <[not public]>2026-06-11 20:41:06 -0400
commitd6ab0e93a64525ce34f89e26d5272efbac513c32 (patch)
treed0ec59a72a32a15d0917d9c6c3bfa2f2a424c1f1 /internal/game/cmd_option.go
parent6b2b4bf470b655f01c5a21c5f558a6102402c214 (diff)
downloadthehouseoficarus-d6ab0e93a64525ce34f89e26d5272efbac513c32.tar.gz
feat: big map and options changes
Diffstat (limited to 'internal/game/cmd_option.go')
-rw-r--r--internal/game/cmd_option.go116
1 files changed, 116 insertions, 0 deletions
diff --git a/internal/game/cmd_option.go b/internal/game/cmd_option.go
new file mode 100644
index 0000000..49085db
--- /dev/null
+++ b/internal/game/cmd_option.go
@@ -0,0 +1,116 @@
+package game
+
+import (
+ "fmt"
+ "strconv"
+ "strings"
+
+ "thirdcollapse/internal/net"
+ "thirdcollapse/internal/player"
+)
+
+func (g *Game) doOption(sess *net.Session, input string) {
+ p := sess.Player.(*player.Player)
+
+ if input == "" {
+ sess.WriteLine("")
+ sess.WriteLine(fmt.Sprintf(" %-14s %-10s %-22s %s", "Option", "Value", "Valid", "Description"))
+ for _, def := range player.OptionDefs {
+ val := formatOptionValue(p, &def)
+ valid := formatValidValues(&def)
+ sess.WriteLine(fmt.Sprintf(" %-14s %-10s %-22s %s", def.Name, val, valid, def.Description))
+ }
+ return
+ }
+
+ parts := strings.Fields(input)
+ name := strings.ToLower(parts[0])
+ def := player.GetOptionDef(name)
+ if def == nil {
+ sess.WriteLine(fmt.Sprintf("\nUnknown option: %s", name))
+ return
+ }
+
+ if len(parts) == 1 {
+ val := formatOptionValue(p, def)
+ valid := formatValidValues(def)
+ sess.WriteLine(fmt.Sprintf("\n%s = %s [%s]", def.Name, val, valid))
+ sess.WriteLine(fmt.Sprintf(" %s", def.Description))
+ return
+ }
+
+ value := strings.ToLower(parts[1])
+ parsed, ok := parseOptionValue(def, value)
+ if !ok {
+ valid := formatValidValues(def)
+ sess.WriteLine(fmt.Sprintf("\nInvalid value for %s: %s [%s]", def.Name, value, valid))
+ return
+ }
+
+ if p.Options == nil {
+ p.Options = make(map[string]any)
+ }
+ p.Options[def.Name] = parsed
+ g.AccountStore.SaveCharacter(p)
+ sess.WriteLine(fmt.Sprintf("\n%s set to %s.", def.Name, formatOptionValue(p, def)))
+}
+
+func formatOptionValue(p *player.Player, def *player.OptionDef) string {
+ switch def.Type {
+ case player.OptBool:
+ if p.OptionBool(def.Name) {
+ return "on"
+ }
+ return "off"
+ case player.OptString:
+ return p.OptionString(def.Name)
+ case player.OptInt:
+ return strconv.Itoa(p.OptionInt(def.Name))
+ }
+ return ""
+}
+
+func formatValidValues(def *player.OptionDef) string {
+ switch def.Type {
+ case player.OptBool:
+ return "on/off"
+ case player.OptString:
+ if len(def.ValidValues) > 0 {
+ return strings.Join(def.ValidValues, "/")
+ }
+ return "string"
+ case player.OptInt:
+ return "num"
+ }
+ return ""
+}
+
+func parseOptionValue(def *player.OptionDef, input string) (any, bool) {
+ switch def.Type {
+ case player.OptBool:
+ switch input {
+ case "on", "true", "yes", "1":
+ return true, true
+ case "off", "false", "no", "0":
+ return false, true
+ }
+ return nil, false
+ case player.OptString:
+ if len(def.ValidValues) == 0 {
+ return input, true
+ }
+ for _, v := range def.ValidValues {
+ if strings.EqualFold(v, input) {
+ return v, true
+ }
+ }
+ return nil, false
+ case player.OptInt:
+ n, err := strconv.Atoi(input)
+ if err != nil {
+ return nil, false
+ }
+ return n, true
+ }
+ return nil, false
+}