/*********
        ** Private methods
        *********/
        private static void ReloadCustomChests(object sender, EventArgs e)
        {
            if (!Context.IsWorldReady)
            {
                return;
            }

            MegaStorageMod.ModMonitor.VerboseLog("SaveManager: ReloadCustomChests");
            LegacyHelper.FixLegacyOptions();
            StateManager.PlacedChests.Clear();
            foreach (var location in CommonHelper.GetLocations())
            {
                var placedChests = location.Objects.Pairs
                                   .Where(c => c.Value is Chest chest && CustomChestFactory.ShouldBeCustomChest(chest))
                                   .ToDictionary(
                    c => c.Key,
                    c => c.Value.ToCustomChest(c.Key));

                foreach (var placedChest in placedChests)
                {
                    var pos         = placedChest.Key;
                    var customChest = placedChest.Value;
                    MegaStorageMod.ModMonitor.VerboseLog($"Loading Chest at: {location.Name}: {customChest.Name} ({pos})");
                    location.objects[placedChest.Key] = customChest;
                    StateManager.PlacedChests.Add(new Tuple <GameLocation, Vector2>(location, pos), customChest);
                }
            }
        }
Exemple #2
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();
        }
Exemple #3
0
        private void OnInventoryChanged(object sender, InventoryChangedEventArgs e)
        {
            _monitor.VerboseLog("OnInventoryChanged");
            if (!e.IsLocalPlayer || e.Added.Count() != 1)
            {
                return;
            }

            var addedItem = e.Added.Single();

            if (addedItem is CustomChest)
            {
                return;
            }

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

            _monitor.VerboseLog("OnInventoryChanged: converting");

            var index = Game1.player.Items.IndexOf(addedItem);

            Game1.player.Items[index] = addedItem.ToCustomChest();
        }
Exemple #4
0
        private static void OnObjectListChanged(object sender, ObjectListChangedEventArgs e)
        {
            MegaStorageMod.ModMonitor.VerboseLog("OnObjectListChanged");

            if (e.Added.Count() != 1 && e.Removed.Count() != 1)
            {
                return;
            }

            var itemPosition = e.Added.Count() == 1
                ? e.Added.Single()
                : e.Removed.Single();

            var pos  = itemPosition.Key;
            var item = itemPosition.Value;
            var key  = new Tuple <GameLocation, Vector2>(e.Location, pos);

            if (e.Added.Count() == 1 &&
                !(item is CustomChest) &&
                CustomChestFactory.ShouldBeCustomChest(item))
            {
                MegaStorageMod.ModMonitor.VerboseLog("OnObjectListChanged: converting");
                var customChest = item.ToCustomChest(pos);
                e.Location.objects[pos] = customChest;
                if (!StateManager.PlacedChests.ContainsKey(key))
                {
                    StateManager.PlacedChests.Add(key, customChest);
                }
                else
                {
                    StateManager.PlacedChests[key] = customChest;
                }
            }
            else if (e.Removed.Count() == 1 && item is CustomChest)
            {
                MegaStorageMod.ModMonitor.VerboseLog("OnObjectListChanged: untrack");
                if (StateManager.PlacedChests.ContainsKey(key))
                {
                    StateManager.PlacedChests.Remove(new Tuple <GameLocation, Vector2>(e.Location, pos));
                }
            }
        }