Beispiel #1
0
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event data.</param>
        private void OnChestInventoryChanged(object sender, ChestInventoryChangedEventArgs e)
        {
            if (skipTriggers > 0)
            {
                skipTriggers--;
                return;
            }
            bool menuOpened = Game1.activeClickableMenu != null;

            skipTriggers += chestFactory.UpdateContent(e.Chest, e.Location, e.Added, e.Removed, e.QuantityChanged);
            if (!menuOpened)
            {
                Game1.exitActiveMenu();
            }
        }
Beispiel #2
0
        private void OnChestChanged(object sender, EventArgs e)
        {
            ChestInventoryChangedEventArgs chestEvent = e as ChestInventoryChangedEventArgs;
            Chest chest = chestEvent.Chest;

            if (chest.specialChestType == 1)
            {
                int itemCount = (chestsToShip.ContainsKey(chest)) ? chestsToShip[chest].Count : 0;
                chestsToShip[chestEvent.Chest] = new List <Item>(chestEvent.Chest.items);

                if (chestsToShip[chest].Count > itemCount)
                {
                    Log("Added " + (chestsToShip[chest].Count - itemCount) + " items to ship.");
                }
            }
        }
Beispiel #3
0
        private static void OnChestInventoryChanged(object sender, ChestInventoryChangedEventArgs e)
        {
            MegaStorageMod.ModMonitor.VerboseLog("OnChestInventoryChanged");
            if (e.Added.Count() != 1)
            {
                return;
            }

            var addedItem = e.Added.Single();

            if (!(addedItem is CustomChest customChest))
            {
                return;
            }

            MegaStorageMod.ModMonitor.VerboseLog("OnChestInventoryChanged: converting");
            var index = e.Chest.items.IndexOf(addedItem);

            e.Chest.items[index] = customChest.ToObject();
        }
        private void OnChestInventoryChange(object sender, ChestInventoryChangedEventArgs eventArgs)
        {
            var stopWatch = new Stopwatch();

            stopWatch.Start();
            if (Context.IsMultiplayer)
            {
                this.Monitor.Log(
                    $"Disabled because the current context is multiplayer. The mod has not been tested in MP yet.",
                    LogLevel.Warn);
                return;
            }

            var chest = eventArgs.Chest;

            if (Debugging)
            {
                this.Monitor.Log($"After inventory change, the chest has", LogLevel.Debug);
                LogChestContents(chest);
            }

            var copiedList = chest.items.ToList();

            copiedList = copiedList.OrderBy(item => item, new ItemComparer()).ToList();
            chest.items.Clear();
            chest.items.AddRange(copiedList);
            if (Debugging)
            {
                this.Monitor.Log($"After ordering, the chest has", LogLevel.Debug);
                LogChestContents(chest);
            }

            stopWatch.Stop();
            UpdateElapsedTimeInformation(stopWatch.Elapsed.TotalMilliseconds);
            var maximum = $"Maximum: {_maximumElapsedMilliseconds:F3} ms";
            var mean    = $"Mean: {_totalElapsedMilliseconds / _sortings:F3} ms";
            var message = $"Took {stopWatch.Elapsed.TotalMilliseconds:F3} ms to sort a chest. {maximum}. {mean}.";

            this.Monitor.Log(message, LogLevel.Info);
        }
 /// <summary>Raised after items are added or removed from a chest.</summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event arguments.</param>
 protected virtual void OnChestInventoryChanged(object sender, ChestInventoryChangedEventArgs e)
 {
 }