Пример #1
0
        /// <summary>
        /// Creates a guest outside.
        /// </summary>
        public void AddGuest(string name, int stars)
        {
            // Get the outside.
            Room outside = Rooms.Where(x => (x is EmptyRoom) && (x as EmptyRoom).Entrance).FirstOrDefault();

            // An outside was found so we spawn people there.
            if (outside != null)
            {
                Guest guest = new Guest(outside);
                guest.StayState      = StayState.CheckIn;
                guest.Classification = stars;
                Guests.Add(name, guest);
                guest.FindAndTargetRoom(x => (x is Lobby && (x as Lobby).Receptionist != null));

                // Subscribe to remove event
                guest.RemoveObjectEvent += RemoveObject;
            }
            else
            {
                return;
            }
        }
Пример #2
0
        /// <summary>
        /// Remove a object.
        /// </summary>
        /// <param name="object">The object to remove.</param>
        public void RemoveObject(object sender, EventArgs e)
        {
            HotelObject hotelObject = (HotelObject)sender;

            if (hotelObject is Person)
            {
                // Remove guest from the hotel.
                if (hotelObject is Guest)
                {
                    string item  = Guests.First(x => x.Value == hotelObject).Key;
                    Guest  guest = (Guest)hotelObject;

                    if (guest.Room != null)
                    {
                        if (guest.Room.State != RoomState.Emergency && guest.Room.State != RoomState.InCleaning)
                        {
                            guest.Room.State = RoomState.Dirty;
                        }
                        guest.Room = null;
                    }

                    //Remove the guest from a checkin/out queue where applicable.
                    if (guest.CurrentRoom is Lobby)
                    {
                        (guest.CurrentRoom as Lobby).RemoveFromQueues(guest);
                    }

                    Guests.Remove(item);
                }
                // Remove receptionist from hotel.
                else if (hotelObject is Receptionist)
                {
                    Lobby lobby = Rooms.Where(x => x is Lobby && (x as Lobby).Receptionist == hotelObject) as Lobby;
                    if (lobby != null)
                    {
                        lobby.Receptionist = null;
                    }
                    Staff.Remove(hotelObject as Person);
                }
                // Remove cleaner from the hotel.
                else if (hotelObject is Cleaner)
                {
                    Cleaner cleaner = (Cleaner)hotelObject;
                    Staff.Remove(cleaner);

                    // Spawn a ghost
                    CleanerGhost cGhost = new CleanerGhost(cleaner.CurrentRoom);
                    cGhost.RemoveObjectEvent += RemoveObject;
                    Staff.Add(cGhost);
                }
                else if (hotelObject is CleanerGhost)
                {
                    CleanerGhost cleanerGhost = (CleanerGhost)hotelObject;

                    // Spawn a new cleaner
                    Cleaner cleaner = new Cleaner(cleanerGhost.CurrentRoom);
                    cleaner.RemoveObjectEvent += RemoveObject;
                    Staff.Add(cleaner);
                    // Make it walk indoors
                    cleaner.FindAndTargetRoom(x => (x is Lobby && (x as Lobby).Receptionist != null));

                    Staff.Remove(cleanerGhost);
                }

                hotelObject.RemoveObjectEvent -= RemoveObject;
            }
        }