private static void SendToSMLHelper <T>(IDictionary <string, T> uniqueEntries) where T : ICraftingTab { foreach (T item in uniqueEntries.Values) { CustomCraft.CustomCraftingTab(item); } Logger.Log($"Custom Crafting Tabs were patched."); }
private static void SendToSMLHelper <T>(IDictionary <string, T> uniqueEntries) where T : ICraftingTab { foreach (T item in uniqueEntries.Values) { CustomCraft.CustomCraftingTab(item); } if (uniqueEntries.Count > 0) { Logger.Log($"Custom Crafting Tabs were successfully patched"); } }
private static void SendToSMLHelper <T>(IDictionary <TechType, T> uniqueEntries) where T : ITechTyped { int successCount = 0; foreach (T item in uniqueEntries.Values) { bool result = CustomCraft.AddEntry(item); if (result) { successCount++; } } Logger.Log($"{successCount} of {uniqueEntries.Count} {typeof(T).Name} entries were patched."); }
private static void PatchCustomSizes() { customSizeList = new CustomSizeList(); if (File.Exists(CustomSizesFile)) { string serializedData = File.ReadAllText(CustomSizesFile); if (!string.IsNullOrEmpty(serializedData) && customSizeList.Deserialize(serializedData) && customSizeList.Count > 0) { foreach (ICustomSize customSize in customSizeList) { try { CustomCraft.CustomizeItemSize(customSize.ItemID, customSize.Width, customSize.Height); } catch { Logger.Log($"Error on CustomizeItemSize{Environment.NewLine}" + $"Entry with error:{Environment.NewLine}" + $"{customSize}"); } } Logger.Log($"CustomSizes loaded. File reformatted."); File.WriteAllText(CustomSizesFile, customSizeList.PrintyPrint()); } else { Logger.Log($"No CustomSizes were loaded. File was empty or malformed."); } } else { File.WriteAllText(CustomSizesFile, $"# Custom Sizes go in this file #{Environment.NewLine}" + $"# Check the CustomSizes_Samples.txt file in the SampleFiles folder for details on how to set your own custom sizes #{Environment.NewLine}"); Logger.Log($"{CustomSizesFile} file not found. Empty file created."); } }
private static void PatchModifiedRecipes() { modifiedRecipeList = new ModifiedRecipeList(); if (File.Exists(ModifiedRecipesFile)) { string serializedData = File.ReadAllText(ModifiedRecipesFile); if (!string.IsNullOrEmpty(serializedData) && modifiedRecipeList.Deserialize(serializedData) && modifiedRecipeList.Count > 0) { foreach (IModifiedRecipe item in modifiedRecipeList) { try { CustomCraft.ModifyRecipe(item.ItemID, item.SmlHelperRecipe()); } catch { Logger.Log($"Error on ModifyRecipe{Environment.NewLine}" + $"Entry with error:{Environment.NewLine}" + $"{item}"); } } Logger.Log($"ModifiedRecipes loaded. File reformatted."); File.WriteAllText(ModifiedRecipesFile, modifiedRecipeList.PrintyPrint()); } else { Logger.Log($"No ModifiedRecipes were loaded. File was empty or malformed."); } } else { File.WriteAllText(ModifiedRecipesFile, $"# Modified Recipes #{Environment.NewLine}" + $"# Check the ModifiedRecipes_Samples.txt file in the SampleFiles folder for details on how to alter existing crafting recipes #{Environment.NewLine}"); Logger.Log($"{ModifiedRecipesFile} file not found. Empty file created."); } }
private static void PatchAddedRecipes() { addedRecipeList = new AddedRecipeList(); if (File.Exists(AddedRecipiesFile)) { string serializedData = File.ReadAllText(AddedRecipiesFile); if (!string.IsNullOrEmpty(serializedData) && addedRecipeList.Deserialize(serializedData) && addedRecipeList.Count > 0) { foreach (IAddedRecipe item in addedRecipeList) { try { CustomCraft.AddRecipe(item.ItemID, item.SmlHelperRecipe(), new CraftingPath(item.Path)); } catch { Logger.Log($"Error on AddRecipe{Environment.NewLine}" + $"Entry with error:{Environment.NewLine}" + $"{item}"); } } Logger.Log($"AddedRecipies loaded. File reformatted."); File.WriteAllText(AddedRecipiesFile, addedRecipeList.PrintyPrint()); } else { Logger.Log($"No AddedRecipes were loaded. File was empty or malformed."); } } else { File.WriteAllText(AddedRecipiesFile, $"# Added Recipes #{Environment.NewLine}" + $"# Check the AddedRecipes_Samples.txt file in the SampleFiles folder for details on how to add recipes for items normally not craftable #{Environment.NewLine}"); Logger.Log($"{AddedRecipiesFile} file not found. Empty file created."); } }
public void CompleteCraft(int quality, bool makersMark, Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool, CustomCraft customCraft) { int badCraft = craftSystem.CanCraft(from, tool, m_Type); if (badCraft > 0) { if (tool != null && !tool.Deleted && tool.UsesRemaining > 0) { from.SendGump(new CraftGump(from, craftSystem, tool, badCraft)); } else { from.SendLocalizedMessage(badCraft); } return; } int checkResHue = 0, checkMaxAmount = 0; object checkMessage = null; // Not enough resource to craft it if (!ConsumeRes(from, typeRes, craftSystem, ref checkResHue, ref checkMaxAmount, ConsumeType.None, ref checkMessage)) { if (tool != null && !tool.Deleted && tool.UsesRemaining > 0) { from.SendGump(new CraftGump(from, craftSystem, tool, checkMessage)); } else if (checkMessage is int && (int)checkMessage > 0) { from.SendLocalizedMessage((int)checkMessage); } else if (checkMessage is string) { from.SendMessage((string)checkMessage); } return; } else if (!ConsumeAttributes(from, ref checkMessage, false)) { if (tool != null && !tool.Deleted && tool.UsesRemaining > 0) { from.SendGump(new CraftGump(from, craftSystem, tool, checkMessage)); } else if (checkMessage is int && (int)checkMessage > 0) { from.SendLocalizedMessage((int)checkMessage); } else if (checkMessage is string) { from.SendMessage((string)checkMessage); } return; } bool toolBroken = false; int ignored = 1; int endquality = 1; bool allRequiredSkills = true; if (CheckSkills(from, typeRes, craftSystem, ref ignored, ref allRequiredSkills)) { // Resource int resHue = 0; int maxAmount = 0; object message = null; // Not enough resource to craft it if (!ConsumeRes(from, typeRes, craftSystem, ref resHue, ref maxAmount, ConsumeType.All, ref message)) { if (tool != null && !tool.Deleted && tool.UsesRemaining > 0) { from.SendGump(new CraftGump(from, craftSystem, tool, message)); } else if (message is int i && i > 0) { from.SendLocalizedMessage(i); } else if (message is string s) { from.SendMessage(s); } return; } else if (!ConsumeAttributes(from, ref message, true)) { if (tool != null && !tool.Deleted && tool.UsesRemaining > 0) { from.SendGump(new CraftGump(from, craftSystem, tool, message)); } else if (message is int i && i > 0) { from.SendLocalizedMessage(i); } else if (message is string s) { from.SendMessage(s); } return; }
private static void PrePassSMLHelper <T>(List <T> entries, ref IDictionary <TechType, T> uniqueEntries) where T : ITechTyped { // Use the ToSet function as a copy constructor - this way we can iterate across the // temp structure, but change the permanent one in the case of duplicates foreach (T item in entries) { // Sanity check of the blueprints ingredients and linked items to be sure that it only contains known items // Modded items are okay, but they must be for mods the player already has installed bool internalItemsPassCheck = true; if (item is IModifiedRecipe recipe) { foreach (EmIngredient ingredient in recipe.Ingredients) { TechType ingredientID = CustomCraft.GetTechType(ingredient.ItemID); if (ingredientID == TechType.None) { QuickLogger.Warning($"Entry with ID of '{item.ItemID}' contained an unknown ingredient '{ingredient.ItemID}'. Entry will be discarded."); internalItemsPassCheck = false; continue; } } foreach (string linkedItem in recipe.LinkedItems) { TechType linkedItemID = CustomCraft.GetTechType(linkedItem); if (linkedItemID == TechType.None) { QuickLogger.Warning($"Entry with ID of '{item.ItemID}' contained an unknown linked item '{linkedItem}'. Entry will be discarded."); internalItemsPassCheck = false; continue; } } } if (!internalItemsPassCheck) { continue; // item will not be added to the uniqueEntries dictionary } // Now we can safely do the prepass check in case we need to create a new modded TechType TechType entryId = CustomCraft.PrePass(item); if (entryId == TechType.None) { QuickLogger.Warning($"Could not resolve ID of '{item.ItemID}'. Discarded entry."); continue; } if (uniqueEntries.ContainsKey(entryId)) { QuickLogger.Warning($"Duplicate entry for '{item.ItemID}' was already added by another working file. Kept first one. Discarded duplicate."); continue; } // All checks passed uniqueEntries.Add(entryId, item); } if (entries.Count > 0) { QuickLogger.Message($"{uniqueEntries.Count} of {entries.Count} {typeof(T).Name} entries staged for patching"); } }