コード例 #1
0
        public void HideAndSaveCustomChests()
        {
            _monitor.VerboseLog("InventorySaver: HideAndSaveCustomChests");
            _inventoryCustomChests = new Dictionary <int, CustomChest>();
            var deserializedChests = new List <DeserializedChest>();
            var customChests       = Game1.player.Items.OfType <CustomChest>();

            foreach (var customChest in customChests)
            {
                var chest = customChest.ToChest();
                var index = Game1.player.Items.IndexOf(customChest);
                _convenientChestsAPI.CopyChestData(customChest, chest);
                Game1.player.Items[index] = chest;
                var deserializedChest = customChest.ToDeserializedChest(index);
                _monitor.VerboseLog($"Hiding and saving: {deserializedChest}");
                deserializedChests.Add(deserializedChest);
                _inventoryCustomChests.Add(index, customChest);
            }
            if (!Context.IsMainPlayer)
            {
                _monitor.VerboseLog("Not main player!");
                return;
            }
            var saveData = new SaveData
            {
                DeserializedChests = deserializedChests
            };

            _modHelper.Data.WriteSaveData(SaveDataKey, saveData);
        }
コード例 #2
0
        public void HideAndSaveCustomChests()
        {
            _monitor.VerboseLog("LocationInventorySaver: HideAndSaveCustomChests");
            _locationInventoryCustomChests = new Dictionary <GameLocation, Dictionary <Vector2, Dictionary <int, CustomChest> > >();
            var deserializedChests = new List <DeserializedChest>();
            var locations          = Game1.locations.Concat(Game1.getFarm().buildings.Select(x => x.indoors.Value).Where(x => x != null));

            foreach (var location in locations)
            {
                var chestPositions = location.objects.Pairs.Where(x => x.Value is Chest).ToDictionary(pair => pair.Key, pair => (Chest)pair.Value);
                if (!chestPositions.Any())
                {
                    continue;
                }
                var customChestsInChestPositions = new Dictionary <Vector2, Dictionary <int, CustomChest> >();
                foreach (var chestPosition in chestPositions)
                {
                    var position            = chestPosition.Key;
                    var chest               = chestPosition.Value;
                    var customChestsInChest = chest.items.OfType <CustomChest>().ToList();
                    if (!customChestsInChest.Any())
                    {
                        continue;
                    }
                    var customChestIndexes = new Dictionary <int, CustomChest>();
                    var locationName       = location.uniqueName?.Value ?? location.Name;
                    foreach (var customChest in customChestsInChest)
                    {
                        var index = chest.items.IndexOf(customChest);
                        _convenientChestsAPI.CopyChestData(customChest, chest);
                        chest.items[index] = customChest.ToChest();
                        customChestIndexes.Add(index, customChest);
                        var deserializedChest = customChest.ToDeserializedChest(locationName, position, index);
                        _monitor.VerboseLog($"Hiding and saving: {deserializedChest}");
                        deserializedChests.Add(deserializedChest);
                    }
                    customChestsInChestPositions.Add(position, customChestIndexes);
                }
                _locationInventoryCustomChests.Add(location, customChestsInChestPositions);
            }
            if (!Context.IsMainPlayer)
            {
                _monitor.VerboseLog("Not main player!");
                return;
            }
            var saveData = new SaveData
            {
                DeserializedChests = deserializedChests
            };

            _modHelper.Data.WriteSaveData(SaveDataKey, saveData);
        }