/// <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); } } } }
/// <summary>Gets all doors near any player.</summary> /// <param name="location">The location to look in.</param> /// <returns>The doors that were found.</returns> private IEnumerable <Door> GetDoorsNearPlayers(GameLocation location) { if (!this.doors.TryGetValue(Utils.GetLocationName(location), out IDictionary <Point, Door> doorsInLocation)) { yield break; } foreach (Farmer farmer in location.farmers) { for (int i = -2; i < 3; 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(farmer.getTileX() + i, farmer.getTileY()), out Door door) && door.Extras.IsAutomaticDoor && door.Orientation == Orientation.Horizontal) { yield return(door); if (DoorManager.GetDoubleDoor(door, doorsInLocation, out Door doubleDoor)) { yield return(doubleDoor); } } if (doorsInLocation.TryGetValue(new Point(farmer.getTileX(), farmer.getTileY() + i), out door) && door.Extras.IsAutomaticDoor && door.Orientation == Orientation.Vertical) { yield return(door); if (DoorManager.GetDoubleDoor(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); } } }
/// <summary>Unforcefully toggles a door state if found at the position or near it.</summary> /// <param name="locationName">The location to toggle the door in.</param> /// <param name="mouseTile">The position to look for a door at.</param> public void MouseToggleDoor(string locationName, Point mouseTile) { if (!this.doors.TryGetValue(locationName, out IDictionary <Point, Door> doorsInLocation)) { return; } if (DoorManager.TryGetDoorFromMouse(mouseTile, doorsInLocation, out Door door)) { foreach (Door toggleDoor in this.TryToggleDoor(door, doorsInLocation, false)) { this.onToggledDoor(toggleDoor); } } }
/// <summary>Gets the mouse cursor to display if a door is found.</summary> /// <param name="locationName">The location to check in.</param> /// <param name="playerTile">The position the player is at.</param> /// <param name="mouseTile">The position of the mouse.</param> /// <param name="cursor">The resulting cursor index, if any.</param> /// <param name="transparency">The resulting transparency value, if any.</param> /// <returns>Whether a door was found.</returns> public bool TryGetMouseCursorForDoor(string locationName, Point playerTile, Point mouseTile, out int cursor, out float transparency) { cursor = 0; transparency = 0; if (!this.doors.TryGetValue(locationName, out IDictionary <Point, Door> doorsInLocation) || !DoorManager.TryGetDoorFromMouse(mouseTile, doorsInLocation, out Door _)) { return(false); } cursor = 2; transparency = Utils.GetTaxiCabDistance(playerTile, mouseTile) <= this.config.DoorToggleRadius ? 1f : 0.5f; return(true); }