예제 #1
0
 public static int GetDrop(EDropSourceCategory category)
 {
     return(GetDrop(new Dictionary <int, float>(), true, category));
 }
예제 #2
0
    public static int GetDrop(Dictionary <int, float> customItemMap, bool includeDefaults, EDropSourceCategory category)
    {
        //Determine whether an item drops
        float dropRate      = m_DropCategoryDropRates[category];
        float randomPointer = Random.Range(0f, 1f);

        if (randomPointer > (dropRate))
        {
            return(Consts.NULL_ITEM_ID);
        }

        //Choose the item to drop

        //This is a list of available items, in the same order as selection list.
        List <int> commonItemList    = new List <int>();
        List <int> uncommonItemList  = new List <int>();
        List <int> rareItemList      = new List <int>();
        List <int> epicItemList      = new List <int>();
        List <int> legendaryItemList = new List <int>();

        Dictionary <EItemRarity, List <int> > itemLists = new Dictionary <EItemRarity, List <int> >();

        itemLists[EItemRarity.COMMON]    = commonItemList;
        itemLists[EItemRarity.UNCOMMON]  = uncommonItemList;
        itemLists[EItemRarity.RARE]      = rareItemList;
        itemLists[EItemRarity.EPIC]      = epicItemList;
        itemLists[EItemRarity.LEGENDARY] = legendaryItemList;

        //This is a variable used to segment items into a list.

        /*For example, the first item will be placed at its drop chance,
         *  while the second will be placed at the 1st item plus the 2nd item's cumulative drop chances.
         */
        /*This makes it easy to pick items using a random number,
         * since we can one by one check whether the random no is less than the first item,
         * less than the second item, etc
         */
        if (includeDefaults)
        {
            int[] categoryItems = m_DropCategoryLists[category];

            float specialTotalWeight = 0;
            foreach (int value in customItemMap.Values)
            {
                specialTotalWeight += value;
            }

            //Determine whether to use special items or default items
            float j = Random.Range(0, 1);

            //If using default items
            if (j >= specialTotalWeight)
            {
                foreach (int item in categoryItems)
                {
                    EItemRarity rarity;
                    if (ItemManager.IsPassiveItem(item))
                    {
                        rarity = ItemManager.GetPassiveItem(item).Rarity;
                    }
                    else if (ItemManager.IsWeaponItem(item))
                    {
                        rarity = ItemManager.GetWeaponItem(item).Rarity;
                    }
                    else
                    {
                        rarity = ItemManager.GetActiveItem(item).Rarity;
                    }
                    itemLists[rarity].Add(item);
                }

                List <int> rarityItemList;
                #region Drop Rarity Code - NEEDS REVISION
                //float selector = Random.Range(0, 1);
                //if (selector < m_RarityToDropRateMap[EItemRarity.LEGENDARY]) {
                //    rarityItemList = itemLists[EItemRarity.LEGENDARY];
                //}
                //else {
                //    selector -= m_RarityToDropRateMap[EItemRarity.LEGENDARY];
                //}
                //if (selector < m_RarityToDropRateMap[EItemRarity.EPIC]) {
                //    rarityItemList = itemLists[EItemRarity.EPIC];
                //}
                //else {
                //    selector -= m_RarityToDropRateMap[EItemRarity.EPIC];
                //}
                //if (selector < m_RarityToDropRateMap[EItemRarity.RARE]) {
                //    rarityItemList = itemLists[EItemRarity.RARE];
                //}
                //else {
                //    selector -= m_RarityToDropRateMap[EItemRarity.RARE];
                //}
                //if (selector < m_RarityToDropRateMap[EItemRarity.UNCOMMON]) {
                //    rarityItemList = itemLists[EItemRarity.UNCOMMON];
                //}
                #endregion

                rarityItemList = itemLists[EItemRarity.COMMON];
                return(rarityItemList[Random.Range(0, rarityItemList.Count - 1)]);
            }
            //If using special items
        }

        if (customItemMap.Keys.Count == 0)
        {
            return(Consts.NULL_ITEM_ID);
        }
        //Add special items to selection list
        float        dropChance    = 0;
        List <float> selectionList = new List <float>();
        List <int>   itemList      = new List <int>();
        foreach (int item in customItemMap.Keys)
        {
            dropChance += customItemMap[item];
            selectionList.Add(dropChance);
            itemList.Add(item);
        }
        float random = Random.Range(0, dropChance);
        int   i      = 0;
        while (selectionList[i] < random)
        {
            i++;
        }
        return(itemList[i]);
    }