Esempio n. 1
0
 public void ReplicateMaterialRecursion(int curDepth, int maxDepth, List <int> replicatingItems, List <ItemIdCount> materialList)
 {
     if (curDepth >= maxDepth)
     {
         return;
     }
     else
     {
         List <ItemIdCount> nextMaterialList = new List <ItemIdCount> ();
         foreach (ItemIdCount mIic in materialList)
         {
             int ownMaterialCount = CSUtils.GetItemCountFromAllStorage(mIic.protoId, Assembly) + GetAllCompoundItemCount(mIic.protoId);
             if (ownMaterialCount > 0)
             {
                 if (mIic.count <= ownMaterialCount)
                 {
                     continue;
                 }
                 else
                 {
                     mIic.count -= ownMaterialCount;
                 }
             }
             List <ItemIdCount> mMaterialList;
             int mProductCount;
             ReplicateItem(mIic, replicatingItems, out mMaterialList, out mProductCount);
             if (mIic.count > 0)
             {
                 //level01
                 foreach (ItemIdCount mMIic in mMaterialList)
                 {
                     mMIic.count = mMIic.count * Mathf.CeilToInt(mIic.count * 1.0f / mProductCount);                   //needCount
                     CSUtils.AddItemIdCount(nextMaterialList, mMIic.protoId, mMIic.count);
                 }
             }
         }
         if (nextMaterialList.Count == 0)
         {
             return;
         }
         curDepth++;
         ReplicateMaterialRecursion(curDepth, maxDepth, replicatingItems, nextMaterialList);
     }
 }
Esempio n. 2
0
    public List <ItemIdCount> GetItemsInProcessing()
    {
        List <ItemIdCount> processingItems = new List <ItemIdCount> ();

        for (int i = 0; i < mTaskTable.Length; i++)
        {
            if (mTaskTable[i] != null)
            {
                if (mTaskTable[i].IsWorking())
                {
                    ProcessingTask pt = mTaskTable[i];
                    if (pt.itemList.Count > 0)
                    {
                        foreach (ItemIdCount iic in pt.itemList)
                        {
                            CSUtils.AddItemIdCount(processingItems, iic.protoId, iic.count);
                        }
                    }
                }
            }
        }
        return(processingItems);
    }
Esempio n. 3
0
    public void CreateNewTaskWithItems(List <ItemIdCount> allItemsList)
    {
        if (Assembly == null || Assembly.Storages == null)
        {
            return;
        }

        List <int>         replicatingItems       = new List <int> ();
        List <ItemIdCount> allMaterialItemsInNeed = new List <ItemIdCount> ();

        foreach (ItemIdCount iic in allItemsList)
        {
            //1.get the formula/find the best formula for the item,
            List <ItemIdCount> materialList;
            int productItemCount;
            ReplicateItem(iic, replicatingItems, out materialList, out productItemCount);
            //--to do:product not enough, but material can be replicate
            if (iic.count > 0)
            {
                //level01
                foreach (ItemIdCount mIic in materialList)
                {
                    mIic.count = mIic.count * Mathf.CeilToInt(iic.count * 1.0f / productItemCount);               //needCount
                    CSUtils.AddItemIdCount(allMaterialItemsInNeed, mIic.protoId, mIic.count);
                }
            }
        }

        ReplicateMaterialRecursion(0, 2, replicatingItems, allMaterialItemsInNeed);

        if (replicatingItems.Count > 0)
        {
            CSAutocycleMgr.Instance.ShowReplicatorFor(replicatingItems);
        }
        //3.update allItemsLIst
        allItemsList.RemoveAll(it => it.count == 0);
    }
Esempio n. 4
0
    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);
    }