public void GetItemMaterialFromFactory(CSFactory factory, List <ItemIdCount> itemsNeedToGet, ref bool transferedItem) { foreach (ItemIdCount iic in itemsNeedToGet) { Replicator.KnownFormula[] msList = UIGraphControl.GetReplicator().GetKnowFormulasByProductItemId(iic.protoId); if (msList == null || msList.Length == 0) { continue; } Replicator.Formula ms = Replicator.Formula.Mgr.Instance.Find(msList[0].id); foreach (Replicator.Formula.Material mt in ms.materials) { int itemCount = factory.GetCompoundEndItemCount(mt.itemId); if (itemCount > 0) { if (CSUtils.AddToStorage(mt.itemId, itemCount, core)) { factory.CountDownItem(mt.itemId, itemCount); transferedItem = true; } } } } }
public void GetItemFromStorageAndFactory(Dictionary <CSCommon, List <ItemIdCount> > requirementsMachine, List <CSCommon> storages, CSFactory factory, ref List <ItemIdCount> itemsNeedToGet) { foreach (KeyValuePair <CSCommon, List <ItemIdCount> > kvp in requirementsMachine) { foreach (ItemIdCount iic in kvp.Value) { //1.storage,storageRequire int gotCount = 0; int getCountFromStorage = 0; if (kvp.Key as CSStorage == null) { foreach (CSCommon sc in storages) { CSStorage cst = sc as CSStorage; int itemCount = cst.GetItemCount(iic.protoId); if (itemCount > 0) { if (itemCount >= iic.count - gotCount) { gotCount = iic.count; getCountFromStorage = iic.count; break; } else { gotCount += itemCount; getCountFromStorage += itemCount; } } } if (gotCount == iic.count) { if (kvp.Key.MeetDemand(iic.protoId, gotCount)) { CSUtils.CountDownItemFromAllStorage(iic.protoId, gotCount, core); } continue; } } //2.factory int leftCount = iic.count - gotCount; int getCountFromFac = 0; if (factory != null) { int factoryItemCount = factory.GetCompoundEndItemCount(iic.protoId); if (factoryItemCount > 0) { int countDownCount = 0; if (factoryItemCount >= leftCount) { countDownCount = leftCount; } else { countDownCount = factoryItemCount; } gotCount += countDownCount; getCountFromFac += countDownCount; } } if (gotCount == iic.count) { if (kvp.Key.MeetDemand(iic.protoId, gotCount)) { if (getCountFromStorage > 0) { CSUtils.CountDownItemFromAllStorage(iic.protoId, getCountFromStorage, core); } if (getCountFromFac > 0) { factory.CountDownItem(iic.protoId, getCountFromFac); } } continue; } else { if (gotCount > 0) { if (kvp.Key.MeetDemand(iic.protoId, gotCount)) { if (getCountFromStorage > 0) { CSUtils.CountDownItemFromAllStorage(iic.protoId, getCountFromStorage, core); } if (getCountFromFac > 0) { factory.CountDownItem(iic.protoId, getCountFromFac); } } } } leftCount = iic.count - gotCount; //3.add to needToGet ItemIdCount addNeed = itemsNeedToGet.Find(it => it.protoId == iic.protoId); if (addNeed != null) { addNeed.count += leftCount; } else { itemsNeedToGet.Add(new ItemIdCount(iic.protoId, leftCount)); } } } }