mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-24 14:19:56 +02:00
Show kills leaderboard at the end of hunger-games
This commit is contained in:
+684
-338
File diff suppressed because it is too large
Load Diff
@@ -42,13 +42,15 @@ module.exports = class HungerGamesCommand extends Command {
|
|||||||
let sun = true;
|
let sun = true;
|
||||||
let turn = 0;
|
let turn = 0;
|
||||||
let bloodbath = true;
|
let bloodbath = true;
|
||||||
|
const kills = {};
|
||||||
|
for (const tribute of tributes) kills[tribute] = 0;
|
||||||
const remaining = new Set(shuffle(tributes));
|
const remaining = new Set(shuffle(tributes));
|
||||||
while (remaining.size > 1) {
|
while (remaining.size > 1) {
|
||||||
if (!bloodbath && sun) ++turn;
|
if (!bloodbath && sun) ++turn;
|
||||||
const sunEvents = bloodbath ? events.bloodbath : sun ? events.day : events.night;
|
const sunEvents = bloodbath ? events.bloodbath : sun ? events.day : events.night;
|
||||||
const results = [];
|
const results = [];
|
||||||
const deaths = [];
|
const deaths = [];
|
||||||
this.makeEvents(remaining, sunEvents, deaths, results);
|
this.makeEvents(remaining, kills, sunEvents, deaths, results);
|
||||||
let text = stripIndents`
|
let text = stripIndents`
|
||||||
__**${bloodbath ? 'Bloodbath' : sun ? `Day ${turn}` : `Night ${turn}`}:**__
|
__**${bloodbath ? 'Bloodbath' : sun ? `Day ${turn}` : `Night ${turn}`}:**__
|
||||||
${results.join('\n')}
|
${results.join('\n')}
|
||||||
@@ -72,7 +74,12 @@ module.exports = class HungerGamesCommand extends Command {
|
|||||||
}
|
}
|
||||||
this.client.games.delete(msg.channel.id);
|
this.client.games.delete(msg.channel.id);
|
||||||
const remainingArr = Array.from(remaining);
|
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) {
|
} catch (err) {
|
||||||
this.client.games.delete(msg.channel.id);
|
this.client.games.delete(msg.channel.id);
|
||||||
throw err;
|
throw err;
|
||||||
@@ -89,7 +96,7 @@ module.exports = class HungerGamesCommand extends Command {
|
|||||||
.replace(/\(Player6\)/gi, `**${tributes[5]}**`);
|
.replace(/\(Player6\)/gi, `**${tributes[5]}**`);
|
||||||
}
|
}
|
||||||
|
|
||||||
makeEvents(tributes, eventsArr, deaths, results) {
|
makeEvents(tributes, kills, eventsArr, deaths, results) {
|
||||||
const turn = new Set(tributes);
|
const turn = new Set(tributes);
|
||||||
for (const tribute of tributes) {
|
for (const tribute of tributes) {
|
||||||
if (!turn.has(tribute)) continue;
|
if (!turn.has(tribute)) continue;
|
||||||
@@ -104,6 +111,7 @@ module.exports = class HungerGamesCommand extends Command {
|
|||||||
results.push(this.parseEvent(event.text, [tribute]));
|
results.push(this.parseEvent(event.text, [tribute]));
|
||||||
} else {
|
} else {
|
||||||
const current = [tribute];
|
const current = [tribute];
|
||||||
|
if (event.killers.includes(1)) kills[tribute] += event.deaths.length;
|
||||||
if (event.deaths.includes(1)) {
|
if (event.deaths.includes(1)) {
|
||||||
deaths.push(tribute);
|
deaths.push(tribute);
|
||||||
tributes.delete(tribute);
|
tributes.delete(tribute);
|
||||||
@@ -111,6 +119,7 @@ module.exports = class HungerGamesCommand extends Command {
|
|||||||
for (let i = 2; i <= event.tributes; i++) {
|
for (let i = 2; i <= event.tributes; i++) {
|
||||||
const turnArr = Array.from(turn);
|
const turnArr = Array.from(turn);
|
||||||
const tribu = turnArr[Math.floor(Math.random() * turnArr.length)];
|
const tribu = turnArr[Math.floor(Math.random() * turnArr.length)];
|
||||||
|
if (event.killers.includes(i)) kills[tribu] += event.deaths.length;
|
||||||
if (event.deaths.includes(i)) {
|
if (event.deaths.includes(i)) {
|
||||||
deaths.push(tribu);
|
deaths.push(tribu);
|
||||||
tributes.delete(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
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "111.1.5",
|
"version": "111.1.6",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user