示例#1
0
        /// <summary>Migrate legacy container data, if needed.</summary>
        private void MigrateLegacyData()
        {
            // chests
            foreach (var chest in this.ChestFactory.GetChests(RangeHandler.Unlimited()))
            {
                chest.Container.MigrateLegacyData();
            }

            // shipping bin
            var binData = this.Helper.Data.ReadSaveData <ContainerData>("shipping-bin");

            if (binData != null)
            {
                Farm farm = Game1.getFarm();
                binData.ToModData(farm.modData, discriminator: ShippingBinContainer.ModDataDiscriminator);
                this.Helper.Data.WriteSaveData <ContainerData>("shipping-bin", null);
            }
        }
示例#2
0
        /// <summary>Get the player chest from the specified menu (if any).</summary>
        /// <param name="menu">The menu to check.</param>
        public ManagedChest GetChestFromMenu(ItemGrabMenu menu)
        {
            RangeHandler range = RangeHandler.Unlimited();

            // get from opened inventory
            {
                object      target    = menu.behaviorOnItemGrab?.Target;
                List <Item> inventory = (target as Chest)?.items ?? (target as IContainer)?.Inventory;
                if (inventory != null)
                {
                    ManagedChest chest = this.GetChests(range).FirstOrDefault(p => p.Container.IsSameAs(inventory));
                    if (chest != null)
                    {
                        return(chest);
                    }
                }
            }

            // fallback to open chest
            return(this.GetChests(range).FirstOrDefault(p => p.Container.IsOpen()));
        }