/// <summary>Gets all doors near the given position.</summary> /// <param name="location">The location to look in.</param> /// <param name="position">The position to search at.</param> /// <returns>The doors that were found.</returns> private IEnumerable <Door> GetAutomaticDoorsNearPosition(GameLocation location, Point position) { if (!this.doors.TryGetValue(Utils.GetLocationName(location), out IDictionary <Point, Door> doorsInLocation)) { yield break; } for (int i = -1 * this.config.DoorToggleRadius; i <= this.config.DoorToggleRadius; i++) { // Search along the x axis for horizontal doors and along the y axis for vertical doors (parallel to the hallway direction). if (doorsInLocation.TryGetValue(new Point(position.X + i, position.Y), out Door door) && (door.Extras.IsAutomaticDoor || this.config.MakeAllDoorsAutomatic) && door.Orientation == Orientation.Horizontal) { yield return(door); if (DoorManager.TryGetDoubleDoor(door, doorsInLocation, out Door doubleDoor)) { yield return(doubleDoor); } } if (doorsInLocation.TryGetValue(new Point(position.X, position.Y + i), out door) && (door.Extras.IsAutomaticDoor || this.config.MakeAllDoorsAutomatic) && door.Orientation == Orientation.Vertical) { yield return(door); if (DoorManager.TryGetDoubleDoor(door, doorsInLocation, out Door doubleDoor)) { yield return(doubleDoor); } } } }
/********* ** Private methods *********/ /// <summary>Tries to toggle a door, also toggling the accompanying double door if successful.</summary> /// <param name="door">The door to toggle.</param> /// <param name="doorsInLocation">The other doors in the location</param> /// <param name="force">Whether to toggle forcefully or not.</param> /// <returns>All doors that were toggled.</returns> private IEnumerable <Door> TryToggleDoor(Door door, IDictionary <Point, Door> doorsInLocation, bool force) { if (door.Toggle(force, true)) { yield return(door); if (DoorManager.TryGetDoubleDoor(door, doorsInLocation, out Door doubleDoor) && doubleDoor.Toggle(force, true)) { yield return(doubleDoor); } } }