Exemplo n.º 1
0
        //Correctly give grass starters instead of hay when silos are full and not full
        private void AttemptToGiveGrassStarter(Vector2 location, bool silosAreFull)
        {
            bool added = BetterHayGrass.TryAddItemToInventory(297);

            if (!added && Config.DropHayOnGroundIfNoRoomInInventory)
            {
                BetterHayGrass.DropOnGround(location, 297);
                added = true;
            }

            if (!silosAreFull && added)
            {
                Game1.getFarm().piecesOfHay.Value -= 1;
            }
        }
Exemplo n.º 2
0
        /// <summary>Raised after the game state is updated (≈60 times per second).</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void OnUpdateTicked(object sender, UpdateTickedEventArgs e)
        {
            // check for removed grass and spawn hay if appropriate
            if (Config.EnableGettingHayFromGrassAnytime && e.IsMultipleOf(8))
            {
                if (Game1.player?.currentLocation?.terrainFeatures == null || this.lastTerrainFeatures == null || Game1.player.currentLocation != this.CurrentLocation)
                {
                    return;
                }

                foreach (KeyValuePair <Vector2, TerrainFeature> item in this.lastTerrainFeatures)
                {
                    if (!Game1.player.currentLocation.terrainFeatures.FieldDict.ContainsKey(item.Key) && item.Value is Grass grass && grass.numberOfWeeds.Value <= 0 && grass.grassType.Value == 1)
                    {
                        if ((Game1.IsMultiplayer
                                ? Game1.recentMultiplayerRandom
                                : new Random((int)(Game1.uniqueIDForThisGame + item.Key.X * 1000.0 + item.Key.Y * 11.0)))
                            .NextDouble() < 0.5)
                        {
                            if (Game1.player.CurrentTool is MeleeWeapon && (Game1.player.CurrentTool.Name.Contains("Scythe") || Game1.player.CurrentTool.ParentSheetIndex == 47))
                            {
                                if (this.IsWithinRange(Game1.player.getTileLocation(), item.Key, 3))
                                {
                                    if (this.dropGrassStarterRandom.NextDouble() < Config.ChanceToDropGrassStarterInsteadOfHay)
                                    {
                                        this.AttemptToGiveGrassStarter(item.Key, Game1.getFarm().piecesOfHay.Value == Utility.numSilos() * 240);
                                    }
                                    else if (Game1.getFarm().tryToAddHay(1) != 0)
                                    {
                                        if (!BetterHayGrass.TryAddItemToInventory(178) && Config.DropHayOnGroundIfNoRoomInInventory)
                                        {
                                            BetterHayGrass.DropOnGround(item.Key, 178);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                this.lastTerrainFeatures = Game1.player.currentLocation?.terrainFeatures?.FieldDict.ToDictionary(
                    entry => entry.Key,
                    entry => entry.Value.Value
                    );
            }
        }
Exemplo n.º 3
0
        //Update tick - check for removed grass and spawn hay if appropriate
        private void EighthUpdateTick(object sender, EventArgs e)
        {
            if (Game1.currentLocation?.terrainFeatures == null || lastTerrainFeatures == null || Game1.currentLocation != currentLocation)
            {
                return;
            }


            foreach (var item in this.lastTerrainFeatures.Where(x => x.Value is Grass && IsWithinRange(Game1.player.getTileLocation(), x.Key, 4)))
            {
                TerrainFeature x = null;
                if (!this.currentLocation.terrainFeatures.TryGetValue(item.Key, out x) || !(x is Grass))
                {
                    if (((Game1.IsMultiplayer ? Game1.recentMultiplayerRandom : new Random((int)((double)Game1.uniqueIDForThisGame + (double)item.Key.X * 1000.0 + (double)item.Key.Y * 11.0))).NextDouble() < 0.5))
                    {
                        if (Game1.player.CurrentTool is MeleeWeapon && (Game1.player.CurrentTool.Name.Contains("Scythe") || Game1.player.CurrentTool.parentSheetIndex == 47))
                        {
                            if (dropGrassStarterRandom.NextDouble() < config.ChanceToDropGrassStarterInsteadOfHay)
                            {
                                AttemptToGiveGrassStarter(item.Key, Game1.getFarm().piecesOfHay == Utility.numSilos() * 240);
                            }
                            else if (Game1.getFarm().tryToAddHay(1) != 0)
                            {
                                if (!BetterHayGrass.TryAddItemToInventory(178) && config.DropHayOnGroundIfNoRoomInInventory)
                                {
                                    BetterHayGrass.DropOnGround(item.Key, 178);
                                }
                            }
                        }
                    }
                }
            }

            lastTerrainFeatures = Game1.currentLocation?.terrainFeatures?.Pairs.ToDictionary(entry => entry.Key,
                                                                                             entry => entry.Value);
        }