Ejemplo n.º 1
0
        private static ChestResult OpenChest(PropType propLevel, ChestResult chestResult)
        {
            var result  = GetChectResult(propLevel);
            var isMulti = Startup.Ran.Next(3) == 1;
            Action <PropType> addItem = (itemProb) =>
            {
                var itemType = ItemPropList[itemProb][Startup.Ran.Next(0, ItemPropList[itemProb].Count)];
                if (chestResult.ItemList.ContainsKey(itemType))
                {
                    ++chestResult.ItemList[itemType];
                }
                else
                {
                    chestResult.ItemList[itemType] = 1;
                }
            };

            //炫酷的诅咒宝箱
            if (propLevel == PropType.Lv10)
            {
                result  = result == PropType.Lv10 ? PropType.Lv10 : PropType.Lv1;
                isMulti = false;
            }
            if (isMulti)
            {
                var maxProbLevel = result.GetHashCode();
                while (maxProbLevel > 0)
                {
                    var itemProb = (PropType)Startup.Ran.Next(1, maxProbLevel + 1);
                    maxProbLevel -= itemProb.GetHashCode();
                    addItem(itemProb);
                }
            }
            else
            {
                var isWepon = Startup.Ran.Next(2) == 1;
                if (isWepon)
                {
                    chestResult.WeponList.Add(new WeponInfo(result, Startup.MyGameData.PlayerLevel));
                }
                else
                {
                    addItem(result);
                }
            }
            return(chestResult);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Plays the chest game
        /// </summary>
        /// <returns>A completed Task</returns>
        public async Task ChestGame()
        {
            Log.Info("Playing the chest game");

            // Select a random chest
            int choice = new Random().Next(TotalChests) + 1;

            Log.Info($"Selecting chest {choice}");

            string url  = _config.ChestUrl + choice;
            var    resp = await _client.GetStringAsync(url);

            var chest = new ChestResult(resp);

            Log.Info($"Winning chest was chest {chest.WinnerChest}");
            string result = chest.WinnerChest == choice ? "Won" : "Lost";

            Log.Info($"Result: {result}");
        }
Ejemplo n.º 3
0
        public static ChestResult OpenChestResult(ItemEntity chest, int count)
        {
            var itemInfo     = chest.GetItemAttr();
            var needKeyCount = (int)itemInfo.Data * count;

            if (chest.GetItemInfo().Count < needKeyCount)
            {
                throw new MsgException($"开启[{count}]个[{itemInfo.Name}]需要[{needKeyCount}]把钥匙,你的钥匙不足");
            }
            var openResult = new ChestResult();

            for (var i = 0; i < count; i++)
            {
                OpenChest(itemInfo.PropLevel, openResult);
            }
            foreach (var item in openResult.ItemList)
            {
                item.Key.AddItem(item.Value);
            }
            Startup.MyGameData.WeponList.AddRange(openResult.WeponList);
            chest.AddItem(-count);
            ItemEntity.ChestKey.UseItemActAndCheck(-(int)chest.GetItemAttr().Data *count, null);
            return(openResult);
        }