コード例 #1
0
        Item GenerateRandomItem(int tier)
        {
            switch (Utility.Next(8))
            {
            case 0:
            case 1:
                return(null);

            case 2:
            case 3:     // material
                var materialList = from m in MaterialInfo.MaterialTypes where m.Hardness == tier && m.IsVisible == true && MaterialInfo.IsLooseOrSolid(m.Id) select m;
                var material     = materialList.Skip(Utility.Next(materialList.Count())).FirstOrDefault();

                switch (material.Rarity)
                {
                case Rarity.Uncommon:
                    return(new Item()
                    {
                        Type = ItemBase.TypesByMaterial[material.Id], Amount = Utility.Next(20) + 1
                    });

                case Rarity.Epic:
                    return(new Item()
                    {
                        Type = ItemBase.TypesByMaterial[material.Id], Amount = Utility.Next(10) + 1
                    });

                default:
                    return(new Item()
                    {
                        Type = ItemBase.TypesByMaterial[material.Id], Amount = Utility.Next(20) + 1
                    });
                }

            case 4:     // rare
                var rareList = from c in rareItems where c.Type.Tier == 0 || c.Type.Tier == tier select c;
                var rare     = rareList.Skip(Utility.Next(rareList.Count())).FirstOrDefault();
                if (rare != null)
                {
                    return new Item()
                           {
                               Type = rare.Type, Amount = Utility.Next(rare.Amount) + 1
                           }
                }
                ;
                break;

            default:     // common
                var commonList = from c in commonItems where c.Type.Tier == 0 || c.Type.Tier == tier select c;
                var common     = commonList.Skip(Utility.Next(commonList.Count())).FirstOrDefault();
                if (common != null)
                {
                    return new Item()
                           {
                               Type = common.Type, Amount = Utility.Next(common.Amount) + 1
                           }
                }
                ;
                break;
            }

            return(null);
        }
    }