示例#1
0
        private static void AddCustomEquipment(
            AvatarState avatarState,
            IRandom random,
            SkillSheet skillSheet,
            EquipmentItemSheet equipmentItemSheet,
            EquipmentItemOptionSheet equipmentItemOptionSheet,
            int level,
            int recipeId,
            params int[] optionIds
            )
        {
            if (!equipmentItemSheet.TryGetValue(recipeId, out var equipmentRow))
            {
                return;
            }

            var itemId     = random.GenerateRandomGuid();
            var equipment  = (Equipment)ItemFactory.CreateItemUsable(equipmentRow, itemId, 0, level);
            var optionRows = new List <EquipmentItemOptionSheet.Row>();

            foreach (var optionId in optionIds)
            {
                if (!equipmentItemOptionSheet.TryGetValue(optionId, out var optionRow))
                {
                    continue;
                }
                optionRows.Add(optionRow);
            }

            AddOption(skillSheet, equipment, optionRows, random);

            avatarState.inventory.AddItem2(equipment);
        }
        public static HashSet <int> SelectOption(
            EquipmentItemOptionSheet optionSheet,
            SkillSheet skillSheet,
            EquipmentItemSubRecipeSheet.Row subRecipe,
            IRandom random,
            Equipment equipment
            )
        {
            var optionSelector = new WeightedSelector <EquipmentItemOptionSheet.Row>(random);
            var optionIds      = new HashSet <int>();

            // Skip sort subRecipe.Options because it had been already sorted in WeightedSelector.Select();
            foreach (var optionInfo in subRecipe.Options)
            {
                if (!optionSheet.TryGetValue(optionInfo.Id, out var optionRow))
                {
                    continue;
                }

                optionSelector.Add(optionRow, optionInfo.Ratio);
            }

            IEnumerable <EquipmentItemOptionSheet.Row> optionRows =
                new EquipmentItemOptionSheet.Row[0];

            try
            {
                optionRows = optionSelector.SelectV3(subRecipe.MaxOptionLimit);
            }
            catch (Exception e) when(
                e is InvalidCountException ||
                e is ListEmptyException
                )
            {
                return(optionIds);
            }
            finally
            {
                foreach (var optionRow in optionRows.OrderBy(r => r.Id))
                {
                    if (optionRow.StatType != StatType.NONE)
                    {
                        var statMap = GetStat(optionRow, random);
                        equipment.StatsMap.AddStatAdditionalValue(statMap.StatType, statMap.Value);
                    }
                    else
                    {
                        var skill = GetSkill(optionRow, skillSheet, random);
                        if (!(skill is null))
                        {
                            equipment.Skills.Add(skill);
                        }
                    }

                    optionIds.Add(optionRow.Id);
                }
            }

            return(optionIds);
        }
示例#3
0
        public static void AddAndUnlockOption(
            AgentState agentState,
            Equipment equipment,
            IRandom random,
            EquipmentItemSubRecipeSheetV2.Row subRecipe,
            EquipmentItemOptionSheet optionSheet,
            SkillSheet skillSheet
            )
        {
            foreach (var optionInfo in subRecipe.Options
                     .OrderByDescending(e => e.Ratio)
                     .ThenBy(e => e.RequiredBlockIndex)
                     .ThenBy(e => e.Id))
            {
                if (!optionSheet.TryGetValue(optionInfo.Id, out var optionRow))
                {
                    continue;
                }

                var value = random.Next(1, GameConfig.MaximumProbability + 1);
                if (value > optionInfo.Ratio)
                {
                    continue;
                }

                if (optionRow.StatType != StatType.NONE)
                {
                    var statMap = CombinationEquipment5.GetStat(optionRow, random);
                    equipment.StatsMap.AddStatAdditionalValue(statMap.StatType, statMap.Value);
                    equipment.Update(equipment.RequiredBlockIndex + optionInfo.RequiredBlockIndex);
                    equipment.optionCountFromCombination++;
                    agentState.unlockedOptions.Add(optionRow.Id);
                }
                else
                {
                    var skill = CombinationEquipment5.GetSkill(optionRow, skillSheet, random);
                    if (!(skill is null))
                    {
                        equipment.Skills.Add(skill);
                        equipment.Update(equipment.RequiredBlockIndex + optionInfo.RequiredBlockIndex);
                        equipment.optionCountFromCombination++;
                        agentState.unlockedOptions.Add(optionRow.Id);
                    }
                }
            }
        }
示例#4
0
        public static void AddItem(CostumeItemSheet costumeItemSheet,
                                   EquipmentItemSheet equipmentItemSheet,
                                   EquipmentItemOptionSheet optionSheet,
                                   SkillSheet skillSheet,
                                   MaterialItemSheet materialItemSheet,
                                   ConsumableItemSheet consumableItemSheet,
                                   IRandom random,
                                   Item item,
                                   AddedItemInfo addedItemInfo,
                                   AvatarState avatarState)
        {
            switch (item.ItemSubType)
            {
            case ItemSubType.FullCostume:
            case ItemSubType.HairCostume:
            case ItemSubType.EarCostume:
            case ItemSubType.EyeCostume:
            case ItemSubType.TailCostume:
            case ItemSubType.Title:
                if (costumeItemSheet.TryGetValue(item.ID, out var costumeRow))
                {
                    var costume =
                        ItemFactory.CreateCostume(costumeRow, addedItemInfo.TradableId);
                    avatarState.inventory.AddItem(costume);
                }

                break;

            case ItemSubType.Weapon:
            case ItemSubType.Armor:
            case ItemSubType.Belt:
            case ItemSubType.Necklace:
            case ItemSubType.Ring:
                if (equipmentItemSheet.TryGetValue(item.ID, out var equipmentRow))
                {
                    var equipment = (Equipment)ItemFactory.CreateItemUsable(equipmentRow,
                                                                            addedItemInfo.TradableId,
                                                                            0,
                                                                            item.Level);

                    if (item.OptionIds.Length > 0)
                    {
                        var optionRows = new List <EquipmentItemOptionSheet.Row>();
                        foreach (var optionId in item.OptionIds)
                        {
                            if (!optionSheet.TryGetValue(optionId, out var optionRow))
                            {
                                continue;
                            }

                            optionRows.Add(optionRow);
                        }

                        AddOption(skillSheet, equipment, optionRows, random);
                    }

                    avatarState.inventory.AddItem(equipment);
                }

                break;

            case ItemSubType.Hourglass:
            case ItemSubType.ApStone:
                if (materialItemSheet.TryGetValue(item.ID, out var materialRow))
                {
                    var material = ItemFactory.CreateTradableMaterial(materialRow);
                    avatarState.inventory.AddItem(material, item.Count);
                    addedItemInfo.TradableId = material.TradableId;
                }

                break;

            case ItemSubType.Food:
                if (consumableItemSheet.TryGetValue(item.ID, out var consumableRow))
                {
                    var consumable = (Consumable)ItemFactory.CreateItemUsable(consumableRow,
                                                                              addedItemInfo.TradableId,
                                                                              0,
                                                                              item.Level);
                    avatarState.inventory.AddItem(consumable);
                }

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }