public static float CommitTransaction(Customer cust, GameType game) { if (!instance.mainMenuMode) { if (Logistics.GetStock(game) > 0) { //Success cust.CommitTransaction(true); float revenue = MarketManager.GetSalePrice(game); AdjustCash(revenue); EndDayManager.AddRevenue(game, revenue); Logistics.ExpendGame(game); return(revenue); } else { //Failure cust.CommitTransaction(false); return(0); } } else { cust.CommitTransaction(true); return(0); } }
IEnumerator GoShopping() { actionId = 0; step = 0; //Move to interact point of the Showcase. TODO: Choose interact point agent.SetDestination(GameManager.GetInteractable(Departments.Showcase).position); yield return(new WaitUntil(() => { return CheckDistance(agent.destination); })); //Look at the parent object yield return(new WaitUntil(() => { return RotateTowards(GameManager.GetDeptObject(Departments.Showcase).transform.position) < lookAngleBuffer; })); SetObstruction(true); isInActivity = true; //Wait to visualize look. Animate yield return(new WaitForSeconds(lookTime)); isInActivity = false; SetObstruction(false); //Check for availability if (Logistics.GetStock(GameDemand) <= 0) { CommitTransaction(false); StartCoroutine(LeaveBusiness()); yield break; } step++; //Move character. TODO: Choose interact point Cashier cashier = GameManager.GetDeptScript(Departments.Cashier) as Cashier; agent.SetDestination(GameManager.GetInteractable(Departments.Cashier).position); yield return(new WaitUntil(() => { return CheckDistance(agent.destination); })); //Look at the parent object yield return(new WaitUntil(() => { return RotateTowards(GameManager.GetDeptObject(Departments.Cashier).transform.position) < lookAngleBuffer; })); SetObstruction(true); isInActivity = true; //Wait to visualize look. Animate yield return(new WaitForSeconds(cashier.ServeSpeed)); //Do transaction, then wait as visualization TotalSpendings += GameManager.CommitTransaction(this, GameDemand); yield return(new WaitForSeconds(1.5f)); isInActivity = false; SetObstruction(false); //Move out from the shop. StartCoroutine(LeaveBusiness()); }
void PopulateInitialRestock() { for (int i = 0; i < restockRows.Length; i++) { if (MarketManager.IsGameAvailable(i)) { restockRows[i].gameName.transform.parent.gameObject.SetActive(true); restockRows[i].gameName.text = string.Format("{0}", MarketManager.GetGameNames((GameType)i)); restockRows[i].stockText.text = string.Format("{0:N0}", Logistics.GetStock(i)); restockRows[i].priceText.text = "$0"; restockRows[i].stockSlider.value = 0; restockRows[i].stockSlider.maxValue = Logistics.GetCapacity() - Logistics.GetStock(i); } else { restockRows[i].gameName.transform.parent.gameObject.SetActive(false); } } }
void UpdateRestockUI(int id) { float totalPrice = 0; int totalStock = 0; if (addedStocks[id] != 0) { restockRows[id].stockText.text = string.Format("{0:N0} ({1:+#;-#;0})", Logistics.GetStock((GameType)id), addedStocks[id]); } else { restockRows[id].stockText.text = string.Format("{0:N0}", Logistics.GetStock((GameType)id)); } restockRows[id].priceText.text = string.Format("${0:N0}", MarketManager.GetBuyPrice(id) * addedStocks[id]); for (int i = 0; i < addedStocks.Length; i++) { if (MarketManager.IsGameAvailable(i)) { totalPrice += MarketManager.GetBuyPrice(i) * addedStocks[i]; totalStock += addedStocks[i]; } } instance.moneyText.text = GameManager.Cash > 0 ? string.Format("${0:N0}", GameManager.Cash - totalPrice) : string.Format("<color=red>-${0:N0}</color>", Mathf.Abs(GameManager.Cash - totalPrice));; if (Logistics.GetTotalStocks() + totalStock > Logistics.GetCapacity()) { restockTitle.text = string.Format("Restock <color=red>({0}/{1})</color>", Logistics.GetTotalStocks() + totalStock, Logistics.GetCapacity()); } else { restockTitle.text = string.Format("Restock ({0}/{1})", Logistics.GetTotalStocks() + totalStock, Logistics.GetCapacity()); } if (Logistics.GetTotalStocks() + totalStock > Logistics.GetCapacity() || GameManager.Cash - totalPrice < 0) { instance.commitButton.interactable = false; } else { instance.commitButton.interactable = true; } }
// Update is called once per frame void Update() { if (exiting) { return; } if (!depts.ContainsKey(Departments.Logistics) || !depts.ContainsKey(Departments.Cashier) || !depts.ContainsKey(Departments.Showcase)) { Debug.LogError("Cannot load game: Department requirements not met\nRequired Logistics, Cashier and Showcase"); enabled = false; } if (canSpawnCustomer && !isSpawning) { t += Time.deltaTime; } if (t >= NetCustomerSpawnTime && canSpawnCustomer) { t = 0; isSpawning = true; StartCoroutine(SpawnTime()); } if (!mainMenuMode) { timeText.text = string.Format("{0:N0}:{1:00}", DaytimeManager.TimeHour, DaytimeManager.TimeMinute); stockTab.totalStocks.text = string.Format("{0:N0}/{1:N0}", Logistics.GetTotalStocks(), Logistics.GetCapacity()); stockTab.totalStocksBar.maxValue = Logistics.GetCapacity(); stockTab.totalStocksBar.value = Logistics.GetTotalStocks(); stockTab.totalStocksFill.color = Color.HSVToRGB((1 - (float)Logistics.GetTotalStocks() / Logistics.GetCapacity()) / 3.6f, 1, 1); for (int i = 0; i < 5; i++) { if (MarketManager.IsGameAvailable((GameType)i)) { stockTab.gameTitles[i].text = MarketManager.GetGameNames((GameType)i); stockTab.gameStocks[i].text = Logistics.GetStock(i).ToString("n0"); if (i > 0) { stockTab.separators[i - 1].SetActive(true); } } else { stockTab.gameTitles[i].text = ""; stockTab.gameStocks[i].text = ""; if (i > 0) { stockTab.separators[i - 1].SetActive(false); } } } //Input (touch) if (Time.timeScale != 0 && !EndDayManager.IsPanelOpen) { var touch = Input.touches; if (touch.Length == 1 && touch[0].deltaPosition.magnitude > 0.2f) { Vector3 delta = new Vector3(touch[0].deltaPosition.x, 0, touch[0].deltaPosition.y); cameraPivot.Translate(delta * -Time.deltaTime * 0.4f * panSensitivity); } else if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject()) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { ISelectable sel = hit.collider.GetComponent <ISelectable>(); if (sel != null && !(sel is Showcase)) { if (selected == null) { selectStatusAnim.Play("Open"); } DeselectAll(); selected = sel; selected.Select(); } else { if (selected != null) { selectStatusAnim.Play("Close"); } DeselectAll(); } } } } if (selected != null) { if (selected is Customer) { var selectedCustomer = selected as Customer; customerSelect.SetActive(true); departmentSelect.SetActive(false); customerSelectContents.NameText.text = selectedCustomer.custName; customerSelectContents.Text1Text.text = selectedCustomer.CurrentActionName + " " + (selectedCustomer.CurrentActionName == "Shopping" ? MarketManager.GetGameNames(selectedCustomer.GameDemand) : ""); customerSelectContents.Bar1Slider.maxValue = 100; customerSelectContents.Bar1Slider.value = selectedCustomer.Happiness; customerSelectContents.Progress1Slider.maxValue = selectedCustomer.MaxProgressTime; customerSelectContents.Progress1Slider.value = selectedCustomer.CurrentProgressTime; customerSelectContents.stat1.text = selectedCustomer.Visits.ToString("n0"); customerSelectContents.stat2.text = string.Format("${0:n0}", selectedCustomer.TotalSpendings); } else if (selected is DepartmentBase) { var selectedDept = selected as DepartmentBase; departmentSelect.SetActive(true); customerSelect.SetActive(false); departmentSelectContents.departmentName.text = selectedDept.departmentName; departmentSelectContents.trustBar.maxValue = 100; departmentSelectContents.trustBar.value = selectedDept.CurrentTrust; if (selected is Cashier || selected is CustomerService) { departmentSelectContents.workSpeedLbl.text = "Work Speed"; } else { departmentSelectContents.workSpeedValue.text = "Effectiveness"; } departmentSelectContents.workSpeedValue.text = string.Format("{0:N0}%", selectedDept.WorkSpeed * 100); } } } }