void DestoryGoods() { GoodsValueCall.DeleteGoodsArray(BeltActCall.GoodsOnBelt); Destroy(BeltActCall.GoodsOnBelt); BeltActCall.GoodsOnBelt = null; }
public List <float> BuyItem(string Name, string BuyerName, int Num) { List <float> result = new List <float>(); int Index = getSalesIndex(Name); if (Index == -1) { Debug.Log("No Info of " + Name + ". Try from " + BuyerName); result.Add(-1f); return(result); } SalesInfo TargetItem = SalesItemArray[Index]; GoodsValue SellerGoodsValueCall = CompanyManagerCall.GetCompanyValue(TargetItem.Seller).GetGoodsValue().GetComponent <GoodsValue>(); EconomyValue SellerEconomyCall = CompanyManagerCall.GetCompanyValue(TargetItem.Seller).GetEconomyValue().GetComponent <EconomyValue>(); int Limit = 0; if (TargetItem.ItemCount >= Num) { Limit = Num; } else if (TargetItem.ItemCount > 0) { Limit = TargetItem.ItemCount; } else { // Debug.Log("Lack of stock " + TargetItem.ItemCount + " " + Num); result.Add(-2f); return(result); } float TotalQualityValue = TargetItem.QualityEvaluation * TargetItem.SoldCount; for (int i = 0; i < Limit; i++) { int GoodsID = SellerGoodsValueCall.FindGoodsID(Name, false); if (GoodsID == -1) { Debug.Log("No Info of " + TargetItem.Seller + "'s " + Name + ". Try from " + BuyerName); result.Add(-1f); return(result); } if (BuyerName != "Consumer") { GoodsValue BuyerGoodsValueCall = CompanyManagerCall.GetCompanyValue(BuyerName).GetGoodsValue().GetComponent <GoodsValue>(); EconomyValue BuyerEconomyCall = CompanyManagerCall.GetCompanyValue(BuyerName).GetEconomyValue().GetComponent <EconomyValue>(); if (BuyerEconomyCall.Balance < TargetItem.Price) { result.Add(0f); return(result); } BuyerGoodsValueCall.AddGoodsArray(Name, SellerGoodsValueCall.CheckQuality(GoodsID)); BuyerEconomyCall.AddHistory(TimeManagerCall.TimeValue, "Buy", Name, "Buy " + Name + " from " + TargetItem.Seller, -TargetItem.Price); } result.Add(SellerGoodsValueCall.CheckQuality(GoodsID)); SellerGoodsValueCall.DeleteGoodsArray(GoodsID); SellerEconomyCall.AddHistory(TimeManagerCall.TimeValue, "Sell", Name, TargetItem.Seller + " Sells " + Name + " to " + BuyerName, TargetItem.Price); if (TargetItem.Seller == CompanyManagerCall.PlayerCompanyName && TargetItem.SoldCount == 0) { NotificationManagerCall.AddNews("Award", "Your first shipment of " + Name + " products has been made!"); } TargetItem.ItemCount--; TargetItem.SoldCount++; } foreach (var quality in result) { TotalQualityValue += quality; } TargetItem.QualityEvaluation = TotalQualityValue / TargetItem.SoldCount; if (PanelControllerCall.CurrentSidePanel != null) { if (PanelControllerCall.CurrentSidePanel.name == "ContractPanel") { ContractPanelController PanelComponent = PanelControllerCall.CurrentSidePanel.GetComponent <ContractPanelController>(); PanelComponent.UpdateRemainQuantityText(); if (PanelComponent.CurrentItem == TargetItem.RecipeInfo.Recipe.OutputName) { PanelComponent.UpdateSalesInfo(); } } } return(result); }
void ProcessingGoods() { for (int i = 0; i < InputNumber; i++) { // Check the belt has correct object if (Mover[i].GetComponent <BeltAct>().GoodsOnBelt != null) { for (int j = 0; j < InputNumber; j++) { if (RegisteredInput[j] == -1) { if (GoodsValueCall.FindGoodsName(int.Parse(Mover[i].GetComponent <BeltAct>().GoodsOnBelt.name)) == TargetGoodsRecipe.InputName[j]) { // Write belt's index to RegisteredInput RegisteredInput[j] = i; break; } else { RegisteredInput[j] = -1; } } } } } for (int i = 0; i < InputNumber; i++) { if (Mover[i].GetComponent <BeltAct>().GoodsOnBelt != null) { PrevBelt[i].GetComponent <BeltAct>().ChangeNeedStop(true, gameObject); } } // Input check routine for (int i = 0; i < InputNumber; i++) { if (Mover[i].GetComponent <BeltAct>().GoodsOnBelt != null) { if (!Mover[i].GetComponent <BeltAct>().isCenter(-1)) { return; } else if (Mover[i].GetComponent <BeltAct>().isCenter(-1)) { for (int j = 0; j < InputNumber;) { // Check all RegisteredInput if (RegisteredInput[j] == i) { // Correct input. break the check routine break; } j++; if (j == InputNumber) { // Wrong input. Object will be destroy GoodsValueCall.DeleteGoodsArray(int.Parse(Mover[i].GetComponent <BeltAct>().GoodsOnBelt.name)); Destroy(Mover[i].GetComponent <BeltAct>().GoodsOnBelt); PrevBelt[i].GetComponent <BeltAct>().ChangeNeedStop(false, gameObject); Mover[i].GetComponent <BeltAct>().GoodsOnBelt = null; return; } } } } } // Now processing if (Mover[0].GetComponent <BeltAct>().GoodsOnBelt != null && ProcessedGoods == null) { Mover[0].GetComponent <BeltAct>().ChangeNeedStop(true, gameObject); for (int i = 0; i < InputNumber; i++) { if (Mover[i].GetComponent <BeltAct>().GoodsOnBelt == null) { // If there is empty belt, wait for that return; } } // If there is something one belt and no previous processed object // Start processing if (!isWaiting) { if (ObjectActCall.WorkSpeed == 0) { return; } StartCoroutine(Waiter()); } else { return; } } else if (Mover[0].GetComponent <BeltAct>().GoodsOnBelt != null && ProcessedGoods != null) { // If there is something on belt and previous processed object // Waiting object must not come in processor Mover[0].GetComponent <BeltAct>().ChangeNeedStop(false, gameObject); } else if (Mover[0].GetComponent <BeltAct>().GoodsOnBelt == null && ProcessedGoods != null) { // If there is nothing on belt but previous processed object // Clear the processed object info ProcessedGoods = null; for (int i = 0; i < InputNumber; i++) { // Now waiting object can come in Mover[0].GetComponent <BeltAct>().ChangeNeedStop(true, gameObject); // Clear the RegisteredInput RegisteredInput[i] = -1; } } else { // If there is nothing Mover[0].GetComponent <BeltAct>().ChangeNeedStop(true, gameObject); for (int i = 0; i < InputNumber; i++) { // Processor is ready for object PrevBelt[i].GetComponent <BeltAct>().ChangeNeedStop(false, gameObject); } } }