From a1b6613c6c6a2f8d6e1ecd47e766bd40f92ac295 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Sun, 28 Jun 2026 02:40:30 -0400 Subject: feat: admin accounts, god mode, OLC commands like dig/room, 'inline' objects changed to 'local' objects --- internal/game/cmd_room_mob.go | 82 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 internal/game/cmd_room_mob.go (limited to 'internal/game/cmd_room_mob.go') diff --git a/internal/game/cmd_room_mob.go b/internal/game/cmd_room_mob.go new file mode 100644 index 0000000..ced170f --- /dev/null +++ b/internal/game/cmd_room_mob.go @@ -0,0 +1,82 @@ +package game + +import ( + "fmt" + "os" + + "gopkg.in/yaml.v3" + "thehouseoficarus/internal/net" + "thehouseoficarus/internal/world" +) + +func (g *Game) roomMob(sess *net.Session, action string, args []string) { + switch action { + case "addmob": + g.roomAddMob(sess, args) + case "remmob": + g.roomRemMob(sess, args) + } +} + +func (g *Game) roomAddMob(sess *net.Session, args []string) { + if len(args) == 0 { + sess.WriteLine("Usage: room addmob ") + return + } + mobID := args[0] + if _, err := g.MobStore.LoadDef(mobID); err != nil { + sess.WriteLine(fmt.Sprintf("Mob '%s' not found in data/mobs/.", mobID)) + return + } + p := sess.Player + room, _, err := g.loadRoomWrite(p) + if err != nil { + sess.WriteLine(fmt.Sprintf("Error loading room: %v", err)) + return + } + for _, m := range room.Mobs { + if m.ID == mobID { + sess.WriteLine(fmt.Sprintf("Mob '%s' is already in this room.", mobID)) + return + } + } + room.Mobs = append(room.Mobs, world.RoomMob{ID: mobID}) + + path, _ := g.World.GetRoomPath(p.RoomID) + data, _ := yaml.Marshal(room) + os.WriteFile(path, data, 0644) + sess.WriteLine(fmt.Sprintf("Added mob '%s' to room.", mobID)) +} + +func (g *Game) roomRemMob(sess *net.Session, args []string) { + if len(args) == 0 { + sess.WriteLine("Usage: room remmob ") + return + } + mobID := args[0] + p := sess.Player + room, _, err := g.loadRoomWrite(p) + if err != nil { + sess.WriteLine(fmt.Sprintf("Error loading room: %v", err)) + return + } + found := false + filtered := room.Mobs[:0] + for _, m := range room.Mobs { + if m.ID == mobID { + found = true + } else { + filtered = append(filtered, m) + } + } + if !found { + sess.WriteLine(fmt.Sprintf("Mob '%s' not found in this room.", mobID)) + return + } + room.Mobs = filtered + + path, _ := g.World.GetRoomPath(p.RoomID) + data, _ := yaml.Marshal(room) + os.WriteFile(path, data, 0644) + sess.WriteLine(fmt.Sprintf("Removed mob '%s' from room.", mobID)) +} -- cgit v1.2.3