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);
    }
Exemple #2
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);
        }
    }