示例#1
0
        public static bool TryQuickStack(bool stackToCurrentlyOpenIfNotSearchForNearbyAccess)
        {
            Player player = Main.player[Main.myPlayer];

            if (player.IsStackingItems())
            {
                return(false);
            }

            TEStorageHeart heart = StoragePlayer.GetStorageHeart();

            if (!stackToCurrentlyOpenIfNotSearchForNearbyAccess)
            {
                // Vanilla quick stack to all chests is approximately a circle with radius 12.5
                for (int i = -13; i <= 13; i++)
                {
                    for (int j = -13; j <= 13; j++)
                    {
                        int x = (int)player.position.X / 16 + i;
                        int y = (int)player.position.Y / 16 + j;

                        Tile tile = Main.tile[x, y];
                        if (tile == null)
                        {
                            continue;
                        }

                        if (tile.frameX % 36 == 18)
                        {
                            x--;
                        }
                        if (tile.frameY % 36 == 18)
                        {
                            y--;
                        }

                        int     tileType = tile.type;
                        ModTile modTile  = TileLoader.GetTile(tileType);
                        if (modTile == null || !(modTile is StorageAccess))
                        {
                            continue;
                        }

                        if ((player.Center - new Vector2(x, y) * 16).Length() < 200)
                        {
                            heart = ((StorageAccess)modTile).GetHeart(x, y);
                        }
                    }
                }
            }
            if (heart == null)
            {
                return(false);
            }

            List <Item> items = new List <Item>();

            for (int k = 10; k < 50; k++)
            {
                var item = player.inventory[k];
                if (!item.IsAir && !item.favorited)
                {
                    if (heart.HasItem(item, true))
                    {
                        items.Add(player.inventory[k]);
                    }
                }
            }

            if (Main.netMode == 0)
            {
                foreach (Item item in items)
                {
                    heart.DepositItem(item);
                }
            }
            else
            {
                NetHelper.SendDepositAll(heart.ID, items);
                foreach (Item item in items)
                {
                    item.SetDefaults(0, true);
                }
            }

            // Play the stash sound
            // The if is here so minimize IL hacking in DrawInventory...
            if (items.Count != 0 && !stackToCurrentlyOpenIfNotSearchForNearbyAccess)
            {
                Main.PlaySound(7, -1, -1, 1, 1f, 0f);
            }
            return(items.Count != 0);
        }