Show kills leaderboard at the end of hunger-games

This commit is contained in:
Dragon Fire
2020-03-02 14:35:59 -05:00
parent fc4a194a28
commit c0852d2bf8
3 changed files with 713 additions and 342 deletions
File diff suppressed because it is too large Load Diff
+28 -3
View File
@@ -42,13 +42,15 @@ module.exports = class HungerGamesCommand extends Command {
let sun = true;
let turn = 0;
let bloodbath = true;
const kills = {};
for (const tribute of tributes) kills[tribute] = 0;
const remaining = new Set(shuffle(tributes));
while (remaining.size > 1) {
if (!bloodbath && sun) ++turn;
const sunEvents = bloodbath ? events.bloodbath : sun ? events.day : events.night;
const results = [];
const deaths = [];
this.makeEvents(remaining, sunEvents, deaths, results);
this.makeEvents(remaining, kills, sunEvents, deaths, results);
let text = stripIndents`
__**${bloodbath ? 'Bloodbath' : sun ? `Day ${turn}` : `Night ${turn}`}:**__
${results.join('\n')}
@@ -72,7 +74,12 @@ module.exports = class HungerGamesCommand extends Command {
}
this.client.games.delete(msg.channel.id);
const remainingArr = Array.from(remaining);
return msg.say(`And the winner is... ${remainingArr[0]}!`);
return msg.say(stripIndents`
And the winner is... **${remainingArr[0]}**!
__**Kills Leaderboard:**__
${this.makeLeaderboard(kills).join('\n')}
`);
} catch (err) {
this.client.games.delete(msg.channel.id);
throw err;
@@ -89,7 +96,7 @@ module.exports = class HungerGamesCommand extends Command {
.replace(/\(Player6\)/gi, `**${tributes[5]}**`);
}
makeEvents(tributes, eventsArr, deaths, results) {
makeEvents(tributes, kills, eventsArr, deaths, results) {
const turn = new Set(tributes);
for (const tribute of tributes) {
if (!turn.has(tribute)) continue;
@@ -104,6 +111,7 @@ module.exports = class HungerGamesCommand extends Command {
results.push(this.parseEvent(event.text, [tribute]));
} else {
const current = [tribute];
if (event.killers.includes(1)) kills[tribute] += event.deaths.length;
if (event.deaths.includes(1)) {
deaths.push(tribute);
tributes.delete(tribute);
@@ -111,6 +119,7 @@ module.exports = class HungerGamesCommand extends Command {
for (let i = 2; i <= event.tributes; i++) {
const turnArr = Array.from(turn);
const tribu = turnArr[Math.floor(Math.random() * turnArr.length)];
if (event.killers.includes(i)) kills[tribu] += event.deaths.length;
if (event.deaths.includes(i)) {
deaths.push(tribu);
tributes.delete(tribu);
@@ -122,4 +131,20 @@ module.exports = class HungerGamesCommand extends Command {
}
}
}
makeLeaderboard(kills) {
let i = 0;
let previousPts = null;
let positionsMoved = 1;
return tributes.sort((a, b) => kills[b] - kills[a]).map(tribute => {
if (previousPts === kills[tribute]) {
positionsMoved++;
} else {
i += positionsMoved;
positionsMoved = 1;
}
previousPts = kills[tribute];
return `**${i}.** ${tribute} (${kills[tribute]} Kills)`;
});
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "111.1.5",
"version": "111.1.6",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {