Example #1
0
 /// <summary>
 /// Method invoked when the player creates an object. This is to account for if the player creates and places stairs, which would turn into a ladder.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void PlacedStairs(object sender, EventArgsLocationObjectsChanged e)
 {
     if (Game1.currentLocation is MineShaft)
     {
         CheckAdjacentTilesForLadder();
     }
 }
Example #2
0
 //Try and convert a placed down hopper to a hay anytime hopper
 private void HandleHopperMaybePlacedDown(object sender, EventArgsLocationObjectsChanged e)
 {
     if (e.Location == Game1.player.currentLocation)
     {
         this.ConvertHopper <SObject, BetterHayHopper>(e.Location);
     }
 }
Example #3
0
        public void ActionItemAddedRemoved(object sender, EventArgsLocationObjectsChanged 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);
                }
            }
        }
Example #4
0
 private void OnLocationObjectsChanged(object sender, EventArgsLocationObjectsChanged e)
 {
     if (!IsMappingActivated)
     {
         return;
     }
     Log.Trace("Location objects changed...");
     Traverser.Instance.TraverseLocation(Game1.currentLocation, Wrap);
 }
        private void OnLocationObjectsChanged(object sender, EventArgsLocationObjectsChanged e)
        {
            if (!IsActivated)
            {
                return;
            }
            var sw = Stopwatch.StartNew();

            Traverser.Instance.TraverseLocationLight(Game1.currentLocation, ToSmartObject);
            Log.InfoAsync($"Activation of objects (cause: changes in {Game1.currentLocation?.Name}) finished: {sw.ElapsedMilliseconds} ms");
        }
Example #6
0
 /// <summary>The method invoked when an object is added or removed to a location.</summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event arguments.</param>
 private void LocationEvents_LocationObjectsChanged(object sender, EventArgsLocationObjectsChanged e)
 {
     try
     {
         this.ReloadMachinesIn(Game1.currentLocation);
     }
     catch (Exception ex)
     {
         this.HandleError(ex, "updating the current location");
     }
 }
        /// <summary>The method invoked when an object is added or removed to a location.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void LocationEvents_LocationObjectsChanged(object sender, EventArgsLocationObjectsChanged e)
        {
            this.VerboseLog("Object list changed, reloading machines in current location.");

            try
            {
                this.ReloadQueue.Add(Game1.currentLocation);
            }
            catch (Exception ex)
            {
                this.HandleError(ex, "updating the current location");
            }
        }
Example #8
0
        private void CreatedOrDestroyedGate(object sender, EventArgsLocationObjectsChanged e)
        {
            this.gateList = new SerializableDictionary <Vector2, StardewValley.Object>();
            OverlaidDictionary <Vector2, SObject> objects = Game1.currentLocation.objects;

            foreach (Vector2 key in objects.Keys)
            {
                if (objects[key].name.Equals("Gate"))
                {
                    this.gateList.Add(key, objects[key]);
                    //this.Monitor.Log(string.Format("{0}", (object)key.ToString()), (LogLevel)1);
                }
            }
        }
Example #9
0
        private void LocationEvents_ObjectsChanged(object sender, EventArgsLocationObjectsChanged e)
        {
            if (e.Added.Any())
            {
                foreach (KeyValuePair <Vector2, StardewValley.Object> pair in e.Added)
                {
                    //Monitor.Log($"  Object Added: {pair.Value.Name} {pair.Value.ParentSheetIndex}, {e.Location.Name}-{pair.Key.X},{pair.Key.Y}", LogLevel.Trace);

                    //Handle creating new instances
                    if (pair.Value.parentSheetIndex == AutoGrabber.ParentIndex)
                    {
                        var g = new AutoGrabber(e.Location, pair.Value, pair.Key);
                        if (!AutoGrabbers.ContainsKey(g.Id))
                        {
                            Monitor.Log($"  - Adding Instance {g.Id}");
                            AutoGrabbers.Add(g.Id, g);
                        }
                    }
                }

                foreach (var grabber in AutoGrabbers.Where(g => (bool)g.Value.FeatureType <Forage>().Value).ToArray())
                {
                    if (grabber.Value.Location.Name == e.Location.Name)
                    {
                        (grabber.Value.FeatureType <Forage>() as Forage).ActionItemAddedRemoved(sender, e);
                    }
                }
            }
            if (e.Removed.Any())
            {
                foreach (KeyValuePair <Vector2, StardewValley.Object> pair in e.Removed)
                {
                    //Monitor.Log($"  Object Removed: {pair.Value.Name}, ID: {pair.Value.ParentSheetIndex}, Location: {e.Location.Name}-{pair.Key.X},{pair.Key.Y}", LogLevel.Trace);

                    //Handle removing instances
                    if (pair.Value.ParentSheetIndex == AutoGrabber.ParentIndex)
                    {
                        var grabber = AutoGrabbers.Values.Where(g => g.Location.Equals(e.Location) && g.Tile.Equals(pair.Key)).FirstOrDefault();
                        if (grabber != null)
                        {
                            Monitor.Log($"  Cleaning instance {grabber.Id}");
                            AutoGrabbers.Remove(grabber.Id);
                        }
                    }
                }
            }
        }
Example #10
0
        /// <summary>The method invoked when an object is added or removed to a location.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void LocationEvents_ObjectsChanged(object sender, EventArgsLocationObjectsChanged e)
        {
            if (!this.EnableAutomation)
            {
                return;
            }

            this.VerboseLog($"Object list changed in {e.Location.Name}, reloading machines in current location.");

            try
            {
                this.ReloadQueue.Add(e.Location);
            }
            catch (Exception ex)
            {
                this.HandleError(ex, "updating the current location");
            }
        }
Example #11
0
 private void CreatedStairs(object sender, EventArgsLocationObjectsChanged e)
 {
     if (Game1.currentLocation is MineShaft)
     {
         Layer currentLayer = Game1.currentLocation.map.GetLayer("Buildings");
         for (int yTile = 0; yTile < currentLayer.LayerHeight; yTile++)
         {
             for (int xTile = 0; xTile < currentLayer.LayerWidth; xTile++)
             {
                 Tile currentTile = currentLayer.Tiles[xTile, yTile];
                 if (currentTile != null && currentTile.TileIndex == 173 && !ladderList.ContainsKey(new Vector2(xTile, yTile)))
                 {
                     ladderList.Add(new Vector2(xTile, yTile), currentTile);
                     Game1.currentLocation.map.GetLayer("Buildings").Tiles[xTile, yTile].TileIndexProperties.Add(new KeyValuePair <string, PropertyValue>("Passable", propValue));
                 }
             }
         }
     }
 }
Example #12
0
 private static void LocationEvents_ObjectsChanged(object sender, EventArgsLocationObjectsChanged e)
 {
     // adds lightsources to newly placed sprinkler
     if (!ModEntry.Config.UseSprinklersAsLamps)
     {
         return;
     }
     foreach (KeyValuePair <Vector2, Object> pair in e.Added)
     {
         Object obj = pair.Value;
         if (obj.ParentSheetIndex == PrismaticSprinklerItem.INDEX)
         {
             int id = (int)obj.TileLocation.X * 4000 + (int)obj.TileLocation.Y;
             obj.lightSource = new LightSource(4, new Vector2((obj.boundingBox.X + 32), (obj.boundingBox.Y + 32)), 2.0f, Color.Black, id);
             obj.Name        = "Prismatic Scarecrow Sprinkler";
             Game1.currentLocation.sharedLights.Add(obj.lightSource.Clone());
         }
     }
 }
Example #13
0
        private void LocationEvents_LocationObjectsChanged(object sender, EventArgsLocationObjectsChanged e)
        {
            this.bridges.Remove(Game1.currentLocation);

            // When the player places a TubeObject, it's placed as an object. Gather them and replace them with TubeTerrain
            // instead. This seems to be the only way to place terrain features.
            // We also remove any temporary "junk" objects, which are only used to trigger this event.
            List <Vector2> tubes = new List <Vector2>();
            List <Vector2> junk  = new List <Vector2>();

            foreach (var obj in Game1.currentLocation.objects)
            {
                if (obj.Value.parentSheetIndex == TubeInfo.objectData.sdvId)
                {
                    tubes.Add(obj.Key);
                }
                if (obj.Value.parentSheetIndex == TubeInfo.junkObjectData.sdvId)
                {
                    junk.Add(obj.Key);
                }
            }
            foreach (var pos in tubes)
            {
                SObject obj = Game1.currentLocation.objects[pos];
                Game1.currentLocation.objects.Remove(pos);

                if (!Game1.currentLocation.terrainFeatures.ContainsKey(pos))
                {
                    Game1.currentLocation.terrainFeatures.Add(pos, new TubeTerrain());
                }
                else
                {
                    Game1.player.addItemToInventory(obj);
                }
            }
            foreach (var pos in junk)
            {
                Game1.currentLocation.objects.Remove(pos);
            }

            TubeTerrain.updateSpritesInLocation(Game1.currentLocation);
        }
Example #14
0
        private static void LocationEvents_ObjectsChanged(object sender, EventArgsLocationObjectsChanged e)
        {
            Vector2 pos;
            SObject obj;
            var     loc = Game1.currentLocation;

            if (e.Location is MineShaft || Game1.newDay)
            {
                return;
            }

            foreach (var item in e.Added)
            {
                pos = item.Key;
                obj = item.Value;
                if ((_config.Machines.ContainsKey(obj.name) || obj is Cask) &&
                    Machines.TryGetValue(loc, out var list))
                {
                    list.Add(pos);
                }
                else if (obj is CrabPot && CrabPots.TryGetValue(loc, out list))
                {
                    list.Add(pos);
                }
            }

            foreach (var item in e.Removed)
            {
                pos = item.Key;
                obj = item.Value;
                if (Machines.TryGetValue(loc, out var list))
                {
                    list.Remove(pos);
                }
                if (CrabPots.TryGetValue(loc, out list))
                {
                    list.Remove(pos);
                }
                break;
            }
        }
Example #15
0
        /// <summary>
        ///     Placed down tappers are the same instance as tappers in the inventory, leading to really weird behavior.
        ///     Instead, we'll copy them.
        /// </summary>
        private void LocationEvents_ObjectsChanged(object sender, EventArgsLocationObjectsChanged e)
        {
            if (e.Location != Game1.player.currentLocation)
            {
                return;
            }

            IDictionary <Vector2, SObject> toReplace = new Dictionary <Vector2, SObject>();

            foreach (KeyValuePair <Vector2, SObject> item in e.Added)
            {
                if (Game1.player.items.Contains(item.Value))
                {
                    this.Monitor.Log($"{item.Value.GetType().Name} was placed down and exists in the inventory.",
                                     LogLevel.Trace);
                    toReplace[item.Key] = this.Copy(item.Value);
                }
            }

            foreach (KeyValuePair <Vector2, SObject> item in toReplace)
            {
                Game1.currentLocation.objects[item.Key] = item.Value;
            }
        }
 private void LocationEvents_LocationObjectsChanged(object sender, EventArgsLocationObjectsChanged e)
 {
     addSimpleMachinesToAutomation();
 }
Example #17
0
 /// <summary>The method invoked when an object is added or removed to a location.</summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event arguments.</param>
 private void LocationEvents_LocationObjectsChanged(object sender, EventArgsLocationObjectsChanged e)
 {
     this.Machines[Game1.currentLocation] = this.Factory.GetMachinesIn(Game1.currentLocation, this.Helper.Reflection).ToArray();
 }
Example #18
0
 //Try and convert a placed down hopper to a hay anytime hopper
 private void HandleHopperMaybePlacedDown(object sender, EventArgsLocationObjectsChanged e)
 {
     ConvertHopper <SObject, BetterHayHopper>(e.Added.ToDictionary(entry => entry.Key, entry => entry.Value));
 }
Example #19
0
        private void LocationEvents_ObjectsChanged(object sender, EventArgsLocationObjectsChanged e)
        {
            if (!Config.DoHarvestTruffles)
            {
                return;
            }

            GameLocation foragerMap;

            foragerMap = Game1.getLocationFromName(Config.GlobalForageMap);
            if (foragerMap == null)
            {
                return;
            }

            foragerMap.Objects.TryGetValue(new Vector2(Config.GlobalForageTileX, Config.GlobalForageTileY), out Object grabber);

            if (grabber == null || !grabber.Name.Contains("Grabber"))
            {
                return;
            }


            System.Random random = new System.Random();
            foreach (KeyValuePair <Vector2, Object> pair in e.Added)
            {
                if (pair.Value.ParentSheetIndex != 430 || pair.Value.bigCraftable.Value)
                {
                    continue;
                }

                if ((grabber.heldObject.Value as Chest).items.Count >= 36)
                {
                    return;
                }

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

                if (!obj.isForage(null) && !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;
                    }
                }

                Monitor.Log($"Grabbing truffle: {obj.Stack}x{quality[obj.Quality]}", LogLevel.Trace);
                (grabber.heldObject.Value as Chest).addItem(obj);
                e.Location.Objects.Remove(pair.Key);

                if (Config.DoGainExperience)
                {
                    gainExperience(FORAGING, 7);
                }
            }

            if ((grabber.heldObject.Value as Chest).items.Count > 0)
            {
                grabber.showNextIndex.Value = true;
            }
        }
Example #20
0
 void OnLocationObjectsChanged(object sender, EventArgsLocationObjectsChanged e)
 {
     LocationEvents.ObjectsChanged -= OnLocationObjectsChanged;
     CaskSweep();
 }