Skip to content

Commit

Permalink
Merge pull request #2 from Miguel-Thewolf/master
Browse files Browse the repository at this point in the history
Get changes from master
  • Loading branch information
EienWolf authored Jun 1, 2024
2 parents 062497e + 6827250 commit 53ace95
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 30 deletions.
38 changes: 16 additions & 22 deletions BetterJunimos/BetterJunimos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<JunimoHut>())
.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<JunimoHut>())
.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) {
Expand Down
13 changes: 6 additions & 7 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.GetParentLocation() is null)
if (__instance.currentLocation is Farm)
__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) {
if (Game1.random.NextDouble() < 0.02 && __instance.currentLocation.IsFarm) {
__instance.pathfindToRandomSpotAroundHut();
}
else {
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion BetterJunimos/Utils/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class Util {

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

Expand Down

0 comments on commit 53ace95

Please sign in to comment.