public GameObject CreateGoods(string name) { int ID = 0; if ((ID = GoodsValueCall.FindGoodsID(name, false)) == -1) { Debug.Log("There is no " + name + " in Warehouse"); return(null); } foreach (var tmp in GoodsRecipeCall.RecipeArray) { GameObject newGoods = GameObject.Instantiate(GoodsPrefab); GameObject GoodsStruct = GameObject.Instantiate(Resources.Load <GameObject>("GameSystem/Goods/Object/" + name), newGoods.transform); GoodsStruct.name = name; newGoods.transform.SetParent(transform); newGoods.transform.name = ID.ToString(); GoodsValueCall.ChangeInMapState(ID, true, newGoods); return(newGoods); } Debug.Log("There is no " + name); return(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); }