package world import ( "gopkg.in/yaml.v3" "thehouseoficarus/internal/action" ) type ExitDir string const ( North ExitDir = "north" South ExitDir = "south" East ExitDir = "east" West ExitDir = "west" Up ExitDir = "up" Down ExitDir = "down" ) var ExitAliases = map[string]ExitDir{ "n": North, "s": South, "e": East, "w": West, "u": Up, "d": Down, } var OppositeExit = map[ExitDir]ExitDir{ North: South, South: North, East: West, West: East, Up: Down, Down: Up, } var ExitOrder = []ExitDir{ North, South, East, West, Up, Down, } type SpawnDef struct { ID string `yaml:"id"` Quantity int `yaml:"quantity"` RespawnTicks float64 `yaml:"respawn_ticks"` } type ExitDef struct { Room int `yaml:"room"` Condition *action.Condition `yaml:"condition"` BlockedMessage string `yaml:"blocked_message"` SetFlags map[string]any `yaml:"set_flags"` SetPlayerFlags map[string]any `yaml:"set_player_flags"` } func (e *ExitDef) UnmarshalYAML(value *yaml.Node) error { if value.Kind == yaml.ScalarNode { var n int if err := value.Decode(&n); err != nil { return err } e.Room = n return nil } type raw ExitDef return value.Decode((*raw)(e)) } type Room struct { ID int `yaml:"id"` Name string `yaml:"name"` Description string `yaml:"description"` Descriptions []RoomDesc `yaml:"descriptions,omitempty"` Exits map[ExitDir]ExitDef `yaml:"exits"` Objects []RoomObject `yaml:"objects"` ItemSpawns []SpawnDef `yaml:"item_spawns"` Mobs []RoomMob `yaml:"mobs"` OnEnter []EnterStep `yaml:"on_enter"` Hazard string `yaml:"hazard"` } type RoomDesc struct { Text string `yaml:"text"` Condition *action.Condition `yaml:"condition"` } type RoomMob struct { ID string `yaml:"id"` WanderRooms []int `yaml:"wander_rooms"` WanderInterval float64 `yaml:"wander_interval"` } func (rm *RoomMob) UnmarshalYAML(value *yaml.Node) error { if value.Kind == yaml.ScalarNode { var s string if err := value.Decode(&s); err != nil { return err } rm.ID = s return nil } type raw RoomMob return value.Decode((*raw)(rm)) } type EnterStep struct { Message string `yaml:"message"` Condition *action.Condition `yaml:"condition"` Delay int `yaml:"delay"` SetFlags map[string]any `yaml:"set_flags"` SetPlayerFlags map[string]any `yaml:"set_player_flags"` } // IsTimed reports whether the step carries cutscene semantics: a tick delay or // a flag mutation. A room whose qualifying on_enter steps are all non-timed is // printed synchronously; any timed step turns the sequence into a scheduled // cutscene. func (e EnterStep) IsTimed() bool { return e.Delay > 0 || len(e.SetFlags) > 0 || len(e.SetPlayerFlags) > 0 } type RoomObject struct { ID string `yaml:"id"` WanderRooms []int `yaml:"wander_rooms"` WanderInterval float64 `yaml:"wander_interval"` }