Ejemplo n.º 1
0
        public void ActionItemAddedRemoved(object sender, ObjectListChangedEventArgs e)
        {
            if (!IsAllowed || !(bool)Value || Grabber.IsChestFull)
            {
                return;
            }
            //Utilities.Monitor.Log($"  {Grabber.InstanceName} Attempting to forage truffle items", StardewModdingAPI.LogLevel.Trace);
            System.Random random      = new System.Random();
            Vector2[]     nearbyTiles = Grabber.RangeEntireMap ? Utilities.GetLocationObjectTiles(Grabber.Location).ToArray() : Grabber.NearbyTilesRange;

            foreach (KeyValuePair <Vector2, SVObject> pair in e.Added)
            {
                if (pair.Value.ParentSheetIndex != 430 || pair.Value.bigCraftable.Value || !nearbyTiles.Contains(pair.Key))
                {
                    continue;
                }

                SVObject obj = pair.Value;
                if (obj.Stack == 0)
                {
                    obj.Stack = 1;
                }

                //make sure its a forageable and grabable
                if (!obj.isForage(null) && !Utilities.IsGrabbableWorld(obj))
                {
                    continue;
                }

                if (Game1.player.professions.Contains(16))
                {
                    obj.Quality = 4;
                }
                else if (random.NextDouble() < Game1.player.ForagingLevel / 30.0)
                {
                    obj.Quality = 2;
                }
                else if (random.NextDouble() < Game1.player.ForagingLevel / 15.0)
                {
                    obj.Quality = 1;
                }

                if (Game1.player.professions.Contains(13))
                {
                    while (random.NextDouble() < 0.2)
                    {
                        obj.Stack += 1;
                    }
                }
                //Utilities.Monitor.Log($"    {Grabber.InstanceName} foraged: {obj.Name} {obj.Stack} {pair.Key.X},{pair.Key.Y}", StardewModdingAPI.LogLevel.Trace);
                Grabber.GrabberChest.addItem(obj);
                e.Location.Objects.Remove(pair.Key);
                if (Grabber.GainExperience)
                {
                    Utilities.GainExperience(Grabber.FORAGING, 7);
                }
            }
        }
Ejemplo n.º 2
0
        private void OnOneSecondElapsed(object sender, EventArgs args)
        {
            if (!Context.IsWorldReady || config.TicksInterval == 0)
            {
                return;
            }
            Player player = Game1.player;

            ticksElapsed = (byte)((ticksElapsed + 1) % config.TicksInterval);
            if (ticksElapsed == 0)
            {
                Rectangle    bb       = ExpandBoundingBox(Game1.player.GetBoundingBox(), Game1.tileSize * 5, Game1.tileSize * 5);
                GameLocation location = Game1.currentLocation;

                //AutoHarvest Grown Crops
                if (config.AutoHarvestCrops)
                {
                    foreach (Vector2 position in location.terrainFeatures.Keys)
                    {
                        TerrainFeature feature = location.terrainFeatures[position];
                        if (feature is HoeDirt dirt)
                        {
                            Crop crop = dirt.crop;
                            if (crop == null)
                            {
                                continue;
                            }
                            if (config.AutoDestroyDeadCrops && crop.dead)
                            {
                                dirt.destroyCrop(position);
                                continue;
                            }
                            if (!crop.fullyGrown || !bb.Intersects(feature.getBoundingBox(position)))
                            {
                                continue;
                            }
                            crop.harvest((int)position.X, (int)position.Y, dirt);
                        }
                    }
                }

                //Collecting Forages
                if (config.AutoCollectForages)
                {
                    ICollection <Vector2> keys = new List <Vector2>(location.Objects.Keys);
                    foreach (Vector2 vec in keys)
                    {
                        SVObject obj = location.Objects[vec];
                        if (!bb.Intersects(obj.boundingBox))
                        {
                            continue;
                        }
                        if (obj.isForage(location))
                        {
                            Random random = new Random((int)Game1.uniqueIDForThisGame / 2 + (int)Game1.stats.DaysPlayed + (int)vec.X + (int)vec.Y * 777);
                            if (player.professions.Contains(16))
                            {
                                obj.quality = 4;
                            }
                            else
                            {
                                if (random.NextDouble() < player.ForagingLevel / 30f)
                                {
                                    obj.quality = 2;
                                }
                                else if (random.NextDouble() < player.ForagingLevel / 15f)
                                {
                                    obj.quality = 1;
                                }
                            }
                            if (player.couldInventoryAcceptThisItem(obj))
                            {
                                if (player.IsMainPlayer)
                                {
                                    Game1.playSound("pickUpItem");
                                    DelayedAction.playSoundAfterDelay("coin", 300);
                                }
                                player.animateOnce(279 + player.FacingDirection);
                                if (!location.isFarmBuildingInterior())
                                {
                                    player.gainExperience(2, 7);
                                }
                                else
                                {
                                    player.gainExperience(0, 5);
                                }
                                player.addItemToInventoryBool(obj.getOne(), false);
                                Stats expr_70E     = Game1.stats;
                                uint  itemsForaged = expr_70E.ItemsForaged;
                                expr_70E.ItemsForaged = itemsForaged + 1u;
                                if (player.professions.Contains(13) && random.NextDouble() < 0.2 && !obj.questItem && player.couldInventoryAcceptThisItem(obj) && !location.isFarmBuildingInterior())
                                {
                                    player.addItemToInventoryBool(obj.getOne(), false);
                                    player.gainExperience(2, 7);
                                }
                                location.Objects.Remove(vec);
                                return;
                            }
                        }
                    }
                }
            }
        }