Example #1
0
    public bool Add(List <ItemIdCount> itemList)
    {
        List <MaterialItem> miList = CSUtils.ItemIdCountToMaterialItem(itemList);
        bool flag = m_Package.Add(miList);

        UpdateDataToUI();
        return(flag);
    }
Example #2
0
    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));
    }
Example #3
0
    public bool CanAdd(List <ItemIdCount> itemList)
    {
        List <MaterialItem> miList = CSUtils.ItemIdCountToMaterialItem(itemList);

        return(m_Package.CanAdd(miList));
    }
Example #4
0
    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();
            }
        }
    }