/// <summary> /// Subtract the cost of a review from the current balance /// and add the review to the list of reviews for this level /// </summary> /// <param name="levelID"></param> /// <param name="review"></param> public void ConfirmReviwedResourceRequest(LevelID levelID, ReviewedResourceRequest review) { ReviewedResourceRequestList list = GetEntryWithLatestAttempt(levelID).reviews; // Check if the game manager exists and the review was not denied if (GameManager.Instance && review.CurrentStatus != ReviewedResourceRequest.Status.Denied) { // Add the item to the resource manager and subtract the total cost Item itemObjectGranted = GameManager.Instance.LevelData.GetItemWithID(review.Request.ItemRequested).itemObject; GameManager.Instance.m_resourceManager.AddItem(itemObjectGranted.ItemName, review.QuantityGranted); GameManager.Instance.SubtractFromBalance(review.TotalCost); } list.Reviews.Add(review); }
private bool ResourceRequestGeneratesQuestion(ReviewedResourceRequest review) { // Get the categories of all fixed quesitons IEnumerable <QuizCategory> testedCategories = template.AllQuestions .Select(q => q.Category); // Create the category this request represents QuizCategory myCategory = new QuizCategory(review.Request.ItemAddressed, review.Request.NeedAddressed); // Resource request will generate a question // if the status is not denied or invalid, // and the category of the review is somewhere in the quiz return(review.CurrentStatus != ReviewedResourceRequest.Status.Denied && review.CurrentStatus != ReviewedResourceRequest.Status.Invalid && (review.Request.NeedAddressed == NeedType.Terrain || review.Request.NeedAddressed == NeedType.FoodSource) && testedCategories.Contains(myCategory)); }
private bool ResourceRequestWasSubmitted(ItemID requestedItem, int requestQuantity) { // Grab a bunch of references to various scripts in the Notebook NotebookUI notebook = GameManager.Instance.NotebookUI; ReviewedResourceRequestDisplay reviewDisplay = notebook.GetComponentInChildren <ReviewedResourceRequestDisplay>(true); ReviewedResourceRequest review = reviewDisplay.LastReviewConfirmed; // If there is a review that was just confirmed then check if it was the correct request if (review != null) { ResourceRequest request = review.Request; return(request.ItemRequested == requestedItem && request.QuantityRequested == requestQuantity); } else { return(false); } }
public override void Setup() { base.Setup(); // Confirm button confirms the review given confirmButton.onClick.AddListener(() => { displayRoot.SetActive(false); lastReviewConfirmed = review; UIParent.Data.Concepts.ConfirmReviwedResourceRequest(LevelID.Current(), review); onReviewConfirmed.Invoke(); }); // Cancel button disables the display cancelButton.onClick.AddListener(() => { displayRoot.SetActive(false); }); // At the setup, make sure the display is inactive displayRoot.SetActive(false); }
public static ReviewedResourceRequest Review(ResourceRequest request) { // Create a new review for this request ReviewedResourceRequest review = new ReviewedResourceRequest() { Request = request }; if (GameManager.Instance) { if (request.QuantityRequested <= 0) { return(review); } // Get the item object with the given id Item itemObject = GameManager.Instance.LevelData.GetItemWithID(request.ItemRequested).itemObject; // Compute the total price float totalPrice = itemObject.Price * request.QuantityRequested; // If the balance exceeds the total price, grant the item if (totalPrice <= GameManager.Instance.Balance) { review.QuantityGranted = request.QuantityRequested; } // If the balance is less than the total price but more than the price for one object, // grant only the amount you can actually buy else if (itemObject.Price <= GameManager.Instance.Balance) { review.QuantityGranted = (int)(GameManager.Instance.Balance / itemObject.Price); } // If there is not enough money for any item, don't grant any else { review.QuantityGranted = 0; } } return(review); }
/// <summary> /// Ask the display to review a resource request and display the result /// </summary> /// <param name="request"></param> public void DisplayReview(ResourceRequest request) { // Create the review review = ReviewedResourceRequest.Review(new ResourceRequest(request)); // Set the border color based on the review status if (review.CurrentStatus == ReviewedResourceRequest.Status.Invalid) { border.color = statusColors.colors[(int)ReviewedResourceRequest.Status.Denied]; } else { border.color = statusColors.colors[(int)review.CurrentStatus]; } // Set the status and reason text statusText.text = review.CurrentStatus.ToString(); statusReasonText.text = review.StatusReason; // Change the text displayed based on whether the request was granted or denied if ((int)review.CurrentStatus < 2) { itemText.text = review.QuantityGranted + " " + request.ItemRequested.Data.Name.Get(ItemName.Type.Colloquial); costText.text = "$" + review.TotalCost; } else { itemText.text = "<no items granted>"; costText.text = "<no cost>"; } // Can only cancel a request that was not denied cancelButton.gameObject.SetActive(review.CurrentStatus != ReviewedResourceRequest.Status.Denied); // Enable the object for the display displayRoot.SetActive(true); }