Esempio n. 1
0
 void ShowMedicineNeed(ItemIdCount iic)
 {
     if (uiObj != null)
     {
         uiObj.TreatMedicineShow(iic);
     }
 }
        public List <ItemIdCount> RandomItemDict(int count, System.Random rand = null)
        {
            List <ItemIdCount> items = new List <ItemIdCount>();

            if (rand == null)
            {
                rand = new System.Random((int)System.DateTime.UtcNow.Ticks);
            }

//			if(count ==0)
//				Debug.LogError(string.Format("RandomItemDict count 0!"));
            for (int i = 0; i < count; i++)
            {
                int type;
                int level = RandomTypeLevel(out type, rand);
                List <RandomItemTypeInfo> riti = RandomItemTypeInfo.RandomItemTypeInfoByLevel(level, type);
                if (riti != null && riti.Count > 0)
                {
                    RandomItemTypeInfo ritiPicked = new RandomItemTypeInfo();
                    ritiPicked = riti[rand.Next(riti.Count)];
                    int    itemProtoId = ritiPicked.prototypeItem_id;
                    double countDouble = ritiPicked.itemAmount * (1 + ritiPicked.itemFloating * rand.NextDouble());
                    int    itemCount   = Mathf.RoundToInt((float)countDouble);
                    if (itemCount > 0)
                    {
                        ItemIdCount mi = new ItemIdCount(itemProtoId, itemCount);
                        items.Add(mi);
//					}else{
//
//						Debug.LogError(string.Format("RandomItemDict itemCount 0:{0},{1}",ritiPicked.prototypeItem_id,ritiPicked.itemAmount));
                    }
                }
            }
            return(items);
        }
Esempio n. 3
0
 public static void ParseData(byte[] data, CSProcessingData recordData)
 {
     using (MemoryStream ms = new MemoryStream(data))
         using (BinaryReader reader = new BinaryReader(ms))
         {
             recordData.isAuto = BufferHelper.ReadBoolean(reader);
             int taskCount = BufferHelper.ReadInt32(reader);
             for (int i = 0; i < taskCount; i++)
             {
                 int            taskIndex = BufferHelper.ReadInt32(reader);
                 ProcessingTask pt        = new ProcessingTask();
                 int            itemCount = BufferHelper.ReadInt32(reader);
                 for (int j = 0; j < itemCount; j++)
                 {
                     ItemIdCount po = new ItemIdCount();
                     po.protoId = BufferHelper.ReadInt32(reader);
                     po.count   = BufferHelper.ReadInt32(reader);
                     pt.itemList.Add(po);
                 }
                 pt.runCount  = BufferHelper.ReadInt32(reader);
                 pt.m_CurTime = BufferHelper.ReadSingle(reader);
                 pt.m_Time    = BufferHelper.ReadSingle(reader);
                 recordData.mTaskTable[taskIndex] = pt;
             }
         }
 }
Esempio n. 4
0
    public bool RemoveItem(int protoId)
    {
        //--to do:
        if (cs != null)
        {
            return(false);
        }

        bool        existed    = false;
        ItemIdCount existedPob = null;

        foreach (ItemIdCount pob in itemList)
        {
            if (pob.protoId == protoId)
            {
                existedPob = pob;
                existed    = true;
            }
        }
        if (existed)
        {
            itemList.Remove(existedPob);
            return(true);
        }

        return(false);
    }
Esempio n. 5
0
 public static void Serialize(uLink.BitStream stream, object value, params object[] codecOptions)
 {
     try
     {
         ItemIdCount to = value as ItemIdCount;
         stream.WriteInt32(to.protoId);
         stream.WriteInt32(to.count);
     }
     catch (System.Exception e)
     {
         throw e;
     }
 }
Esempio n. 6
0
 public override bool MeetDemand(ItemIdCount supplyItem)
 {
     if (CSUtils.CanAddToStorage(supplyItem.protoId, supplyItem.count, Assembly))
     {
         CSUtils.AddToStorage(supplyItem.protoId, supplyItem.count, Assembly);
         return(true);
     }
     else
     {
         CSAutocycleMgr.Instance.ShowTips(ETipType.storage_full);
         return(false);
     }
 }
Esempio n. 7
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);
            }
        }
    }
Esempio n. 8
0
 public static object Deserialize(uLink.BitStream stream, params object[] codecOptions)
 {
     try
     {
         int         protoId = stream.ReadInt32();
         int         count   = stream.ReadInt32();
         ItemIdCount to      = new ItemIdCount(protoId, count);
         return(to);
     }
     catch (System.Exception e)
     {
         throw e;
     }
 }
Esempio n. 9
0
    public bool AddItem(ItemIdCount po)
    {
        //--to do:
        if (cs != null)
        {
            return(false);
        }

        bool        existed    = false;
        ItemIdCount existedPob = null;

        foreach (ItemIdCount pob in itemList)
        {
            if (pob.protoId == po.protoId)
            {
                existedPob = pob;
                existed    = true;
            }
        }

        if (existed)
        {
            if (existedPob.count >= ProcessingObjInfo.GetPobMax(existedPob.protoId))
            {
                return(false);
            }
            existedPob.count += po.count;
            if (existedPob.count > ProcessingObjInfo.GetPobMax(existedPob.protoId))
            {
                existedPob.count = ProcessingObjInfo.GetPobMax(existedPob.protoId);
            }
            return(true);
        }
        else
        {
            //2.check room
            if (itemList.Count >= ProcessingConst.OBJ_MAX)
            {
                return(false);
            }
            if (po.count > ProcessingObjInfo.GetPobMax(po.protoId))
            {
                po.count = ProcessingObjInfo.GetPobMax(po.protoId);
            }
            itemList.Add(po);
            return(true);
        }
    }
Esempio n. 10
0
    /// <summary>
    /// 治疗药物设置
    /// </summary>
    /// <param name="_ic"></param>
    public void TreatMedicineShow(ItemIdCount _ic)
    {
        if (m_MedicineAboutTreat_Show == null)
        {
            return;
        }
        if (!m_MedicineAboutTreat_Show.transform.parent.gameObject.activeSelf)
        {
            m_MedicineAboutTreat_Show.transform.parent.gameObject.SetActive(true);
        }
        ItemSample _ip = new ItemSample();

        _ip.protoId = _ic.protoId;
        //ItemProto _protoData = _ip.protoData;
        m_MedicineAboutTreat_Show.m_Grid.SetItem(_ip);
        m_MedicineAboutTreat_Show.NeedCnt = _ic.count;
        //if (!hasUsedMedicine)//没得药品放在里面
        //    m_MedicineAboutTreat_Show.m_Grid.SetGridForbiden(true);
    }
Esempio n. 11
0
    public List <ItemIdCount> GetCompoudingItem()
    {
        List <ItemIdCount> doingItem = new List <ItemIdCount> ();

        foreach (CompoudItem ci in Data.m_CompoudItems)
        {
            if (ci.curTime < ci.time)
            {
                ItemIdCount dItem = doingItem.Find(it => it.protoId == ci.itemID);
                if (dItem != null)
                {
                    dItem.count += ci.itemCnt;
                }
                else
                {
                    doingItem.Add(new ItemIdCount(ci.itemID, ci.itemCnt));
                }
            }
        }
        return(doingItem);
    }
Esempio n. 12
0
    public List <ItemIdCount> GetCompoudingEndItem()
    {
        List <ItemIdCount> finishList = new List <ItemIdCount> ();

        foreach (CompoudItem ci in Data.m_CompoudItems)
        {
            if (ci.curTime >= ci.time)
            {
                ItemIdCount fItem = finishList.Find(it => it.protoId == ci.itemID);
                if (fItem != null)
                {
                    fItem.count += ci.itemCnt;
                }
                else
                {
                    finishList.Add(new ItemIdCount(ci.itemID, ci.itemCnt));
                }
            }
        }
        return(finishList);
    }
Esempio n. 13
0
 public virtual bool MeetDemand(ItemIdCount supplyItem)
 {
     return(true);
 }
Esempio n. 14
0
    void Update()
    {
        if (!PeGameMgr.IsSingle)
        {
            return;
        }
        if (core == null)
        {
            Init();
        }
        if (core == null)
        {
            return;
        }
        counter++;
        if (counter % 450 == 0)
        {
            counter = 0;
            //--to do
            //1.collect requirements
            if (core.Storages == null)
            {
                return;
            }

            CSFactory factory = core.Factory;

            List <CSCommon> storages = core.Storages;
            ClearRequirements();
            List <CSCommon> allCommon = core.GetBelongCommons();
            foreach (CSCommon cse in allCommon)
            {
                if ((cse as CSPPCoal != null) || (cse as CSFarm != null) /*|| (cse as CSMedicalTreat !=null)*/)
                {
                    List <ItemIdCount> requirementsList = cse.GetRequirements();
                    if (requirementsList != null && requirementsList.Count > 0)
                    {
                        if (cse as CSPPCoal != null)
                        {
                            ppcoalRequirements.Add(cse, requirementsList);
                        }
                        //					if(cse as CSMedicalTreat!=null)
                        //						treatRequirements.Add(cse,requirementsList);
                        if (cse as CSFarm != null)
                        {
                            farmRequirements.Add(cse, requirementsList);
                        }
                    }
                }
            }
            bool transferedFactoryItem = false;
            //--to do
            if (storages != null)
            {
                //0.transfer factoryEndItem
                if (factory != null)
                {
                    List <ItemIdCount> replicateEndItem = factory.GetCompoudingEndItem();
                    if (replicateEndItem.Count > 0)
                    {
                        List <int> protoList = CSStorage.GetAutoProtoIdList();
                        foreach (ItemIdCount rIic in replicateEndItem)
                        {
                            if (protoList.Contains(rIic.protoId))
                            {
                                if (CSUtils.AddToStorage(rIic.protoId, rIic.count, core))
                                {
                                    factory.CountDownItem(rIic.protoId, rIic.count);
                                    transferedFactoryItem = true;
                                }
                            }
                        }
                    }
                }

                List <ItemIdCount> requirementsList = storages[0].GetRequirements();
                if (requirementsList != null && requirementsList.Count > 0)
                {
                    storageRequirements.Add(storages[0], requirementsList);
                }
            }

            //2.check doing requirements** one by one? && do requirements
            //1)check storage&factory Get supply
            List <ItemIdCount> itemsNeedToGet = new List <ItemIdCount> ();
            GetItemFromStorageAndFactory(ppcoalRequirements, storages, factory, ref itemsNeedToGet);
            GetItemFromStorageAndFactory(farmRequirements, storages, factory, ref itemsNeedToGet);
            GetItemFromStorageAndFactory(storageRequirements, storages, factory, ref itemsNeedToGet);

            if (itemsNeedToGet.Count > 0)
            {
                //3.analysis to processing or replicate
                //1).check is replicating
                if (factory != null)
                {
                    List <ItemIdCount> itemsInReplicating = new List <ItemIdCount>();
                    List <ItemIdCount> compoundingList    = factory.GetCompoudingItem();
                    foreach (ItemIdCount needItem in itemsNeedToGet)
                    {
                        ItemIdCount cItem = compoundingList.Find(it => it.protoId == needItem.protoId);
                        if (cItem != null)
                        {
                            if (cItem.count >= needItem.count)
                            {
                                itemsInReplicating.Add(new ItemIdCount(cItem.protoId, needItem.count));
                            }
                            else
                            {
                                itemsInReplicating.Add(new ItemIdCount(cItem.protoId, cItem.count));
                            }
                        }
                    }
                    if (itemsInReplicating.Count > 0)
                    {
                        foreach (ItemIdCount ic in itemsInReplicating)
                        {
                            ItemIdCount decreaseItem = itemsNeedToGet.Find(it => it.protoId == ic.protoId);
                            if (decreaseItem.count > ic.count)
                            {
                                decreaseItem.count -= ic.count;
                            }
                            else
                            {
                                itemsNeedToGet.Remove(decreaseItem);
                            }
                        }
                    }

                    //2).put material into storage
                    GetItemMaterialFromFactory(factory, itemsNeedToGet, ref transferedFactoryItem);
                    if (transferedFactoryItem)
                    {
                        ShowTips(ETipType.factory_to_storage);
                    }

                    //3).count what need Processing/ replicate some
                    //1-check can be replicated,if ok, replicate
                    factory.CreateNewTaskWithItems(itemsNeedToGet);
                }
                //2-check the left things to resolve to resource
                //3-in 2,check resource already have, remove it
                List <ItemIdCount> resourceItems = ResolveItemsToProcess(itemsNeedToGet, core, factory);
//				foreach(ItemIdCount iic in resourceItems){
//					int gotCount =0;
//					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;
//								break;
//							}else{
//								gotCount += itemCount;
//							}
//						}
//					}
//					iic.count-=gotCount;
//				}

                resourceItems.RemoveAll(it => it.count <= 0);
                if (resourceItems.Count > 0)
                {
                    //3).check is Processing
                    CSProcessing process = core.ProcessingFacility;
                    if (process != null)
                    {
                        List <ItemIdCount> processingList = process.GetItemsInProcessing();
                        foreach (ItemIdCount iic in processingList)
                        {
                            CSUtils.RemoveItemIdCount(resourceItems, iic.protoId, iic.count);
                        }
                    }
                    if (resourceItems.Count > 0)
                    {
                        //4).assign processing task
                        if (process != null)
                        {
                            process.CreateNewTaskWithItems(resourceItems);
                        }
                    }
                }
            }



            //meet desire
            ClearDesires();
            if (storages != null)
            {
                List <ItemIdCount> desireList = storages[0].GetDesires();
                if (desireList != null && desireList.Count > 0)
                {
                    storageDesires.Add(storages[0], desireList);
                    List <ItemIdCount> itemsDesireToGet = new List <ItemIdCount> ();
                    GetItemFromStorageAndFactory(storageDesires, storages, factory, ref itemsDesireToGet);
                    if (itemsDesireToGet.Count > 0 && factory != null)
                    {
                        if (factory != null)
                        {
                            List <ItemIdCount> itemsInReplicating = new List <ItemIdCount>();
                            List <ItemIdCount> compoundingList    = factory.GetCompoudingItem();
                            foreach (ItemIdCount needItem in itemsDesireToGet)
                            {
                                ItemIdCount cItem = compoundingList.Find(it => it.protoId == needItem.protoId);
                                if (cItem != null)
                                {
                                    if (cItem.count >= needItem.count)
                                    {
                                        itemsInReplicating.Add(new ItemIdCount(cItem.protoId, needItem.count));
                                    }
                                    else
                                    {
                                        itemsInReplicating.Add(new ItemIdCount(cItem.protoId, cItem.count));
                                    }
                                }
                            }
                            if (itemsInReplicating.Count > 0)
                            {
                                foreach (ItemIdCount ic in itemsInReplicating)
                                {
                                    ItemIdCount decreaseItem = itemsDesireToGet.Find(it => it.protoId == ic.protoId);
                                    if (decreaseItem.count > ic.count)
                                    {
                                        decreaseItem.count -= ic.count;
                                    }
                                    else
                                    {
                                        itemsDesireToGet.Remove(decreaseItem);
                                    }
                                }
                            }
                        }
                        factory.CreateNewTaskWithItems(itemsDesireToGet);
                    }
                }
            }


            //medical system
            if (core.MedicalCheck != null && core.MedicalTreat != null && core.MedicalTent != null &&
                core.MedicalCheck.IsRunning && core.MedicalTreat.IsRunning && core.MedicalTent.IsRunning &&
                (core.MedicalCheck.WorkerCount + core.MedicalTreat.WorkerCount + core.MedicalTent.WorkerCount > 0))
            {
                if (lastTime < 0)
                {
                    lastTime = GameTime.PlayTime.Second;
                }
                else
                {
                    core.MedicineResearchState += GameTime.PlayTime.Second - lastTime;
                    lastTime = GameTime.PlayTime.Second;
                    if (storages != null && core.MedicineResearchState >= medicineSupplyTime)
                    {
                        Debug.Log("supplyMedicineTime");
                        core.MedicineResearchTimes++;
                        List <ItemIdCount> supportMedicine = new List <ItemIdCount> ();
                        //try supply
                        foreach (MedicineSupply ms in CSMedicineSupport.AllMedicine)
                        {
                            if (core.MedicineResearchTimes - ms.rounds * Mathf.FloorToInt(core.MedicineResearchTimes / ms.rounds)
                                < 1)
                            {
                                if (CSUtils.GetItemCountFromAllStorage(ms.protoId, core) < ItemAsset.ItemProto.GetItemData(ms.protoId).maxStackNum)
                                {
                                    supportMedicine.Add(new ItemIdCount(ms.protoId, ms.count));
                                }
                            }
                        }
                        if (supportMedicine.Count > 0)
                        {
                            if (CSUtils.AddItemListToStorage(supportMedicine, core))
                            {
                                ShowTips(ETipType.medicine_supply);
                            }
                            else
                            {
                                ShowTips(ETipType.storage_full);
                            }
                        }

                        core.MedicineResearchState = 0;
                        if (core.MedicineResearchTimes == Int32.MaxValue)
                        {
                            core.MedicineResearchTimes = 0;
                        }
                    }
                }
            }
            else
            {
                lastTime = GameTime.PlayTime.Second;
            }
        }
    }
Esempio n. 15
0
 public override bool MeetDemand(ItemIdCount supplyItem)
 {
     return(MeetDemand(supplyItem.protoId, supplyItem.count));
 }
Esempio n. 16
0
    public override bool Equals(object obj)
    {
        ItemIdCount iic = obj as ItemIdCount;

        return(protoId == iic.protoId && count == iic.count);
    }
    public static void LoadData()
    {
//		int id=0;
//		for(int level=0;level<LEVEL_MAX;level++){
//			DungeonBaseData dbd = new DungeonBaseData ();
//			dbd.id=id++;
//			dbd.level=level;
//			dbd.landMonsterId = new List<IdWeight> ();
//			dbd.landMonsterId.Add(new IdWeight (104,50));
//			dbd.landMonsterId.Add(new IdWeight (106,50));
//			dbd.waterMonsterId = new List<IdWeight> ();
////			dbd.waterMonsterId.Add(new IdWeight (21,50));
//			dbd.waterMonsterId.Add(new IdWeight (16,100));
//			dbd.monsterAmount =0.1f+level*0.05f;
//			dbd.monsterBuff =1;
//			dbd.itemId = new List<IdWeight> ();
//			dbd.itemId.Add(new IdWeight (76,50));
//			dbd.itemId.Add(new IdWeight (80,50));
//			dbd.itemAmount = 0.1f+level*0.05f;
//			dbd.rareItemId=new List<IdWeight> ();
//			dbd.rareItemId.Add(new IdWeight (71,50));
//			dbd.rareItemId.Add(new IdWeight (74,50));
//			dungeonData.Add(dbd.id,dbd);
//			if(!levelId.ContainsKey(level))
//				levelId[level]= new List<int> ();
//			levelId[level].Add(dbd.id);
//		}

        SqliteDataReader reader = LocalDatabase.Instance.ReadFullTable("Rdungeon_monster_item");

        while (reader.Read())
        {
            DungeonBaseData dbd = new DungeonBaseData();
            dbd.id                 = Convert.ToInt32(reader.GetString(reader.GetOrdinal("id")));
            dbd.level              = Convert.ToInt32(reader.GetString(reader.GetOrdinal("level")));
            dbd.landMonsterId      = RandomDunGenUtil.GetIdWeightList(reader.GetString(reader.GetOrdinal("landmonsterid")));
            dbd.waterMonsterId     = RandomDunGenUtil.GetIdWeightList(reader.GetString(reader.GetOrdinal("watermonsterid")));
            dbd.monsterAmount      = Convert.ToSingle(reader.GetString(reader.GetOrdinal("monsteramount")));
            dbd.monsterBuff        = Convert.ToInt32(reader.GetString(reader.GetOrdinal("monsterbuff")));
            dbd.bossId             = RandomDunGenUtil.GetIdWeightList(reader.GetString(reader.GetOrdinal("bossid")));
            dbd.bossWaterId        = RandomDunGenUtil.GetIdWeightList(reader.GetString(reader.GetOrdinal("bosswaterid")));
            dbd.bossMonsterBuff    = Convert.ToInt32(reader.GetString(reader.GetOrdinal("bossbuff")));
            dbd.minBossId          = RandomDunGenUtil.GetIdWeightList(reader.GetString(reader.GetOrdinal("minbossid")));
            dbd.minBossWaterId     = RandomDunGenUtil.GetIdWeightList(reader.GetString(reader.GetOrdinal("minbosswaterid")));
            dbd.minBossMonsterBuff = Convert.ToInt32(reader.GetString(reader.GetOrdinal("minbossbuff")));
            dbd.itemId             = RandomDunGenUtil.GetIdWeightList(reader.GetString(reader.GetOrdinal("itemid")));
            dbd.itemAmount         = Convert.ToSingle(reader.GetString(reader.GetOrdinal("itemamount")));
            dbd.rareItemId         = RandomDunGenUtil.GetIdWeightList(reader.GetString(reader.GetOrdinal("rareitemid")));
            dbd.rareItemChance     = Convert.ToSingle(reader.GetString(reader.GetOrdinal("rareitemchance")));
            dbd.specifiedItems     = ItemIdCount.ParseStringToList(reader.GetString(reader.GetOrdinal("specifieditems")));
            dbd.dungeonFlowPath    = reader.GetString(reader.GetOrdinal("dungeonflowpath"));
            dbd.type               = Convert.ToInt32(reader.GetString(reader.GetOrdinal("type")));
            dbd.rareItemTags       = RandomDunGenUtil.GetIdWeightList(reader.GetString(reader.GetOrdinal("rareItemtags")));



            dungeonData.Add(dbd.id, dbd);
            if (!levelId.ContainsKey(dbd.level))
            {
                levelId[dbd.level] = new List <int> ();
            }
            levelId[dbd.level].Add(dbd.id);
        }
        DungeonBaseData.InitIsoTagList();
    }
Esempio n. 18
0
    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));
                }
            }
        }
    }
Esempio n. 19
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);
    }