1 import { Task } from './task';
2 import { db } from '../lib/db';
9 export const tick = new Task<Tick>('tick', async (task, job) => {
11 const nextTick = job.data.lastTick+1;
13 // +population*1.1 is where we take into account farms for bonus food production
14 let sql = `update cities set
15 credits = credits + population * 2,
35 special_attacker_trainer * 10 +
36 special_defender_trainer * 8 +
41 mining_facilities * 8 +
45 ) + solar_panels * 125,
49 (alloys + mining_facilities * 20),
53 (population + round(population * 0.08)),
60 db.raw(`update ticks set current_tick = ${nextTick}, last_tick_at = ${Date.now()}`)
67 const now = new Date();
68 const nextTickAt = 60 - now.getMinutes();
69 console.log(`Tick scheduled for ${nextTickAt}min`);
74 }, { delay: 60000 * nextTickAt});