Skip to content

Commit

Permalink
Extra buildeable zones fix-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel Angel Padilla Abrego committed May 30, 2024
1 parent 4fbee88 commit e1cb1f4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
38 changes: 22 additions & 16 deletions BetterJunimos/BetterJunimos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -643,24 +643,30 @@ private static void AllowJunimoHutPurchasing() {

private void SpawnJunimoCommand() {
var currentLocation = Game1.player.currentLocation;

if (currentLocation.IsFarm || currentLocation.IsGreenhouse) {
var junimoHuts = Util.GetAllFarms()
.FindAll(farm => farm.Equals(currentLocation))
.SelectMany(farm => farm.buildings.OfType<JunimoHut>())
.ToList();

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));
//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();
}
else {
Util.SendMessage(Helper.Translation.Get("msg.cannot-spawn-here"));
var junimoHuts = Util.GetAllFarms()
.FindAll(farm => farm.Equals(locationtoeval))
.SelectMany(farm => farm.buildings.OfType<JunimoHut>())
.ToList();

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));
// 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"));
// }
}

private static void CheckForWages(JunimoHut hut) {
Expand Down
13 changes: 7 additions & 6 deletions BetterJunimos/Patches/JunimoHarvesterPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public static bool Prefix(JunimoHarvester __instance,
if (__instance.controller != null)
return false;

if (__instance.currentLocation is Farm)
if (__instance.currentLocation.GetParentLocation() is null)
__instance.returnToJunimoHut(__instance.currentLocation);
else {
// can't walk back to the hut from here, just despawn
Expand All @@ -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 && __instance.currentLocation.IsFarm) {
if (Game1.random.NextDouble() < 0.02) {
__instance.pathfindToRandomSpotAroundHut();
}
else {
Expand Down Expand Up @@ -246,7 +246,8 @@ __instance.controller.pathToEndPoint is not null &&
hut.tileX is not null &&
hut.tileY is not null &&
__instance.currentLocation is not null &&
__instance.currentLocation.IsFarm && (
//__instance.currentLocation.IsFarm && //No nos interesa que sea o no granja
(
Math.Abs(__instance.controller.pathToEndPoint.Last().X - hut.tileX.Value - 1) > radius ||
Math.Abs(__instance.controller.pathToEndPoint.Last().Y - hut.tileY.Value - 1) > radius
);
Expand Down Expand Up @@ -297,10 +298,10 @@ __instance.currentLocation is not null &&
// unlucky, send Junimo home
___netAnimationEvent.Fire(0);

if (__instance.currentLocation is Farm) {
if (__instance.currentLocation.GetParentLocation() is null){
__instance.returnToJunimoHut(__instance.currentLocation);
}
else if (__instance.currentLocation.IsGreenhouse) {
else if (__instance.currentLocation.GetParentLocation() is not null) {
returnToGreenhouseDoor(__instance, __instance.currentLocation);
}
else {
Expand Down Expand Up @@ -349,7 +350,7 @@ private static void returnToGreenhouseDoor(JunimoHarvester junimo, GameLocation
}

private static Point GreenhouseDoor(GameLocation location) {
foreach (var warp in location.warps.Where(warp => warp.TargetName == "Farm"))
foreach (var warp in location.warps.Where(warp => warp.TargetName == location.GetParentLocation().Name))
{
return new Point(warp.X, warp.Y);
}
Expand Down
4 changes: 3 additions & 1 deletion BetterJunimos/Utils/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public class Util {
internal static JunimoGreenhouse Greenhouse;

public static List<GameLocation> GetAllFarms() {
return Game1.locations.Where(loc => loc.IsFarm && loc.IsOutdoors).ToList();
return Game1.locations
//.Where(loc => loc.IsFarm && loc.IsOutdoors) //Obten todas las ubicaciones
.ToList();
}

public static int CurrentWorkingRadius {
Expand Down

0 comments on commit e1cb1f4

Please sign in to comment.