public static void GetForgeCost_Postfix(ForgeMenu __instance, Item left_item, Item right_item, ref int __result) { try { if (left_item != null && right_item != null) { // if merging rings, then calculate different cost based on the total amount of rings being combined // if only two, rings, than keep normal cost of 20, otherwise, gets 100 per ring combined (max of 999) if (left_item.getCategoryName().Equals("Ring") && left_item.category == right_item.category) { Ring left_ring = (Ring)left_item; Ring right_ring = (Ring)right_item; int total_rings = GetCombinedRingTotal(left_ring) + GetCombinedRingTotal(right_ring); if (total_rings > 2) { int new_cost = GetTotalCombinedRingsCost(total_rings); __result = new_cost; } } } } catch (Exception ex) { ModMonitor.Log($"Failed in {nameof(GetForgeCost_Postfix)}:\n{ex}", LogLevel.Error); } }
/// <summary>The method to call before <see cref="ForgeMenu.SpendLeftItem"/>.</summary> /// <returns>Returns whether to run the original method.</returns> private static bool Before_SpendLeftItem(ForgeMenu __instance) { if (ForgeMenuPatcher.justCrafted != null) { ForgeMenuPatcher.justCrafted.BaseItem.Consume(ref __instance.leftIngredientSpot.item); return(false); } return(true); }
private static int GetAndDrawCost(ForgeMenu forgeMenu, Item leftItem, Item rightItem) { int cost = forgeMenu.GetForgeCost(forgeMenu.leftIngredientSpot.item, forgeMenu.rightIngredientSpot.item); if (cost is not(10 or 15 or 20)) { Game1.spriteBatch.DrawString(Game1.dialogueFont, "x" + cost, new Vector2(forgeMenu.xPositionOnScreen + 345, forgeMenu.yPositionOnScreen + 320), new Color(226, 124, 65)); } return(cost); }
public void Setup(ForgeMenu forgeMenu, Item item, string text = null) { ForgeMenu = forgeMenu; Item = item; itemImage.sprite = item.Base.itemIcon; if (string.IsNullOrWhiteSpace(text)) { itemName.text = item.ColoredInspectorName; } else { itemName.text = text; } }
/// <summary>The method to call before <see cref="ForgeMenu.GetForgeCost"/>.</summary> /// <returns>Returns whether to run the original method.</returns> private static bool Before_GetForgeCost(ForgeMenu __instance, Item left_item, Item right_item, ref int __result) { if (left_item == null || right_item == null) { return(true); } foreach (var recipe in CustomForgeRecipe.Recipes) { if (recipe.BaseItem.HasEnoughFor(left_item) && recipe.IngredientItem.HasEnoughFor(right_item)) { __result = recipe.CinderShardCost; return(false); } } return(true); }
/********* ** Private methods *********/ ///// <summary>The method to call before <see cref="ForgeMenu.GenerateHighlightDictionary"/>.</summary> //private static bool Before_GenerateHighlightDictionary(ForgeMenu __instance) //{ // var this__highlightDictionary_ = SpaceCore.Instance.Helper.Reflection.GetField<Dictionary<Item, bool>>(__instance, "_highlightDictionary"); // this__highlightDictionary_.SetValue(new Dictionary<Item, bool>()); // var this__highlightDictionary = this__highlightDictionary_.GetValue(); // List<Item> item_list = new List<Item>(__instance.inventory.actualInventory); // if (Game1.player.leftRing.Value != null) // { // item_list.Add(Game1.player.leftRing.Value); // } // if (Game1.player.rightRing.Value != null) // { // item_list.Add(Game1.player.rightRing.Value); // } // foreach (Item item in item_list) // { // if (item == null) // { // continue; // } // if (Utility.IsNormalObjectAtParentSheetIndex(item, 848)) // { // this__highlightDictionary[item] = true; // } // else if (__instance.leftIngredientSpot.item == null && __instance.rightIngredientSpot.item == null) // { // bool valid = false; // if (item is Ring) // { // valid = true; // } // if (item is Tool && BaseEnchantment.GetAvailableEnchantmentsForItem(item as Tool).Count > 0) // { // valid = true; // } // if (BaseEnchantment.GetEnchantmentFromItem(null, item) != null) // { // valid = true; // } // foreach (var recipe in CustomForgeRecipe.Recipes) // { // if (recipe.BaseItem.HasEnoughFor(item) || recipe.IngredientItem.HasEnoughFor(item)) // valid = true; // } // this__highlightDictionary[item] = valid; // } // else if (__instance.leftIngredientSpot.item != null && __instance.rightIngredientSpot.item != null) // { // this__highlightDictionary[item] = false; // } // else if (__instance.leftIngredientSpot.item != null) // { // this__highlightDictionary[item] = __instance.IsValidCraft(__instance.leftIngredientSpot.item, item); // } // else // { // this__highlightDictionary[item] = __instance.IsValidCraft(item, __instance.rightIngredientSpot.item); // } // } // return false; //} /// <summary>The method to call before <see cref="ForgeMenu.IsValidCraft"/>.</summary> /// <returns>Returns whether to run the original method.</returns> private static bool Before_IsValidCraft(ForgeMenu __instance, Item left_item, Item right_item, ref bool __result) { if (left_item == null || right_item == null) { return(true); } foreach (var recipe in CustomForgeRecipe.Recipes) { if (recipe.BaseItem.HasEnoughFor(left_item) && recipe.IngredientItem.HasEnoughFor(right_item)) { __result = true; return(false); } } return(true); }
/// <summary>The method to call before <see cref="ForgeMenu.CraftItem"/>.</summary> private static bool Before_CraftItem(ForgeMenu __instance, Item left_item, Item right_item, bool forReal, ref Item __result) { if (left_item == null || right_item == null) { return(true); } foreach (var recipe in Mod.instance.Forge) { if (left_item.Name == recipe.BaseItemName && right_item.GetContextTags().Contains(recipe.IngredientContextTag) && Mod.instance.Epu.CheckConditions(recipe.AbleToForgeConditions)) { __result = Utility.fuzzyItemSearch(recipe.ResultItemName); return(false); } } return(true); }
/********* ** Private methods *********/ /// <summary>The method to call before <see cref="ForgeMenu.IsValidCraft"/>.</summary> private static bool Before_IsValidCraft(ForgeMenu __instance, Item left_item, Item right_item, ref bool __result) { if (left_item == null || right_item == null) { return(true); } foreach (var recipe in Mod.instance.Forge) { if (left_item.Name == recipe.BaseItemName && right_item.GetContextTags().Contains(recipe.IngredientContextTag) && Mod.instance.Epu.CheckConditions(recipe.AbleToForgeConditions)) { __result = true; return(false); } } return(true); }
public static bool Prefix(ForgeMenu __instance, Item left_item, Item right_item, ref int __result) { if (left_item == null || right_item == null) { return(true); } foreach (var recipe in Mod.instance.forge) { if (left_item.Name == recipe.BaseItemName && right_item.GetContextTags().Contains(recipe.IngredientContextTag) && Mod.instance.epu.CheckConditions(recipe.AbleToForgeConditions)) { __result = recipe.CinderShardCost; return(false); } } return(true); }
/// <summary>The method to call before <see cref="ForgeMenu.CraftItem"/>.</summary> /// <returns>Returns whether to run the original method.</returns> private static bool Before_CraftItem(ForgeMenu __instance, Item left_item, Item right_item, bool forReal, ref Item __result) { if (left_item == null || right_item == null) { return(true); } foreach (var recipe in CustomForgeRecipe.Recipes) { if (recipe.BaseItem.HasEnoughFor(left_item) && recipe.IngredientItem.HasEnoughFor(right_item)) { if (forReal) { ForgeMenuPatcher.justCrafted = recipe; } __result = recipe.CreateResult(left_item, right_item); return(false); } } return(true); }
/// <summary>The method to call before <see cref="ForgeMenu.GetForgeCost"/>.</summary> private static bool Before_GetForgeCost(ForgeMenu __instance, Item left_item, Item right_item, ref int __result) { if (left_item == null || right_item == null) { return(true); } foreach (var recipe in Mod.instance.Forge) { bool isMatch = left_item.Name == recipe.BaseItemName && right_item.GetContextTags().Contains(recipe.IngredientContextTag) && Mod.instance.CheckEpuCondition(recipe.AbleToForgeConditions); if (isMatch) { __result = recipe.CinderShardCost; return(false); } } return(true); }
public static void _UpdateDescriptionText_Postfix(ForgeMenu __instance, ref string ___displayedDescription) { try { if (__instance.inventory != null && __instance.leftIngredientSpot != null && __instance.rightIngredientSpot != null) { Item left_item = __instance.leftIngredientSpot.item; Item right_item = __instance.rightIngredientSpot.item; if (left_item != null && right_item != null) { if (left_item.getCategoryName().Equals("Ring") && left_item.category == right_item.category) { Ring left_ring = (Ring)left_item; Ring right_ring = (Ring)right_item; int total_left_rings = GetCombinedRingTotal(left_ring); int total_right_rings = GetCombinedRingTotal(right_ring); int total_rings = total_left_rings + total_right_rings; int cost = GetTotalCombinedRingsCost(total_rings); if (total_rings > 2) { ___displayedDescription += $"\nCost: {cost}"; } int sucess_rate = 100 - GetBreakChance(total_rings); ___displayedDescription += $"\nChance of sucess: {sucess_rate}%"; } } } } catch (Exception ex) { ModMonitor.Log($"Failed in {nameof(_UpdateDescriptionText_Postfix)}:\n{ex}", LogLevel.Error); } }
public static bool CraftItem_Prefix(ForgeMenu __instance, ref ForgeMenu.CraftState ____craftState, string ___displayedDescription, Item left_item, Item right_item, ref Item __result, bool forReal = false) { try { if (left_item != null && right_item != null) { if (left_item.getCategoryName().Equals("Ring") && left_item.category == right_item.category) { Ring left_ring = (Ring)left_item; Ring right_ring = (Ring)right_item; int total_left_rings = GetCombinedRingTotal(left_ring); int total_right_rings = GetCombinedRingTotal(right_ring); int total_rings = total_left_rings + total_right_rings; if (forReal == true) { int breakChance = GetBreakChance(total_rings); Random r = new Random(); int instabilityForgeRoll = r.Next(0, 100); if (instabilityForgeRoll < breakChance) { ModMonitor.Log($"Was unstable ({instabilityForgeRoll} of {breakChance}). Will not forge the result", LogLevel.Trace); if (DataLoader.ModConfig.DestroyRingOnFailure) { int brokenRingRoll = r.Next(0, total_rings); bool keepRightItem = true; if (total_left_rings >= total_right_rings && brokenRingRoll >= total_left_rings) { keepRightItem = false; } else if (total_left_rings < total_right_rings && brokenRingRoll < total_right_rings) { keepRightItem = false; } if (keepRightItem) { __result = right_item; __instance.leftIngredientSpot.item = right_item; __instance.rightIngredientSpot.item = left_item; ModMonitor.Log($"keeping right ring", LogLevel.Trace); } else { __result = left_item; ModMonitor.Log($"keeping left ring", LogLevel.Trace); } ModMonitor.Log($"brokenRingRoll: {brokenRingRoll}, {total_left_rings}, {total_right_rings}", LogLevel.Trace); } else { __result = left_ring; ____craftState = ForgeMenu.CraftState.InvalidRecipe; } Game1.playSound("rockGolemDie"); return(false); } else { ModMonitor.Log($"Successfull {instabilityForgeRoll} of {breakChance}! will forge as it should.", LogLevel.Trace); } } } } } catch (Exception ex) { ModMonitor.Log($"Failed in {nameof(CraftItem_Prefix)}:\n{ex}", LogLevel.Error); } ModMonitor.Log($"running original", LogLevel.Trace); return(true); }
internal static void ForgeMenuPatch(ForgeMenu __instance) { try { int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position string toSpeak = " "; if (__instance.leftIngredientSpot != null && __instance.leftIngredientSpot.containsPoint(x, y)) { if (__instance.leftIngredientSpot.item == null) { toSpeak = "Input weapon or tool here"; } else { Item item = __instance.leftIngredientSpot.item; toSpeak = $"Weapon slot: {item.Stack} {item.DisplayName}"; } } else if (__instance.rightIngredientSpot != null && __instance.rightIngredientSpot.containsPoint(x, y)) { if (__instance.rightIngredientSpot.item == null) { toSpeak = "Input gemstone here"; } else { Item item = __instance.rightIngredientSpot.item; toSpeak = $"Gemstone slot: {item.Stack} {item.DisplayName}"; } } else if (__instance.startTailoringButton != null && __instance.startTailoringButton.containsPoint(x, y)) { toSpeak = "Star forging button"; } else if (__instance.unforgeButton != null && __instance.unforgeButton.containsPoint(x, y)) { toSpeak = "Unforge button"; } else if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) { toSpeak = "Trashcan"; } else if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) { toSpeak = "ok button"; } else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) { toSpeak = "drop item"; } else if (__instance.equipmentIcons.Count > 0 && __instance.equipmentIcons[0].containsPoint(x, y)) { toSpeak = "Left ring Slot"; if (Game1.player.leftRing.Value != null) { toSpeak = $"{toSpeak}: {Game1.player.leftRing.Value.DisplayName}"; } } else if (__instance.equipmentIcons.Count > 0 && __instance.equipmentIcons[1].containsPoint(x, y)) { toSpeak = "Right ring Slot"; if (Game1.player.rightRing.Value != null) { toSpeak = $"{toSpeak}: {Game1.player.rightRing.Value.DisplayName}"; } } else { for (int i = 0; i < __instance.inventory.inventory.Count; i++) { if (!__instance.inventory.inventory[i].containsPoint(x, y)) { continue; } if (__instance.inventory.actualInventory[i] == null) { toSpeak = "Empty slot"; } else { toSpeak = $"{__instance.inventory.actualInventory[i].Stack} {__instance.inventory.actualInventory[i].DisplayName}"; } if (forgeMenuQuery != $"{toSpeak}:{i}") { forgeMenuQuery = $"{toSpeak}:{i}"; MainClass.ScreenReader.Say(toSpeak, true); } return; } } if (forgeMenuQuery != toSpeak) { forgeMenuQuery = toSpeak; MainClass.ScreenReader.Say(toSpeak, true); if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) { Game1.playSound("drop_item"); } } } catch (System.Exception e) { MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); } }