From 458dfd933e218e1a72865905a62618385c1d13d4 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 19 Jun 2019 21:01:53 +1000 Subject: [PATCH] Amended the freeze code --- public/news/2019-06-19-01.md | 2 ++ server/profiles.js | 20 +++++++++----------- server/statistics.js | 9 ++++----- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/public/news/2019-06-19-01.md b/public/news/2019-06-19-01.md index b04e5fc..bca9b1d 100644 --- a/public/news/2019-06-19-01.md +++ b/public/news/2019-06-19-01.md @@ -2,6 +2,8 @@ It's Freezing In Here! --- _19 June 2019_ +Edit: Actually, I realize freezing the tick rate for EVERYONE is unfair if you're under 100 gold - you'll never be able to train a unit. As such, I've amended the algorithm to only affect those with gold equal to or higher than 100. + I've frozen the gold tick due to the recent surge in the gold supply. This is a temporary measure, as I'm hoping it'll drop to a more reasonable level as players do their thing. I'm hoping to pull another all nighter tonight, simply because I do my best work at night. I'm also planning on releasing "content updates" every Sunday my time to keep everyone entertained. I'll try to add _something_ new gameplay-wise every week. diff --git a/server/profiles.js b/server/profiles.js index 306081b..37eae65 100644 --- a/server/profiles.js +++ b/server/profiles.js @@ -479,8 +479,7 @@ const runGoldTick = (connection) => { //determine the correct tick rate based on the current gold average let tickRate = (() => { - //TMP: freeze the tick rate - return null; + return -60; //TMP: semi-freeze the tick rate if (results[0].goldAverage < 120) return 5; if (results[0].goldAverage < 130) return 15; if (results[0].goldAverage < 140) return 30; @@ -491,15 +490,14 @@ const runGoldTick = (connection) => { if (oldTickRate !== tickRate) { if (goldTickJob) goldTickJob.stop(); - //TMP: freeze the tickRate - if (tickRate === null) { - log('Tick rate frozen'); - oldTickRate = tickRate; - return; - } - - goldTickJob = new CronJob(`0 */${tickRate} * * * *`, () => { - let query = 'UPDATE profiles SET gold = gold + recruits;'; + //NOTE: negative tickRate means restrict the tick to people with gold < 100 + goldTickJob = new CronJob(`0 */${tickRate > 0 ? tickRate : -tickRate} * * * *`, () => { + let query; + if (tickRate > 0) { + query = 'UPDATE profiles SET gold = gold + recruits;'; + } else { + query = 'UPDATE profiles SET gold = gold + recruits WHERE gold < 100;'; + } connection.query(query, (err) => { if (err) throw err; diff --git a/server/statistics.js b/server/statistics.js index 17aa8e3..15aed2f 100644 --- a/server/statistics.js +++ b/server/statistics.js @@ -18,15 +18,14 @@ const statisticsRequest = (connection) => (req, res) => { //determine the correct tick rate based on the current gold average //NOTE: copy/pasted let tickRate = (() => { - //TMP: freeze the tick rate - return null; + return -60; //TMP: semi-freeze the tick rate if (results[0].goldAverage < 120) return 5; if (results[0].goldAverage < 130) return 15; if (results[0].goldAverage < 140) return 30; return 60; //slow it way down })(); - let nextTick = tickRate ? tickRate - (new Date()).getMinutes() % tickRate : null; + let nextTick = Math.abs(tickRate) - (new Date()).getMinutes() % Math.abs(tickRate); let query = 'SELECT COUNT(*) AS activity FROM accounts WHERE lastActivityTime >= DATE_SUB(CURRENT_TIMESTAMP(), INTERVAL 1 DAY);'; connection.query(query, (err, results) => { @@ -51,8 +50,8 @@ const statisticsRequest = (connection) => (req, res) => { 'Scientist Total': scientistTotal, 'Spy Total': { string: '[Classified]', color: 'red' }, 'Gold Average': `${round(goldAverage)}`, - 'Gold Tick Rate': tickRate ? `${tickRate} minutes` : { string: 'Frozen', color: 'red' }, - 'Gold Next Tick': nextTick ? `${nextTick} minute${nextTick === 1 ? '' : 's'} from now` : { string: 'Frozen', color: 'red' } + 'Gold Tick Rate': tickRate > 0 ? `${tickRate} minutes` : { string: `${Math.abs(tickRate)} minutes (restricted to gold < 100)`, color: 'yellow' }, + 'Gold Next Tick': `${nextTick} minute${nextTick === 1 ? '' : 's'} from now` }); res.end(); });