aboutsummaryrefslogtreecommitdiff
path: root/internal/world/room.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-07-08 19:59:14 -0400
committerhistoria <[not public]>2026-07-08 19:59:14 -0400
commit09d325dcf5e779eab5550d3fd3377bde50101428 (patch)
treea433be903aabbf1d2eadce2aacdac12a9eb8dde0 /internal/world/room.go
parent9184377301c2604e003f36426788c032fb0ca524 (diff)
downloadthehouseoficarus-09d325dcf5e779eab5550d3fd3377bde50101428.tar.gz
feat: unify on use, on look, and on kill. all support same conditions/actions now.
Diffstat (limited to 'internal/world/room.go')
-rw-r--r--internal/world/room.go71
1 files changed, 22 insertions, 49 deletions
diff --git a/internal/world/room.go b/internal/world/room.go
index 2da40fb..08e18a4 100644
--- a/internal/world/room.go
+++ b/internal/world/room.go
@@ -75,13 +75,12 @@ type SpawnDef struct {
}
type ExitDef struct {
- Room int `yaml:"room"`
- Condition *behavior.Condition `yaml:"condition,omitempty"`
- BlockedMessage string `yaml:"blocked_message,omitempty"`
- SetGlobalFlags map[string]any `yaml:"set_global_flags,omitempty"`
- SetPlayerFlags map[string]any `yaml:"set_player_flags,omitempty"`
- Hidden bool `yaml:"hidden,omitempty"`
- AlwaysBlocked bool `yaml:"always_blocked,omitempty"`
+ Room int `yaml:"room"`
+ Condition *behavior.Condition `yaml:"condition,omitempty"`
+ BlockedMessage string `yaml:"blocked_message,omitempty"`
+ OnTraverse []behavior.Interaction `yaml:"on_traverse,omitempty"`
+ Hidden bool `yaml:"hidden,omitempty"`
+ AlwaysBlocked bool `yaml:"always_blocked,omitempty"`
}
func (e *ExitDef) UnmarshalYAML(value *yaml.Node) error {
@@ -106,7 +105,7 @@ type Room struct {
Objects []RoomObject `yaml:"objects"`
ItemSpawns []SpawnDef `yaml:"item_spawns"`
Mobs []RoomMob `yaml:"mobs"`
- OnEnter []EnterStep `yaml:"on_enter"`
+ OnEnter []behavior.StepAction `yaml:"on_enter"`
Hazard string `yaml:"hazard"`
BlockTransport bool `yaml:"block_transport"`
Triggers []TriggerDef `yaml:"triggers"`
@@ -131,32 +130,6 @@ func (rm *RoomMob) UnmarshalYAML(value *yaml.Node) error {
return value.Decode((*raw)(rm))
}
-type EnterStep struct {
- Message string `yaml:"message"`
- Condition *behavior.Condition `yaml:"condition"`
- Delay int `yaml:"delay"`
- SetGlobalFlags map[string]any `yaml:"set_global_flags"`
- SetPlayerFlags map[string]any `yaml:"set_player_flags"`
- Broadcast string `yaml:"broadcast"`
- BroadcastGlobal string `yaml:"broadcast_global"`
- SpawnMob *SpawnMobConfig `yaml:"spawn_mob"`
- DespawnMob string `yaml:"despawn_mob"`
- GiveItem string `yaml:"give_item"`
- TakeItem string `yaml:"take_item"`
- Teleport int `yaml:"teleport"`
- Heal int `yaml:"heal"`
-}
-
-// IsTimed reports whether the step carries enter-sequence semantics (any
-// non-zero field means it needs per-tick scheduling rather than synchronous
-// printing).
-func (e EnterStep) IsTimed() bool {
- return e.Delay > 0 || len(e.SetGlobalFlags) > 0 || len(e.SetPlayerFlags) > 0 ||
- e.Message != "" || e.Broadcast != "" || e.BroadcastGlobal != "" ||
- e.SpawnMob != nil || e.DespawnMob != "" || e.GiveItem != "" ||
- e.TakeItem != "" || e.Teleport != 0 || e.Heal != 0
-}
-
// RoomObject is either a reference to a file-backed object definition (only
// `id`/wander fields set) or a fully local object definition (Local != nil).
// An entry is treated as local when it carries any passive content field
@@ -190,7 +163,7 @@ func (ro *RoomObject) UnmarshalYAML(value *yaml.Node) error {
return err
}
isLocal := def.Name != "" || len(def.Description) > 0 || def.InRoomDescription != "" ||
- len(def.Aliases) > 0 || def.Color != "" || def.OnLook != nil
+ len(def.Aliases) > 0 || def.Color != "" || len(def.OnLook) > 0
if isLocal {
ro.ID = NormalizeObjectName(def.Name)
ro.Local = &def
@@ -204,19 +177,19 @@ func (ro *RoomObject) UnmarshalYAML(value *yaml.Node) error {
func (ro RoomObject) MarshalYAML() (interface{}, error) {
if ro.Local != nil {
type inlineObj struct {
- Name string `yaml:"name"`
- Aliases []string `yaml:"aliases,omitempty"`
- Color string `yaml:"color,omitempty"`
- Hidden bool `yaml:"hidden,omitempty"`
- InRoomDescription string `yaml:"inroom_description,omitempty"`
- RemovalItem string `yaml:"removal_item,omitempty"`
- Description behavior.DescList `yaml:"description,omitempty"`
- UseInteractions []object.UseInteraction `yaml:"use_interactions,omitempty"`
- Steal *object.ObjectSteal `yaml:"steal,omitempty"`
- Gather *behavior.GatherConfig `yaml:"gather,omitempty"`
- Talk *behavior.TalkConfig `yaml:"talk,omitempty"`
- Safespot *object.SafespotConfig `yaml:"safespot,omitempty"`
- OnLook *behavior.NodeAction `yaml:"on_look,omitempty"`
+ Name string `yaml:"name"`
+ Aliases []string `yaml:"aliases,omitempty"`
+ Color string `yaml:"color,omitempty"`
+ Hidden bool `yaml:"hidden,omitempty"`
+ InRoomDescription string `yaml:"inroom_description,omitempty"`
+ RemovalItem string `yaml:"removal_item,omitempty"`
+ Description behavior.DescList `yaml:"description,omitempty"`
+ OnUse []behavior.Interaction `yaml:"on_use,omitempty"`
+ Steal *object.ObjectSteal `yaml:"steal,omitempty"`
+ Gather *behavior.GatherConfig `yaml:"gather,omitempty"`
+ Talk *behavior.TalkConfig `yaml:"talk,omitempty"`
+ Safespot *object.SafespotConfig `yaml:"safespot,omitempty"`
+ OnLook []behavior.Interaction `yaml:"on_look,omitempty"`
}
def := ro.Local
return inlineObj{
@@ -227,7 +200,7 @@ func (ro RoomObject) MarshalYAML() (interface{}, error) {
InRoomDescription: def.InRoomDescription,
RemovalItem: def.RemovalItem,
Description: def.Description,
- UseInteractions: def.UseInteractions,
+ OnUse: def.OnUse,
Steal: def.Steal,
Gather: def.Gather,
Talk: def.Talk,