Skip to content

Commit

Permalink
Detect all locations indicated to be outdoor farms
Browse files Browse the repository at this point in the history
  • Loading branch information
roccojiang committed Apr 23, 2024
1 parent 78357c1 commit 226d996
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 22 deletions.
1 change: 0 additions & 1 deletion BetterJunimos/Abilities/JunimoAbilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ public static bool ActionCoolingDown(GameLocation location, IJunimoAbility abili
}

private static bool ItemInHut(Guid id, string item) {
// BetterJunimos.SMonitor.Log($"Items in huts keys = ${string.Join(",", ItemsInHuts.Keys)}", LogLevel.Debug);
return ItemsInHuts[id].TryGetValue(item, out var present) && present;
}

Expand Down
2 changes: 1 addition & 1 deletion BetterJunimos/BetterJunimos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ private void SpawnJunimoCommand() {
var currentLocation = Game1.player.currentLocation;

if (currentLocation.IsFarm || currentLocation.IsGreenhouse) {
var junimoHuts = Util.getFarms()
var junimoHuts = Util.GetAllFarms()
.FindAll(farm => farm.Equals(currentLocation))
.SelectMany(farm => farm.buildings.OfType<JunimoHut>())
.ToList();
Expand Down
1 change: 0 additions & 1 deletion BetterJunimos/Patches/JunimoHutPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public static bool Prefix(JunimoHut __instance, ref bool __result) {
private static bool SearchAroundHut(JunimoHut hut) {
var id = Util.GetHutIdFromHut(hut);
var radius = Util.CurrentWorkingRadius;
// GameLocation farm = Game1.getFarm();
GameLocation farm = Game1.currentLocation;

// SearchHutGrid manages hut.lastKnownCropLocation and Util.Abilities.lastKnownCropLocations
Expand Down
2 changes: 1 addition & 1 deletion BetterJunimos/Utils/JunimoProgression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ internal void ListAvailableActions(Guid id) {


public static bool HutOnTile(Vector2 pos) {
return Util.getFarms().Any(farm => farm.buildings.Any(b => b is JunimoHut && b.occupiesTile(pos)));
return Util.GetAllFarms().Any(farm => farm.buildings.Any(b => b is JunimoHut && b.occupiesTile(pos)));
}

private string Get(string key) {
Expand Down
23 changes: 5 additions & 18 deletions BetterJunimos/Utils/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,8 @@ public class Util {
internal static JunimoProgression Progression;
internal static JunimoGreenhouse Greenhouse;

public static List<GameLocation> getFarms() {
// TODO: use the trick from Discord?

var farms = new List<GameLocation> { Game1.getFarm() };

var ridgesideSummitFarm = Game1.getLocationFromName("Custom_Ridgeside_SummitFarm");
if (ridgesideSummitFarm != null) {
farms.Add(ridgesideSummitFarm);
}

// BetterJunimos.SMonitor.Log($"Buildings found in main farm ${string.Join(",", farms[0].buildings)}", LogLevel.Debug);
// BetterJunimos.SMonitor.Log($"Buildings found in summit farm ${string.Join(",", farms[1].buildings)}", LogLevel.Debug);

return farms;
public static List<GameLocation> GetAllFarms() {
return Game1.locations.Where(loc => loc.IsFarm && loc.IsOutdoors).ToList();
}

public static int CurrentWorkingRadius {
Expand All @@ -55,23 +43,22 @@ public static int CurrentWorkingRadius {
}

public static List<JunimoHut> GetAllHuts() {
return getFarms().SelectMany(farm => farm.buildings.OfType<JunimoHut>().ToList()).ToList();
return GetAllFarms().SelectMany(farm => farm.buildings.OfType<JunimoHut>().ToList()).ToList();
}

public static Guid GetHutIdFromHut(JunimoHut hut) {
return getFarms().Select(farm => farm.buildings.GuidOf(hut)).ToList().Find(guid => guid != Guid.Empty);
return GetAllFarms().Select(farm => farm.buildings.GuidOf(hut)).ToList().Find(guid => guid != Guid.Empty);
}

public static JunimoHut GetHutFromId(Guid id) {
foreach (var farm in getFarms()) {
foreach (var farm in GetAllFarms()) {
if (farm.buildings.TryGetValue(id, out var hut)) {
return hut as JunimoHut;
}
}

BetterJunimos.SMonitor.Log($"Could not get hut from id ${id}", LogLevel.Error);
return null;
// return getFarms().Select(farm => farm.buildings[id]).ToList().Find(hut => hut != null) as JunimoHut;
}

public static void AddItemToChest(GameLocation farm, Chest chest, SObject item) {
Expand Down

0 comments on commit 226d996

Please sign in to comment.