private static void CalcResourcesReserv(Storage storage, Industry industry) { List <GoodsStack> result = new List <GoodsStack>(); for (int c = 0; c < industry.construction.Length; c++) { for (int r = 0; r < industry.construction[c].recipe.perTurn.Length; r++) { if (industry.construction[c].recipe.perTurn[r].amount < 0) { int index = result.FindIndex(x => x.id == industry.construction[c].recipe.perTurn[r].goodsId); if (index > -1) { result[index] = new GoodsStack { id = result[index].id, amount = result[index].amount + (int)(industry.construction[c].recipe.perTurn[r].amount * Settings.Industry.PROCESSING_RESERV_TURN * -1) }; continue; } result.Add(new GoodsStack { id = result[index].id, amount = (int)(industry.construction[c].recipe.perTurn[r].amount * Settings.Industry.PROCESSING_RESERV_TURN * -1) }); } } } }
private void UpdateElement(GoodsStack stack) { var index = displayedGoods.FindIndex(x => x.id == stack.id); if (index < 0) { return; } displayedGoods[index] = stack; goStacks[index].GetComponent <GoodStackScr>().SetStack(stack); }
private static GoodsStack[] TestAddResources(int count) { GoodsStack[] result = new GoodsStack[Data.goodsArr.Length]; for (int i = 0; i < Data.goodsArr.Length; i++) { result[i] = new GoodsStack { id = Data.goodsArr[i].id, amount = count }; } return(result); }
private void AddElement(GoodsStack stack) { int index = displayedGoods.FindIndex(x => x.id == stack.id); if (index > -1) { return; } var go = Instantiate( PrefabService.UI.GoodsStack, content.GetComponent <RectTransform>(), false ); go.GetComponent <GoodStackScr>().SetStack(stack); goStacks.Add(go); displayedGoods.Add(stack); }
public bool Add(GoodsStack stack) { if (stack.amount <= 0) { return(false); } if (goodsArr == null) { goodsArr = new GoodsStack[0]; } int index = Array.FindIndex(goodsArr, x => x.id == stack.id); if (index > -1) { goodsArr[index].amount += stack.amount; return(true); } goodsArr = goodsArr.Concat(new GoodsStack[] { stack }).ToArray(); return(true); }
public bool Subtract(GoodsStack stack) { if (goodsArr == null) { return(false); } int index = Array.FindIndex(goodsArr, x => x.id == stack.id); if (index < 0) { return(false); } if (goodsArr[index].amount < stack.amount) { return(false); } goodsArr[index].amount -= stack.amount; if (goodsArr[index].amount == 0) { DeleteStack(index); } return(true); }
public bool isEnoughGoods(GoodsStack stack) { return(Array.Exists(goodsArr, x => x.id == stack.id && x.amount >= stack.amount)); }
public void SetStack(GoodsStack stack) { goodsName.text = Data.GetGoodsById(stack.id).name; this.amaunt.text = stack.amount.ToString(); image.sprite = PrefabService.goodsImages[stack.id]; }