From 16d81aca5178bc1dc08c2325d87799cb747a8ab4 Mon Sep 17 00:00:00 2001 From: NeroWolf Date: Sun, 24 Mar 2024 20:04:22 -0400 Subject: [PATCH] Update for Stardew Valley 1.6 and SMAPI 4.0 Updated from .Net 5.0 to .Net 6.0 Updated for SMAPI 4.0 and Stardew Valley 1.6 API changes. Added ToolData for each tool type we care about and added ToolUpdateData to each to allow for natural population of Clint's shop. Removed Blacksmith.cs as it was not longer was needed. Added some Harmony hooks to catch the MigrateLegacyItemId for tools already at Prismatic coming from 1.5 and set the ItemID to that which was added to the ToolData. Removed some no longer needed Harmony hooks. Updated some magic numbers with some predefined constants for better readability. --- .editorconfig | 67 +++++++++++++++ PrismaticTools/Framework/AssetEditor.cs | 14 +-- PrismaticTools/Framework/Blacksmith.cs | 59 ------------- PrismaticTools/Framework/PrismaticItems.cs | 2 + PrismaticTools/Framework/PrismaticPatches.cs | 71 ++++++++------- PrismaticTools/ModEntry.cs | 90 ++++++++++++++++---- PrismaticTools/PrismaticTools.csproj | 6 +- 7 files changed, 192 insertions(+), 117 deletions(-) delete mode 100644 PrismaticTools/Framework/Blacksmith.cs diff --git a/.editorconfig b/.editorconfig index 083f401..2b59378 100644 --- a/.editorconfig +++ b/.editorconfig @@ -70,3 +70,70 @@ csharp_prefer_braces = false:suggestion csharp_new_line_before_open_brace = true csharp_new_line_before_else = false csharp_new_line_before_catch = false +csharp_indent_labels = one_less_than_current +csharp_using_directive_placement = outside_namespace:silent +csharp_prefer_simple_using_statement = true:suggestion +csharp_style_namespace_declarations = block_scoped:silent +csharp_style_prefer_method_group_conversion = true:silent +csharp_style_prefer_top_level_statements = true:silent +csharp_style_prefer_primary_constructors = true:suggestion +csharp_style_expression_bodied_operators = false:silent +csharp_style_expression_bodied_lambdas = true:silent +csharp_style_expression_bodied_local_functions = false:silent + +[*.{cs,vb}] +#### Naming styles #### + +# Naming rules + +dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion +dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface +dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i + +dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.types_should_be_pascal_case.symbols = types +dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case + +dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members +dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case + +# Symbol specifications + +dotnet_naming_symbols.interface.applicable_kinds = interface +dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.interface.required_modifiers = + +dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum +dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.types.required_modifiers = + +dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method +dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.non_field_members.required_modifiers = + +# Naming styles + +dotnet_naming_style.begins_with_i.required_prefix = I +dotnet_naming_style.begins_with_i.required_suffix = +dotnet_naming_style.begins_with_i.word_separator = +dotnet_naming_style.begins_with_i.capitalization = pascal_case + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case +dotnet_style_operator_placement_when_wrapping = beginning_of_line +tab_width = 4 +end_of_line = crlf +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_null_propagation = true:suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion +dotnet_style_prefer_auto_properties = true:silent +dotnet_style_object_initializer = true:suggestion +dotnet_style_collection_initializer = true:suggestion diff --git a/PrismaticTools/Framework/AssetEditor.cs b/PrismaticTools/Framework/AssetEditor.cs index ef3e577..2de95bf 100644 --- a/PrismaticTools/Framework/AssetEditor.cs +++ b/PrismaticTools/Framework/AssetEditor.cs @@ -3,6 +3,8 @@ using Microsoft.Xna.Framework.Graphics; using StardewModdingAPI; using StardewModdingAPI.Events; +using StardewValley; +using StardewValley.GameData.Objects; namespace PrismaticTools.Framework { public class AssetEditor { @@ -27,12 +29,12 @@ public void OnAssetRequested(AssetRequestedEventArgs e) { } // new item data - else if (e.NameWithoutLocale.IsEquivalentTo("Data/ObjectInformation")) { + else if (e.NameWithoutLocale.IsEquivalentTo("Data/Objects")) { e.Edit(asset => { - var data = asset.AsDictionary().Data; + var data = asset.AsDictionary().Data; - data.Add(PrismaticBarItem.INDEX, $"{this.barName}/{PrismaticBarItem.PRICE}/{PrismaticBarItem.EDIBILITY}/{PrismaticBarItem.TYPE} {PrismaticBarItem.CATEGORY}/{this.barName}/{this.barDesc}"); - data.Add(PrismaticSprinklerItem.INDEX, $"{this.sprinklerName}/{PrismaticSprinklerItem.PRICE}/{PrismaticSprinklerItem.EDIBILITY}/{PrismaticSprinklerItem.TYPE} {PrismaticSprinklerItem.CATEGORY}/{this.sprinklerName}/{this.sprinklerDesc}"); + data.Add(PrismaticBarItem.INDEX.ToString(), new ObjectData { Name = this.barName, DisplayName = this.barName, Description = this.barDesc, Price = PrismaticBarItem.PRICE, Type = PrismaticBarItem.TYPE, Category = PrismaticBarItem.CATEGORY, Edibility = PrismaticBarItem.EDIBILITY, SpriteIndex = PrismaticBarItem.INDEX }); + data.Add(PrismaticSprinklerItem.INDEX.ToString(), new ObjectData { Name = this.sprinklerName, DisplayName = this.sprinklerName, Description = this.sprinklerDesc, Price = PrismaticSprinklerItem.PRICE, Type = PrismaticSprinklerItem.TYPE, Category = PrismaticSprinklerItem.CATEGORY, Edibility = PrismaticSprinklerItem.EDIBILITY, SpriteIndex = PrismaticSprinklerItem.INDEX }); }); } @@ -47,9 +49,9 @@ public void OnAssetRequested(AssetRequestedEventArgs e) { newDict.Add(key, data[key]); if (key.Equals("Iridium Sprinkler")) { if (asset.Locale != "en") - newDict.Add("Prismatic Sprinkler", $"{PrismaticBarItem.INDEX} 2 787 2/Home/{PrismaticSprinklerItem.INDEX}/false/Farming {PrismaticSprinklerItem.CRAFTING_LEVEL}/{this.sprinklerName}"); + newDict.Add("Prismatic Sprinkler", $"{PrismaticBarItem.INDEX.ToString()} 2 787 2/Home/{PrismaticSprinklerItem.INDEX.ToString()}/false/Farming {PrismaticSprinklerItem.CRAFTING_LEVEL}/{this.sprinklerName}"); else - newDict.Add("Prismatic Sprinkler", $"{PrismaticBarItem.INDEX} 2 787 2/Home/{PrismaticSprinklerItem.INDEX}/false/Farming {PrismaticSprinklerItem.CRAFTING_LEVEL}"); + newDict.Add("Prismatic Sprinkler", $"{PrismaticBarItem.INDEX.ToString()} 2 787 2/Home/{PrismaticSprinklerItem.INDEX.ToString()}/false/Farming {PrismaticSprinklerItem.CRAFTING_LEVEL}"); } } diff --git a/PrismaticTools/Framework/Blacksmith.cs b/PrismaticTools/Framework/Blacksmith.cs deleted file mode 100644 index 4a6a9de..0000000 --- a/PrismaticTools/Framework/Blacksmith.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System.Collections.Generic; -using StardewModdingAPI.Events; -using StardewValley; -using StardewValley.Menus; -using StardewValley.Tools; - -namespace PrismaticTools.Framework { - internal class BlacksmithInitializer { - private static readonly int UpgradeCost = ModEntry.Config.PrismaticToolCost; - - public static void Init(IModEvents events) { - events.Display.MenuChanged += OnMenuChanged; - } - - /// Raised after a game menu is opened, closed, or replaced. - /// The event sender. - /// The event arguments. - private static void OnMenuChanged(object sender, MenuChangedEventArgs e) { - if (!(e.NewMenu is ShopMenu menu)) { - return; - } - List categories = ModEntry.ModHelper.Reflection.GetField>(menu, "categoriesToSellHere").GetValue(); - if (!categories.Contains(Object.GemCategory) || !categories.Contains(Object.mineralsCategory) || !categories.Contains(Object.metalResources)) { - return; - } - Farmer who = Game1.player; - - Tool toolFromName1 = who.getToolFromName("Axe"); - Tool toolFromName2 = who.getToolFromName("Watering Can"); - Tool toolFromName3 = who.getToolFromName("Pickaxe"); - Tool toolFromName4 = who.getToolFromName("Hoe"); - Tool tool; - - List forSale = menu.forSale; - Dictionary stock = menu.itemPriceAndStock; - - if (toolFromName1 != null && toolFromName1.UpgradeLevel == 4) { - tool = new Axe { UpgradeLevel = 5 }; - forSale.Add(tool); - stock.Add(tool, new[] { UpgradeCost, 1, PrismaticBarItem.INDEX }); - } - if (toolFromName2 != null && toolFromName2.UpgradeLevel == 4) { - tool = new WateringCan { UpgradeLevel = 5 }; - forSale.Add(tool); - stock.Add(tool, new[] { UpgradeCost, 1, PrismaticBarItem.INDEX }); - } - if (toolFromName3 != null && toolFromName3.UpgradeLevel == 4) { - tool = new Pickaxe { UpgradeLevel = 5 }; - forSale.Add(tool); - stock.Add(tool, new[] { UpgradeCost, 1, PrismaticBarItem.INDEX }); - } - if (toolFromName4 != null && toolFromName4.UpgradeLevel == 4) { - tool = new Hoe { UpgradeLevel = 5 }; - forSale.Add(tool); - stock.Add(tool, new[] { UpgradeCost, 1, PrismaticBarItem.INDEX }); - } - } - } -} diff --git a/PrismaticTools/Framework/PrismaticItems.cs b/PrismaticTools/Framework/PrismaticItems.cs index 657ad14..042d38e 100644 --- a/PrismaticTools/Framework/PrismaticItems.cs +++ b/PrismaticTools/Framework/PrismaticItems.cs @@ -3,6 +3,7 @@ namespace PrismaticTools.Framework { public class PrismaticSprinklerItem { public const int INDEX = 1113; + public const string ID = "(O)1113"; public const int PRICE = 2000; public const int EDIBILITY = -300; public const string TYPE = "Crafting"; @@ -12,6 +13,7 @@ public class PrismaticSprinklerItem { public class PrismaticBarItem : Object { public const int INDEX = 1112; + public const string ID = "(O)1112"; public const int PRICE = 2500; public const string TYPE = "Basic"; public const int CATEGORY = metalResources; diff --git a/PrismaticTools/Framework/PrismaticPatches.cs b/PrismaticTools/Framework/PrismaticPatches.cs index 87c4cbc..bbf7740 100644 --- a/PrismaticTools/Framework/PrismaticPatches.cs +++ b/PrismaticTools/Framework/PrismaticPatches.cs @@ -16,26 +16,22 @@ internal static class PrismaticPatches { /**** ** Furnace patches ****/ - public static void Farmer_GetTallyOfObject(ref int __result, int index, bool bigCraftable) { - if (index == 382 && !bigCraftable && __result <= 0) - __result = 666666; - } public static bool Object_PerformObjectDropInAction(ref SObject __instance, ref bool __result, ref Item dropInItem, bool probe, Farmer who) { if (!(dropInItem is SObject object1)) return false; - if (object1.ParentSheetIndex != 74) + if (object1.ParentSheetIndex != Object.prismaticShardIndex) return true; if (__instance.name.Equals("Furnace")) { - if (who.IsLocalPlayer && who.getTallyOfObject(382, false) == 666666) { + if (who.IsLocalPlayer && who.Items.CountId(Object.coalQID) <= 0) { if (!probe && who.IsLocalPlayer) Game1.showRedMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:Object.cs.12772")); return false; } if (__instance.heldObject.Value == null && !probe) { - __instance.heldObject.Value = new SObject(PrismaticBarItem.INDEX, 5); + __instance.heldObject.Value = new SObject(PrismaticBarItem.INDEX.ToString(), 5); __instance.MinutesUntilReady = 2400; who.currentLocation.playSound("furnace"); __instance.initializeLightSource(__instance.TileLocation); @@ -46,7 +42,7 @@ public static bool Object_PerformObjectDropInAction(ref SObject __instance, ref alphaFade = 0.005f }); for (int index = who.Items.Count - 1; index >= 0; --index) { - if (who.Items[index] is SObject obj && obj.ParentSheetIndex == 382) { + if (who.Items[index] is SObject obj && obj.ParentSheetIndex == Object.coal) { --who.Items[index].Stack; if (who.Items[index].Stack <= 0) { who.Items[index] = null; @@ -59,9 +55,9 @@ public static bool Object_PerformObjectDropInAction(ref SObject __instance, ref __result = object1.Stack <= 0; return false; } - if (__instance.heldObject.Value == null & probe) { - if (object1.ParentSheetIndex == 74) { - __instance.heldObject.Value = new SObject(); + if (__instance.heldObject.Value == null && probe) { + if (object1.ParentSheetIndex == Object.prismaticShardIndex) { + //__instance.heldObject.Value = new SObject(); // Ends up spawning a -1 Object __result = true; return false; } @@ -110,22 +106,17 @@ public static bool Farm_AddCrows(ref Farm __instance) { return false; } - public static void After_Object_IsSprinkler(ref SObject __instance, ref bool __result) { - if (__instance.ParentSheetIndex == PrismaticSprinklerItem.INDEX) - __result = true; - } - public static void After_Object_GetBaseRadiusForSprinkler(ref SObject __instance, ref int __result) { if (__instance.ParentSheetIndex == PrismaticSprinklerItem.INDEX) __result = ModEntry.Config.SprinklerRange; } - public static bool Object_UpdatingWhenCurrentLocation(ref SObject __instance, GameTime time, GameLocation environment) { + public static bool Object_UpdatingWhenCurrentLocation(ref SObject __instance, GameTime time) { var obj = __instance; // enable sprinkler scarecrow/light if (obj.ParentSheetIndex == PrismaticSprinklerItem.INDEX) - TryEnablePrismaticSprinkler(environment, obj.TileLocation, obj); + TryEnablePrismaticSprinkler(__instance.Location, obj.TileLocation, obj); return true; } @@ -144,13 +135,13 @@ public static bool Object_OnPlacing(ref SObject __instance, GameLocation locatio ** Tool patches ****/ public static void Tree_PerformToolAction(ref Tree __instance, Tool t, int explosion) { - if (t is Axe axe && axe.UpgradeLevel == 5 && explosion <= 0 && ModEntry.ModHelper.Reflection.GetField(__instance, "health").GetValue() > -99f) { + if (t is Axe axe && axe.UpgradeLevel == 5 && explosion <= 0 && ModEntry.ModHelper.Reflection.GetField(__instance, "health").GetValue().Value > -99f) { __instance.health.Value = 0.0f; } } public static void FruitTree_PerformToolAction(ref FruitTree __instance, Tool t, int explosion) { - if (t is Axe axe && axe.UpgradeLevel == 5 && explosion <= 0 && ModEntry.ModHelper.Reflection.GetField(__instance, "health").GetValue() > -99f) { + if (t is Axe axe && axe.UpgradeLevel == 5 && explosion <= 0 && ModEntry.ModHelper.Reflection.GetField(__instance, "health").GetValue().Value > -99f) { __instance.health.Value = 0.0f; } } @@ -165,7 +156,7 @@ public static void Pickaxe_DoFunction(ref Pickaxe __instance, GameLocation locat } } - public static void ResourceClump_PerformToolAction(ref ResourceClump __instance, Tool t, int damage, Vector2 tileLocation, GameLocation location) { + public static void ResourceClump_PerformToolAction(ref ResourceClump __instance, Tool t, int damage, Vector2 tileLocation) { if (t is Axe && t.UpgradeLevel == 5 && (__instance.parentSheetIndex.Value == 600 || __instance.parentSheetIndex.Value == 602)) { __instance.health.Value = 0; } @@ -195,30 +186,46 @@ public static void Tool_TilesAffected_Postfix(ref List __result, Vector } } - public static bool Tool_Name(Tool __instance, ref string __result) { + public static bool Axe_MigrateLegacyItemId(Axe __instance) { if (__instance.UpgradeLevel == 5) { + __instance.ItemId = "PrismaticAxe"; + return false; + } + return true; + } - switch (__instance.BaseName) { - case "Axe": __result = ModEntry.ModHelper.Translation.Get("prismaticAxe"); break; - case "Pickaxe": __result = ModEntry.ModHelper.Translation.Get("prismaticPickaxe"); break; - case "Watering Can": __result = ModEntry.ModHelper.Translation.Get("prismaticWatercan"); break; - case "Hoe": __result = ModEntry.ModHelper.Translation.Get("prismaticHoe"); break; - } - //__result = "Prismatic " + __instance.BaseName; - //__result = ModEntry.ModHelper.Translation.Get("prismatic.prefix") + " " + Game1.content.LoadString("Strings\\StringsFromCSFiles:Axe.cs.1"); + public static bool WateringCan_MigrateLegacyItemId(WateringCan __instance) { + if (__instance.UpgradeLevel == 5) { + __instance.ItemId = "PrismaticWateringCan"; return false; } return true; } - public static bool Tool_DisplayName(Tool __instance, ref string __result) { + public static bool Pickaxe_MigrateLegacyItemId(Pickaxe __instance) { if (__instance.UpgradeLevel == 5) { - __result = __instance.Name; + __instance.ItemId = "PrismaticPickaxe"; return false; } return true; } + public static bool Hoe_MigrateLegacyItemId(Hoe __instance) { + if (__instance.UpgradeLevel == 5) { + __instance.ItemId = "PrismaticHoe"; + return false; + } + return true; + } + + public static void Tool_Update(Tool __instance, Farmer who) { + // The watering can naturally pushes the upward facing to a blank sqaure. The next after + // the prismatic up spirte is the fishing pole. Instead we should reset to the beginning and go backward + // by one to use that blank area. + if (__instance is WateringCan && who.FacingDirection == 0) { + __instance.CurrentParentTileIndex = __instance.InitialParentTileIndex - 1; + } + } /********* ** Private methods diff --git a/PrismaticTools/ModEntry.cs b/PrismaticTools/ModEntry.cs index 1eb9ff9..16397fd 100644 --- a/PrismaticTools/ModEntry.cs +++ b/PrismaticTools/ModEntry.cs @@ -6,6 +6,7 @@ using StardewModdingAPI; using StardewModdingAPI.Events; using StardewValley; +using StardewValley.GameData.Tools; using StardewValley.TerrainFeatures; using StardewValley.Tools; @@ -33,8 +34,7 @@ public override void Entry(IModHelper helper) { helper.Events.GameLoop.UpdateTicked += this.OnUpdateTicked; helper.Events.Player.InventoryChanged += this.OnInventoryChanged; helper.Events.Content.AssetRequested += this.OnAssetRequested; - - BlacksmithInitializer.Init(helper.Events); + helper.Events.GameLoop.GameLaunched += this.OnGameLauched; this.InitColors(); @@ -44,10 +44,6 @@ public override void Entry(IModHelper helper) { private void ApplyPatches(Harmony harmony) { // furnaces - harmony.Patch( - original: AccessTools.Method(typeof(Farmer), nameof(Farmer.getTallyOfObject)), - prefix: new HarmonyMethod(typeof(PrismaticPatches), nameof(PrismaticPatches.Farmer_GetTallyOfObject)) - ); harmony.Patch( original: AccessTools.Method(typeof(Object), nameof(Object.performObjectDropInAction)), prefix: new HarmonyMethod(typeof(PrismaticPatches), nameof(PrismaticPatches.Object_PerformObjectDropInAction)) @@ -58,10 +54,6 @@ private void ApplyPatches(Harmony harmony) { original: AccessTools.Method(typeof(Farm), nameof(Farm.addCrows)), prefix: new HarmonyMethod(typeof(PrismaticPatches), nameof(PrismaticPatches.Farm_AddCrows)) ); - harmony.Patch( - original: AccessTools.Method(typeof(Object), nameof(Object.IsSprinkler)), - postfix: new HarmonyMethod(typeof(PrismaticPatches), nameof(PrismaticPatches.After_Object_IsSprinkler)) - ); harmony.Patch( original: AccessTools.Method(typeof(Object), nameof(Object.GetBaseRadiusForSprinkler)), postfix: new HarmonyMethod(typeof(PrismaticPatches), nameof(PrismaticPatches.After_Object_GetBaseRadiusForSprinkler)) @@ -97,12 +89,24 @@ private void ApplyPatches(Harmony harmony) { postfix: new HarmonyMethod(typeof(PrismaticPatches), nameof(PrismaticPatches.Tool_TilesAffected_Postfix)) ); harmony.Patch( - original: AccessTools.Property(typeof(Tool), nameof(Tool.Name)).GetMethod, - prefix: new HarmonyMethod(typeof(PrismaticPatches), nameof(PrismaticPatches.Tool_Name)) + original: AccessTools.Method(typeof(Axe), "MigrateLegacyItemId"), + prefix: new HarmonyMethod(typeof(PrismaticPatches), nameof(PrismaticPatches.Axe_MigrateLegacyItemId)) + ); + harmony.Patch( + original: AccessTools.Method(typeof(WateringCan), "MigrateLegacyItemId"), + prefix: new HarmonyMethod(typeof(PrismaticPatches), nameof(PrismaticPatches.WateringCan_MigrateLegacyItemId)) + ); + harmony.Patch( + original: AccessTools.Method(typeof(Pickaxe), "MigrateLegacyItemId"), + prefix: new HarmonyMethod(typeof(PrismaticPatches), nameof(PrismaticPatches.Pickaxe_MigrateLegacyItemId)) ); harmony.Patch( - original: AccessTools.Property(typeof(Tool), nameof(Tool.DisplayName)).GetMethod, - prefix: new HarmonyMethod(typeof(PrismaticPatches), nameof(PrismaticPatches.Tool_DisplayName)) + original: AccessTools.Method(typeof(Hoe), "MigrateLegacyItemId"), + prefix: new HarmonyMethod(typeof(PrismaticPatches), nameof(PrismaticPatches.Hoe_MigrateLegacyItemId)) + ); + harmony.Patch( + original: AccessTools.Method(typeof(Tool), nameof(Tool.Update)), + postfix: new HarmonyMethod(typeof(PrismaticPatches), nameof(PrismaticPatches.Tool_Update)) ); } @@ -139,8 +143,17 @@ public override object GetApi() { private void UpgradeTools(string command, string[] args) { foreach (Item item in Game1.player.Items) { - if (item is Axe || item is WateringCan || item is Pickaxe || item is Hoe) { - (item as Tool).UpgradeLevel = 5; + if ((item is Axe || item is WateringCan || item is Pickaxe || item is Hoe) && (item as Tool).UpgradeLevel != 5) { + Tool t = (item as Tool); + int upgrades = 5 - t.UpgradeLevel; + // Offset Tile sprite by how many upgrades we have to make + // If upgrading over 3, skip 21 slots to align with the next row. + t.InitialParentTileIndex += upgrades >= 3 ? 7 * upgrades + 21 : 7 * (upgrades); + t.UpgradeLevel = 5; + if (item is Axe) { t.ItemId = "PrismaticAxe"; } + else if (item is WateringCan) { t.ItemId = "PrismaticWateringCan"; } + else if (item is Pickaxe) { t.ItemId = "PrismaticPickaxe"; } + else if (item is Hoe) { t.ItemId = "PrismaticHoe"; } } } } @@ -204,6 +217,51 @@ private void OnAssetRequested(object sender, AssetRequestedEventArgs e) { this.AssetEditor.OnAssetRequested(e); } + /// Raised when the game is launched for the first time. + /// The event sender. + /// The event arguments + private void OnGameLauched(object sender, GameLaunchedEventArgs e) { + Game1.toolData.Add("PrismaticAxe", this.DuplicateAndInitData(Game1.toolData["IridiumAxe"], "prismaticAxe", this.CreateUpgradeData("IridiumAxe"))); + Game1.toolData.Add("PrismaticWateringCan", this.DuplicateAndInitData(Game1.toolData["IridiumWateringCan"], "prismaticWatercan", this.CreateUpgradeData("IridiumWateringCan"))); + Game1.toolData.Add("PrismaticPickaxe", this.DuplicateAndInitData(Game1.toolData["IridiumPickaxe"], "prismaticPickaxe", this.CreateUpgradeData("IridiumPickaxe"))); + Game1.toolData.Add("PrismaticHoe", this.DuplicateAndInitData(Game1.toolData["IridiumHoe"], "prismaticHoe", this.CreateUpgradeData("IridiumHoe"))); + } + + /// Duplicates data from the passed in Tool Data and sets and fields that need to be updated. + /// The ToolData class to copy + /// The name of the new tool being added. + /// Tool upgrade information that describes who this tool upgrades from. + /// The offset from the parent sprite. + /// The offset from the parent menu sprite. + /// A fillde out ToolData class. + private ToolData DuplicateAndInitData(ToolData data, string name, ToolUpgradeData upgradeData, int offsetSprite = 7, int offsetMenuSprite = 7) { + ToolData newData = new ToolData(); + newData.ClassName = data.ClassName; + newData.Name = name; + newData.AttachmentSlots = data.AttachmentSlots; + newData.DisplayName = ModEntry.ModHelper.Translation.Get(name); + newData.Description = data.Description; + newData.Texture = data.Texture; + newData.SpriteIndex = data.SpriteIndex + offsetSprite; + newData.MenuSpriteIndex = data.MenuSpriteIndex + offsetMenuSprite; + newData.UpgradeLevel = data.UpgradeLevel + 1; + newData.CanBeLostOnDeath = data.CanBeLostOnDeath; + newData.UpgradeFrom = new List { upgradeData }; + return newData; + } + + /// Creates a new ToolUpgradeData setting the passed in id as the tool to upgrade from. + /// Name of the parent tool to upgrade from. + /// A filled out ToolUpgradeData class. + private ToolUpgradeData CreateUpgradeData(string requiredToolId) { + ToolUpgradeData newData = new ToolUpgradeData(); + newData.Price = ModEntry.Config.PrismaticToolCost; + newData.TradeItemId = PrismaticBarItem.INDEX.ToString(); + newData.RequireToolId = requiredToolId; + newData.TradeItemAmount = 5; + return newData; + } + private void InitColors() { int n = 24; for (int i = 0; i < n; i++) { diff --git a/PrismaticTools/PrismaticTools.csproj b/PrismaticTools/PrismaticTools.csproj index ccce6bc..045a9cd 100644 --- a/PrismaticTools/PrismaticTools.csproj +++ b/PrismaticTools/PrismaticTools.csproj @@ -1,12 +1,10 @@ 1.7.1 - net5.0 - + net6.0 true - - + \ No newline at end of file