const rand = require('./rand') const { WorldModel, ResourcePriceModel } = global.config module.exports = async () => { let world = await WorldModel.findByPk(1) // Получаем все ресурсы и их цены let resources = await ResourcePriceModel.findAll(); if (resources.length === 0) { return console.error('Ресурсы не найдены в базе данных.'); } // Считаем среднюю стоимость ресурсов let totalPrice = resources.reduce((sum, resource) => sum + resource.price, 0); let averagePrice = totalPrice / resources.length; // Рассчитываем стоимость материала let materialPrice = Math.round(averagePrice / 10); // Округляем до целого числа // Обновляем модель World world.matPrice = materialPrice; await world.save(); console.log(`Стоимость материала обновлена: ${materialPrice}`); }