Amended the freeze code

This commit is contained in:
2019-06-19 21:01:53 +10:00
parent 74696d717b
commit 458dfd933e
3 changed files with 15 additions and 16 deletions
+9 -11
View File
@@ -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;
+4 -5
View File
@@ -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();
});