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 StockManage() { int Difference = 0; switch (Name) { case "General Industry Co.": Difference = 999 - GoodsValueCall.GetGoodsCount("Paper roll", true); if (Difference > 0) { for (int i = 0; i < Difference; i++) { GoodsValueCall.AddGoodsArray("Paper roll", Random.Range(0.8f, 1f)); } } break; case "Federal Agency of Industry": Difference = 999 - GoodsValueCall.GetGoodsCount("Plastic mass", true); if (Difference > 0) { for (int i = 0; i < Difference; i++) { GoodsValueCall.AddGoodsArray("Plastic mass", Random.Range(0.5f, 1f)); } } Difference = 999 - GoodsValueCall.GetGoodsCount("Silicon mass", true); if (Difference > 0) { for (int i = 0; i < Difference; i++) { GoodsValueCall.AddGoodsArray("Silicon mass", Random.Range(0.7f, 1f)); } } break; // case "Sasio" : // Difference = 999 - GoodsValueCall.GetGoodsCount("Packaged Cal-100", true); // if(Difference > 0) // { // for(int i = 0; i < Difference; i++) // { // GoodsValueCall.AddGoodsArray("Packaged Cal-100", Random.Range(0.6f, 0.8f)); // } // } // Difference = 999 - GoodsValueCall.GetGoodsCount("Cal-100", true); // if(Difference > 0) // { // for(int i = 0; i < Difference; i++) // { // GoodsValueCall.AddGoodsArray("Cal-100", Random.Range(0.6f, 0.8f)); // } // } // Difference = 999 - GoodsValueCall.GetGoodsCount("CM100", true); // if(Difference > 0) // { // for(int i = 0; i < Difference; i++) // { // GoodsValueCall.AddGoodsArray("CM100", Random.Range(0.6f, 0.8f)); // } // } // break; } SalesValueCall.UpdateItemCount(Name); }