Use steamUUID in highscore if available

pull/29/head
HardiReady 2018-03-04 10:55:59 +01:00
parent 5d3c9cbe91
commit a09064ea38
2 changed files with 30 additions and 26 deletions

View File

@ -36,30 +36,35 @@ campaignPlayer.route('/ranking/:campaignId')
}
const rankingItems = [];
new Set(items.map(x => x.name)).forEach(playerName => {
const playerInstances = items.filter(p => p.name === playerName);
const resItem = {
name: playerName,
kill: 0,
vehicle: 0,
death: 0,
friendlyFire: 0,
revive: 0,
respawn: 0,
flagTouch: 0
};
for (let i = 0; i < playerInstances.length; i++) {
resItem.kill += playerInstances[i].kill;
resItem.death += playerInstances[i].death;
resItem.friendlyFire += playerInstances[i].friendlyFire;
resItem.vehicle += playerInstances[i].vehicle;
resItem.revive += playerInstances[i].revive;
resItem.respawn += playerInstances[i].respawn;
resItem.flagTouch += playerInstances[i].flagTouch;
}
resItem.fraction = playerInstances[playerInstances.length - 1].fraction;
rankingItems.push(resItem);
});
// check only first player to have valid steamUUID - then decide if tracked by name or by ID
const usesUUID = isSteamUUID(items[0].steamUUID);
new Set(items.map(usesUUID ? x => x.steamUUID : x => x.name))
.forEach(player => {
const playerInstances = items.filter(usesUUID ? p => p.steamUUID === player : p => p.name === player);
const resItem = {
name: usesUUID ? playerInstances[playerInstances.length - 1].name : player,
kill: 0,
vehicle: 0,
death: 0,
friendlyFire: 0,
revive: 0,
respawn: 0,
flagTouch: 0
};
for (let i = 0; i < playerInstances.length; i++) {
resItem.kill += playerInstances[i].kill;
resItem.death += playerInstances[i].death;
resItem.friendlyFire += playerInstances[i].friendlyFire;
resItem.vehicle += playerInstances[i].vehicle;
resItem.revive += playerInstances[i].revive;
resItem.respawn += playerInstances[i].respawn;
resItem.flagTouch += playerInstances[i].flagTouch;
}
resItem.fraction = playerInstances[playerInstances.length - 1].fraction;
rankingItems.push(resItem);
});
function getSortedField(fieldName) {
let num = 1;

View File

@ -5,7 +5,6 @@ const isSteamUUID = (input) => {
return steamUIDPattern.test(input)
};
const sortCollectionBy = (collection, key) => {
collection.sort((a, b) => {
a = a[key].toLowerCase();
@ -50,8 +49,8 @@ const decimalToTimeString = (decimal) => {
(seconds < 10 ? '0' + seconds : seconds);
};
exports.isSteamUUID = isSteamUUID;
exports.sortCollection = sortCollectionBy;
exports.playerArrayContains = playerArrayContains;
exports.timeStringToDecimal = timeStringToDecimal;
exports.decimalToTimeString = decimalToTimeString;
exports.isSteamUUID = isSteamUUID;