public void UpdateItemCount(string CompanyName, string Name) { if (CompanyManagerCall.GetCompanyValue(CompanyName) == null) { // Debug.Log("There is no " + CompanyName + " in CompanyManager"); return; } List <GoodsValue.Goods> GoodsList = new List <GoodsValue.Goods>(); GoodsList.AddRange(CompanyManagerCall.GetCompanyValue(CompanyName).GetGoodsValue().GetComponent <GoodsValue>().GetAllGoodsInfo(Name, true)); foreach (var SalesItem in SalesItemArray) { if (SalesItem.RecipeInfo.Recipe.OutputName == Name && SalesItem.Seller == CompanyName) { SalesItem.ItemCount = GoodsList.Count; } } if (PanelControllerCall.CurrentSidePanel != null) { if (PanelControllerCall.CurrentSidePanel.name == "ContractPanel") { ContractPanelController PanelComponent = PanelControllerCall.CurrentSidePanel.GetComponent <ContractPanelController>(); if (PanelComponent.CurrentCategory != "Storage") { PanelComponent.UpdateRemainQuantityText(); } } } }
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 StoredAmountChangePanelUpdate(Goods Info, bool Sign) { PanelControllerCall.UpdateFactoryInfo("Warehouse", GetStoredGoods().Count, TotalCapacity); if (PanelControllerCall.CurrentSidePanel != null) { if (PanelControllerCall.CurrentSidePanel.name == "ContractPanel") { ContractPanelController PanelComponent = PanelControllerCall.CurrentSidePanel.GetComponent <ContractPanelController>(); if (PanelComponent.CurrentCategory == "Storage") { PanelComponent.UpdateRemainQuantityText(); if (PanelComponent.CurrentItem == Info.Name) { if (GetStoredGoods(Info.Name).Count == 0 && Sign) { PanelComponent.UpdateList(true); if (PanelComponent.TargetItemSalesInfo == null) { PanelComponent.ClearInfoPanel(); } } } else { if (GetStoredGoods(Info.Name).Count == 0 && Sign) { PanelComponent.UpdateList(true); } if (GetStoredGoods(Info.Name).Count == 1 && !Sign) { PanelComponent.UpdateList(true); } } } } if (PanelControllerCall.CurrentSidePanel.name == "GoodsCreatorPanel") { GoodsCreatorPanelController PanelComponent = PanelControllerCall.CurrentSidePanel.GetComponent <GoodsCreatorPanelController>(); if (PanelComponent.CurrentCategory == Info.Type || PanelComponent.CurrentCategory == "All") { PanelComponent.UpdateRemainQuantityText(); if (PanelComponent.CurrentItem == Info.Name) { if (GetStoredGoods(Info.Name).Count == 0 && Sign) { PanelComponent.UpdateList(true); if (PanelComponent.CallTargetGoodsCreator.TargetGoodsName != Info.Name) { PanelComponent.ClearInfoPanel(); } } } else { if (GetStoredGoods(Info.Name).Count == 0 && Sign) { PanelComponent.UpdateList(true); } if (GetStoredGoods(Info.Name).Count == 1 && !Sign) { PanelComponent.UpdateList(true); } } } else { if (GetStoredGoods(Info.Name).Count == 0 && Sign) { PanelComponent.UpdateList(false); } if (GetStoredGoods(Info.Name).Count == 1 && !Sign) { PanelComponent.UpdateList(false); } } } } }