Esempio n. 1
0
        /// <summary>Raised after objects are added or removed in a location.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void OnObjectListChanged(object sender, ObjectListChangedEventArgs e)
        {
            // Placed down tappers are the same instance as tappers in the inventory, leading to really weird behavior.
            // Instead, we'll copy them.

            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;
            }
        }
Esempio n. 2
0
 private void OnWorld_ObjectListChanged(object sender, ObjectListChangedEventArgs e)
 {
     foreach (var pair in e.Added)
     {
         ActivateSprinkler(pair.Value);
     }
 }
Esempio n. 3
0
        private void OnObjectListChanged(object sender, ObjectListChangedEventArgs e)
        {
            if (!Context.IsMainPlayer)
            {
                return;
            }

            if (!Game1.player.modData.ContainsKey(ObeliskLocationsKey))
            {
                Game1.player.modData.Add(ObeliskLocationsKey, JsonConvert.SerializeObject(new List <MiniObelisk>()));
            }

            List <MiniObelisk> miniObelisks = JsonConvert.DeserializeObject <List <MiniObelisk> >(Game1.player.modData[ObeliskLocationsKey]);

            // Add any new obelisks
            foreach (var tileToObelisk in e.Added.Where(o => o.Value.ParentSheetIndex == 238 && o.Value.bigCraftable))
            {
                StardewValley.Object obelisk = tileToObelisk.Value;
                if (!obelisk.modData.ContainsKey(ObeliskNameDataKey))
                {
                    obelisk.modData.Add(ObeliskNameDataKey, String.Empty);
                }

                miniObelisks.Add(new MiniObelisk(e.Location.NameOrUniqueName, tileToObelisk.Key, obelisk.modData[ObeliskNameDataKey]));
            }

            // Remove any removed obelisks
            foreach (var tileToObelisk in e.Removed.Where(o => o.Value.ParentSheetIndex == 238 && o.Value.bigCraftable))
            {
                miniObelisks = miniObelisks.Where(o => !(o.LocationName == e.Location.NameOrUniqueName && o.Tile == tileToObelisk.Key)).ToList();
            }

            Game1.player.modData[ObeliskLocationsKey] = JsonConvert.SerializeObject(miniObelisks);
        }
Esempio n. 4
0
 private void OnObjectListChanged(object sender, ObjectListChangedEventArgs e)
 {
     if (!e.IsCurrentLocation)
     {
         return;
     }
     if (e.Location is StardewValley.Locations.MineShaft mine)
     {
         var ladderHasSpawned = Helper.Reflection.GetField <bool>(mine, "ladderHasSpawned").GetValue();
         if (ladderHasSpawned)
         {
             _ladderStones.Clear();
         }
         else if (_ladderStones.Count <= 0)
         {
             FindLadders(mine);
         }
     }
     if (LocationHasNodes(e.Location))
     {
         foreach (var pair in e.Removed)
         {
             _nodeStones.Remove(pair.Key);
         }
     }
 }
Esempio n. 5
0
        private void OnObjectListChanged(object sender, ObjectListChangedEventArgs e)

        {
            var changedEvent = new { location = e.Location.NameOrUniqueName };

            this.MessageStreams("ON_OBJECT_LIST_CHANGED", changedEvent);
        }
Esempio n. 6
0
        /// <summary>Raised after objects are added or removed in a location.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void OnObjectListChanged(object sender, ObjectListChangedEventArgs e)
        {
            if (!Context.IsPlayerFree)
            {
                return;
            }

            // transfer fields for placed chest
            if (this.PreviousHeldChest != null && e.Location == Game1.currentLocation)
            {
                var placed = e.Added.Select(p => p.Value).OfType <Chest>().LastOrDefault();
                if (placed != null)
                {
                    Chest original = this.PreviousHeldChest;

                    placed.Name = original.Name;
                    placed.playerChoiceColor.Value = original.playerChoiceColor.Value;
                    placed.heldObject.Value        = original.heldObject.Value;
                    placed.MinutesUntilReady       = original.MinutesUntilReady;
                    if (original.items.Any())
                    {
                        placed.items.CopyFrom(original.items);
                    }
                }
            }
        }
Esempio n. 7
0
        private void WorldOnObjectListChanged(object?sender, ObjectListChangedEventArgs e)
        {
            // If there are no SObjects removed, we don't need to do anything here.
            if (!e.Removed.Any())
            {
                return;
            }

            foreach (var o in e.Removed)
            {
                if (o.Value.Name.Equals("STN Teleporter"))
                {
                    logger.Log($"Object in {e.Location} at {o.Key} named STN Teleporter removed.");

                    Teleporter teleporter = teleporters.FindTeleporter(e.Location, o.Key);

                    logger.Log("Teleporters prior to removal: ");
                    foreach (Teleporter t in teleporters.Teleporters)
                    {
                        logger.Log($"Tile: {t.Tile}; Key: {t.Key}");
                    }

                    if (teleporter != null)
                    {
                        teleporters.Teleporters.Remove(teleporter);
                    }

                    logger.Log("Teleporters after to removal: ");
                    foreach (Teleporter t in teleporters.Teleporters)
                    {
                        logger.Log($"Tile: {t.Tile}; Key: {t.Key}");
                    }
                }
            }
        }
Esempio n. 8
0
        private void OnObjectListChanged(object sender, ObjectListChangedEventArgs e)
        {
            _monitor.VerboseLog("OnObjectListChanged");
            if (e.Added.Count() != 1)
            {
                return;
            }

            var addedItemPosition = e.Added.Single();
            var addedItem         = addedItemPosition.Value;

            if (addedItem is CustomChest)
            {
                return;
            }

            if (!CustomChestFactory.ShouldBeCustomChest(addedItem))
            {
                return;
            }

            _monitor.VerboseLog("OnObjectListChanged: converting");

            var position = addedItemPosition.Key;
            var item     = e.Location.objects[position];

            e.Location.objects[position] = item.ToCustomChest();
        }
 /// <summary>
 /// Adds listeners for each garden pot
 /// </summary>
 private void OnObjectListChanged(object sender, ObjectListChangedEventArgs e)
 {
     foreach (IndoorPot indoorPot in e.Added.Select(kvp => kvp.Value).OfType <IndoorPot>())
     {
         SetupWaterableLocationListener(indoorPot.hoeDirt.Value, indoorPot);
     }
 }
Esempio n. 10
0
 private void ObjectListChanged(object sender, ObjectListChangedEventArgs e)
 {
     GameLocation location = e.Location;
     List<Vector2> machinesInLocation;
     if (!TrackedMachines.ContainsKey(location))
     {
         machinesInLocation = new List<Vector2>();
         TrackedMachines[location] = machinesInLocation;
     }
     machinesInLocation = TrackedMachines[location];
     foreach (KeyValuePair<Vector2, Object> pair in e.Added)
     {
         if (MachineTypes.Contains(pair.Value.Name))
         {
             machinesInLocation.Add(pair.Key);
             Monitor.Log("Adding machine at location " + pair.Key.X + ", " + pair.Key.Y);
         }
     }
     foreach (KeyValuePair<Vector2, Object> pair in e.Removed)
     {
         if (MachineTypes.Contains(pair.Value.Name))
         {
             machinesInLocation.Remove(pair.Key);
             Monitor.Log("Removing machine at location " + pair.Key.X + ", " + pair.Key.Y);
         }
     }
 }
 /// <inheritdoc cref="IWorldEvents.ObjectListChanged"/>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event data.</param>
 private void OnObjectListChanged(object sender, ObjectListChangedEventArgs e)
 {
     if (e.IsCurrentLocation)
     {
         this.FixLadders();
     }
 }
Esempio n. 12
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, ObjectListChangedEventArgs e)
 {
     if (Game1.currentLocation is MineShaft)
     {
         CheckAdjacentTilesForLadder();
     }
 }
Esempio n. 13
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);
                }
            }
        }
Esempio n. 14
0
 private void OnObjectListChanged(object sender, ObjectListChangedEventArgs e)
 {
     foreach (var obj in e.Removed)
     {
         if (obj.Value is Chest chest && IsMaterialStorageChest(chest))
         {
             _assignedChests.Remove(chest);
         }
     }
 }
Esempio n. 15
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 World_ObjectListChanged(object sender, ObjectListChangedEventArgs e)
        {
            if (!this.EnableAutomation)
            {
                return;
            }

            this.VerboseLog($"Object list changed in {e.Location.Name}, reloading machines in current location.");
            this.ReloadQueue.Add(e.Location);
        }
Esempio n. 16
0
 /// <summary>Raised after objects are added or removed in a location.</summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event arguments.</param>
 private void OnObjectListChanged(object sender, ObjectListChangedEventArgs e)
 {
     //Try and convert a placed down hopper to a hay anytime hopper
     if (Config.EnableTakingHayFromHoppersAnytime)
     {
         if (e.Location == Game1.player.currentLocation)
         {
             this.ConvertHopper <SObject, BetterHayHopper>(e.Location);
         }
     }
 }
Esempio n. 17
0
 private void ObjectChanged(object sender, ObjectListChangedEventArgs e)
 {
     if (e.IsCurrentLocation && e.Removed.Count() == 0 && e.Added.Count() == 1)
     {
         var item = e.Added.Single().Value;
         if (item.bigCraftable.Value && item.isPlaceable())
         {
             lastPlaced = item;
         }
     }
 }
Esempio n. 18
0
 private void ObjectsChanged(object sender, ObjectListChangedEventArgs e)
 {
     foreach (var kvp in e.Added)
     {
         var o = kvp.Value;
         if (o.ParentSheetIndex == myChestID && !(o is CompactorChest))
         {
             e.Location.Objects[kvp.Key] = new CompactorChest(o);
         }
     }
 }
Esempio n. 19
0
 private void OnObjectListChanged(object sender, ObjectListChangedEventArgs e)
 {
     foreach (var kvp in e.Added)
     {
         var obj = kvp.Value;
         if (obj is IndoorPot indoorPot)
         {
             SetupIndoorPotListeners(indoorPot);
         }
     }
 }
Esempio n. 20
0
 private void OnObjectListChanged(object sender, ObjectListChangedEventArgs e)
 {
     foreach (var keyValuePair in e.Added)
     {
         if (GrabberController.ItemShouldBeVersatileGrabber(keyValuePair.Value))
         {
             // Converts the placed object to a versatile grabber
             VersatileGrabber grabber = new VersatileGrabber(keyValuePair.Value);
             e.Location.objects[keyValuePair.Key] = grabber;
         }
     }
 }
Esempio n. 21
0
        /// <inheritdoc cref="IWorldEvents.ObjectListChanged"/>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event data.</param>
        private void OnObjectListChanged(object?sender, ObjectListChangedEventArgs e)
        {
            if (!this.EnableAutomationChangeTracking || this.MachineManager.IsReloadQueued(e.Location))
            {
                return;
            }

            this.Monitor.VerboseLog(
                this.ReloadIfNeeded(e.Location, this.GetDiffList(e.Added, e.Removed))
                    ? $"Object list changed in {e.Location.Name}, reloading its machines."
                    : $"Object list changed in {e.Location.Name}, but no reload is needed."
                );
        }
Esempio n. 22
0
 /// <summary>Called when the an object has been added/removed from a game location/,map
 /// This method implements...
 /// </summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event arguments.</param>
 private void World_ObjectListChanged(object sender, ObjectListChangedEventArgs e)
 {
     if (
         Context.IsPlayerFree &&
         e.IsCurrentLocation &&
         (e.Added != null)
         )
     {
         foreach (var item in e.Added)
         {
         }
     }
 }
Esempio n. 23
0
        /// <inheritdoc cref="IWorldEvents.ObjectListChanged"/>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event data.</param>
        private void OnObjectListChanged(object?sender, ObjectListChangedEventArgs e)
        {
            if (!this.EnableAutomation)
            {
                return;
            }

            if (e.Added.Concat(e.Removed).Any(obj => this.MachineManager.Factory.IsAutomatable(e.Location, obj.Key, obj.Value)))
            {
                this.Monitor.VerboseLog($"Object list changed in {e.Location.Name}, reloading its machines.");
                this.MachineManager.QueueReload(e.Location);
            }
        }
        /// <summary>Raised after objects are added or removed in a location.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event data.</param>
        private void OnObjectListChanged(object sender, ObjectListChangedEventArgs e)
        {
            this.gateList = new SerializableDictionary <Vector2, SObject>();
            OverlaidDictionary 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);
                }
            }
        }
Esempio n. 25
0
        /// <summary>
        /// Object list changed event handler.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">E.</param>
        private void OnPlacingProcessor(object sender, ObjectListChangedEventArgs e)
        {
            IList <Processor> processors = new List <Processor>();

            foreach (KeyValuePair <Vector2, SObject> kv in e.Added)
            {
                if (ShouldReplaceWithProcessor(kv.Value, out Processor processor))
                {
                    processors.Add(processor);
                }
            }

            PlaceObjects(e.Location, processors);
        }
Esempio n. 26
0
        private void WorldOnObjectListChanged(object sender, ObjectListChangedEventArgs e)
        {
            if (e.IsCurrentLocation && e.Removed.Any())
            {
                foreach (var keyValuePair in e.Removed)
                {
                    var pos = keyValuePair.Key;
                    var obj = keyValuePair.Value;

                    // Game1.createRadialDebris();
                    // Game1.createMultipleObjectDebris();
                    // e.Location.debris.Add(new Debris(Item));
                }
            }
        }
Esempio n. 27
0
        /// <summary>Raised after objects are added or removed in a location.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event data.</param>
        private void OnObjectListChanged(object sender, ObjectListChangedEventArgs 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);
                        }
                    }
                }
            }
        }
Esempio n. 28
0
        /// <summary>
        /// Object list changed event handler.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">E.</param>
        private void OnObjectListChanged(object sender, ObjectListChangedEventArgs e)
        {
            if (!locationProcessors.TryGetValue(e.Location, out IList <Processor> processors))
            {
                locationProcessors[e.Location] = processors = new List <Processor>();
            }

            foreach (KeyValuePair <Vector2, SObject> kv in e.Added)
            {
                if (ShouldReplaceWithProcessor(kv.Value, out Processor processor))
                {
                    processors.Add(processor);
                }
            }

            PlaceObjects(e.Location, processors);
        }
Esempio n. 29
0
        private void OnObjectListChanged(object sender, ObjectListChangedEventArgs e)
        {
            if (doingStuff)
            {
                return;
            }
            doingStuff = true;

            var loc = e.Location;

            foreach (var pair in e.Removed)
            {
                var pos = pair.Key;
                var obj = pair.Value;

                if (!obj.bigCraftable.Value)
                {
                    continue;
                }
                var entry = entries.SingleOrDefault(cle => cle.Name == obj.Name);
                if (entry == null)
                {
                    continue;
                }

                int ind = obj.GetBiggerIndex();

                int     relPosX = ind % entry.Width, relPosY = entry.Length - 1 - ind / entry.Width;
                Vector2 basePos = new Vector2(pos.X - relPosX, pos.Y - relPosY);
                for (int ix = 0; ix < entry.Width; ++ix)
                {
                    for (int iy = 0; iy < entry.Length; ++iy)
                    {
                        Vector2 localPos = basePos + new Vector2(ix, iy);
                        if (localPos == pos || !loc.Objects.ContainsKey(localPos))
                        {
                            continue;
                        }
                        loc.Objects.Remove(localPos);
                    }
                }
            }

            doingStuff = false;
        }
        private void OnPlacingProcessor(object sender, ObjectListChangedEventArgs e)
        {
            List <Processor> processors = new List <Processor>();

            foreach (KeyValuePair <Vector2, SObject> kv in e.Added)
            {
                if (!(kv.Value is Processor))
                {
                    Processor processor = Processor.FromObject(kv.Value);
                    if (processor != null)
                    {
                        processors.Add(processor);
                    }
                }
            }

            PlaceObjects(e.Location, processors);
        }