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); }
void RPC_S2C_InitDataProcessing(uLink.BitStream stream, uLink.NetworkMessageInfo info) { CSProcessingData recordData = (CSProcessingData)_ColonyObj._RecordData; recordData.m_CurDeleteTime = stream.Read <float>(); recordData.m_CurRepairTime = stream.Read <float>(); recordData.m_DeleteTime = stream.Read <float>(); recordData.m_Durability = stream.Read <float>(); recordData.m_RepairTime = stream.Read <float>(); recordData.m_RepairValue = stream.Read <float>(); //--to do init tasktable byte[] dataArray = stream.Read <byte[]>(); CSProcessing.ParseData(dataArray, recordData); }
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; } } }
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); }
CSCommon _CreateCommon(int type) { CSCommon csc = null; switch (type) { case CSConst.etStorage: csc = new CSStorage(); CSStorage css = csc as CSStorage; css.m_Info = CSInfoMgr.m_StorageInfo; css.m_Creator = this; css.m_Package.ExtendPackage(CSInfoMgr.m_StorageInfo.m_MaxItem, CSInfoMgr.m_StorageInfo.m_MaxEquip, CSInfoMgr.m_StorageInfo.m_MaxRecource, CSInfoMgr.m_StorageInfo.m_MaxArmor); break; case CSConst.etEnhance: csc = new CSEnhance(); CSEnhance csen = csc as CSEnhance; csen.m_Creator = this; csen.m_Info = CSInfoMgr.m_EnhanceInfo; break; case CSConst.etRepair: csc = new CSRepair(); CSRepair csr = csc as CSRepair; csr.m_Creator = this; csr.m_Info = CSInfoMgr.m_RepairInfo; break; case CSConst.etRecyle: csc = new CSRecycle(); CSRecycle csrc = csc as CSRecycle; csrc.m_Creator = this; csrc.m_Info = CSInfoMgr.m_RecycleInfo; break; case CSConst.etDwelling: csc = new CSDwellings(); CSDwellings csd = csc as CSDwellings; csd.m_Creator = this; csd.m_Info = CSInfoMgr.m_DwellingsInfo; // Find the npc to live if (!PeGameMgr.IsMulti) { int index = 0; foreach (KeyValuePair <int, CSCommon> kvp in m_CommonEntities) { if (index >= csd.m_NPCS.Length) { break; } if (kvp.Value.m_Type == CSConst.etDwelling) { CSDwellings dwellings = kvp.Value as CSDwellings; if (dwellings.IsRunning) { continue; } for (int i = 0; i < dwellings.m_NPCS.Length; i++) { if (dwellings.m_NPCS[i] != null) { csd.AddNpcs(dwellings.m_NPCS[i]); dwellings.RemoveNpc(dwellings.m_NPCS[i]); index++; } } } } } break; case CSConst.etppCoal: csc = new CSPPCoal(); CSPPCoal cscppc = csc as CSPPCoal; cscppc.m_Creator = this; cscppc.m_Power = 10000; cscppc.m_RestPower = 10000; cscppc.m_Info = CSInfoMgr.m_ppCoal; break; case CSConst.etppSolar: csc = new CSPPSolar(); CSPPSolar cspps = csc as CSPPSolar; cspps.m_Creator = this; cspps.m_Power = 10000; cspps.m_RestPower = 10000; cspps.m_Info = CSInfoMgr.m_ppCoal; break; case CSConst.etFarm: csc = new CSFarm(); csc.m_Creator = this; csc.m_Info = CSInfoMgr.m_FarmInfo; break; case CSConst.etFactory: csc = new CSFactory(); csc.m_Creator = this; csc.m_Info = CSInfoMgr.m_FactoryInfo; break; case CSConst.etProcessing: csc = new CSProcessing(this); CSProcessing csp = csc as CSProcessing; csp.m_Info = CSInfoMgr.m_ProcessingInfo; break; case CSConst.etTrade: csc = new CSTrade(this); CSTrade cst = csc as CSTrade; cst.m_Info = CSInfoMgr.m_Trade; break; case CSConst.etTrain: csc = new CSTraining(this); CSTraining cstrain = csc as CSTraining; cstrain.m_Info = CSInfoMgr.m_Train; break; case CSConst.dtCheck: csc = new CSMedicalCheck(this); CSMedicalCheck csCheck = csc as CSMedicalCheck; csCheck.m_Info = CSInfoMgr.m_Check; break; case CSConst.dtTreat: csc = new CSMedicalTreat(this); CSMedicalTreat csTreat = csc as CSMedicalTreat; csTreat.m_Info = CSInfoMgr.m_Treat; break; case CSConst.dtTent: csc = new CSMedicalTent(this); CSMedicalTent csTent = csc as CSMedicalTent; csTent.m_Info = CSInfoMgr.m_Tent; break; case CSConst.dtppFusion: csc = new CSPPFusion(); CSPPFusion csFusion = csc as CSPPFusion; csFusion.m_Creator = this; csFusion.m_Power = 10000; csFusion.m_RestPower = 100000; csFusion.m_Info = CSInfoMgr.m_ppFusion; break; default: break; } return(csc); }