Skip to content

Commit

Permalink
etc
Browse files Browse the repository at this point in the history
  • Loading branch information
aedenthorn committed Jan 7, 2023
1 parent 93273da commit 44c9645
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 84 deletions.
11 changes: 6 additions & 5 deletions HelpWanted/Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ private static List<int> GetRandomItemList(List<int> possibleItems)
{
if (!int.TryParse(str, out int i))
continue;
if (i > 1000)
{
var x = i;
}
Object obj = new Object(i, 1);
if (!Config.AllowArtisanGoods && obj is not null && obj.Category == Object.artisanGoodsCategory)
continue;
if (Config.MaxPrice > 0 && obj is not null && obj.Price > Config.MaxPrice)
continue;
items.Add(i);
}
if (!items.Any() || (!Config.IgnoreVanillaItemSelection && possibleItems?.Any() != true))
Expand All @@ -87,7 +88,7 @@ private static List<int> GetRandomItemList(List<int> possibleItems)
if (idx >= 0)
{
Object obj = new Object(idx, 1);
if (obj is null || !items.Contains(obj.Category))
if (obj is null || !items.Contains(obj.Category) || (!Config.AllowArtisanGoods && obj.Category == Object.artisanGoodsCategory) || (Config.MaxPrice > 0 && obj.Price > Config.MaxPrice))
{
possibleItems.RemoveAt(i);
}
Expand Down
3 changes: 3 additions & 0 deletions HelpWanted/ModConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ public class ModConfig
public bool ModEnabled { get; set; } = true;
public bool MustLikeItem { get; set; } = true;
public bool MustLoveItem { get; set; } = false;
public bool AllowArtisanGoods { get; set; } = true;
public bool IgnoreVanillaItemSelection { get; set; } = true;
public bool OneQuestPerVillager { get; set; } = true;
public bool AvoidMaxHeartQuests { get; set; } = true;
public int MaxPrice { get; set; } = -1;
public int QuestDays { get; set; } = 2;
public int MaxQuests { get; set; } = 10;
public float NoteScale { get; set; } = 2;
Expand Down
17 changes: 12 additions & 5 deletions HelpWanted/ModEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ private void GameLoop_GameLaunched(object sender, StardewModdingAPI.Events.GameL
setValue: value => Config.MustLoveItem = value
);

configMenu.AddBoolOption(
mod: ModManifest,
name: () => "Allow Artisan Goods",
getValue: () => Config.AllowArtisanGoods,
setValue: value => Config.AllowArtisanGoods = value
);

configMenu.AddBoolOption(
mod: ModManifest,
name: () => "Ignore Game's Item Choice",
Expand All @@ -243,12 +250,12 @@ private void GameLoop_GameLaunched(object sender, StardewModdingAPI.Events.GameL
getValue: () => Config.OneQuestPerVillager,
setValue: value => Config.OneQuestPerVillager = value
);
configMenu.AddBoolOption(

configMenu.AddNumberOption(
mod: ModManifest,
name: () => "One Quest / Villager",
getValue: () => Config.OneQuestPerVillager,
setValue: value => Config.OneQuestPerVillager = value
name: () => "Max Item Price",
getValue: () => Config.MaxPrice,
setValue: value => Config.MaxPrice = value
);

configMenu.AddNumberOption(
Expand Down
2 changes: 1 addition & 1 deletion HelpWanted/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Name": "Help Wanted",
"Author": "aedenthorn",
"Version": "0.4.5",
"Version": "0.5.1",
"Description": "Help Wanted.",
"UniqueID": "aedenthorn.HelpWanted",
"EntryDll": "HelpWanted.dll",
Expand Down
31 changes: 24 additions & 7 deletions OmniTools/CodePatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,12 @@ public static void Postfix(IClickableMenu __instance, Keys key)
if (c.containsPoint(mouse.X, mouse.Y))
{
int slotNumber = Convert.ToInt32(c.name);
if (slotNumber >= inv.actualInventory.Count || inv.actualInventory[slotNumber] is null || !inv.actualInventory[slotNumber].modData.TryGetValue(toolsKey, out string toolsString))
if (slotNumber >= inv.actualInventory.Count || inv.actualInventory[slotNumber] is not Tool || !inv.actualInventory[slotNumber].modData.TryGetValue(toolsKey, out string toolsString))
return;
inv.actualInventory[slotNumber] = CycleTool(inv.actualInventory[slotNumber] as Tool, toolsString);
var newTool = CycleTool(inv.actualInventory[slotNumber] as Tool, toolsString);
if(slotNumber == Game1.player.CurrentToolIndex)
UpdateEnchantments(Game1.player, inv.actualInventory[slotNumber] as Tool, newTool);
inv.actualInventory[slotNumber] = newTool;
return;
}
}
Expand All @@ -127,9 +130,12 @@ public static void Postfix(IClickableMenu __instance, Keys key)
if (c.containsPoint(mouse.X, mouse.Y))
{
int slotNumber = Convert.ToInt32(c.name);
if (slotNumber >= inv.actualInventory.Count || inv.actualInventory[slotNumber] is null || !inv.actualInventory[slotNumber].modData.TryGetValue(toolsKey, out string toolsString))
if (slotNumber >= inv.actualInventory.Count || inv.actualInventory[slotNumber] is not Tool || !inv.actualInventory[slotNumber].modData.TryGetValue(toolsKey, out string toolsString))
return;
inv.actualInventory[slotNumber] = RemoveTool(inv.actualInventory[slotNumber] as Tool, toolsString);
var newTool = RemoveTool(inv.actualInventory[slotNumber] as Tool, toolsString);
if (slotNumber == Game1.player.CurrentToolIndex)
UpdateEnchantments(Game1.player, inv.actualInventory[slotNumber] as Tool, newTool);
inv.actualInventory[slotNumber] = newTool;
return;
}
}
Expand Down Expand Up @@ -200,6 +206,7 @@ public static void Prefix(Farmer __instance)
Tool t = SmartSwitch(__instance.CurrentTool, __instance.currentLocation, tile, tools);
if (t is not null)
{
UpdateEnchantments(__instance, __instance.CurrentTool, t);
__instance.CurrentTool = t;
}
}
Expand Down Expand Up @@ -260,9 +267,19 @@ public static void Prefix(HoeDirt __instance)
{
if (!Config.EnableMod || !Config.SwitchForCrops || Game1.player.CurrentTool is not Tool || !Game1.player.CurrentTool.modData.ContainsKey(toolsKey))
return;
Tool tool = SwitchForTerrainFeature(Game1.player.CurrentTool, __instance);
if (tool is not null)
Game1.player.CurrentTool = tool;
Tool t = SwitchForTerrainFeature(Game1.player.CurrentTool, __instance);
if (t is not null)
{
foreach (var e in Game1.player.CurrentTool.enchantments)
{
e.OnUnequip(Game1.player);
}
Game1.player.CurrentTool = t;
foreach (var e in t.enchantments)
{
e.ApplyTo(t, Game1.player);
}
}
}
}
}
Expand Down
14 changes: 13 additions & 1 deletion OmniTools/Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,18 @@ public static Tool RemoveTool(Tool currentTool, string toolsString)
return t;
}


public static void UpdateEnchantments(Farmer player, Tool oldTool, Tool newTool)
{
foreach (var e in oldTool.enchantments)
{
e.OnUnequip(player);
}
foreach (var e in newTool.enchantments)
{
e.OnEquip(player);
}
}
public static Tool GetToolFromInfo(ToolInfo toolInfo)
{
Tool t = GetToolFromDescription(toolInfo.description.index, toolInfo.description.upgradeLevel);
Expand All @@ -381,7 +393,7 @@ public static Tool GetToolFromInfo(ToolInfo toolInfo)
try
{
var type = typeof(Game1).Assembly.GetType(s);
AccessTools.Method(t.enchantments.GetType(), "Add").Invoke(t.enchantments, new object[] { Activator.CreateInstance(type) });
AccessTools.Method(t.GetType(), "AddEnchantment").Invoke(t, new object[] { Activator.CreateInstance(type) });
}
catch { }
}
Expand Down
15 changes: 13 additions & 2 deletions OmniTools/ModEntry.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using HarmonyLib;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Netcode;
using Newtonsoft.Json;
using StardewModdingAPI;
using StardewModdingAPI.Utilities;
Expand Down Expand Up @@ -91,11 +92,21 @@ private void Input_ButtonPressed(object sender, StardewModdingAPI.Events.ButtonP
return;
if(e.Button == Config.CycleButton)
{
Game1.player.CurrentTool = CycleTool(Game1.player.CurrentTool, toolsString);
var newTool = CycleTool(Game1.player.CurrentTool, toolsString);
if(newTool != null)
{
UpdateEnchantments(Game1.player, Game1.player.CurrentTool, newTool);
Game1.player.CurrentTool = newTool;
}
}
else if(e.Button == Config.RemoveButton)
{
Game1.player.CurrentTool = RemoveTool(Game1.player.CurrentTool, toolsString);
var newTool = RemoveTool(Game1.player.CurrentTool, toolsString);
if (newTool != null)
{
UpdateEnchantments(Game1.player, Game1.player.CurrentTool, newTool);
Game1.player.CurrentTool = newTool;
}
}
}

Expand Down
94 changes: 53 additions & 41 deletions OmniTools/OmniToolsAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,38 @@ namespace OmniTools
{
public class OmniToolsAPI : IOmniToolsAPI
{
public Tool SmartSwitch(Tool tool, GameLocation gameLocation, Vector2 tile)
public Tool SmartSwitch(Tool tool, GameLocation gameLocation, Vector2 tile, Farmer f = null)
{
return ModEntry.SmartSwitch(tool, gameLocation, tile);
var newTool = ModEntry.SmartSwitch(tool, gameLocation, tile);
if (f is not null && newTool is not null)
{
ModEntry.UpdateEnchantments(f, tool, newTool);
}
return newTool;
}

public Tool SwitchTool(Tool tool, Type toolType)
public Tool SwitchTool(Tool tool, Type toolType, Farmer f = null)
{
return ModEntry.SwitchTool(tool, toolType);
var newTool = ModEntry.SwitchTool(tool, toolType);
if (f is not null && newTool is not null)
{
ModEntry.UpdateEnchantments(f, tool, newTool);
}
return newTool;
}
public bool IsOmniTool(Tool tool)
{
return tool.modData.ContainsKey(ModEntry.toolsKey);
}
public string[] GetToolNames(Tool tool)
{
if (!tool.modData.TryGetValue(ModEntry.toolsKey, out var toolsString))
return null;
return JsonConvert.DeserializeObject<List<ToolInfo>>(toolsString).Select(i => i.displayName).ToArray();
}
public Tool[] GetTools(Tool tool)
{
return ModEntry.GetToolsFromTool(tool);
}
public Tool SwitchForResourceClump(Tool tool, ResourceClump clump)
{
Expand All @@ -37,21 +61,6 @@ public Tool SwitchForFarmAnimal(Tool tool, FarmAnimal animal)
{
return ModEntry.SwitchForAnimal(tool, animal);
}
public bool IsOmniTool(Tool tool)
{
return tool.modData.ContainsKey(ModEntry.toolsKey);
}
public string[] GetToolNames(Tool tool)
{
if (!tool.modData.TryGetValue(ModEntry.toolsKey, out var toolsString))
return null;
return JsonConvert.DeserializeObject<List<ToolInfo>>(toolsString).Select(i => i.displayName).ToArray();
}
public Tool[] GetTools(Tool tool)
{

return ModEntry.GetToolsFromTool(tool);
}
}

public interface IOmniToolsAPI
Expand All @@ -60,8 +69,31 @@ public interface IOmniToolsAPI
/// <param name="tool">The omni-tool to be switched.</param>
/// <param name="gameLocation">The current game location.</param>
/// <param name="tile">The coordinates of the tile being acted upon.</param>
/// <param name="f">The farmer holding the tool (optional).</param>
/// <returns>The altered tool or <c>null</c> if no appropriate change is detected.</returns>
public Tool SmartSwitch(Tool tool, GameLocation gameLocation, Vector2 tile);
public Tool SmartSwitch(Tool tool, GameLocation gameLocation, Vector2 tile, Farmer f = null);

/// <summary>Switch tools to a specific tool type.</summary>
/// <param name="tool">The omni-tool to be switched.</param>
/// <param name="toolType">The tool type to switch to.</param>
/// <param name="f">The farmer holding the tool (optional).</param>
/// <returns>The altered tool or <c>null</c> if no tool of the type is found in the omni-tool.</returns>
public Tool SwitchTool(Tool tool, Type toolType, Farmer f = null);

/// <summary>Check if a tool is an omni-tool.</summary>
/// <param name="tool">The omni-tool to be checked.</param>
/// <returns>True if the tool is an omni-tool.</returns>
public bool IsOmniTool(Tool tool);

/// <summary>Get names of tools stored in an omni-tool.</summary>
/// <param name="tool">The omni-tool.</param>
/// <returns>An array of tool display names stored in the omni-tool (does not include the tool itself).</returns>
public string[] GetToolNames(Tool tool);

/// <summary>Get tools stored in an omni-tool.</summary>
/// <param name="tool">The omni-tool.</param>
/// <returns>An array of tools stored in the omni-tool (does not include the tool itself).</returns>
public Tool[] GetTools(Tool tool);

/// <summary>Switch tools based on a <see cref="StardewValley.TerrainFeatures.ResourceClump">resource clump</see>.</summary>
/// <param name="tool">The omni-tool to be switched.</param>
Expand All @@ -80,32 +112,12 @@ public interface IOmniToolsAPI
/// <param name="clump">The <see cref="StardewValley.TerrainFeatures.TerrainFeature">terrain feature</see>.</param>
/// <returns>The altered tool or <c>null</c> if no appropriate change is detected.</returns>
public Tool SwitchForTerrainFeature(Tool tool, TerrainFeature tf);

/// <summary>Switch tools based on a <see cref="StardewValley.FarmAnimal">farm animal</see>.</summary>
/// <param name="tool">The omni-tool to be switched.</param>
/// <param name="clump">The <see cref="StardewValley.FarmAnimal">farm animal</see>.</param>
/// <returns>The altered tool or <c>null</c> if no appropriate change is detected.</returns>
public Tool SwitchForFarmAnimal(Tool tool, FarmAnimal animal);

/// <summary>Switch tools to a specific tool type.</summary>
/// <param name="tool">The omni-tool to be switched.</param>
/// <param name="toolType">The tool type to switch to.</param>
/// <returns>The altered tool or <c>null</c> if no tool of the type is found in the omni-tool.</returns>
public Tool SwitchTool(Tool tool, Type toolType);

/// <summary>Check if a tool is an omni-tool.</summary>
/// <param name="tool">The omni-tool to be checked.</param>
/// <returns>True if the tool is an omni-tool.</returns>
public bool IsOmniTool(Tool tool);

/// <summary>Get names of tools stored in an omni-tool.</summary>
/// <param name="tool">The omni-tool.</param>
/// <returns>An array of tool display names stored in the omni-tool (does not include the tool itself).</returns>
public string[] GetToolNames(Tool tool);

/// <summary>Get tools stored in an omni-tool.</summary>
/// <param name="tool">The omni-tool.</param>
/// <returns>An array of tools stored in the omni-tool (does not include the tool itself).</returns>
public Tool[] GetTools(Tool tool);
}
}
2 changes: 1 addition & 1 deletion OmniTools/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Name": "Omni Tools",
"Author": "aedenthorn",
"Version": "0.4.1",
"Version": "0.4.2",
"Description": "Omni Tools.",
"UniqueID": "aedenthorn.OmniTools",
"EntryDll": "OmniTools.dll",
Expand Down
Loading

0 comments on commit 44c9645

Please sign in to comment.