Exemplo n.º 1
0
        private IEnumerable <ChestEntry> BuildChestEntries()
        {
            foreach (var location in Game1.locations)
            {
                foreach (var pair in GetLocationChests(location))
                {
                    yield return(new ChestEntry
                    {
                        Address = new ChestAddress
                        {
                            LocationType = ChestLocationType.Normal,
                            LocationName = location.Name,
                            Tile = pair.Key,
                        },
                        AcceptedItemKinds = ChestDataManager.GetChestData(pair.Value).AcceptedItemKinds,
                    });
                }

                // chests in constructed buildings
                if (location is BuildableGameLocation buildableLocation)
                {
                    var buildings = buildableLocation.buildings.Where(b => b.indoors != null);

                    foreach (var building in buildings)
                    {
                        foreach (var pair in GetLocationChests(building.indoors))
                        {
                            yield return(new ChestEntry
                            {
                                Address = new ChestAddress
                                {
                                    LocationType = ChestLocationType.Building,
                                    LocationName = location.Name,
                                    BuildingName = building.nameOfIndoors,
                                    Tile = pair.Key,
                                },
                                AcceptedItemKinds = ChestDataManager.GetChestData(pair.Value).AcceptedItemKinds,
                            });
                        }
                    }
                }

                if (location is FarmHouse farmHouse && Game1.player.HouseUpgradeLevel >= 1)
                {
                    var chest = farmHouse.fridge;

                    yield return(new ChestEntry
                    {
                        Address = new ChestAddress
                        {
                            LocationType = ChestLocationType.Refrigerator
                        },
                        AcceptedItemKinds = ChestDataManager.GetChestData(chest).AcceptedItemKinds
                    });
                }
            }
        }
Exemplo n.º 2
0
        public void CopyChestData(Chest source, Chest target)
        {
            IChestDataManager chestDataManager = ModEntry.CategorizeChests.ChestDataManager;
            ChestData         sourceData       = chestDataManager.GetChestData(source);
            ChestData         targetData       = chestDataManager.GetChestData(target);

            targetData.AcceptedItemKinds.Clear();
            foreach (var itemKey in sourceData.AcceptedItemKinds)
            {
                targetData.AddAccepted(itemKey);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Attempt to move as much as possible of the player's inventory
        /// into the given chest, subject to the chest's capacity and its
        /// configured list of items to accept.
        /// </summary>
        /// <param name="chest">The chest to put the items in.</param>
        public void DumpItemsToChest(Chest chest)
        {
            var chestData = ChestDataManager.GetChestData(chest);

            bool shouldPlaySound = false;

            foreach (var item in GetInventoryItems())
            {
                try
                {
                    if (chestData.Accepts(item))
                    {
                        bool movedSome = TryPutItemInChest(chest, item);
                        if (movedSome)
                        {
                            shouldPlaySound = true;
                        }
                    }
                }
                catch (ItemNotImplementedException)
                {
                    // it's fine, just skip it
                }
            }

            if (shouldPlaySound)
            {
                Game1.playSound("dwop");
            }
        }
Exemplo n.º 4
0
        private IEnumerable <ChestEntry> BuildChestEntries()
        {
            foreach (var location in Game1.locations)
            {
                // chests
                foreach (var pair in GetLocationChests(location))
                {
                    yield return(new ChestEntry(
                                     ChestDataManager.GetChestData(pair.Value),
                                     new ChestAddress(location.Name, pair.Key)
                                     ));
                }

                switch (location)
                {
                // buildings
                case BuildableGameLocation buildableLocation:
                    foreach (var building in buildableLocation.buildings.Where(b => b.indoors.Value != null))
                    {
                        foreach (var pair in GetLocationChests(building.indoors.Value))
                        {
                            yield return(new ChestEntry(
                                             ChestDataManager.GetChestData(pair.Value),
                                             new ChestAddress(location.Name, pair.Key, ChestLocationType.Building, building.nameOfIndoors)
                                             ));
                        }
                    }
                    break;

                // fridges
                case FarmHouse farmHouse when farmHouse.upgradeLevel >= 1:
                    yield return(new ChestEntry(
                                     ChestDataManager.GetChestData(farmHouse.fridge.Value),
                                     new ChestAddress {
                        LocationName = farmHouse.uniqueName?.Value ?? farmHouse.Name, LocationType = ChestLocationType.Refrigerator
                    }
                                     ));

                    break;
                }
            }
        }
Exemplo n.º 5
0
        private void OpenCategoryMenu()
        {
            var chestData = ChestDataManager.GetChestData(Chest);

            CategoryMenu          = new CategoryMenu(chestData, ItemDataManager, TooltipManager);
            CategoryMenu.Position = new Point(
                ItemGrabMenu.xPositionOnScreen + ItemGrabMenu.width / 2 - CategoryMenu.Width / 2 - 6 * Game1.pixelZoom,
                ItemGrabMenu.yPositionOnScreen - 10 * Game1.pixelZoom
                );
            CategoryMenu.OnClose += CloseCategoryMenu;
            AddChild(CategoryMenu);

            SetItemsClickable(false);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Read the given save data and use it to reconstruct the mod state.
        /// </summary>
        /// <param name="token">The save data.</param>
        public void LoadData(JToken token)
        {
            var serializer = new JsonSerializer();

            serializer.Converters.Add(new StringEnumConverter());
            var data = token.ToObject <SaveData>(serializer);

            foreach (var entry in data.ChestEntries)
            {
                var chest     = ChestFinder.GetChestByAddress(entry.Address);
                var chestData = ChestDataManager.GetChestData(chest);

                chestData.AcceptedItemKinds = entry.AcceptedItemKinds
                                              .Where(itemKey => ItemDataManager.HasItem(itemKey));
            }
        }