Пример #1
0
        private void Awake()
        {
            _magicRarityColor           = Config.Bind("Item Colors", "Magic Rarity Color", "Blue", "The color of Magic rarity items, the lowest magic item tier. (Optional, use an HTML hex color starting with # to have a custom color.) Available options: Red, Orange, Yellow, Green, Teal, Blue, Indigo, Purple, Pink, Gray");
            _magicMaterialIconColor     = Config.Bind("Item Colors", "Magic Crafting Material Icon Index", 5, "Indicates the color of the icon used for magic crafting materials. A number between 0 and 9. Available options: 0=Red, 1=Orange, 2=Yellow, 3=Green, 4=Teal, 5=Blue, 6=Indigo, 7=Purple, 8=Pink, 9=Gray");
            _rareRarityColor            = Config.Bind("Item Colors", "Rare Rarity Color", "Yellow", "The color of Rare rarity items, the second magic item tier. (Optional, use an HTML hex color starting with # to have a custom color.) Available options: Red, Orange, Yellow, Green, Teal, Blue, Indigo, Purple, Pink, Gray");
            _rareMaterialIconColor      = Config.Bind("Item Colors", "Rare Crafting Material Icon Index", 2, "Indicates the color of the icon used for rare crafting materials. A number between 0 and 9. Available options: 0=Red, 1=Orange, 2=Yellow, 3=Green, 4=Teal, 5=Blue, 6=Indigo, 7=Purple, 8=Pink, 9=Gray");
            _epicRarityColor            = Config.Bind("Item Colors", "Epic Rarity Color", "Purple", "The color of Epic rarity items, the third magic item tier. (Optional, use an HTML hex color starting with # to have a custom color.) Available options: Red, Orange, Yellow, Green, Teal, Blue, Indigo, Purple, Pink, Gray");
            _epicMaterialIconColor      = Config.Bind("Item Colors", "Epic Crafting Material Icon Index", 7, "Indicates the color of the icon used for epic crafting materials. A number between 0 and 9. Available options: 0=Red, 1=Orange, 2=Yellow, 3=Green, 4=Teal, 5=Blue, 6=Indigo, 7=Purple, 8=Pink, 9=Gray");
            _legendaryRarityColor       = Config.Bind("Item Colors", "Legendary Rarity Color", "Teal", "The color of Legendary rarity items, the highest magic item tier. (Optional, use an HTML hex color starting with # to have a custom color.) Available options: Red, Orange, Yellow, Green, Teal, Blue, Indigo, Purple, Pink, Gray");
            _legendaryMaterialIconColor = Config.Bind("Item Colors", "Legendary Crafting Material Icon Index", 4, "Indicates the color of the icon used for legendary crafting materials. A number between 0 and 9. Available options: 0=Red, 1=Orange, 2=Yellow, 3=Green, 4=Teal, 5=Blue, 6=Indigo, 7=Purple, 8=Pink, 9=Gray");
            _setItemColor                = Config.Bind("Item Colors", "Set Item Color", "#26ffff", "The color of set item text and the set item icon. Use a hex color, default is cyan");
            _magicRarityDisplayName      = Config.Bind("Rarity", "Magic Rarity Display Name", "Magic", "The name of the lowest rarity.");
            _rareRarityDisplayName       = Config.Bind("Rarity", "Rare Rarity Display Name", "Rare", "The name of the second rarity.");
            _epicRarityDisplayName       = Config.Bind("Rarity", "Epic Rarity Display Name", "Epic", "The name of the third rarity.");
            _legendaryRarityDisplayName  = Config.Bind("Rarity", "Legendary Rarity Display Name", "Legendary", "The name of the highest rarity.");
            UseScrollingCraftDescription = Config.Bind("Crafting UI", "Use Scrolling Craft Description", true, "Changes the item description in the crafting panel to scroll instead of scale when it gets too long for the space.");
            _gatedItemTypeModeConfig     = Config.Bind("Balance", "Item Drop Limits", GatedItemTypeMode.MustKnowRecipe, "Sets how the drop system limits what item types can drop. Unlimited: no limits, exactly what's in the loot table will drop. MustKnowRecipe: items will drop so long as the player has discovered their recipe. MustHaveCrafted: items will only drop once the player has crafted one or picked one up. If an item type cannot drop, it will downgrade to an item of the same type and skill that the player has unlocked (i.e. swords will stay swords)");

            MagicItemEffectDefinitions.Initialize(LoadJsonFile <MagicItemEffectsList>("magiceffects.json"));
            LootRoller.Initialize(LoadJsonFile <LootConfig>("loottables.json"));
            GatedItemTypeHelper.Initialize(LoadJsonFile <ItemInfoConfig>("iteminfo.json"));
            RecipesHelper.Initialize(LoadJsonFile <RecipesConfig>("recipes.json"));
            PrintInfo();

            LoadAssets();

            ExtendedItemData.LoadExtendedItemData += SetupTestMagicItem;
            ExtendedItemData.LoadExtendedItemData += MagicItemComponent.OnNewExtendedItemData;
            ExtendedItemData.NewExtendedItemData  += MagicItemComponent.OnNewExtendedItemData;

            _harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), PluginId);

            LootTableLoaded?.Invoke();
        }
Пример #2
0
        public static void TryRegisterRecipes()
        {
            if (!IsObjectDBReady())
            {
                return;
            }

            RecipesHelper.SetupRecipes();
        }
Пример #3
0
 public static void InitializeConfig()
 {
     LootRoller.Initialize(_lootConfigFile.Value);
     MagicItemEffectDefinitions.Initialize(_magicEffectsConfigFile.Value);
     GatedItemTypeHelper.Initialize(_itemInfoConfigFile.Value);
     RecipesHelper.Initialize(_recipesConfigFile.Value);
     EnchantCostsHelper.Initialize(_enchantCostsConfigFile.Value);
     MagicItemNames.Initialize(_itemNamesConfigFile.Value);
     AdventureDataManager.Initialize(_adventureDataConfigFile.Value);
 }
Пример #4
0
        public ViewModelRecipeBreakdown(Recipe recipe)
        {
            var inputItems          = new List <ProtoItemWithCountFractional>();
            var outputItems         = new List <ProtoItemWithCountFractional>();
            var outputItemsExtras   = new List <ProtoItemWithCountFractional>();
            var intermediateRecipes = new List <ViewModelIntermediateRecipe>();
            var inputNutrition      = new NutritionValueInfo();
            var outputNutrition     = new NutritionValueInfo();

            var multiplier = 1 / (double)recipe.OutputItems.Items[0].Count;
            var isOriginalRecipeManufacturing = recipe.RecipeType == RecipeType.Manufacturing ||
                                                recipe.RecipeType == RecipeType.ManufacturingByproduct;

            var    originalRecipeDurationPerItem = recipe.OriginalDuration * multiplier;
            double specificDurationCrafting,
                   specificDurationManufacturing;

            if (isOriginalRecipeManufacturing)
            {
                specificDurationCrafting      = 0;
                specificDurationManufacturing = originalRecipeDurationPerItem;
            }
            else
            {
                specificDurationCrafting      = originalRecipeDurationPerItem;
                specificDurationManufacturing = 0;
            }

            var timeSb = new StringBuilder()
                         .AppendLine($"{recipe.Name} — per single item:")
                         .AppendLine();
            var recursiveErrorsSb = new StringBuilder();
            var tag = isOriginalRecipeManufacturing ? "[manufacture]" : "[craft]";

            timeSb.AppendLine($"{tag} {originalRecipeDurationPerItem:0.##}s — x{multiplier:0.##} {recipe.Name}");

            foreach (var outputItem in recipe.OutputItems.Items)
            {
                var entry = new ProtoItemWithCountFractional(outputItem.ProtoItem,
                                                             outputItem.Count * multiplier);
                outputItems.Add(entry);
                outputNutrition.TryAdd(entry);
            }

            ProcessInputRecursive(recipe, multiplier, depth: 0);

            inputItems.Sort(ListOrderComparison);
            outputItems.Sort(ListOrderComparison);
            outputItemsExtras.Sort(ListOrderComparison);

            this.InputItems          = inputItems;
            this.OutputItems         = outputItems;
            this.OutputItemsExtras   = outputItemsExtras;
            this.IntermediateRecipes = intermediateRecipes;

            this.InputTotalNutritionValue  = inputNutrition;
            this.OutputTotalNutritionValue = outputNutrition;

            this.RecipesDurationTotalText = ClientTimeFormatHelper.FormatTimeDuration(
                specificDurationCrafting,
                roundSeconds: false)
                                            + " + "
                                            + ClientTimeFormatHelper.FormatTimeDuration(
                specificDurationManufacturing,
                roundSeconds: false);

            timeSb.AppendLine()
            .AppendLine($"Total duration: {this.RecipesDurationTotalText} (crafting + manufacturing)");
            this.recipeTimeCalculation = timeSb.ToString().Trim('\r', '\n');

            this.RecursiveErrors = recursiveErrorsSb.Length > 0
                                       ? "Nested recipes recursion detected."
                                   + Environment.NewLine
                                   + "Recursion was broken when looking for recipes for these item(s):"
                                   + Environment.NewLine
                                   + recursiveErrorsSb
                                   + Environment.NewLine
                                   + "Intermediate recipes list:"
                                   + string.Join("",
                                                 this.IntermediateRecipes.Select(
                                                     r => Environment.NewLine
                                                     + "* "
                                                     + r.ViewModelCraftingRecipe.Title))
                                   + Environment.NewLine
                                   + Environment.NewLine
                                   + $"Please edit {nameof(BasicItems)} or {nameof(RecipesHelper.BlacklistRecipes)} lists in {nameof(ViewModelRecipeBreakdown)}.cs (Editor.mpk)"
                                       : null;

            void ProcessInputRecursive(Recipe outerRecipe, double outerMultiplier, int depth)
            {
                foreach (var inputItem in outerRecipe.InputItems)
                {
                    if (BasicItems.Contains(inputItem.ProtoItem.GetType()))
                    {
                        // don't lookup recipe
                        var entry = new ProtoItemWithCountFractional(inputItem.ProtoItem,
                                                                     inputItem.Count * outerMultiplier);
                        AddListEntry(inputItems, entry);
                        inputNutrition.TryAdd(entry);
                        continue;
                    }

                    var inputItemRecipe = RecipesHelper.FindFirstRecipe(inputItem.ProtoItem);
                    if (inputItemRecipe == null)
                    {
                        // no recipe
                        var entry = new ProtoItemWithCountFractional(inputItem.ProtoItem,
                                                                     inputItem.Count * outerMultiplier);
                        AddListEntry(inputItems, entry);
                        inputNutrition.TryAdd(entry);
                        continue;
                    }

                    if (depth > 20)
                    {
                        // recursion went too deep, stop here
                        recursiveErrorsSb.AppendLine("* " + inputItem.ProtoItem.Name);
                        return;
                    }

                    // expand recipe
                    var recipeMultiplier = inputItem.Count / (double)inputItemRecipe.OutputItems.Items[0].Count;
                    AddIntermediateRecipe(intermediateRecipes,
                                          inputItemRecipe,
                                          recipeMultiplier * outerMultiplier);

                    ProcessInputRecursive(inputItemRecipe,
                                          recipeMultiplier * outerMultiplier,
                                          depth: depth + 1);

                    var isManufacturing = inputItemRecipe.RecipeType == RecipeType.Manufacturing ||
                                          inputItemRecipe.RecipeType == RecipeType.ManufacturingByproduct;
                    var inputItemRecipeDuration = inputItemRecipe.OriginalDuration
                                                  * recipeMultiplier
                                                  * outerMultiplier;

                    if (isManufacturing)
                    {
                        specificDurationManufacturing += inputItemRecipeDuration;
                    }
                    else
                    {
                        specificDurationCrafting += inputItemRecipeDuration;
                    }

                    var tag = isManufacturing ? "[manufacture]" : "[craft]";
                    timeSb.AppendLine(
                        $"{tag} {ClientTimeFormatHelper.FormatTimeDuration(inputItemRecipeDuration, roundSeconds: true)} — x{recipeMultiplier * outerMultiplier:0.##} {inputItemRecipe.Name} (for {outerRecipe.Name})");

                    foreach (var outputItem in inputItemRecipe.OutputItems.Items)
                    {
                        if (outputItem.ProtoItem == inputItem.ProtoItem)
                        {
                            continue;
                        }

                        var entry = new ProtoItemWithCountFractional(outputItem.ProtoItem,
                                                                     outputItem.Count
                                                                     * recipeMultiplier
                                                                     * outerMultiplier);
                        AddListEntry(outputItemsExtras, entry);
                        outputNutrition.TryAdd(entry);
                    }
                }
            }
        }