private void OnRecycled() { Dictionary <int, int> recycleItems = GetRecycleItems(); if (null == recycleItems) { return; } List <ItemIdCount> resourceGot = new List <ItemIdCount>(); foreach (KeyValuePair <int, int> kvp in recycleItems) { resourceGot.Add(new ItemIdCount(kvp.Key, kvp.Value)); } if (resourceGot.Count <= 0) { return; } List <MaterialItem> materialList = CSUtils.ItemIdCountToMaterialItem(resourceGot); ItemPackage accessor = PeCreature.Instance.mainPlayer.GetCmpt <PlayerPackageCmpt>().package._playerPak; if (null == accessor) { return; } bool addToPackage = false; //lz-2016.12.27 尝试添加到玩家背包 if (accessor.CanAdd(materialList)) { accessor.Add(materialList); GameUI.Instance.mItemPackageCtrl.ResetItem(); addToPackage = true; CSUtils.ShowTips(RecycleConst.INFORM_FINISH_TO_PACKAGE); } //lz-2016.12.27 尝试添加到基地存储箱 if (!addToPackage && Assembly != null && Assembly.Storages != null) { foreach (CSCommon css in Assembly.Storages) { CSStorage storage = css as CSStorage; if (storage.m_Package.CanAdd(materialList)) { storage.m_Package.Add(materialList); addToPackage = true; CSUtils.ShowTips(RecycleConst.INFORM_FINISH_TO_STORAGE); break; } } } //lz-2016.12.27 尝试生成一个小球放物品 if (!addToPackage) { System.Random rand = new System.Random(); List <ItemIdCount> itemIdNum = resourceGot.FindAll(it => it.count > 0); if (itemIdNum.Count <= 0) { return; } int[] items = CSUtils.ItemIdCountListToIntArray(itemIdNum); Vector3 resultPos = Position + new Vector3(0f, 0.72f, 0f); if (BuildingLogic != null) { if (BuildingLogic.m_ResultTrans.Length > 0) { Transform trans = BuildingLogic.m_ResultTrans[rand.Next(BuildingLogic.m_ResultTrans.Length)]; if (trans != null) { resultPos = trans.position; } } } while (RandomItemMgr.Instance.ContainsPos(resultPos)) { resultPos += new Vector3(0, 0.01f, 0); } RandomItemMgr.Instance.GenProcessingItem(resultPos + new Vector3((float)rand.NextDouble() * 0.15f, 0, (float)rand.NextDouble() * 0.15f), items); addToPackage = true; CSUtils.ShowTips(RecycleConst.INFORM_FINISH_TO_RANDOMITEM); } if (addToPackage) { // Delete Item; ItemMgr.Instance.DestroyItem(m_Item.itemObj.instanceId); m_Item = null; // Call back if (onRecylced != null) { onRecylced(); } } }
public RandomItemObj GetTaskResult(float percent, List <ItemIdCount> itemList) { System.Random rand = new System.Random(); //--to do: wait //count item 10%random //create item //add to npcpackage List <ItemIdCount> resourceGot = new List <ItemIdCount> (); foreach (ItemIdCount item in itemList) { int getCount = Mathf.FloorToInt(item.count * percent); resourceGot.Add(new ItemIdCount(item.protoId, getCount)); } List <ItemIdCount> itemIdNum = resourceGot.FindAll(it => it.count > 0); if (itemIdNum.Count <= 0) { return(null); } //put into storage bool addInStorage = false; if (Assembly != null && Assembly.Storages != null) { List <MaterialItem> materialList = CSUtils.ItemIdCountToMaterialItem(itemIdNum); foreach (CSCommon css in Assembly.Storages) { CSStorage storage = css as CSStorage; if (storage.m_Package.CanAdd(materialList)) { storage.m_Package.Add(materialList); addInStorage = true; //--to do: inform player CSUtils.ShowTips(ProcessingConst.INFORM_FINISH_TO_STORAGE); break; } else { if (CSAutocycleMgr.Instance != null) { CSAutocycleMgr.Instance.ShowTips(ETipType.storage_full); } } } } if (addInStorage) { return(null); } int[] items = CSUtils.ItemIdCountListToIntArray(itemIdNum); Vector3 resultPos = Position + new Vector3(0f, 0.72f, 0f); if (BuildingLogic != null) { if (BuildingLogic.m_ResultTrans.Length > 0) { Transform trans = BuildingLogic.m_ResultTrans[rand.Next(BuildingLogic.m_ResultTrans.Count())]; if (trans != null) { resultPos = trans.position; } } } while (RandomItemMgr.Instance.ContainsPos(resultPos)) { resultPos += new Vector3(0, 0.01f, 0); } //return new RandomItemObj(resultPos + new Vector3((float)rand.NextDouble()*0.15f, 0, (float)rand.NextDouble()*0.15f), items); CSUtils.ShowTips(ProcessingConst.INFORM_FINISH_TO_RANDOMITEM); return(RandomItemMgr.Instance.GenProcessingItem(resultPos + new Vector3((float)rand.NextDouble() * 0.15f, 0, (float)rand.NextDouble() * 0.15f), items)); }
public void OnCancelCompound(int index) { if (index < Data.m_CompoudItems.Count) { CompoudItem ci = Data.m_CompoudItems[index]; // if(ci.IsFinished) // return; if (PeGameMgr.IsSingle) { //1.storage add materials // 0)get materials List <ItemIdCount> materialList = new List <ItemIdCount> (); Replicator.Formula ms = Replicator.Formula.Mgr.Instance.FindByProductId(ci.itemID); foreach (Replicator.Formula.Material mt in ms.materials) { materialList.Add(new ItemIdCount(mt.itemId, mt.itemCount * ci.itemCnt / ms.m_productItemCount)); } // 1)storage not full if (!CSUtils.AddItemListToStorage(materialList, Assembly)) // 2)storage full, gen object { System.Random rand = new System.Random(); Vector3 pos; if (gameLogic != null) { pos = Position + gameLogic.transform.rotation * (new Vector3(0, 0, 4)); } else { pos = Position + new Vector3(0, 0, 6); } pos = pos + new Vector3((float)rand.NextDouble() * 0.1f, 0, (float)rand.NextDouble() * 0.1f); while (RandomItemMgr.Instance.ContainsPos(pos)) { pos += new Vector3(0, 0.01f, 0); } RandomItemMgr.Instance.GenFactoryCancel(pos, CSUtils.ItemIdCountListToIntArray(materialList)); } if (m_CurCompoundIndex == index) { if (m_Counter != null) { CSMain.Instance.DestoryCounter(m_Counter); m_Counter = null; } } if (m_CurCompoundIndex > index) { m_CurCompoundIndex--; } Data.m_CompoudItems.Remove(ci); } else { _Net.RPCServer(EPacketType.PT_CL_FCT_GenFactoryCancel, index, ci); if (m_CurCompoundIndex == index) { if (m_Counter != null) { CSMain.Instance.DestoryCounter(m_Counter); m_Counter = null; } } if (m_CurCompoundIndex > index) { m_CurCompoundIndex--; } Data.m_CompoudItems.Remove(ci); } } }