Пример #1
0
        /// <summary>
        /// Checks if a given <see cref="Actor"/> can see a given
        /// <see cref="Thing"/> from their current location(s).
        /// </summary>
        /// <param name="actor">the <see cref="Actor"/> trying to interact with something</param>
        /// <param name="item">the <see cref="Thing"/> being interacted with</param>
        /// <returns>true if the <see cref="Actor"/> can see the <see cref="Thing"/>; false otherwise</returns>
        public static bool CanSee(Actor actor, Thing item)
        {
            // if either the item's location or the actor's location is null,
            // return false
            if (item.GetLocation() == null || actor.GetLocation() == null) {
                return false; }

            // if there are no opaque barriers between the item and the actor,
            // return true
            else if (GetTopMostVisibleContainer(actor.GetLocation())
                  == GetTopMostVisibleContainer(item.GetLocation())) {
                return true; }

            // if the item is held in someone's hands,
            else if (typeof(Hands) ==
                GetTopMostVisibleContainer(item.GetLocation()).GetType()) {

                // do an explicit cast for the sake of legibility
                Hands hands = (Hands)GetTopMostVisibleContainer(
                    item.GetLocation());

                // if the hands belongs to the actor, return true
                if (hands.GetOwner() == actor) {
                    return true; }

                // if the actor can see the owner of the hands, return true
                else if (GetTopMostVisibleContainer(actor.GetLocation())
                        == GetTopMostVisibleContainer(
                            hands.GetOwner().GetLocation())){
                    return true; }

                // otherwise, the hands cannot be seen,
                // so the item cannot be seen either
                return false;

            } // end case "item is in someone's hands"

            // if the item is a piece of clothing currently being worn
            // or is inside a piece of clothing currently being worn,
            else if (typeof(Clothes) == GetTopMostVisibleContainer(item.GetLocation()).GetType()) {

                // if the person wearing the clothing is the actor, return true
                if (((Clothes)GetTopMostVisibleContainer(item.GetLocation())).GetOwner() == actor) {
                    return true; }

                // if the item is worn by someone else and it is visible, return true
                else if (((Clothes)item.GetLocation()).GetOwner().GetVisibleRecursiveContents().Contains(item)){
                    return true; }

                // if it's not visible, return false
                else {
                    return false; }

            } // end case "item is being worn"

            // otherwise, return false
            return false;
        }
Пример #2
0
        /// <summary>
        /// Checks if a given <see cref="Actor"/> can see a given
        /// <see cref="Thing"/> from their current location(s).
        /// </summary>
        /// <param name="actor">the <see cref="Actor"/> trying to interact with something</param>
        /// <param name="item">the <see cref="Thing"/> being interacted with</param>
        /// <returns>true if the <see cref="Actor"/> can see the <see cref="Thing"/>; false otherwise</returns>
        public static bool CanSee(Actor actor, Thing item)
        {
            // if either the item's location or the actor's location is null, return false
            if (item.GetLocation() == null || actor.GetLocation() == null) {
                return false; }

            // if there are no opaque barriers between the item and the actor, return true
            else if (GetTopMostVisibleContainer(actor.GetLocation()) == GetTopMostVisibleContainer(item.GetLocation())) {
                return true; }

            // if the item is in an inventory,
            else if (typeof(Inventory) == item.GetLocation().GetType()) {

                // if the inventory belongs to the actor, return true
                if (((Inventory)item.GetLocation()).GetOwner() == actor) {
                    return true; }

                else { // theft is not coded yet
                    throw new Exception("Theft has not been coded for yet."); }

            } // end case "item is in an inventory"

            // if the item is a piece of clothing currently being worn
            // or is inside a piece of clothing currently being worn,
            else if (typeof(Clothes) == GetTopMostVisibleContainer(item.GetLocation()).GetType()) {

                // if the person wearing the clothing is the actor, return true
                if (((Clothes)GetTopMostVisibleContainer(item.GetLocation())).GetOwner() == actor) {
                    return true; }

                // if the item is worn by someone else and it is visible, return true
                else if (((Clothes)item.GetLocation()).GetOwner().GetVisibleRecursiveContents().Contains(item)){
                    return true; }

                // if it's not visible, return false
                else {
                    return false; }

            } // end case "item is being worn"

            // otherwise, return false
            return false;
        }
Пример #3
0
 /// <summary>
 /// Moves a <see cref="Thing"/> into a given <see cref="Container"/>,
 /// regardless of where the <see cref="Thing"/> is before the move.
 /// Can be used to bring a <see cref="Thing"/> into play.
 /// Therefore, the <see cref="Thing"/>'s location may be null.
 /// This function checks for that possibility and handles it.
 /// </summary>
 /// <param name="item">the <see cref="Thing"/> to move</param>
 /// <param name="place">the <see cref="Container"/> to put it in</param>
 public static void Move(Thing item, Container place)
 {
     if (item.GetLocation() != null) {
         item.GetLocation().RemoveThing(item); }
     item.SetLocation(place);
     place.AddThing(item);
 }
Пример #4
0
 /// <summary>
 /// Determines whether or not the given <see cref="Thing"/> is visible
 /// to the <see cref="player"/>.
 /// </summary>
 /// <param name="item">the <see cref="Thing"/> to check if visible</param>
 /// <returns>true if the <see cref="Thing"/> is visible to the <see cref="player"/>; false otherwise</returns>
 public static bool IsVisible(Thing item)
 {
     return GetTopMostVisibleContainer(item.GetLocation()) == GetTopMostVisibleContainer(player.GetLocation());
 }