示例#1
0
        private void HandleFailedUpgrade(Item item, ItemOptionLink itemOption)
        {
            switch (this.Configuration.FailResult)
            {
            case ItemFailResult.DecreaseOptionByOne:
                itemOption.Level = Math.Max(itemOption.Level - 1, 1);
                break;

            case ItemFailResult.DecreaseOptionByOneOrRemove:
                itemOption.Level -= 1;
                if (itemOption.Level == 0)
                {
                    item.ItemOptions.Remove(itemOption);
                }

                break;

            case ItemFailResult.SetOptionToLevelOne:
                itemOption.Level = 1;
                break;

            default:
                // do nothing
                break;
            }
        }
        private void CheckPrice(byte id, byte dropLevel, byte maxDurability, byte height, byte width, byte group, int value, byte level, long price, bool luck = false, bool option = false, bool skill = false)
        {
            var itemDefinition = MockRepository.GenerateStub <ItemDefinition>();

            itemDefinition.DropLevel  = dropLevel;
            itemDefinition.Durability = maxDurability;
            itemDefinition.Height     = height;
            itemDefinition.Width      = width;
            itemDefinition.Group      = group;
            itemDefinition.Value      = value;
            itemDefinition.Number     = id;
            itemDefinition.Stub(d => d.BasePowerUpAttributes).Return(new List <ItemBasePowerUpDefinition>());
            if (group < 6)
            {
                // weapons should have a min dmg attribute
                itemDefinition.BasePowerUpAttributes.Add(new ItemBasePowerUpDefinition {
                    TargetAttribute = Stats.MinimumPhysBaseDmg
                });
            }

            var item = MockRepository.GenerateStub <Item>();

            item.Definition = itemDefinition;
            item.Durability = itemDefinition.Durability;
            item.Level      = level;
            item.Stub(i => i.ItemOptions).Return(new List <ItemOptionLink>());

            if (luck)
            {
                var optionLink = new ItemOptionLink
                {
                    ItemOption = new IncreasableItemOption
                    {
                        OptionType = ItemOptionTypes.Luck
                    }
                };
                item.ItemOptions.Add(optionLink);
            }

            if (option)
            {
                var optionLink = new ItemOptionLink
                {
                    ItemOption = new IncreasableItemOption
                    {
                        OptionType = ItemOptionTypes.Option
                    }
                };
                item.ItemOptions.Add(optionLink);
            }

            if (skill)
            {
                item.HasSkill = true;
            }

            var buyingPrice = this.calculator.CalculateBuyingPrice(item);

            Assert.That(buyingPrice, Is.EqualTo(price));
        }
示例#3
0
        private void AddRandomExcOptions(Item item)
        {
            var possibleItemOptions = item.Definition.PossibleItemOptions;
            var excellentOptions    = possibleItemOptions.FirstOrDefault(o => o.PossibleOptions.Any(p => p.OptionType == ItemOptionTypes.Excellent));

            if (excellentOptions == null)
            {
                return;
            }

            for (int i = item.ItemOptions.Count(o => o.ItemOption.OptionType == ItemOptionTypes.Excellent); i < excellentOptions.MaximumOptionsPerItem; i++)
            {
                if (i == 0)
                {
                    var itemOptionLink = new ItemOptionLink();
                    itemOptionLink.ItemOption = excellentOptions.PossibleOptions.SelectRandom(this.randomizer);
                    item.ItemOptions.Add(itemOptionLink);
                    continue;
                }

                if (this.randomizer.NextRandomBool(excellentOptions.AddChance))
                {
                    var option = excellentOptions.PossibleOptions.SelectRandom(this.randomizer);
                    while (item.ItemOptions.Any(o => o.ItemOption == option))
                    {
                        option = excellentOptions.PossibleOptions.SelectRandom(this.randomizer);
                    }

                    var itemOptionLink = new ItemOptionLink();
                    itemOptionLink.ItemOption = option;
                    item.ItemOptions.Add(itemOptionLink);
                }
            }
        }
示例#4
0
        /// <summary>
        /// Clones the item option link.
        /// </summary>
        /// <param name="link">The link.</param>
        /// <returns>The cloned item option link.</returns>
        /// <remarks>It does not need to be explicitly added to the context, because it will happen automatically when the context detects the changes of the item.</remarks>
        protected override DataModel.Entities.ItemOptionLink CloneItemOptionLink(DataModel.Entities.ItemOptionLink link)
        {
            var persistentLink = new ItemOptionLink();

            persistentLink.AssignValues(link);
            return(persistentLink);
        }
示例#5
0
 private static void AddAncientBonusOption(TemporaryItem item, ItemChatCommandArgs arguments)
 {
     if (item.Definition != null && arguments.Ancient > default(byte) &&
         item.Definition.PossibleItemSetGroups.FirstOrDefault(set => set.AncientSetDiscriminator == arguments.Ancient) is { } ancientSet &&
         ancientSet.Items.FirstOrDefault(i => i.ItemDefinition == item.Definition) is { } itemOfItemSet)
     {
         var optionLink = new ItemOptionLink {
             ItemOption = itemOfItemSet.BonusOption, Level = arguments.AncientBonusLevel
         };
         item.ItemOptions.Add(optionLink);
         item.ItemSetGroups.Add(ancientSet);
     }
 }
示例#6
0
        private static void AddLuckOption(TemporaryItem item, ItemChatCommandArgs arguments)
        {
            if (item.Definition != null && arguments.Luck)
            {
                var optionLink = new ItemOptionLink
                {
                    ItemOption = item.Definition.PossibleItemOptions
                                 .SelectMany(o => o.PossibleOptions)
                                 .First(o => o.OptionType == ItemOptionTypes.Luck),
                };

                item.ItemOptions.Add(optionLink);
            }
        }
示例#7
0
        private static void AddOption(TemporaryItem item, ItemChatCommandArgs arguments)
        {
            if (item.Definition != null && arguments.Opt > default(byte))
            {
                var itemOption = item.Definition.PossibleItemOptions
                                 .SelectMany(o => o.PossibleOptions)
                                 .First(o => o.OptionType == ItemOptionTypes.Option);

                var level      = arguments.Opt;
                var optionLink = new ItemOptionLink {
                    ItemOption = itemOption, Level = level
                };
                item.ItemOptions.Add(optionLink);
            }
        }
示例#8
0
        /// <summary>
        /// Applies random options to the item.
        /// </summary>
        /// <param name="item">The item.</param>
        protected void ApplyRandomOptions(Item item)
        {
            item.Durability = item.GetMaximumDurabilityOfOnePiece();
            foreach (var option in item.Definition.PossibleItemOptions.Where(o => o.AddsRandomly))
            {
                for (int i = 0; i < option.MaximumOptionsPerItem; i++)
                {
                    if (this.randomizer.NextRandomBool(option.AddChance))
                    {
                        var newOption      = option.PossibleOptions.SelectRandom(this.randomizer);
                        var itemOptionLink = new ItemOptionLink();
                        itemOptionLink.ItemOption = newOption;
                        itemOptionLink.Level      = 1;
                        item.ItemOptions.Add(itemOptionLink);
                    }
                }
            }

            if (item.Definition.MaximumSockets > 0)
            {
                item.SocketCount = this.randomizer.NextInt(1, item.Definition.MaximumSockets + 1);
            }
        }
示例#9
0
        private static void AddExcellentOptions(TemporaryItem item, ItemChatCommandArgs arguments)
        {
            if (item.Definition != null && arguments.ExcellentNumber > default(byte))
            {
                var excellentOptions = item.Definition.PossibleItemOptions
                                       .SelectMany(o => o.PossibleOptions)
                                       .Where(o => o.OptionType == ItemOptionTypes.Excellent)
                                       .Where(o => (o.Number & arguments.ExcellentNumber) > default(byte))
                                       .ToList();

                ushort appliedOptions = default;
                foreach (var excellentOption in excellentOptions)
                {
                    var optionLink = new ItemOptionLink {
                        ItemOption = excellentOption
                    };
                    item.ItemOptions.Add(optionLink);
                    appliedOptions++;
                }

                // every excellent item has skill (if is in item definition)
                item.HasSkill = appliedOptions > default(ushort) && item.Definition.Skill != null;
            }
        }
示例#10
0
        /// <summary>
        /// Gets a random ancient item.
        /// </summary>
        /// <returns>A random ancient item.</returns>
        protected Item GetRandomAncient()
        {
            Item item = new TemporaryItem();

            item.Definition = this.ancientItems.SelectRandom(this.randomizer);
            this.ApplyRandomOptions(item);
            var itemDef = item.Definition;

            if (itemDef.Skill != null && item.Definition.QualifiedCharacters.Any())
            {
                item.HasSkill = true;
            }

            var ancientSet = item.ItemSetGroups.Where(g => g.Options.Any(o => o.OptionType == ItemOptionTypes.AncientOption)).SelectRandom(this.randomizer);

            item.ItemSetGroups.Add(ancientSet);
            var bonusOption     = ancientSet.Items.First(i => i.ItemDefinition == item.Definition).BonusOption; // for example: +5str or +10str
            var bonusOptionLink = new ItemOptionLink();

            bonusOptionLink.ItemOption = bonusOption;
            bonusOptionLink.Level      = bonusOption.LevelDependentOptions.Select(o => o.Level).SelectRandom();
            item.ItemOptions.Add(bonusOptionLink);
            return(item);
        }
示例#11
0
        private static Item CreateItem(Player player, Arguments arguments)
        {
            var item           = new TemporaryItem();
            var itemDefinition = player.GameContext.Configuration.Items.FirstOrDefault(def => def.Group == arguments.Group && def.Number == arguments.Number);

            if (itemDefinition == null)
            {
                throw new ArgumentException($"[GM][/item] {arguments.Group} {arguments.Number} does not exists");
            }

            item.Definition = itemDefinition;
            item.Level      = arguments.Level;
            item.Durability = itemDefinition.Durability;
            item.HasSkill   = itemDefinition.Skill != null && arguments.Skill;

            if (arguments.Opt > 0)
            {
                var optionLink = new ItemOptionLink
                {
                    ItemOption = item.Definition.PossibleItemOptions.SelectMany(o => o.PossibleOptions)
                                 .First(o => o.OptionType == ItemOptionTypes.Option),
                    Level = arguments.Opt,
                };
                item.ItemOptions.Add(optionLink);
            }

            if (arguments.Luck)
            {
                var optionLink = new ItemOptionLink
                {
                    ItemOption = item.Definition.PossibleItemOptions.SelectMany(o => o.PossibleOptions)
                                 .First(o => o.OptionType == ItemOptionTypes.Luck),
                };
                item.ItemOptions.Add(optionLink);
            }

            if (arguments.Exc > 0)
            {
                var excellentOptions = item.Definition.PossibleItemOptions.SelectMany(o => o.PossibleOptions)
                                       .Where(o => o.OptionType == ItemOptionTypes.Excellent)
                                       .Where(o => (o.Number & arguments.Exc) > 0);
                var appliedOptions = 0;

                excellentOptions.ForEach(option =>
                {
                    var optionLink = new ItemOptionLink
                    {
                        ItemOption = option,
                    };
                    item.ItemOptions.Add(optionLink);
                    appliedOptions++;
                });

                // every excellent item has skill (if is in item definition)
                if (appliedOptions > 0 && itemDefinition.Skill != null)
                {
                    item.HasSkill = true;
                }
            }

            return(item);
        }
示例#12
0
        private static Item CreateItem(Player player, Arguments arguments)
        {
            var item           = new TemporaryItem();
            var itemDefinition = player.GameContext.Configuration.Items.FirstOrDefault(def => def.Group == arguments.Group && def.Number == arguments.Number);

            if (itemDefinition is null)
            {
                throw new ArgumentException($"[GM][/item] {arguments.Group} {arguments.Number} does not exist.");
            }

            if (arguments.Level > itemDefinition.MaximumItemLevel)
            {
                throw new ArgumentException($"[GM][/item] Level cannot be greater than {itemDefinition.MaximumItemLevel}.");
            }

            item.Definition = itemDefinition;
            item.Level      = arguments.Level;
            item.Durability = itemDefinition.Durability;
            item.HasSkill   = itemDefinition.Skill != null && arguments.Skill;

            if (arguments.Opt > 0)
            {
                var optionLink = new ItemOptionLink
                {
                    ItemOption = item.Definition.PossibleItemOptions.SelectMany(o => o.PossibleOptions)
                                 .First(o => o.OptionType == ItemOptionTypes.Option),
                    Level = arguments.Opt,
                };
                item.ItemOptions.Add(optionLink);
            }

            if (arguments.Luck)
            {
                var optionLink = new ItemOptionLink
                {
                    ItemOption = item.Definition.PossibleItemOptions.SelectMany(o => o.PossibleOptions)
                                 .First(o => o.OptionType == ItemOptionTypes.Luck),
                };
                item.ItemOptions.Add(optionLink);
            }

            if (arguments.Exc > 0)
            {
                var excellentOptions = item.Definition.PossibleItemOptions.SelectMany(o => o.PossibleOptions)
                                       .Where(o => o.OptionType == ItemOptionTypes.Excellent)
                                       .Where(o => (o.Number & arguments.Exc) > 0);
                var appliedOptions = 0;

                excellentOptions.ForEach(option =>
                {
                    var optionLink = new ItemOptionLink
                    {
                        ItemOption = option,
                    };
                    item.ItemOptions.Add(optionLink);
                    appliedOptions++;
                });

                // every excellent item has skill (if is in item definition)
                if (appliedOptions > 0 && itemDefinition.Skill != null)
                {
                    item.HasSkill = true;
                }
            }

            if (arguments.Ancient > 0 &&
                item.Definition.PossibleItemSetGroups.FirstOrDefault(set => set.AncientSetDiscriminator == arguments.Ancient) is { } ancientSet &&
                ancientSet.Items.FirstOrDefault(i => i.ItemDefinition == item.Definition) is { } itemOfItemSet)
            {
                var optionLink = new ItemOptionLink
                {
                    ItemOption = itemOfItemSet.BonusOption,
                    Level      = arguments.AncientBonusLevel,
                };
                item.ItemOptions.Add(optionLink);
                item.ItemSetGroups.Add(ancientSet);
            }

            item.SocketCount = item.Definition.MaximumSockets;

            return(item);
        }
示例#13
0
        private void CheckPrice(byte id, byte dropLevel, byte maxDurability, byte height, byte width, byte group, int value, byte level, long price, bool luck = false, bool option = false, bool skill = false)
        {
            var itemDefinitionMock = new Mock <ItemDefinition>();

            itemDefinitionMock.SetupAllProperties();
            itemDefinitionMock.Setup(d => d.BasePowerUpAttributes).Returns(new List <ItemBasePowerUpDefinition>());

            var itemDefinition = itemDefinitionMock.Object;

            itemDefinition.DropLevel  = dropLevel;
            itemDefinition.Durability = maxDurability;
            itemDefinition.Height     = height;
            itemDefinition.Width      = width;
            itemDefinition.Group      = group;
            itemDefinition.Value      = value;
            itemDefinition.Number     = id;
            if (group <= 11)
            {
                itemDefinition.ItemSlot = new ItemSlotType();
            }

            if (group < 6)
            {
                // weapons should have a min dmg attribute
                itemDefinition.BasePowerUpAttributes.Add(new ItemBasePowerUpDefinition {
                    TargetAttribute = Stats.MinimumPhysBaseDmg
                });
            }

            var itemMock = new Mock <Item>();

            itemMock.SetupAllProperties();
            itemMock.Setup(i => i.ItemOptions).Returns(new List <ItemOptionLink>());
            var item = itemMock.Object;

            item.Definition = itemDefinition;
            item.Level      = level;
            item.Durability = Math.Max(item.GetMaximumDurabilityOfOnePiece(), maxDurability);

            if (luck)
            {
                var optionLink = new ItemOptionLink
                {
                    ItemOption = new IncreasableItemOption
                    {
                        OptionType = ItemOptionTypes.Luck,
                    },
                };
                item.ItemOptions.Add(optionLink);
            }

            if (option)
            {
                var optionLink = new ItemOptionLink
                {
                    ItemOption = new IncreasableItemOption
                    {
                        OptionType = ItemOptionTypes.Option,
                    },
                    Level = 1,
                };
                item.ItemOptions.Add(optionLink);
            }

            if (skill)
            {
                item.HasSkill = true;
            }

            var buyingPrice = this.calculator.CalculateBuyingPrice(item);

            Assert.That(buyingPrice, Is.EqualTo(price));
        }