/// <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; }
/// <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; }