Exemplo n.º 1
0
    public void ReplicateItem(ItemIdCount iic, List <int> replicatingItems, out List <ItemIdCount> materialList, out int productItemCount)
    {
        Replicator.KnownFormula[] msList = UIGraphControl.GetReplicator().GetKnowFormulasByProductItemId(iic.protoId);
        materialList     = new List <ItemIdCount> ();
        productItemCount = 0;
        if (msList == null || msList.Length == 0)
        {
            return;
        }

        //--to do: temp,only use formula 01?
        Replicator.Formula ms = Replicator.Formula.Mgr.Instance.Find(msList[0].id);
        foreach (Replicator.Formula.Material mt in ms.materials)
        {
            materialList.Add(new ItemIdCount(mt.itemId, mt.itemCount));
        }
        productItemCount = ms.m_productItemCount;
        int productCount = Mathf.CeilToInt(iic.count * 1.0f / ms.m_productItemCount);

        //2.replicate it and count down material in storage
        int countCanGet = CSUtils.GetMaterialListCount(materialList, Assembly);

        if (countCanGet == 0)
        {
            return;
        }
        if (countCanGet >= productCount)
        {
            if (SetCompoudItemAuto(iic.protoId, productCount * ms.m_productItemCount, ms.timeNeed * productCount))
            {
                iic.count = 0;
                foreach (ItemIdCount countDownItem in materialList)
                {
                    CSUtils.CountDownItemFromFactoryAndAllStorage(countDownItem.protoId, countDownItem.count * productCount, Assembly);
                }
                replicatingItems.Add(iic.protoId);
            }
        }
        else
        {
            if (SetCompoudItemAuto(iic.protoId, countCanGet * ms.m_productItemCount, ms.timeNeed * countCanGet))
            {
                iic.count -= countCanGet * ms.m_productItemCount;
                foreach (ItemIdCount countDownItem in materialList)
                {
                    CSUtils.CountDownItemFromFactoryAndAllStorage(countDownItem.protoId, countDownItem.count * countCanGet, Assembly);
                }
                replicatingItems.Add(iic.protoId);
            }
        }
    }