Exemplo n.º 1
0
    public SpaceCoreRecipe(string name, CustomCraftingRecipe recipe, bool cooking, ModEntry mod)
    {
        Recipe  = recipe;
        Cooking = cooking;
        Name    = name;

        Ingredients = recipe.Ingredients.Select <CustomCraftingRecipe.IngredientMatcher, IIngredient>(val => {
            Type type  = val.GetType();
            string cls = type.FullName ?? type.Name;

            // Check for known classes that implement ingredient matchers that
            // we can use our own logic for.
            if (cls.Equals("SpaceCore.CustomCraftingRecipe+ObjectIngredientMatcher"))
            {
                int?index = mod.Helper.Reflection.GetField <int>(val, "objectIndex", false)?.GetValue();
                if (index.HasValue)
                {
                    return(mod.API !.CreateBaseIngredient(index.Value, val.Quantity));
                }
            }
            else if (cls.Equals("DynamicGameAssets.DGACustomCraftingRecipe+DGAIngredientMatcher"))
            {
                var matcher = mod.Helper.Reflection.GetMethod(val, "ItemMatches", false);
                if (matcher != null)
                {
                    bool Match(Item item)
                    {
                        try {
                            return(matcher.Invoke <bool>(item));
                        } catch {
                            return(false);
                        }
                    }

                    return(mod.API !.CreateMatcherIngredient(
                               Match,
                               val.Quantity,
                               val.DispayName,
                               val.IconTexture,
                               val.IconSubrect ?? val.IconTexture.Bounds
                               ));
                }
            }

            // If it's not a specific, known class then we can't guarantee our
            // logic is correct, so fall back to just wrapping SpaceCore's
            // ingredients.
            return(new SpaceCoreIngredient(val));
        }).ToArray();

        Item?example = CreateItem();

        SortValue        = example?.ParentSheetIndex ?? 0;
        QuantityPerCraft = example?.Stack ?? 1;
        Stackable        = (example?.maximumStackSize() ?? 1) > 1;
    }
Exemplo n.º 2
0
        private static bool CraftingPage_layoutRecipes_Prefix(CraftingPage __instance, List <string> playerRecipes)
        {
            int craftingPageX             = __instance.xPositionOnScreen + IClickableMenu.spaceToClearSideBorder + IClickableMenu.borderWidth - 16;
            int spaceBetweenCraftingIcons = 8;
            Dictionary <ClickableTextureComponent, CraftingRecipe> currentPage = Helper.GetHelper().Reflection.GetMethod(__instance, "createNewPage").Invoke <Dictionary <ClickableTextureComponent, CraftingRecipe> >();
            int x = 0;
            int y = 0;
            int i = 0;

            ClickableTextureComponent[,] pageLayout = Helper.GetHelper().Reflection.GetMethod(__instance, "createNewPageLayout").Invoke <ClickableTextureComponent[, ]>();
            List <ClickableTextureComponent[, ]> pageLayouts = new List <ClickableTextureComponent[, ]>();

            pageLayouts.Add(pageLayout);
            foreach (string playerRecipe in playerRecipes)
            {
                i++;
                CraftingRecipe recipe;
                if (IsModdedRecipe(playerRecipe))
                {
                    recipe = new CustomCraftingRecipe(playerRecipe, false);
                }
                else
                {
                    recipe = new CraftingRecipe(playerRecipe, false);
                }
                while (Helper.GetHelper().Reflection.GetMethod(__instance, "spaceOccupied").Invoke <bool>(pageLayout, x, y, recipe))
                {
                    x++;
                    if (x >= 10)
                    {
                        x = 0;
                        y++;
                        if (y >= 4)
                        {
                            currentPage = Helper.GetHelper().Reflection.GetMethod(__instance,
                                                                                  "createNewPage").Invoke <Dictionary <ClickableTextureComponent, CraftingRecipe> >();
                            pageLayout = Helper.GetHelper().Reflection.GetMethod(__instance,
                                                                                 "createNewPageLayout").Invoke <ClickableTextureComponent[, ]>();
                            pageLayouts.Add(pageLayout);
                            x = 0;
                            y = 0;
                        }
                    }
                }
                int id = 200 + i;
                ClickableTextureComponent component;
                if (IsModdedRecipe(playerRecipe))
                {
                    recipe    = new CustomCraftingRecipe(playerRecipe, false);
                    component = new ClickableTextureComponent
                                    ("",
                                    new Rectangle(craftingPageX + x * (64 + spaceBetweenCraftingIcons), Helper.GetHelper().Reflection.GetMethod(__instance, "craftingPageY").Invoke <int>() + y * 72, 64, recipe.bigCraftable ? 128 : 64),
                                    null,
                                    (false && !Game1.player.cookingRecipes.ContainsKey(recipe.name)) ? "ghosted" : "",
                                    DataAccess.GetDataAccess().Sprites[Utilities.GetIDName(playerRecipe) + "_Item"],
                                    recipe.bigCraftable ? new Rectangle(0, 0, 16, 32) : new Rectangle(0, 0, 16, 16),
                                    4f)
                    {
                        myID            = id,
                        rightNeighborID = -99998,
                        leftNeighborID  = -99998,
                        upNeighborID    = -99998,
                        downNeighborID  = -99998,
                        fullyImmutable  = true,
                        region          = 8000
                    };
                }
                else
                {
                    component = new ClickableTextureComponent
                                    ("",
                                    new Rectangle(craftingPageX + x * (64 + spaceBetweenCraftingIcons), Helper.GetHelper().Reflection.GetMethod(__instance, "craftingPageY").Invoke <int>() + y * 72, 64, recipe.bigCraftable ? 128 : 64),
                                    null,
                                    (false && !Game1.player.cookingRecipes.ContainsKey(recipe.name)) ? "ghosted" : "",
                                    recipe.bigCraftable ? Game1.bigCraftableSpriteSheet : Game1.objectSpriteSheet,
                                    recipe.bigCraftable ? Game1.getArbitrarySourceRect(Game1.bigCraftableSpriteSheet, 16, 32, recipe.getIndexOfMenuView()) : Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, recipe.getIndexOfMenuView(), 16, 16),
                                    4f)
                    {
                        myID            = id,
                        rightNeighborID = -99998,
                        leftNeighborID  = -99998,
                        upNeighborID    = -99998,
                        downNeighborID  = -99998,
                        fullyImmutable  = true,
                        region          = 8000
                    };
                }
                currentPage.Add(component, recipe);
                pageLayout[x, y] = component;
                if (recipe.bigCraftable)
                {
                    pageLayout[x, y + 1] = component;
                }
            }
            return(false);
        }