Skip to content

Commit

Permalink
Merge pull request #32 from Tiln1/master
Browse files Browse the repository at this point in the history
Made some minor changes trying to fix the Junimo's inability to plant
  • Loading branch information
hawkfalcon authored Apr 18, 2024
2 parents dc9941f + 11b89fc commit dc13203
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
25 changes: 9 additions & 16 deletions BetterJunimos/Abilities/Base/PlantCropsAbility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public class PlantCropsAbility : IJunimoAbility {
private const string DeluxeSpeedGro = "466";
private const string HyperSpeedGro = "918";

static Dictionary<string, int> WildTreeSeeds = new() {{"292", 8}, {"309", 1}, {"310", 2}, {"311", 3}, {"891", 7}};
static Dictionary<string, Dictionary<string, bool>> cropSeasons = new();

internal PlantCropsAbility(IMonitor Monitor) {
Expand Down Expand Up @@ -69,7 +68,7 @@ public bool PerformAction(GameLocation location, Vector2 pos, JunimoHarvester ju

// BetterJunimos.SMonitor.Log(
// $"PerformAction planting {foundItem.Name} in {location.Name} at at [{pos.X} {pos.Y}]", LogLevel.Debug);
if (Plant(location, pos, foundItem.itemId.ToString())) {
if (Plant(location, pos, foundItem.ItemId)) {
Util.RemoveItemFromChest(chest, foundItem);
// BetterJunimos.SMonitor.Log(
// $"PerformAction planted {foundItem.Name} in {location.Name} at at [{pos.X} {pos.Y}]", LogLevel.Debug);
Expand All @@ -85,9 +84,8 @@ public bool PerformAction(GameLocation location, Vector2 pos, JunimoHarvester ju
/// <summary>Get an item from the chest that is a crop seed, plantable in this season</summary>
private Item PlantableSeed(GameLocation location, Chest chest, string cropType=null) {
var foundItems = chest.Items.ToList().FindAll(item =>
item != null
&& item.Category == ItemCategory
&& !IsTreeSeed(item)
item != null
&& (new StardewValley.Object(item.ItemId, 1)).Type == "Seeds"
&& !(BetterJunimos.Config.JunimoImprovements.AvoidPlantingCoffee && item.ParentSheetIndex == Util.CoffeeId)
);

Expand All @@ -112,17 +110,17 @@ private Item PlantableSeed(GameLocation location, Chest chest, string cropType=n
continue;
}

var key = foundItem.itemId;
var key = foundItem.ItemId;
try {
if (cropSeasons[Game1.currentSeason][key.ToString()]) {
if (cropSeasons[Game1.currentSeason][key]) {
return foundItem;
}
} catch (KeyNotFoundException)
{
// Monitor.Log($"Cache miss: {key} {Game1.currentSeason}", LogLevel.Debug);
var crop = new Crop(foundItem.itemId.ToString(), 0, 0, location);
cropSeasons[Game1.currentSeason][key.ToString()] = crop.IsInSeason(location);
if (cropSeasons[Game1.currentSeason][key.ToString()]) {
var crop = new Crop(key, 0, 0, location);
cropSeasons[Game1.currentSeason][key] = crop.IsInSeason(location);
if (cropSeasons[Game1.currentSeason][key]) {
return foundItem;
}
}
Expand All @@ -131,14 +129,9 @@ private Item PlantableSeed(GameLocation location, Chest chest, string cropType=n

return null;
}

// TODO: look this up properly instead of keeping a list of base-game tree seed item IDs
protected bool IsTreeSeed(Item item) {
return WildTreeSeeds.ContainsKey(item.itemId.ToString());
}

private bool IsTrellisCrop(Item item, GameLocation location) {
Crop crop = new Crop(item.itemId.ToString(), 0, 0, location);
Crop crop = new Crop(item.ItemId, 0, 0, location);
return crop.raisedSeeds.Value;
}

Expand Down
2 changes: 1 addition & 1 deletion BetterJunimos/Abilities/JunimoAbilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private void UpdateHutContainsItems(Guid id, Chest chest, List<string> items) {

private static void UpdateHutContainsItemId(Guid id, Chest chest, string itemId) {
ItemsInHuts[id][itemId] = chest.Items.Any(item =>
item != null && item.ItemId.ToString() == itemId &&
item != null && item.ItemId == itemId &&
!(BetterJunimos.Config.JunimoImprovements.AvoidPlantingCoffee && item.ParentSheetIndex == Util.CoffeeId)
);
}
Expand Down
2 changes: 1 addition & 1 deletion BetterJunimos/Utils/JunimoProgression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ private bool ReceiveItems(Chest chest, int needed, string itemID) {
// BetterJunimos.SMonitor.Log($"ReceiveItems wants {needed} of [{index}]", LogLevel.Debug);
if (needed <= 0) return true;

var inChest = chest.Items.Where(item => item != null && item.itemId.ToString() == itemID).ToList();
var inChest = chest.Items.Where(item => item != null && item.ItemId == itemID).ToList();

foreach (var itemStack in inChest) {
if (itemStack.Stack >= needed) {
Expand Down

0 comments on commit dc13203

Please sign in to comment.