diff --git a/BetterJunimos/BetterJunimos.cs b/BetterJunimos/BetterJunimos.cs index 7a364bb..d105645 100644 --- a/BetterJunimos/BetterJunimos.cs +++ b/BetterJunimos/BetterJunimos.cs @@ -645,30 +645,24 @@ private static void AllowJunimoHutPurchasing() { private void SpawnJunimoCommand() { var currentLocation = Game1.player.currentLocation; - //Util.SendMessage($"Estas en zona {currentLocation.Name} y su padre es {currentLocation.GetParentLocation()?.Name}"); - var locationtoeval = currentLocation; - if (currentLocation.GetParentLocation() is not null) - { - locationtoeval = currentLocation.GetParentLocation(); - } - var junimoHuts = Util.GetAllFarms() - .FindAll(farm => farm.Equals(locationtoeval)) - .SelectMany(farm => farm.buildings.OfType()) - .ToList(); - if (!junimoHuts.Any()) { - Util.SendMessage(Helper.Translation.Get("msg.cannot-spawn-without-hut")); - return; - } + if (currentLocation.IsFarm || currentLocation.IsGreenhouse) { + var junimoHuts = Util.GetAllFarms() + .FindAll(farm => farm.Equals(currentLocation)) + .SelectMany(farm => farm.buildings.OfType()) + .ToList(); - var hut = junimoHuts.ElementAt(Game1.random.Next(0, junimoHuts.Count)); - Util.SpawnJunimoAtPosition(currentLocation, Game1.player.Position, hut, Game1.random.Next(4, 100)); - // if (currentLocation.IsFarm || currentLocation.IsGreenhouse) { - //Quitamos esta condicion en teoria solo nos interesa que haya un junimo hut en la ubicacion en la que estemos - // } - // else { - // Util.SendMessage(Helper.Translation.Get("msg.cannot-spawn-here")); - // } + if (!junimoHuts.Any()) { + Util.SendMessage(Helper.Translation.Get("msg.cannot-spawn-without-hut")); + return; + } + + var hut = junimoHuts.ElementAt(Game1.random.Next(0, junimoHuts.Count)); + Util.SpawnJunimoAtPosition(currentLocation, Game1.player.Position, hut, Game1.random.Next(4, 100)); + } + else { + Util.SendMessage(Helper.Translation.Get("msg.cannot-spawn-here")); + } } private static void CheckForWages(JunimoHut hut) { diff --git a/BetterJunimos/Patches/JunimoHarvesterPatches.cs b/BetterJunimos/Patches/JunimoHarvesterPatches.cs index 196f194..06f19f7 100644 --- a/BetterJunimos/Patches/JunimoHarvesterPatches.cs +++ b/BetterJunimos/Patches/JunimoHarvesterPatches.cs @@ -199,7 +199,7 @@ public static bool Prefix(JunimoHarvester __instance, if (__instance.controller != null) return false; - if (__instance.currentLocation.GetParentLocation() is null) + if (__instance.currentLocation is Farm) __instance.returnToJunimoHut(__instance.currentLocation); else { // can't walk back to the hut from here, just despawn @@ -210,7 +210,7 @@ public static bool Prefix(JunimoHarvester __instance, // Prevent working when not paid else if (BetterJunimos.Config.JunimoPayment.WorkForWages && !Util.Payments.WereJunimosPaidToday) { - if (Game1.random.NextDouble() < 0.02) { + if (Game1.random.NextDouble() < 0.02 && __instance.currentLocation.IsFarm) { __instance.pathfindToRandomSpotAroundHut(); } else { @@ -246,8 +246,7 @@ __instance.controller.pathToEndPoint is not null && hut.tileX is not null && hut.tileY is not null && __instance.currentLocation is not null && - //__instance.currentLocation.IsFarm && //No nos interesa que sea o no granja - ( + __instance.currentLocation.NameOrUniqueName == hut.GetParentLocation().NameOrUniqueName && ( Math.Abs(__instance.controller.pathToEndPoint.Last().X - hut.tileX.Value - 1) > radius || Math.Abs(__instance.controller.pathToEndPoint.Last().Y - hut.tileY.Value - 1) > radius ); @@ -298,10 +297,10 @@ __instance.currentLocation is not null && // unlucky, send Junimo home ___netAnimationEvent.Fire(0); - if (__instance.currentLocation.GetParentLocation() is null){ + if (__instance.currentLocation is Farm) { __instance.returnToJunimoHut(__instance.currentLocation); } - else if (__instance.currentLocation.GetParentLocation() is not null) { + else if (__instance.currentLocation.IsGreenhouse) { returnToGreenhouseDoor(__instance, __instance.currentLocation); } else { @@ -350,7 +349,7 @@ private static void returnToGreenhouseDoor(JunimoHarvester junimo, GameLocation } private static Point GreenhouseDoor(GameLocation location) { - foreach (var warp in location.warps.Where(warp => warp.TargetName == location.GetParentLocation().Name)) + foreach (var warp in location.warps.Where(warp => warp.TargetName == "Farm")) { return new Point(warp.X, warp.Y); } diff --git a/BetterJunimos/Utils/Util.cs b/BetterJunimos/Utils/Util.cs index 7da464f..1aba874 100644 --- a/BetterJunimos/Utils/Util.cs +++ b/BetterJunimos/Utils/Util.cs @@ -32,7 +32,7 @@ public class Util { public static List GetAllFarms() { return Game1.locations - //.Where(loc => loc.IsFarm && loc.IsOutdoors) //Obten todas las ubicaciones + //.Where(loc => loc.IsFarm && loc.IsOutdoors) .ToList(); }