Ejemplo n.º 1
0
    public static bool ConvertAndCraft(Recipe recipe, EntityPlayerLocal player, XUiController ItemController)
    {
        bool result = false;

        XUi xui = ItemController.xui;
        XUiC_CraftingWindowGroup childByType = xui.FindWindowGroupByName("crafting").GetChildByType <XUiC_CraftingWindowGroup>();
        ItemValue itemValue = ((XUiC_ItemStack)ItemController).ItemStack.itemValue;

        if (!CheckIngredients(recipe.ingredients, player))
        {
            return(false);
        }

        // Verify we can craft this.
        if (!recipe.CanCraft(recipe.ingredients, player))
        {
            return(false);
        }

        if (!childByType.AddRepairItemToQueue(recipe.craftingTime, itemValue.Clone(), itemValue.MaxUseTimes))
        {
            WarnQueueFull(player);
            return(false);
        }
        ((XUiC_ItemStack)ItemController).ItemStack = ItemStack.Empty.Clone();
        xui.PlayerInventory.RemoveItems(recipe.ingredients, 1);
        result = true;

        return(result);
    }
        public static bool Prefix(ItemActionEntryRepair __instance)
        {
            // Check if this feature is enabled.
            if (!Configuration.CheckFeatureStatus(AdvFeatureClass, Feature))
            {
                return(true);
            }

            XUi               xui       = __instance.ItemController.xui;
            ItemValue         itemValue = ((XUiC_ItemStack)__instance.ItemController).ItemStack.itemValue;
            ItemClass         forId     = ItemClass.GetForId(itemValue.type);
            EntityPlayerLocal player    = xui.playerUI.entityPlayer;

            XUiC_CraftingWindowGroup childByType = xui.FindWindowGroupByName("crafting").GetChildByType <XUiC_CraftingWindowGroup>();

            List <ItemStack> repairItems = new List <ItemStack>();

            // If the item has a repairItems, use that, instead of the vanilla version.
            if (forId.Properties.Classes.ContainsKey("RepairItems"))
            {
                Recipe            recipe             = new Recipe();
                DynamicProperties dynamicProperties3 = forId.Properties.Classes["RepairItems"];
                recipe.ingredients = ItemsUtilities.ParseProperties(dynamicProperties3);

                // Get an adjusted Craftint time from the player.
                recipe.craftingTime = (int)EffectManager.GetValue(PassiveEffects.CraftingTime, null, recipe.craftingTime, xui.playerUI.entityPlayer, recipe, FastTags.Parse(recipe.GetName()), true, true, true, true, 1, true);
                ItemsUtilities.ConvertAndCraft(recipe, player, __instance.ItemController);
                return(false);
            }
            else if (forId.Properties.Contains("RepairItems")) // to support <property name="RepairItems" value="resourceWood,10,resourceForgedIron,10" />
            {
                Recipe recipe  = new Recipe();
                string strData = forId.Properties.Values["RepairItems"].ToString();
                recipe.ingredients = ItemsUtilities.ParseProperties(strData);

                // Get an adjusted Craftint time from the player.
                recipe.craftingTime = (int)EffectManager.GetValue(PassiveEffects.CraftingTime, null, recipe.craftingTime, xui.playerUI.entityPlayer, recipe, FastTags.Parse(recipe.GetName()), true, true, true, true, 1, true);
                ItemsUtilities.ConvertAndCraft(recipe, player, __instance.ItemController);
                return(false);
            }
            // If there's no RepairTools defined, then fall back to recipe reduction
            else if (forId.RepairTools == null || forId.RepairTools.Length <= 0)
            {
                // Determine, based on percentage left,
                int RecipeCountReduction = 2;
                if (itemValue.PercentUsesLeft < 0.2)
                {
                    RecipeCountReduction = 3;
                }

                // Use the helper method to reduce the recipe count, and control displaying on the UI for consistenncy.
                ItemsUtilities.ConvertAndCraft(forId.GetItemName(), RecipeCountReduction, player, __instance.ItemController);
                return(false);
            }

            // Fall back to possible RepairTools
            return(true);
        }
Ejemplo n.º 3
0
    public override void OnActivated()
    {
        XUi xui = base.ItemController.xui;
        XUiM_PlayerInventory     playerInventory = xui.PlayerInventory;
        ItemValue                itemValue       = ((XUiC_ItemStack)base.ItemController).ItemStack.itemValue;
        ItemClass                forId           = ItemClass.GetForId(itemValue.type);
        XUiC_CraftingWindowGroup childByType     = xui.FindWindowGroupByName("crafting").GetChildByType <XUiC_CraftingWindowGroup>();

        if (itemValue.HasQuality)
        {
            if (itemValue.PercentUsesLeft < 0.30)
            {
                String text = "This item is too worn out to be resharpened.";
                GameManager.ShowTooltip(ItemController.xui.playerUI.entityPlayer, text);
                return;
            }
            if (itemValue.PercentUsesLeft > 0.8)
            {
                String text = "This item is still in pretty good shape.";
                GameManager.ShowTooltip(ItemController.xui.playerUI.entityPlayer, text);
                return;
            }
        }
        if (forId.Properties.Contains("SharpenItem"))
        {
            String strSharpenItem = String.Empty;
            forId.Properties.ParseString("SharpenItem", ref strSharpenItem);
            if (String.IsNullOrEmpty(strSharpenItem))
            {
                return;
            }

            Recipe recipe = new Recipe();
            recipe.count = 1;
            ItemClass itemClass = ItemClass.GetItemClass(strSharpenItem, false);
            if (itemClass == null)
            {
                return;
            }


            int Count = playerInventory.GetItemCount(new ItemValue(itemClass.Id, false));
            if (Count < 1)
            {
                String text = "Not enough " + strSharpenItem + " to craft this: " + Count + " / 1";
                GameManager.ShowTooltip(ItemController.xui.playerUI.entityPlayer, text);
                return;
            }
            if (childByType != null)
            {
                recipe.ingredients.Add(new ItemStack(new ItemValue(itemClass.Id, false), 1));
                recipe.itemValueType = itemValue.type;
                recipe.craftingTime  = 1;
                recipe.craftExpGain  = 1;
            }
            // ItemClass.GetForId(recipe.itemValueType);
            GameRandom random   = GameRandomManager.Instance.CreateGameRandom();
            float      flRandom = random.RandomRange((int)itemValue.UseTimes, ((float)itemValue.MaxUseTimes / 1.20f));
            if (!childByType.AddRepairItemToQueue(recipe.craftingTime, itemValue.Clone(), (int)flRandom))
            {
                WarnQueueFull(ItemController);
                return;
            }
            ((XUiC_ItemStack)ItemController).ItemStack = ItemStack.Empty.Clone();
            playerInventory.RemoveItems(recipe.ingredients, 1);
        }
    }
        public static bool Prefix(ItemActionEntryScrap __instance)
        {
            // Check if this feature is enabled.
            if (!Configuration.CheckFeatureStatus(AdvFeatureClass, Feature))
            {
                return(true);
            }
            #region vanilla_code
            XUi            xui            = __instance.ItemController.xui;
            XUiC_ItemStack xuiC_ItemStack = (XUiC_ItemStack)__instance.ItemController;

            ItemStack itemStack       = xuiC_ItemStack.ItemStack.Clone();
            Recipe    scrapableRecipe = CraftingManager.GetScrapableRecipe(itemStack.itemValue, itemStack.count);
            if (scrapableRecipe == null)
            {
                return(true);
            }

            XUiController xuiController = __instance.ItemController.xui.FindWindowGroupByName("workstation_workbench");
            if (xuiController == null || !xuiController.WindowGroup.isShowing)
            {
                xuiController = xui.FindWindowGroupByName("crafting");
            }

            XUiC_CraftingWindowGroup childByType = xuiController.GetChildByType <XUiC_CraftingWindowGroup>();
            if (childByType == null)
            {
                return(true);
            }
            #endregion  vanilla_code

            LocalPlayerUI    uiforPlayer = LocalPlayerUI.GetUIForPlayer(__instance.ItemController.xui.playerUI.entityPlayer);
            List <ItemStack> scrapItems  = new List <ItemStack>();

            ItemClass forId = ItemClass.GetForId(itemStack.itemValue.type);
            // Check if ScrapItems is specified
            if (forId.Properties.Classes.ContainsKey("ScrapItems"))
            {
                DynamicProperties dynamicProperties3 = forId.Properties.Classes["ScrapItems"];
                scrapItems = ItemsUtilities.ParseProperties(dynamicProperties3);
                ItemsUtilities.Scrap(scrapItems, itemStack, __instance.ItemController);
                return(false);
            }
            else if (forId.Properties.Contains("ScrapItems")) // Support for <property name="ScrapItems" value="resourceWood,0,resourceLeather,2" />
            {
                string strData = forId.Properties.Values["ScrapItems"].ToString();
                scrapItems = ItemsUtilities.ParseProperties(strData);
                ItemsUtilities.Scrap(scrapItems, itemStack, __instance.ItemController);
                return(false);
            }
            // Check if Repair Items is specified, if the ScrapItems wasn't.
            else if (forId.Properties.Classes.ContainsKey("RepairItems"))
            {
                DynamicProperties dynamicProperties3 = forId.Properties.Classes["RepairItems"];
                scrapItems = ItemsUtilities.ParseProperties(dynamicProperties3);
                ItemsUtilities.Scrap(scrapItems, itemStack, __instance.ItemController);
                return(false);
            }
            else if (forId.RepairTools == null || forId.RepairTools.Length <= 0)
            {
                if (CraftingManager.GetRecipe(forId.GetItemName()) == null)
                {
                    return(true);
                }

                if (CraftingManager.GetRecipe(forId.GetItemName()).tags.Test_AnySet(FastTags.Parse("usevanillascrap")))
                {
                    return(true);
                }

                // If there's a recipe, reduce it
                Recipe recipe = ItemsUtilities.GetReducedRecipes(forId.GetItemName(), 2);

                ItemsUtilities.Scrap(recipe.ingredients, itemStack, __instance.ItemController);
                return(false);
            }
            return(true);
        }