public static List <int> resolveProtoIdToProcess(List <int> protoIds) { List <int> resourceId = new List <int> (); foreach (int protoId in protoIds) { if (CSProcessing.CanProcessItem(protoId)) { resourceId.Add(protoId); continue; } List <int> needReplicate = new List <int> (); needReplicate.Add(protoId); do { List <int> tempNeed = new List <int> (); tempNeed.AddRange(needReplicate); foreach (int tempProtoId in tempNeed) { Replicator.KnownFormula[] msList = UIGraphControl.GetReplicator().GetKnowFormulasByProductItemId(tempProtoId); if (msList == null || msList.Length == 0) { needReplicate.Remove(tempProtoId); //Debug.LogError("can't get "+tempProtoId+" for colony"); continue; } //--to do: temp_ only use script 01 Replicator.Formula ms = Replicator.Formula.Mgr.Instance.Find(msList[0].id); foreach (Replicator.Formula.Material mt in ms.materials) { if (CSProcessing.CanProcessItem(mt.itemId)) { if (!resourceId.Contains(mt.itemId)) { resourceId.Add(mt.itemId); } } else { if (!needReplicate.Contains(mt.itemId)) { needReplicate.Add(mt.itemId); } } } needReplicate.Remove(tempProtoId); } }while(needReplicate.Count > 0); } return(resourceId); }
public static List <ItemIdCount> ResolveItemsToProcess(List <ItemIdCount> itemsNeedToGet, CSAssembly core = null, CSFactory factory = null) { List <ItemIdCount> resourceItems = new List <ItemIdCount> (); List <ItemIdCount> ItemsOwnRecord = new List <ItemIdCount> (); foreach (ItemIdCount iic in itemsNeedToGet) { if (CSProcessing.CanProcessItem(iic.protoId)) { resourceItems.Add(iic); continue; } List <ItemIdCount> needReplicate = new List <ItemIdCount> (); needReplicate.Add(iic); do { List <ItemIdCount> tempNeed = new List <ItemIdCount> (); tempNeed.AddRange(needReplicate); foreach (ItemIdCount tempIic in tempNeed) { Replicator.KnownFormula[] msList = UIGraphControl.GetReplicator().GetKnowFormulasByProductItemId(tempIic.protoId); if (msList == null || msList.Length == 0) { needReplicate.Remove(tempIic); //Debug.LogError("can't get "+tempIic.protoId+"for colony"); continue; } //--to do: temp_ only use script 01 Replicator.Formula ms = Replicator.Formula.Mgr.Instance.Find(msList[0].id); foreach (Replicator.Formula.Material mt in ms.materials) { int needCount = mt.itemCount * Mathf.CeilToInt(tempIic.count * 1.0f / ms.m_productItemCount); if (core != null) { int ownMaterialCount = CSUtils.GetItemCountFromAllStorage(mt.itemId, core); if (factory != null) { ownMaterialCount += factory.GetAllCompoundItemCount(mt.itemId); } ItemIdCount ownRecord = ItemsOwnRecord.Find(it => it.protoId == mt.itemId); if (ownMaterialCount > 0) { if (ownRecord == null || ownRecord.count < ownMaterialCount) { int leftRecordCount = 0; if (ownRecord == null) { leftRecordCount = ownMaterialCount; } else { leftRecordCount = ownMaterialCount - ownRecord.count; } int addRecordCount = 0; if (needCount > leftRecordCount) { needCount -= leftRecordCount; addRecordCount = leftRecordCount; } else { needCount = 0; addRecordCount = needCount; } if (ownRecord == null) { ItemsOwnRecord.Add(new ItemIdCount(mt.itemId, addRecordCount)); } else { ownRecord.count += addRecordCount; } if (needCount == 0) { continue; } } } } if (CSProcessing.CanProcessItem(mt.itemId)) { CSUtils.AddItemIdCount(resourceItems, mt.itemId, needCount); } else { CSUtils.AddItemIdCount(needReplicate, mt.itemId, needCount); } } needReplicate.Remove(tempIic); } }while(needReplicate.Count > 0); } return(resourceItems); }