Exemplo n.º 1
0
        public static bool Prefix(JunimoHarvester __instance)
        {
            Vector2 pos          = __instance.getTileLocation();
            var     harvestTimer = Util.Reflection.GetField <int>(__instance, "harvestTimer");

            // avoid flowers, etc (todo: move)
            if (Util.ShouldAvoidHarvesting(pos))
            {
                harvestTimer.SetValue(0);
                __instance.jumpWithoutSound();
                __instance.pathfindToNewCrop();
                return(false);
            }
            int  time = Util.Config.JunimoImprovements.WorkFaster ? 300 : 998;
            Guid id   = Util.GetHutIdFromJunimo(__instance);

            JunimoAbility junimoAbility = Util.Abilities.IdentifyJunimoAbility(pos, id);

            // Use the update() harvesting
            if (junimoAbility == JunimoAbility.HarvestCrops)
            {
                time = 2000;
            }
            else if (junimoAbility != JunimoAbility.None)
            {
                if (!Util.Abilities.PerformAction(junimoAbility, id, pos, __instance))
                {
                    // didn't succeed, move on
                    time = 0;
                }
            }
            else
            {
                __instance.pokeToHarvest();
            }
            harvestTimer.SetValue(time);

            return(false);
        }
        public static bool Prefix(JunimoHarvester __instance, ref int ___harvestTimer, ref NetGuid ___netHome)
        {
            Guid    id  = ___netHome.Value;
            Vector2 pos = __instance.getTileLocation();

            int            time;
            IJunimoAbility junimoAbility = Util.Abilities.IdentifyJunimoAbility(pos, id);

            if (junimoAbility != null)
            {
                // Use the update() harvesting
                if (junimoAbility is HarvestCropsAbility || junimoAbility is HarvestBushesAbility)
                {
                    time = 2000;
                }
                else if (!Util.Abilities.PerformAction(junimoAbility, id, pos, __instance))
                {
                    // didn't succeed, move on
                    time = 0;
                }
                else
                {
                    // succeeded, shake
                    time = Util.Progression.WorkFaster ? 300 : 998;
                }
            }
            else
            {
                // nothing to do, wait a moment
                time = Util.Progression.WorkFaster ? 5 : 200;
                __instance.pokeToHarvest();
            }
            ___harvestTimer = time;

            return(false);
        }
        public static bool Prefix(JunimoHarvester __instance, ref int ___harvestTimer, ref NetGuid ___netHome)
        {
            if (!Context.IsMainPlayer)
            {
                return(true);
            }

            var id  = ___netHome.Value;
            var pos = __instance.getTileLocation();

            // if (__instance.currentLocation.IsGreenhouse) {
            //     BetterJunimos.SMonitor.Log($"PatchTryToHarvestHere: #{__instance.whichJunimoFromThisHut} looking in {__instance.currentLocation.Name} at [{pos.X} {pos.Y}]", LogLevel.Trace);
            // }

            int time;
            var junimoAbility = Util.Abilities.IdentifyJunimoAbility(__instance.currentLocation, pos, id);

            if (junimoAbility != null)
            {
                // if (__instance.currentLocation.IsGreenhouse) {
                //     BetterJunimos.SMonitor.Log(
                //         $"PatchTryToHarvestHere: #{__instance.whichJunimoFromThisHut} performing {junimoAbility.AbilityName()} at {__instance.currentLocation.Name} [{pos.X} {pos.Y}]",
                //         LogLevel.Trace);
                // }

                if (junimoAbility is HarvestBushesAbility)
                {
                    // Use the update() harvesting
                    time = 2000;
                }
                else if (!Util.Abilities.PerformAction(junimoAbility, id, __instance.currentLocation, pos,
                                                       __instance))
                {
                    // didn't succeed, move on
                    time = 0;

                    // add failed action to ability cooldowns
                    Util.Abilities.ActionFailed(__instance.currentLocation, junimoAbility, pos);
                }
                else
                {
                    // succeeded, shake
                    if (junimoAbility is HarvestCropsAbility)
                    {
                        time = 2000;
                    }
                    else if (BetterJunimos.Config.JunimoImprovements.WorkRidiculouslyFast)
                    {
                        time = 20;
                    }
                    else
                    {
                        time = Util.Progression.WorkFaster ? 300 : 998;
                    }

                    // BetterJunimos.SMonitor.Log($"PatchTryToHarvestHere performing {junimoAbility.AbilityName()} time {time}]", LogLevel.Trace);
                }
            }
            else
            {
                // nothing to do, wait a moment
                time = Util.Progression.WorkFaster ? 5 : 200;
                __instance.pokeToHarvest();
            }

            ___harvestTimer = time;

            return(false);
        }