コード例 #1
0
        public ChaosBoxMixResult Execute(Character @char, CChaosBoxItemMixButtonClick mixAditionalInfo = null)
        {
            var cbItems = @char.Inventory.ChaosBox.Items;
            var items   = cbItems.Select(x => x.Value);

            if (BaseCost > @char.Money)
            {
                return(ChaosBoxMixResult.InsufficientMoney);
            }

            @char.Money -= (uint)BaseCost;

            var ingOk = new Dictionary <IngredientInfo, int>();

            foreach (var ing in Ingredients)
            {
                var count = items.Where(x => ing.Match(x)).Count();
                if (ing.Count > count && !ingOk.Any(x => x.Key.IID == ing.IID))
                {
                    return(ChaosBoxMixResult.IncorrectItems);
                }

                ingOk.Add(ing, count);
            }

            var pairIng = (from ing in Ingredients
                           from it in cbItems
                           where ing.Match(it.Value)
                           select new { Address = it.Key, Item = it.Value, Ingredient = ing }).ToList();

            var leftItems = (from it in cbItems
                             where !pairIng.Any(x => x.Item == it.Value)
                             select it).ToList();

            var successRate = GeneralSuccess;

            foreach (var ing in ingOk)
            {
                var scalar = (ing.Value - ing.Key.Count);
                successRate += scalar * 10;
            }

            if (successRate > 100)
            {
                successRate = 100;
            }
            var rand = new Random();
            ChaosBoxMixResult result = ChaosBoxMixResult.Success;

            if (rand.Next(0, 100) > successRate - 1)
            {
                result = ChaosBoxMixResult.Fail;
            }

            @char.Inventory.DeleteChaosBox();

            var            prob = rand.Next(0, 100);
            IngredientInfo res  = null;

            if (result == ChaosBoxMixResult.Success)
            {
                foreach (var r in ResultSuccess)
                {
                    if (prob < r.Success)
                    {
                        res = r;
                        break;
                    }
                    prob -= r.Success;
                }
            }
            else
            {
                res = ResultFail;
            }

            if (res == null)
            {
                res = ResultSuccess.First();
            }

            var res2 = pairIng.FirstOrDefault(x => x.Ingredient.IID == res.IID);

            // find any Seed Spear
            var seed = pairIng.FirstOrDefault(x => x.Item.Number >= 6244 && x.Item.Number <= 6273);

            if (res.ItemNumber != ItemNumber.Invalid || res2 != null)
            {
                var mix = new Item(res.ItemNumber != ItemNumber.Invalid ? res.ItemNumber : res2.Item.Number);

                if (res.Level.Length == 1)
                {
                    mix.Plus = res.Level[0] == 255 ? res2.Item.Plus : (byte)res.Level[0];
                }
                else if (res.Level.Length == 2)
                {
                    mix.Plus = (byte)rand.Next(res.Level[0], res.Level[1]);
                }
                else
                {
                    mix.Plus = res2?.Item.Plus ?? 0;
                }

                if (res.Harmony != -1)
                {
                    mix.Harmony.Option = (byte)res.Harmony;
                    mix.Harmony.Level  = 0;
                }
                else
                {
                    mix.Harmony.Option = res2?.Item.Harmony.Option ?? 0;
                    mix.Harmony.Level  = res2?.Item.Harmony.Level ?? 0;
                }

                mix.Luck      = res.Luck == -1 ? res2?.Item.Luck ?? false : (res.Luck > 0 ? true : false);
                mix.Skill     = res.Skill == -1 ? res2?.Item.Skill ?? false : (res.Skill > 0 ? true : false);
                mix.Option28  = (byte)(res.Option == -1 ? res2?.Item.Option28 ?? 0x00 : res.Option);
                mix.OptionExe = (byte)(res.Excellent == -1 ? res2?.Item.OptionExe ?? 0x00 : res.Excellent);
                mix.SetOption = (byte)(res.SetOption == -1 ? res2?.Item.SetOption ?? 0x00 : res.SetOption);
                if (res.Socket != -1 && seed != null)
                {
                    var code  = seed.Item.Number.Index - 100;
                    var level = code / 6;
                    var type  = (SocketOption)(seed.Item.Plus + (code % 6) * 10 + level * 50);

                    mix.Slots = res2?.Item.Slots ?? new SocketOption[5];
                    mix.Slots[mixAditionalInfo.Info] = type;
                }
                mix.Character = @char;
                mix.Account   = @char.Account;
                mix.Character = @char;
                @char.Inventory.ChaosBox.Add(mix);
            }

            return(result);
        }
コード例 #2
0
ファイル: ChaosMixInfo.cs プロジェクト: tbs005/MuEmu
        public ChaosBoxMixResult Execute(Character @char)
        {
            var cbItems = @char.Inventory.ChaosBox.Items;
            var items   = cbItems.Select(x => x.Value);

            if (BaseCost > @char.Money)
            {
                return(ChaosBoxMixResult.InsufficientMoney);
            }

            @char.Money -= (uint)BaseCost;

            var ingOk = new Dictionary <IngredientInfo, int>();

            foreach (var ing in Ingredients)
            {
                var count = items.Where(x => ing.Match(x)).Count();
                if (ing.Count > count)
                {
                    return(ChaosBoxMixResult.Fail);
                }

                ingOk.Add(ing, count);
            }

            var pairIng = (from ing in Ingredients
                           from it in cbItems
                           where ing.Match(it.Value)
                           select new { Address = it.Key, Item = it.Value, Ingredient = ing }).ToList();

            var leftItems = (from it in cbItems
                             where !pairIng.Any(x => x.Item == it.Value)
                             select it).ToList();

            var successRate = GeneralSuccess;

            foreach (var ing in ingOk)
            {
                var scalar = (ing.Value - ing.Key.Count);
                successRate += scalar * 10;
            }

            if (successRate > 100)
            {
                successRate = 100;
            }
            var rand = new Random();

            if (rand.Next(0, 100) > successRate - 1)
            {
                if (ResultFail.IID == -1)
                {
                    @char.Inventory.DeleteChaosBox();
                }

                return(ChaosBoxMixResult.Fail);
            }

            @char.Inventory.DeleteChaosBox();

            var            prob = rand.Next(0, 100);
            IngredientInfo res  = null;

            foreach (var r in ResultSuccess)
            {
                if (prob < r.Success)
                {
                    res = r;
                    break;
                }
                prob -= r.Success;
            }

            if (res == null)
            {
                res = ResultSuccess.First();
            }

            var res2 = pairIng.FirstOrDefault(x => x.Ingredient.IID == res.IID);

            var mix = new Item(res.ItemNumber != ItemNumber.Invalid ? res.ItemNumber : res2.Item.Number);

            if (res.Level.Length == 1)
            {
                mix.Plus = res.Level[0] == 255 ? res2.Item.Plus : (byte)res.Level[0];
            }
            else if (res.Level.Length == 2)
            {
                mix.Plus = (byte)rand.Next(res.Level[0], res.Level[1]);
            }
            else
            {
                mix.Plus = res2?.Item.Plus ?? 0;
            }

            mix.Luck        = res.Luck == -1 ? res2?.Item.Luck ?? false : (res.Luck > 0 ? true : false);
            mix.Skill       = res.Skill == -1 ? res2?.Item.Skill ?? false : (res.Skill > 0 ? true : false);
            mix.Option28    = (byte)(res.Option == -1 ? res2?.Item.Option28 ?? 0x00 : res.Option);
            mix.Character   = @char;
            mix.AccountId   = @char.Account.ID;
            mix.CharacterId = @char.Id;
            @char.Inventory.ChaosBox.Add(mix);

            return(ChaosBoxMixResult.Success);
        }