/****************************************************** * 基地仓库给特定npc补给(从仓库移除,添加到NPC背包) * ***************************************************/ public static bool CsStorageSupply(PeEntity npc, CSAssembly assembly, int protoId, int count) { if (assembly == null || assembly.Storages == null || npc.packageCmpt == null) { return(false); } int curCount = CSUtils.GetItemCounFromFactoryAndAllStorage(protoId, assembly); if (curCount > count) { if (CSUtils.CountDownItemFromAllStorage(protoId, count, assembly)) { return(npc.packageCmpt.Add(protoId, count)); } } else if (curCount > 0) { if (CSUtils.CountDownItemFromAllStorage(protoId, curCount, assembly)) { return(npc.packageCmpt.Add(protoId, curCount)); } } return(false); }
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)); } } } }