Exemplo n.º 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;
        }
Exemplo n.º 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;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Prints a generic message reporting a simple action with two parameters.
 /// </summary>
 /// <param name="actor">the <see cref="Actor"/> performing the action</param>
 /// <param name="verb">the action being performed</param>
 /// <param name="item1">the first <see cref="Thing"/> the action is performed on</param>
 /// <param name="separator">word or phrase separating the two parameters</param>
 /// <param name="item2">the second <see cref="Thing"/> the action is performed on</param>
 public static void ReportIfVisible(Actor actor, VerbSet verb, Thing item1, string separator, Thing item2)
 {
     ReportIfVisible(actor,
         StringManipulator.CapitalizeFirstLetter(actor.GetSpecificName())
         + ' ' + actor.GetConjugatedVerb(verb)
         + ' ' + item1.GetSpecificName()
         + separator + item2.GetSpecificName() + '.');
 }
Exemplo n.º 4
0
 /// <summary>
 /// Sets the owner of the <see cref="Thing"/> to the specified
 /// <see cref="Actor"/>.
 /// </summary>
 /// <param name="owner">
 /// the <see cref="Actor"/> to give ownership to
 /// </param>
 public void SetOwner(Actor owner)
 {
     this.owner = owner;
 }
Exemplo n.º 5
0
 //===================================================================//
 //                         Constructors                              //
 //===================================================================//
 /// <summary>
 /// Creates a new <see cref="Inventory"/> belonging to the specified <see cref="Actor"/>.
 /// </summary>
 /// <param name="owner">the <see cref="Actor"/> to whom the <see cref="Inventory"/> belongs</param>
 public Inventory(Actor owner)
     : base(owner.GetName() + "'s inventory", owner.GetName() + "'s inventory", isProper: true, canBeTaken: false)
 {
     this.owner = owner;
 }