public bool Add(int protoId, int count) { bool flag = m_Package.Add(protoId, count); UpdateDataToUI(); return(flag); }
public bool Add(int prototypeId, int count, bool newFlag = false) { ItemProto itemData = ItemProto.GetItemData(prototypeId); if (itemData.category == quest_item) { return(_missionPak.Add(prototypeId, count, newFlag)); } else { return(_playerPak.Add(prototypeId, count, newFlag)); } }
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(); } } }