aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_room.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-28 02:40:30 -0400
committerhistoria <[not public]>2026-06-28 02:40:30 -0400
commita1b6613c6c6a2f8d6e1ecd47e766bd40f92ac295 (patch)
tree4ff8fefb029c93f2aa3db7361658b0b4e9805b66 /internal/game/cmd_room.go
parent87dacfbb3dd16e7f55a82361eace98f9a39d75c8 (diff)
downloadthehouseoficarus-a1b6613c6c6a2f8d6e1ecd47e766bd40f92ac295.tar.gz
feat: admin accounts, god mode, OLC commands like dig/room, 'inline' objects changed to 'local' objects
Diffstat (limited to 'internal/game/cmd_room.go')
-rw-r--r--internal/game/cmd_room.go118
1 files changed, 118 insertions, 0 deletions
diff --git a/internal/game/cmd_room.go b/internal/game/cmd_room.go
new file mode 100644
index 0000000..11f919a
--- /dev/null
+++ b/internal/game/cmd_room.go
@@ -0,0 +1,118 @@
+package game
+
+import (
+ "fmt"
+ "os"
+ "strings"
+
+ "gopkg.in/yaml.v3"
+ "thehouseoficarus/internal/behavior"
+ "thehouseoficarus/internal/net"
+ "thehouseoficarus/internal/player"
+ "thehouseoficarus/internal/world"
+)
+
+func (g *Game) executeRoom(sess *net.Session, args []string, rawInput string) {
+ if !g.checkAdmin(sess) {
+ sess.WriteLine("Unknown command.")
+ return
+ }
+ p := sess.Player
+ if p == nil {
+ return
+ }
+ if len(args) == 0 {
+ g.showRoomHelp(sess)
+ return
+ }
+
+ action := strings.ToLower(args[0])
+ rest := args[1:]
+
+ switch action {
+ case "name":
+ g.roomSetName(sess, rest)
+ case "desc":
+ g.roomSetDesc(sess, rest)
+ case "addobj", "remobj", "addlocalobj", "remlocalobj", "hide", "unhide":
+ g.roomObject(sess, action, rest)
+ case "addmob", "remmob":
+ g.roomMob(sess, action, rest)
+ case "addspawn", "remspawn":
+ g.roomSpawn(sess, action, rest)
+ default:
+ sess.WriteLine(fmt.Sprintf("Unknown room action: %s", action))
+ g.showRoomHelp(sess)
+ }
+}
+
+func (g *Game) showRoomHelp(sess *net.Session) {
+ sess.WriteLine("room actions:")
+ sess.WriteLine(" room name <text> — set room name")
+ sess.WriteLine(" room desc <text> — set room description")
+ sess.WriteLine(" room addobj <object_id> — add a referenced object")
+ sess.WriteLine(" room remobj <object_id> — remove a referenced object")
+ sess.WriteLine(" room addlocalobj <name> <description> — add a local object")
+ sess.WriteLine(" room remlocalobj <name> — remove a local object")
+ sess.WriteLine(" room hide <name_or_id> — hide all matching objects")
+ sess.WriteLine(" room unhide <name_or_id> — unhide all matching objects")
+ sess.WriteLine(" room addmob <mob_id> — add a mob spawn")
+ sess.WriteLine(" room remmob <mob_id> — remove a mob spawn")
+ sess.WriteLine(" room addspawn <item_id> [qty] [respawn_ticks] — add an item spawn")
+ sess.WriteLine(" room remspawn <item_id> — remove an item spawn")
+}
+
+func (g *Game) roomSetName(sess *net.Session, args []string) {
+ if len(args) == 0 {
+ sess.WriteLine("Usage: room name <text>")
+ return
+ }
+ text := strings.Join(args, " ")
+ g.writeRoom(sess, func(room *world.Room) {
+ room.Name = text
+ })
+ sess.WriteLine(fmt.Sprintf("Room name set to: %s", text))
+}
+
+func (g *Game) roomSetDesc(sess *net.Session, args []string) {
+ if len(args) == 0 {
+ sess.WriteLine("Usage: room desc <text>")
+ return
+ }
+ text := strings.Join(args, " ")
+ g.writeRoom(sess, func(room *world.Room) {
+ room.Description = behavior.DescList{{Text: text}}
+ })
+ sess.WriteLine("Room description updated.")
+}
+
+func (g *Game) loadRoomWrite(p *player.Player) (*world.Room, string, error) {
+ path, ok := g.World.GetRoomPath(p.RoomID)
+ if !ok {
+ return nil, "", fmt.Errorf("room file not found")
+ }
+ room, err := g.World.LoadRoom(p.RoomID)
+ if err != nil {
+ return nil, "", err
+ }
+ return room, path, nil
+}
+
+func (g *Game) writeRoom(sess *net.Session, fn func(*world.Room)) {
+ p := sess.Player
+ room, path, err := g.loadRoomWrite(p)
+ if err != nil {
+ sess.WriteLine(fmt.Sprintf("Error loading room: %v", err))
+ return
+ }
+ fn(room)
+ data, err := yaml.Marshal(room)
+ if err != nil {
+ sess.WriteLine("Error marshaling room YAML.")
+ return
+ }
+ if err := os.WriteFile(path, data, 0644); err != nil {
+ sess.WriteLine("Error writing room file.")
+ return
+ }
+}