/// <summary> /// Handles a buying request, if the received player currencies has the amount required to buy the selected /// product, the purchase is made and the item is delivered to the player through the Game Observer Manager, /// as well as removing the item from the store list along with the change for that purchase, /// it also selects the leftmost item if there are any left, if there aren't then the game ends. /// </summary> /// <param name="storeId">The id of the store for the purchase to be made on</param> /// <param name="playerCurrencies">The wallet of the player</param> private void OnRequestBuy(int storeId, int[] playerCurrencies) { if (myId == storeId) { GameObject currentItemGO = EventSystem.current.currentSelectedGameObject; Item currentItem = currentItemGO.GetComponent <StoreItemUI>().MyItem; int playerCurrency = playerCurrencies[(int)currentItem.currencyType]; if (playerCurrency >= currentItem.cost) { int playerChange = playerCurrency - currentItem.cost; GameObserverManager.OnDeliverItem(currentItem, currentItem.currencyType, playerChange); _storeItems.Remove(currentItemGO); _numItems--; Destroy(currentItemGO); if (_numItems > 0) { _storeItems[0].GetComponent <Selectable>().Select(); } else { GameManager.Instance.GameDone = true; } } } }
/// <summary> /// Toggles the Store Window depending on the received status variable, also selects the leftmost item in /// display when the window is shown and sends the player the toggle through the Game Observer Manager /// for entering the Interact state of Browsing. When the window is hidden, it then requests that the player /// leaves the Browsing state. /// </summary> /// <param name="storeId">The id of the store that should be toggled</param> /// <param name="status">The desired status of the Store Window</param> private void OnStoreViewToggle(int storeId, bool status) { if (storeId == myId) { storeReference.SetActive(status); GameObserverManager.OnBrowsingToggle(status); if (_numItems > 0) { EventSystem eventSystem = EventSystem.current; eventSystem.SetSelectedGameObject(null); eventSystem.SetSelectedGameObject(_storeItems[0]); } } }