/// <summary>Loads the exits for this room behavior.</summary> public void Load() { var roomRepository = new RelationalRepository <RoomRecord>(); // Standard exits are simple DB records, so we need to load them specifically for this room; // non-standard exits should be loaded just like any other generic Thing. // TODO: These should come as part of the world areas with the document repository, so that // exit Things could get customized with brand new Behaviors without difficulty, etc. string roomNumber = this.Parent.Id.Replace("room/", string.Empty); long persistedRoomID = long.Parse(roomNumber); ICollection <ExitRecord> exits = roomRepository.LoadExitsForRoom(persistedRoomID); foreach (var exitRecord in exits) { // Create a Thing to represent this exit, which can live in multiple places (IE rooms) // as a child of each parent - thus sharing substate (like for doors) will be automatic. var exitBehavior = new ExitBehavior() { ID = exitRecord.ID, }; var exit = new Thing(exitBehavior, new MultipleParentsBehavior()) { Name = "[StandardExit]", Id = "exit/" + exitRecord.ID, }; // Add the exit destinations. string exitRoomA = "room/" + exitRecord.ExitRoomAID.ToString(CultureInfo.InvariantCulture); string exitRoomB = "room/" + exitRecord.ExitRoomBID.ToString(CultureInfo.InvariantCulture); exitBehavior.AddDestination(exitRecord.DirectionA, exitRoomB); exitBehavior.AddDestination(exitRecord.DirectionB, exitRoomA); // Add this Exit Thing as a child of the Room Thing. this.Parent.Add(exit); // Look for the other room; if it exists, add this exit to that room too, else // set up an event reaction to add the exit to the room when it gets loaded. var otherRoom = ThingManager.Instance.FindThing(exitRoomB); if (otherRoom != null) { otherRoom.Add(exit); } else { lock (pendingExitRiggings) { pendingExitRiggings.Add(new PendingExitRigging() { RoomID = exitRoomB, ExitThing = exit, }); } } } // If this room is the secondary parent for a pending exit rigging, rig it up. lock (pendingExitRiggings) { var matchedExitRiggings = this.FindMatchedPendingExitRiggings(this.Parent.Id); foreach (var matchedExitRigging in matchedExitRiggings) { this.Parent.Add(matchedExitRigging.ExitThing); pendingExitRiggings.Remove(matchedExitRigging); } } }