diff options
Diffstat (limited to 'internal/validate/checks.go')
| -rw-r--r-- | internal/validate/checks.go | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/internal/validate/checks.go b/internal/validate/checks.go index 197b8d3..9cff717 100644 --- a/internal/validate/checks.go +++ b/internal/validate/checks.go @@ -521,6 +521,66 @@ func validateCourses(s Source) []Issue { return issues } +func validateRoomEnterSteps(s Source) []Issue { + var issues []Issue + roomIndex := s.World.RoomIndex() + itemIDs := s.Items.IDSet() + mobIDs := s.Mobs.AllDefIDs() + + for id := range roomIndex { + room, err := s.World.LoadRoom(id) + if err != nil || len(room.OnEnter) == 0 { + continue + } + for si, step := range room.OnEnter { + stepPrefix := fmt.Sprintf("Room %d: on_enter[%d]", id, si) + if step.SpawnMob != nil && step.SpawnMob.ID != "" { + if _, ok := mobIDs[step.SpawnMob.ID]; !ok { + issues = append(issues, Issue{ + Level: "ERROR", + Type: "reference", + Message: fmt.Sprintf("%s: spawn_mob %q does not exist", stepPrefix, step.SpawnMob.ID), + }) + } + for _, wr := range step.SpawnMob.DespawnRooms { + if _, ok := roomIndex[wr]; !ok { + issues = append(issues, Issue{ + Level: "ERROR", + Type: "reference", + Message: fmt.Sprintf("%s: spawn_mob despawn_rooms references nonexistent room %d", stepPrefix, wr), + }) + } + } + } + if step.GiveItem != "" && !itemIDs[step.GiveItem] { + issues = append(issues, Issue{ + Level: "ERROR", + Type: "reference", + Message: fmt.Sprintf("%s: give_item %q does not exist", stepPrefix, step.GiveItem), + }) + } + if step.TakeItem != "" && !itemIDs[step.TakeItem] { + issues = append(issues, Issue{ + Level: "ERROR", + Type: "reference", + Message: fmt.Sprintf("%s: take_item %q does not exist", stepPrefix, step.TakeItem), + }) + } + if step.Teleport > 0 { + if _, ok := roomIndex[step.Teleport]; !ok { + issues = append(issues, Issue{ + Level: "ERROR", + Type: "reference", + Message: fmt.Sprintf("%s: teleport to nonexistent room %d", stepPrefix, step.Teleport), + }) + } + } + } + } + + return issues +} + func validateRoomTriggers(s Source) []Issue { var issues []Issue roomIndex := s.World.RoomIndex() |
