public override List <ItemIdCount> GetDesires() { List <ItemIdCount> desireList = new List <ItemIdCount> (); int[] staminaItemList = NpcEatDb.GetEatIDs(EEatType.Hunger); foreach (int protoId in staminaItemList) { if (CSUtils.GetItemCountFromAllStorage(protoId, Assembly) < CYCLE_DESIRE_MIN_COUNT) { desireList.Add(new ItemIdCount(protoId, CYCLE_DESIRE_ADD_COUNT)); } } return(desireList); }
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); } }
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); }
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 override List <ItemIdCount> GetRequirements() { int lifeItemCount = 0; int staminaItemCount = 0; int comfortItemCount = 0; int[] lifeItemList = NpcEatDb.GetEatIDs(EEatType.Hp); //--to do int[] staminaItemList = NpcEatDb.GetEatIDs(EEatType.Hunger); int[] comortItemList = NpcEatDb.GetEatIDs(EEatType.Comfort); foreach (int protoId in lifeItemList) { lifeItemCount += CSUtils.GetItemCountFromAllStorage(protoId, Assembly); } foreach (int protoId in staminaItemList) { staminaItemCount += CSUtils.GetItemCountFromAllStorage(protoId, Assembly); } foreach (int protoId in comortItemList) { comfortItemCount += CSUtils.GetItemCountFromAllStorage(protoId, Assembly); } List <ItemIdCount> requireList = new List <ItemIdCount> (); if (lifeItemCount < CYCLE_MIN_PER_NPC_LIFE * m_MgCreator.GetNpcCount) { requireList.Add(new ItemIdCount(CYCLE_PROTOID_LIFE, Mathf.Max(CYCLE_ADD_MIN_LIFE, Mathf.CeilToInt(CYCLE_MIN_PER_NPC_LIFE * m_MgCreator.GetNpcCount * MAX_ADD_PERCENT_FOR_PER_NPC)))); } if (staminaItemCount < CYCLE_MIN_PER_NPC_STAMINA * m_MgCreator.GetNpcCount) { requireList.Add(new ItemIdCount(CYCLE_PROTOID_STAMINA, Mathf.Max(CYCLE_ADD_MIN_STAMINA, Mathf.CeilToInt(CYCLE_MIN_PER_NPC_STAMINA * m_MgCreator.GetNpcCount * MAX_ADD_PERCENT_FOR_PER_NPC)))); } if (comfortItemCount < CYCLE_MIN_PER_NPC_COMFORT * m_MgCreator.GetNpcCount) { requireList.Add(new ItemIdCount(CYCLE_PROTOID_COMFORT, Mathf.Max(CYCLE_ADD_MIN_COMFORT, Mathf.CeilToInt(CYCLE_MIN_PER_NPC_COMFORT * m_MgCreator.GetNpcCount * MAX_ADD_PERCENT_FOR_PER_NPC)))); } if (CYCLE_MIN_OTHER_0 > CSUtils.GetItemCountFromAllStorage(CYCLE_PROTOID_OTHER_0, Assembly)) { requireList.Add(new ItemIdCount(CYCLE_PROTOID_OTHER_0, CYCLE_ADD_MIN_OTHER_0)); } if (CYCLE_MIN_OTHER_1 > CSUtils.GetItemCountFromAllStorage(CYCLE_PROTOID_OTHER_1, Assembly)) { requireList.Add(new ItemIdCount(CYCLE_PROTOID_OTHER_1, CYCLE_ADD_MIN_OTHER_1)); } //battery List <ItemObject> allBattery = CSUtils.GetItemListInStorage(CYCLE_PROTOID_BATTERY, Assembly); if (allBattery.Count < CYCLE_MIN_BATTERY) { requireList.Add(new ItemIdCount(CYCLE_PROTOID_BATTERY, CYCLE_ADD_MIN_BATTERY)); } else { int availableBattery = 0; foreach (ItemObject bat in allBattery) { Energy eg = bat.GetCmpt <Energy>(); if (eg != null && eg.energy.percent > BATTERY_AVAILABLE) { availableBattery++; } } if (availableBattery < CYCLE_MIN_BATTERY) { requireList.Add(new ItemIdCount(CYCLE_PROTOID_BATTERY, CYCLE_ADD_MIN_BATTERY)); } } if (CYCLE_MIN_OTHER_3 > CSUtils.GetItemCountFromAllStorage(CYCLE_PROTOID_OTHER_3, Assembly)) { requireList.Add(new ItemIdCount(CYCLE_PROTOID_OTHER_3, CYCLE_ADD_MIN_OTHER_3)); } if (CYCLE_MIN_PPCOAL > CSUtils.GetItemCountFromAllStorage(CYCLE_PROTOID_PPCOAL, Assembly)) { requireList.Add(new ItemIdCount(CYCLE_PROTOID_PPCOAL, CYCLE_ADD_MIN_PPCOAL)); } if (CYCLE_MIN_PPFUSION > CSUtils.GetItemCountFromAllStorage(CYCLE_PROTOID_PPFUSION, Assembly)) { requireList.Add(new ItemIdCount(CYCLE_PROTOID_PPFUSION, CYCLE_ADD_MIN_PPFUSION)); } if (CYCLE_MIN_WATER > CSUtils.GetItemCountFromAllStorage(CYCLE_PROTOID_WATER, Assembly)) { requireList.Add(new ItemIdCount(CYCLE_PROTOID_WATER, CYCLE_ADD_MIN_WATER)); } if (CYCLE_MIN_INSECTICIDE > CSUtils.GetItemCountFromAllStorage(CYCLE_PROTOID_INSECTICIDE, Assembly)) { requireList.Add(new ItemIdCount(CYCLE_PROTOID_INSECTICIDE, CYCLE_ADD_MIN_INSECTICIDE)); } return(requireList); }