Exemplo n.º 1
0
        public override void Unload()
        {
            if (!Main.dedServ)
            {
                concurrentTaskHandlerToken?.Cancel();
                concurrentTaskHandler?.Wait();
            }
            instance                   = null;
            translations               = null;
            itemChecklistInstance      = null;
            LootCache.instance         = null;
            ToggleRecipeBrowserHotKey  = null;
            QueryHoveredItemHotKey     = null;
            RecipeBrowserUI.instance   = null;
            RecipeCatalogueUI.instance = null;
            ItemCatalogueUI.instance   = null;
            BestiaryUI.instance        = null;
            CraftUI.instance           = null;
            RecipePath.Refresh(true);
            RecipeBrowserPlayer.seenTiles = null;

            UIElements.UIRecipeSlot.favoritedBackgroundTexture           = null;
            UIElements.UIRecipeSlot.selectedBackgroundTexture            = null;
            UIElements.UIRecipeSlot.ableToCraftBackgroundTexture         = null;
            UIElements.UIRecipeSlot.ableToCraftExtendedBackgroundTexture = null;
            UIElements.UIMockRecipeSlot.ableToCraftBackgroundTexture     = null;
            UIElements.UICheckbox.checkboxTexture  = null;
            UIElements.UICheckbox.checkmarkTexture = null;
            UIHorizontalGrid.moreLeftTexture       = null;
            UIHorizontalGrid.moreRightTexture      = null;
            Utilities.tileTextures = null;
        }
Exemplo n.º 2
0
        public override void Unload()
        {
            instance                   = null;
            translations               = null;
            itemChecklistInstance      = null;
            LootCache.instance         = null;
            ToggleRecipeBrowserHotKey  = null;
            QueryHoveredItemHotKey     = null;
            RecipeBrowserUI.instance   = null;
            RecipeCatalogueUI.instance = null;
            ItemCatalogueUI.instance   = null;
            BestiaryUI.instance        = null;
            CraftUI.instance           = null;
            RecipePath.Refresh(true);
            RecipeBrowserPlayer.seenTiles = null;

            UIElements.UIRecipeSlot.favoritedBackgroundTexture           = null;
            UIElements.UIRecipeSlot.selectedBackgroundTexture            = null;
            UIElements.UIRecipeSlot.ableToCraftBackgroundTexture         = null;
            UIElements.UIRecipeSlot.ableToCraftExtendedBackgroundTexture = null;
            UIElements.UIMockRecipeSlot.ableToCraftBackgroundTexture     = null;
            UIElements.UICheckbox.checkboxTexture  = null;
            UIElements.UICheckbox.checkmarkTexture = null;
            UIHorizontalGrid.moreLeftTexture       = null;
            UIHorizontalGrid.moreRightTexture      = null;
            Utilities.tileTextures = null;

            if (harmonyInstance != null)
            {
                harmonyInstance.UnpatchAll(HarmonyID);
            }
        }
Exemplo n.º 3
0
            public RecipeNode(Recipe recipe, int multiplier, int ChildNumber, CraftPathNode parent, CraftPath craftPath) : base(ChildNumber, parent, craftPath)
            {
                this.recipe     = recipe;
                this.multiplier = multiplier;
                children        = new CraftPathNode[recipe.requiredItem.Count(x => !x.IsAir)];

                List <int> groups = RecipePath.GetAcceptedGroups(recipe);

                for (int i = 0; i < children.Length; i++)                 // For Each Ingredient.
                {
                    bool itemIsRecipeGroupItem = false;
                    foreach (var groupid in groups)
                    {
                        // 6 wood, 4 shadewood works for 10 any wood.

                        // multiplier assumes all same Item in ItemGroup used for all Recipes.
                        if (recipe.requiredItem[i].type == RecipeGroup.recipeGroups[groupid].ValidItems[RecipeGroup.recipeGroups[groupid].IconicItemIndex])
                        {
                            bool foundValidItem   = false;
                            bool foundPartialItem = false;
                            foreach (var validItemID in RecipeGroup.recipeGroups[groupid].ValidItems)
                            {
                                if (craftPath.haveItems.ContainsKey(validItemID) && craftPath.haveItems[validItemID] >= recipe.requiredItem[i].stack * multiplier)
                                {
                                    // Any Wood on left, Wood on Right problem. Wood could be consumed before Wood node, when ShadeWood would be better option.
                                    children[i]    = new HaveItemNode(validItemID, recipe.requiredItem[i].stack * multiplier, i, this, craftPath);
                                    foundValidItem = true;
                                    break;
                                }
                                else if (craftPath.haveItems.ContainsKey(validItemID))
                                {
                                    foundPartialItem = true;
                                }
                            }
                            if (!foundValidItem && foundPartialItem)
                            {
                                List <Tuple <int, int> > listOfItems = new List <Tuple <int, int> >();
                                int remaining = recipe.requiredItem[i].stack * multiplier;
                                foreach (var validItemID in RecipeGroup.recipeGroups[groupid].ValidItems)
                                {
                                    if (remaining > 0 && craftPath.haveItems.ContainsKey(validItemID))
                                    {
                                        int taken = Math.Min(remaining, craftPath.haveItems[validItemID]);
                                        listOfItems.Add(new Tuple <int, int>(validItemID, taken));
                                        remaining -= taken;
                                    }
                                }
                                children[i] = new HaveItemsNode(RecipeGroup.recipeGroups[groupid], listOfItems, i, this, craftPath);
                                if (remaining > 0)
                                {
                                    children[i].children    = new CraftPathNode[1];
                                    children[i].children[0] = new UnfulfilledNode(RecipeGroup.recipeGroups[groupid], remaining, 0, children[i], craftPath);
                                }
                            }
                            else if (!foundValidItem)
                            {
                                children[i] = new UnfulfilledNode(RecipeGroup.recipeGroups[groupid], recipe.requiredItem[i].stack * multiplier, i, this, craftPath);
                            }
                            itemIsRecipeGroupItem = true;
                            break;
                        }
                    }
                    // Does it make more sense to nest these, or add more children slots? Hm, Children match up to recipe ingredient index.... Make a BranchNode?
                    if (!itemIsRecipeGroupItem)
                    {
                        // Recipe Groups can have stacks-size different inputs if needed. Ignore for now and handle: 10 wood needed, 9 wood held and 2 platforms held.

                        if (craftPath.haveItems.ContainsKey(recipe.requiredItem[i].type) && craftPath.haveItems[recipe.requiredItem[i].type] >= recipe.requiredItem[i].stack * multiplier)
                        {
                            // Potential problem: Recipe with multiple of same item. Or Item and ItemGroup that share.
                            // Could implement consumed flag and attempt to consume immediately.
                            children[i] = new HaveItemNode(recipe.requiredItem[i].type, recipe.requiredItem[i].stack * multiplier, i, this, craftPath);
                        }
                        else
                        {
                            if (craftPath.haveItems.ContainsKey(recipe.requiredItem[i].type))
                            {
                                int remainder = recipe.requiredItem[i].stack * multiplier - craftPath.haveItems[recipe.requiredItem[i].type];
                                children[i]             = new HaveItemNode(recipe.requiredItem[i].type, craftPath.haveItems[recipe.requiredItem[i].type], i, this, craftPath);
                                children[i].children    = new CraftPathNode[1];
                                children[i].children[0] = new UnfulfilledNode(recipe.requiredItem[i].type, remainder, 0, children[i], craftPath);
                            }
                            else
                            {
                                children[i] = new UnfulfilledNode(recipe.requiredItem[i].type, recipe.requiredItem[i].stack * multiplier, i, this, craftPath);                                 // assign current?
                            }
                        }
                    }
                    // TODO: Assign CraftPath.Current to 1st or last unfulfilled
                    // TODO: If Loot and Shop and Missing disabled, check
                    // if (RecipePath.isCraftableOptimization && !ItemCatalogueUI.instance.craftResults[item.Key])
                }
            }