示例#1
0
        /// <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);
                        }
                    }
                }
            }
        }
示例#2
0
        /*********
        ** 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))
            {
                yield return(door);

                if (DoorManager.GetDoubleDoor(door, doorsInLocation, out Door doubleDoor) && doubleDoor.Toggle(force))
                {
                    yield return(doubleDoor);
                }
            }
        }