aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_room_spawn.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_spawn.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_spawn.go')
-rw-r--r--internal/game/cmd_room_spawn.go101
1 files changed, 101 insertions, 0 deletions
diff --git a/internal/game/cmd_room_spawn.go b/internal/game/cmd_room_spawn.go
new file mode 100644
index 0000000..d4353e4
--- /dev/null
+++ b/internal/game/cmd_room_spawn.go
@@ -0,0 +1,101 @@
+package game
+
+import (
+ "fmt"
+ "os"
+ "strconv"
+
+ "gopkg.in/yaml.v3"
+ "thehouseoficarus/internal/net"
+ "thehouseoficarus/internal/world"
+)
+
+func (g *Game) roomSpawn(sess *net.Session, action string, args []string) {
+ switch action {
+ case "addspawn":
+ g.roomAddSpawn(sess, args)
+ case "remspawn":
+ g.roomRemSpawn(sess, args)
+ }
+}
+
+func (g *Game) roomAddSpawn(sess *net.Session, args []string) {
+ if len(args) == 0 {
+ sess.WriteLine("Usage: room addspawn <item_id> [quantity] [respawn_ticks]")
+ return
+ }
+ itemID := args[0]
+ if _, err := g.ItemStore.Load(itemID); err != nil {
+ sess.WriteLine(fmt.Sprintf("Item '%s' not found in data/items/.", itemID))
+ return
+ }
+
+ quantity := 1
+ respawnTicks := float64(0)
+ if len(args) >= 2 {
+ if n, err := strconv.Atoi(args[1]); err == nil && n > 0 {
+ quantity = n
+ }
+ }
+ if len(args) >= 3 {
+ if n, err := strconv.ParseFloat(args[2], 64); err == nil && n >= 0 {
+ respawnTicks = n
+ }
+ }
+
+ p := sess.Player
+ room, _, err := g.loadRoomWrite(p)
+ if err != nil {
+ sess.WriteLine(fmt.Sprintf("Error loading room: %v", err))
+ return
+ }
+ for _, s := range room.ItemSpawns {
+ if s.ID == itemID {
+ sess.WriteLine(fmt.Sprintf("Item spawn '%s' already exists in this room.", itemID))
+ return
+ }
+ }
+ room.ItemSpawns = append(room.ItemSpawns, world.SpawnDef{
+ ID: itemID,
+ Quantity: quantity,
+ RespawnTicks: respawnTicks,
+ })
+
+ path, _ := g.World.GetRoomPath(p.RoomID)
+ data, _ := yaml.Marshal(room)
+ os.WriteFile(path, data, 0644)
+ sess.WriteLine(fmt.Sprintf("Added item spawn '%s' x%d (respawn: %.0f ticks) to room.", itemID, quantity, respawnTicks))
+}
+
+func (g *Game) roomRemSpawn(sess *net.Session, args []string) {
+ if len(args) == 0 {
+ sess.WriteLine("Usage: room remspawn <item_id>")
+ return
+ }
+ itemID := 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.ItemSpawns[:0]
+ for _, s := range room.ItemSpawns {
+ if s.ID == itemID {
+ found = true
+ } else {
+ filtered = append(filtered, s)
+ }
+ }
+ if !found {
+ sess.WriteLine(fmt.Sprintf("Item spawn '%s' not found in this room.", itemID))
+ return
+ }
+ room.ItemSpawns = filtered
+
+ path, _ := g.World.GetRoomPath(p.RoomID)
+ data, _ := yaml.Marshal(room)
+ os.WriteFile(path, data, 0644)
+ sess.WriteLine(fmt.Sprintf("Removed item spawn '%s' from room.", itemID))
+}