public static void Postfix(JunimoHut __instance, GameTime time, int __state)
        {
            var junimoSendOutTimer = Util.Reflection.GetField <int>(__instance, "junimoSendOutTimer");
            int sendOutTimer       = __state;

            // from Update
            junimoSendOutTimer.SetValue(sendOutTimer - time.ElapsedGameTime.Milliseconds);
            if (sendOutTimer > 0 || __instance.myJunimos.Count() >= Util.Config.JunimoHuts.MaxJunimos ||
                !__instance.areThereMatureCropsWithinRadius() || Game1.farmEvent != null)
            {
                return;
            }
            // Winter
            if (Game1.IsWinter && !Util.Config.JunimoImprovements.CanWorkInWinter)
            {
                return;
            }
            // Rain
            if (Game1.isRaining && !Util.Config.JunimoImprovements.CanWorkInRain)
            {
                return;
            }

            Util.SpawnJunimoAtHut(__instance);
            junimoSendOutTimer.SetValue(1000);
        }
Example #2
0
        public static void Postfix(JunimoHut __instance, GameTime time, ref int ___junimoSendOutTimer, int __state)
        {
            int sendOutTimer = __state;

            if (sendOutTimer <= 0)
            {
                return;
            }

            ___junimoSendOutTimer = sendOutTimer - time.ElapsedGameTime.Milliseconds;
            // Don't work on farmEvent days
            if (Game1.farmEvent != null)
            {
                return;
            }
            // Winter
            if (Game1.IsWinter && !Util.Config.JunimoImprovements.CanWorkInWinter)
            {
                return;
            }
            // Rain
            if (Game1.isRaining && !Util.Config.JunimoImprovements.CanWorkInRain)
            {
                return;
            }
            // Currently sending out a junimo
            if (___junimoSendOutTimer > 0)
            {
                return;
            }
            // Already enough junimos
            if (__instance.myJunimos.Count() >= Util.Config.JunimoHuts.MaxJunimos)
            {
                return;
            }
            // Nothing to do
            if (!__instance.areThereMatureCropsWithinRadius())
            {
                return;
            }

            Util.SpawnJunimoAtHut(__instance);
            ___junimoSendOutTimer = 1000;
        }
Example #3
0
        public static bool Prefix(JunimoHarvester __instance, ref NetGuid ___netHome, ref NetEvent1Field <int, NetInt> ___netAnimationEvent)
        {
            JunimoHut hut  = Util.GetHutFromId(___netHome.Value);
            int       time = Util.Config.JunimoImprovements.CanWorkInEvenings ? 2400 : 1900;

            if (Game1.timeOfDay > time)
            {
                if (__instance.controller != null)
                {
                    return(false);
                }
                __instance.returnToJunimoHut(__instance.currentLocation);
            }
            // Prevent working when not paid
            else if (Util.Config.JunimoPayment.WorkForWages && !Util.Payments.WereJunimosPaidToday)
            {
                if (Game1.random.NextDouble() < 0.02)
                {
                    __instance.pathfindToRandomSpotAroundHut();
                }
                else
                {
                    // go on strike
                    ___netAnimationEvent.Fire(7);
                }
            }
            else if (Game1.random.NextDouble() < 0.035 || hut.noHarvest.Value)
            {
                __instance.pathfindToRandomSpotAroundHut();
            }
            else
            {
                __instance.controller = new PathFindController(__instance, __instance.currentLocation,
                                                               new PathFindController.isAtEnd(__instance.foundCropEndFunction), -1, false,
                                                               new PathFindController.endBehavior(__instance.reachFirstDestinationFromHut), 100, Point.Zero);

                int radius = Util.MaxRadius;
                if (__instance.controller.pathToEndPoint == null ||
                    Math.Abs(__instance.controller.pathToEndPoint.Last().X - hut.tileX.Value + 1) > radius ||
                    Math.Abs(__instance.controller.pathToEndPoint.Last().Y - hut.tileY.Value + 1) > radius)
                {
                    if (Game1.random.NextDouble() < 0.5 && !hut.lastKnownCropLocation.Equals(Point.Zero))
                    {
                        __instance.controller = new PathFindController(__instance, __instance.currentLocation, hut.lastKnownCropLocation, -1,
                                                                       new PathFindController.endBehavior(__instance.reachFirstDestinationFromHut), 100);
                        // refresh lastKnownCropLocation
                        hut.areThereMatureCropsWithinRadius();
                    }
                    else if (Game1.random.NextDouble() < 0.25)
                    {
                        ___netAnimationEvent.Fire(0);
                        __instance.returnToJunimoHut(__instance.currentLocation);
                    }
                    else
                    {
                        __instance.pathfindToRandomSpotAroundHut();
                    }
                }
                else
                {
                    ___netAnimationEvent.Fire(0);
                }
            }
            return(false);
        }