Implemented King Of The Hill
This commit is contained in:
@@ -39,6 +39,7 @@ let excluded = [ //messages that should not be logged
|
|||||||
'Sale made',
|
'Sale made',
|
||||||
|
|
||||||
'runLadderTick completed',
|
'runLadderTick completed',
|
||||||
|
'King Of The Hill contender found',
|
||||||
|
|
||||||
'Cleaned database',
|
'Cleaned database',
|
||||||
'outerTick'
|
'outerTick'
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ Badge Ideas
|
|||||||
|
|
||||||
* ~~alpha tester~~
|
* ~~alpha tester~~
|
||||||
* capture the flag
|
* capture the flag
|
||||||
* king of the hill
|
* ~~king of the hill~~
|
||||||
* gold horde
|
* gold horde
|
||||||
* ~~Combat Master~~
|
* ~~Combat Master~~
|
||||||
* Beta tester
|
* Beta tester
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
Tonight's All Nighter
|
||||||
|
---
|
||||||
|
_16 June 2019_
|
||||||
|
|
||||||
|
Things I've completed so far:
|
||||||
|
|
||||||
|
* King Of The Hill badge is now enabled (requires 24 hours at the top of the ladder).
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
"filename": "king_of_the_hill.png",
|
"filename": "king_of_the_hill.png",
|
||||||
"description": "Awarded to anyone who keeps their position at the top of the game ladder for 24 hours.",
|
"description": "Awarded to anyone who keeps their position at the top of the game ladder for 24 hours.",
|
||||||
"visible": true,
|
"visible": true,
|
||||||
"unlockable": null
|
"unlockable": true
|
||||||
},
|
},
|
||||||
"Referral Linker": {
|
"Referral Linker": {
|
||||||
"filename": "referral_linker.png",
|
"filename": "referral_linker.png",
|
||||||
|
|||||||
+52
-9
@@ -98,7 +98,7 @@ const selectActiveBadge = (connection) => (req, res) => {
|
|||||||
|
|
||||||
const rewardBadge = (connection, id, badgeName, cb) => {
|
const rewardBadge = (connection, id, badgeName, cb) => {
|
||||||
//TODO: constants as badge/equipment names?
|
//TODO: constants as badge/equipment names?
|
||||||
let query = 'INSERT INTO badges (accountId, name) SELECT ?, ? FROM DUAL WHERE NOT EXISTS(SELECT 1 FROM badges WHERE accountId = ? AND name = ?) LIMIT 1;';
|
let query = 'INSERT INTO badges (accountId, name) SELECT ?, ? FROM DUAL WHERE NOT EXISTS(SELECT 1 FROM badges WHERE accountId = ? AND name = ?);';
|
||||||
connection.query(query, [id, badgeName, id, badgeName], (err, packet) => {
|
connection.query(query, [id, badgeName, id, badgeName], (err, packet) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
@@ -123,20 +123,63 @@ const runBadgeTicks = (connection) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
combatMasterBadgeTickJob.start();
|
combatMasterBadgeTickJob.start();
|
||||||
/*
|
|
||||||
//King Of The Hill
|
|
||||||
let kingOfTheHillBadgeTickJob = new CronJob('0 * * * * *', () => {
|
|
||||||
getLadderData(connection, 0, 1, (err, ladderResults) => {
|
|
||||||
if (err) throw err;
|
|
||||||
|
|
||||||
//TODO: pull badge names into variables. Not good.
|
//King Of The Hill
|
||||||
let query = 'SELECT * FROM badgesTimespan WHERE qualifyTime >= DATE_SUB(CURRENT_TIMESTAMP(), INTERVAL 1 DAY) AND name = "King Of The Hill";';
|
let kingOfTheHillBadgeTickJob = new CronJob('0 * * * * *', () => { //once a minute
|
||||||
|
//NOTE: sloppy implementation - people who have the badge may get "rewarded" twice. Thankfully rewardBadge() prevents this.
|
||||||
|
getLadderData(connection, 'parameter not used (yet)', 0, 1, (err, ladderResults) => {
|
||||||
|
if (err) throw err; //TODO: pull badge names into variables. Not good.
|
||||||
|
|
||||||
|
//only happens with 0 players, but might as well check
|
||||||
|
if (ladderResults.length === 0) {
|
||||||
|
log('No players in ladder');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//get the current contender for king of the hill
|
||||||
|
let query = 'SELECT * FROM badgesTimespan WHERE name = "King Of The Hill";';
|
||||||
connection.query(query, (err, results) => {
|
connection.query(query, (err, results) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
|
const day = 1000*60*60*24; //milliseconds
|
||||||
|
const now = new Date();
|
||||||
|
const qualifyTime = results.length > 0 ? new Date(results[0].qualifyTime) : null;
|
||||||
|
|
||||||
|
//if someone qualifies (1 day)
|
||||||
|
if (results.length > 0 && now - qualifyTime >= day) {
|
||||||
|
rewardBadge(connection, results[0].accountId, results[0].name, (id, badgeName) => log("Badge rewarded", id, badgeName));
|
||||||
|
let query = 'DELETE FROM badgesTimespan WHERE id = ?;';
|
||||||
|
connection.query(query, [results[0].id], (err) => {
|
||||||
|
if (err) throw err;
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//if someone is still a contender for this badge
|
||||||
|
if (results.length > 0 && ladderResults[0].id === results[0].accountId) {
|
||||||
|
//DO NOTHING
|
||||||
|
log('King Of The Hill contender found', ladderResults[0].id, ladderResults[0].username);
|
||||||
|
}
|
||||||
|
|
||||||
|
//if the current contender is NOT in first place
|
||||||
|
else {
|
||||||
|
let query = 'DELETE FROM badgesTimespan WHERE name = "King Of The Hill";';
|
||||||
|
connection.query(query, (err) => {
|
||||||
|
if (err) throw err;
|
||||||
|
|
||||||
|
let query = 'INSERT INTO badgesTimespan (accountId, name) VALUES (?, "King Of The Hill")';
|
||||||
|
connection.query(query, [ladderResults[0].id], (err) => {
|
||||||
|
if (err) throw err;
|
||||||
|
|
||||||
|
log('King Of The Hill contender updated', ladderResults[0].id, ladderResults[0].username);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
|
kingOfTheHillBadgeTickJob.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ const isSpying = (connection, user, cb) => {
|
|||||||
|
|
||||||
const getLadderData = (connection, field, start, length, cb) => {
|
const getLadderData = (connection, field, start, length, cb) => {
|
||||||
//moved here for reusability
|
//moved here for reusability
|
||||||
|
//TODO: implement the field parameter
|
||||||
let query = 'SELECT accounts.id AS id, username, soldiers, recruits, gold FROM accounts JOIN profiles ON accounts.id = profiles.accountId ORDER BY -ladderRank DESC LIMIT ?, ?;';
|
let query = 'SELECT accounts.id AS id, username, soldiers, recruits, gold FROM accounts JOIN profiles ON accounts.id = profiles.accountId ORDER BY -ladderRank DESC LIMIT ?, ?;';
|
||||||
connection.query(query, [Math.max(0, start || 0), Math.max(0, length || 0)], (err, results) => {
|
connection.query(query, [Math.max(0, start || 0), Math.max(0, length || 0)], (err, results) => {
|
||||||
cb(err, results);
|
cb(err, results);
|
||||||
|
|||||||
@@ -199,18 +199,18 @@ CREATE TABLE IF NOT EXISTS badges (
|
|||||||
CONSTRAINT FOREIGN KEY fk_accountId(accountId) REFERENCES accounts(id) ON UPDATE CASCADE ON DELETE CASCADE
|
CONSTRAINT FOREIGN KEY fk_accountId(accountId) REFERENCES accounts(id) ON UPDATE CASCADE ON DELETE CASCADE
|
||||||
);
|
);
|
||||||
|
|
||||||
#CREATE TABLE IF NOT EXISTS badgesTimespan ( #for recording timespan-related badges
|
CREATE TABLE IF NOT EXISTS badgesTimespan ( #for recording timespan-related badges
|
||||||
# id INTEGER UNSIGNED AUTO_INCREMENT PRIMARY KEY UNIQUE,
|
id INTEGER UNSIGNED AUTO_INCREMENT PRIMARY KEY UNIQUE,
|
||||||
# td TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
|
td TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
|
||||||
#
|
|
||||||
# accountId INTEGER UNSIGNED,
|
accountId INTEGER UNSIGNED,
|
||||||
#
|
|
||||||
# name VARCHAR(50) NOT NULL,
|
name VARCHAR(50) NOT NULL,
|
||||||
#
|
|
||||||
# qualifyTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
|
qualifyTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
|
||||||
#
|
|
||||||
# CONSTRAINT FOREIGN KEY fk_accountId(accountId) REFERENCES accounts(id) ON UPDATE CASCADE ON DELETE CASCADE
|
CONSTRAINT FOREIGN KEY fk_accountId(accountId) REFERENCES accounts(id) ON UPDATE CASCADE ON DELETE CASCADE
|
||||||
#);
|
);
|
||||||
|
|
||||||
#banning system
|
#banning system
|
||||||
CREATE TABLE IF NOT EXISTS bannedEmails (
|
CREATE TABLE IF NOT EXISTS bannedEmails (
|
||||||
|
|||||||
Reference in New Issue
Block a user