79 lines
3.8 KiB
C#
79 lines
3.8 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace Harmony.ItemActionEntryCraftPatches
|
|
{
|
|
[HarmonyPatch(typeof(ItemActionEntryCraft))]
|
|
[HarmonyPatch("OnActivated")]
|
|
public class OnActivatedPatch
|
|
{
|
|
public static bool Prefix(ItemActionEntryCraft __instance)
|
|
{
|
|
Recipe recipe = ((XUiC_RecipeEntry)__instance.ItemController).Recipe;
|
|
XUi xui = __instance.ItemController.xui;
|
|
List<XUiC_CraftingWindowGroup> childrenByType = xui.GetChildrenByType<XUiC_CraftingWindowGroup>();
|
|
XUiC_CraftingWindowGroup craftingWindowGroup = (XUiC_CraftingWindowGroup)null;
|
|
for (int index = 0; index < childrenByType.Count; ++index)
|
|
{
|
|
if (childrenByType[index].WindowGroup != null && childrenByType[index].WindowGroup.isShowing)
|
|
{
|
|
craftingWindowGroup = childrenByType[index];
|
|
break;
|
|
}
|
|
}
|
|
if (craftingWindowGroup == null)
|
|
return false;
|
|
if (XUiM_Recipes.GetRecipeIsUnlocked(__instance.ItemController.xui, recipe) && craftingWindowGroup.CraftingRequirementsValid(recipe))
|
|
{
|
|
Log.Out("ItemActionEntryCraftPatches-OnActivated __instance.craftingTier: " + __instance.craftingTier);
|
|
Recipe _recipe = new Recipe()
|
|
{
|
|
itemValueType = recipe.itemValueType,
|
|
count = XUiM_Recipes.GetRecipeCraftOutputCount(xui, recipe),
|
|
craftingArea = recipe.craftingArea,
|
|
craftExpGain = recipe.craftExpGain,
|
|
craftingTime = XUiM_Recipes.GetRecipeCraftTime(xui, recipe),
|
|
craftingToolType = recipe.craftingToolType,
|
|
craftingTier = __instance.craftingTier,
|
|
tags = recipe.tags
|
|
};
|
|
if (!__instance.HasItems(xui, recipe))
|
|
return false;
|
|
bool flag = false;
|
|
for (int index = 0; index < recipe.ingredients.Count; ++index)
|
|
{
|
|
flag |= recipe.ingredients[index].itemValue.HasQuality;
|
|
if (flag || __instance.tempIngredientList[index].count != recipe.ingredients[index].count)
|
|
_recipe.scrapable = true;
|
|
}
|
|
_recipe.AddIngredients(__instance.tempIngredientList);
|
|
XUiC_WorkstationInputGrid childByType = __instance.craftCountControl.WindowGroup.Controller.GetChildByType<XUiC_WorkstationInputGrid>();
|
|
if (craftingWindowGroup.AddItemToQueue(_recipe))
|
|
{
|
|
if (flag)
|
|
__instance.tempIngredientList.Clear();
|
|
if (childByType != null)
|
|
childByType.RemoveItems((IList<ItemStack>)_recipe.ingredients, __instance.craftCountControl.Count, (IList<ItemStack>)__instance.tempIngredientList);
|
|
else
|
|
xui.PlayerInventory.RemoveItems((IList<ItemStack>)_recipe.ingredients, __instance.craftCountControl.Count, (IList<ItemStack>)__instance.tempIngredientList);
|
|
if (flag)
|
|
{
|
|
_recipe.ingredients.Clear();
|
|
_recipe.AddIngredients(__instance.tempIngredientList);
|
|
}
|
|
if (recipe == xui.Recipes.TrackedRecipe)
|
|
{
|
|
xui.Recipes.TrackedRecipe = (Recipe)null;
|
|
xui.Recipes.ResetToPreviousTracked(xui.playerUI.entityPlayer);
|
|
}
|
|
}
|
|
else
|
|
__instance.WarnQueueFull();
|
|
}
|
|
__instance.craftCountControl.IsDirty = true;
|
|
craftingWindowGroup.WindowGroup.Controller.SetAllChildrenDirty();
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|