Ejemplo n.º 1
0
 public static void Postfix(StardewValley.Characters.JunimoHarvester __instance)
 {
     if (Utils.IsAdjacentReadyToHarvestFruitTree(__instance.getTileLocation(), __instance.currentLocation))
     {
         Utils.GetJunimoHarvesterHarvestTimer(__instance).SetValue(2000);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        ///     Actually harvest an adjacent fruit tree to the current location.
        /// </summary>
        internal static void TryToActuallyHarvestFruitTree(StardewValley.Characters.JunimoHarvester harvester)
        {
            if (harvester.currentLocation == null)
            {
                return;
            }

            bool found = GetAdjacentReadyToHarvestFruitTree(harvester.getTileLocation(), harvester.currentLocation,
                                                            out KeyValuePair <Vector2, FruitTree> tree);

            if (found)
            {
                //shake the tree without it releasing any fruit
                int fruitsOnTree = tree.Value.fruitsOnTree.Value;
                tree.Value.fruitsOnTree.Value = 0;
                tree.Value.performUseAction(tree.Key, harvester.currentLocation);
                tree.Value.fruitsOnTree.Value = fruitsOnTree;
                SObject result = GetFruitFromTree(tree.Value);
                if (result != null)
                {
                    harvester.tryToAddItemToHut(result);
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 ///     Gets the private harvest timer field of <see cref="StardewValley.Characters.JunimoHarvester" />
 /// </summary>
 internal static IReflectedField <int> GetJunimoHarvesterHarvestTimer(StardewValley.Characters.JunimoHarvester harvester)
 {
     return(Reflection.GetField <int>(harvester, "harvestTimer"));
 }
Ejemplo n.º 4
0
        public static void Postfix(StardewValley.Characters.JunimoHarvester __instance, GameTime time,
                                   GameLocation location)
        {
            Task backgroundTask = Utils.Reflection.GetField <Task>(__instance, "backgroundTask").GetValue();

            if ((backgroundTask != null && !backgroundTask.IsCompleted) || !Game1.IsMasterGame)
            {
                return;
            }
            if (!Game1.IsMasterGame)
            {
                return;
            }

            int harvestTimer = Utils.GetJunimoHarvesterHarvestTimer(__instance).GetValue();

            harvestTimer += time.ElapsedGameTime.Milliseconds;

            if (harvestTimer <= 0)
            {
                return;
            }

            int newTimer = harvestTimer - time.ElapsedGameTime.Milliseconds;

            if (newTimer > 1000)
            {
                return;
            }

            if (!(harvestTimer >= 1000 && newTimer < 1000))
            {
                return;
            }

            IReflectedField <Item> flastItemHarvested = Utils.Reflection.GetField <Item>(__instance, "lastItemHarvested");

            if (__instance.currentLocation != null && !Utils.Reflection.GetProperty <StardewValley.Buildings.JunimoHut>(__instance, "home").GetValue().noHarvest.Value&&
                Utils.IsAdjacentReadyToHarvestFruitTree(__instance.getTileLocation(), __instance.currentLocation) && (flastItemHarvested.GetValue() == null || flastItemHarvested.GetValue() == lastHarvestedItem))
            {
                Utils.Reflection.GetField <NetEvent1Field <int, NetInt> >(__instance, "netAnimationEvent").GetValue().Fire(5);

                Utils.TryToActuallyHarvestFruitTree(__instance);

                Item lastItemHarvested = flastItemHarvested.GetValue();

                if (lastItemHarvested != null && __instance.currentLocation.farmers.Any())
                {
                    Multiplayer multiplayer =
                        Utils.Reflection.GetField <Multiplayer>(typeof(Game1), "multiplayer").GetValue();
                    multiplayer.broadcastSprites(__instance.currentLocation, new TemporaryAnimatedSprite(
                                                     "Maps\\springobjects",
                                                     Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet,
                                                                                             lastItemHarvested.ParentSheetIndex, 16, 16), 1000f, 1, 0,
                                                     __instance.position + new Vector2(0.0f, -40f), false, false,
                                                     (float)(__instance.getStandingY() / 10000.0 + 0.00999999977648258), 0.02f, Color.White, 4f,
                                                     -0.01f, 0.0f, 0.0f, false)
                    {
                        motion = new Vector2(0.08f, -0.25f)
                    });
                    if (lastItemHarvested is ColoredObject coloredHarvested)
                    {
                        multiplayer.broadcastSprites(__instance.currentLocation, new TemporaryAnimatedSprite(
                                                         "Maps\\springobjects",
                                                         Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet,
                                                                                                 lastItemHarvested.ParentSheetIndex + 1, 16, 16), 1000f, 1, 0,
                                                         __instance.position + new Vector2(0.0f, -40f), false, false,
                                                         (float)(__instance.getStandingY() / 10000.0 + 0.0149999996647239), 0.02f,
                                                         coloredHarvested.color.Value, 4f, -0.01f, 0.0f, 0.0f, false)
                        {
                            motion = new Vector2(0.08f, -0.25f)
                        });
                    }
                }
            }
        }
Ejemplo n.º 5
0
 public static void Prefix(StardewValley.Characters.JunimoHarvester __instance)
 {
     lastHarvestedItem = Utils.Reflection.GetField <Item>(__instance, "lastItemHarvested").GetValue();
 }
Ejemplo n.º 6
0
        public static void ProcessScytheHarvest(Crop crop, int xTile, int yTile,
                                                StardewValley.TerrainFeatures.HoeDirt soil, StardewValley.Characters.JunimoHarvester junimoHarvester)
        {
            Random random = new Random((int)Game1.stats.DaysPlayed + (int)Game1.uniqueIDForThisGame);

            // extra luck fix - num *= 2;
            if (random.NextDouble() < (double)((float)Game1.player.LuckLevel / 1500f) + Game1.dailyLuck / 1200.0 + 9.9999997473787516E-05)
            {
                int num = random.Next(1, 3);
                for (int i = 0; i < num; i++)
                {
                    if (junimoHarvester == null)
                    {
                        Game1.createObjectDebris(crop.indexOfHarvest, xTile, yTile, -1, random.Next(0, 2), 1f, null);
                    }
                    else
                    {
                        junimoHarvester.tryToAddItemToHut(new StardewValley.Object(crop.indexOfHarvest, 1, false, -1, 0));
                    }
                }
                if (junimoHarvester == null || Utility.isOnScreen(junimoHarvester.getTileLocationPoint(), Game1.tileSize, junimoHarvester.currentLocation))
                {
                    Game1.playSound("dwoop");
                }
            }

            // experience fix
            if (junimoHarvester == null)
            {
                int   experienceBase = Convert.ToInt32(Game1.objectInformation[crop.indexOfHarvest].Split(new char[] { '/' })[1]);
                float experience     = (float)(16.0 * Math.Log(0.018 * (double)experienceBase + 1.0, 2.7182818284590451));
                Game1.player.gainExperience(0, (int)Math.Round((double)experience));
            }

            // sunflower seeds fix
            if (crop.indexOfHarvest == 421)
            {
                int indexOfHarvest = 431;
                int num            = random.Next(1, 3);
                for (int i = 0; i < num; i++)
                {
                    if (junimoHarvester == null)
                    {
                        Game1.createObjectDebris(indexOfHarvest, xTile, yTile, -1, 0, 1f, null);
                    }
                    else
                    {
                        junimoHarvester.tryToAddItemToHut(new StardewValley.Object(indexOfHarvest, 1, false, -1, 0));
                    }
                }
            }
        }