Use player map for scoreboard players

pull/18/head
HardiReady 2017-11-06 14:22:18 +01:00
parent 36a1166cae
commit 403b6d8f34
1 changed files with 19 additions and 18 deletions

View File

@ -17,13 +17,12 @@ const parseWarLog = (lineArray, war) => {
players: []
};
const addPlayersIfNotExists = (inputPlayers) => {
inputPlayers.forEach(player => {
if (player && player.name && player.fraction && !playerArrayContains(stats.players, player)) {
player['warId'] = war._id;
stats.players.push(player);
}
})
const addPlayerIfNotExists = (inputPlayer) => {
const player = getPlayerAndFractionFromString(inputPlayer);
if (player && player.name && player.fraction && !playerArrayContains(stats.players, player)) {
player['warId'] = war._id;
stats.players.push(player);
}
};
lineArray.some(line => {
@ -52,14 +51,12 @@ const parseWarLog = (lineArray, war) => {
friendlyFire: shooter ? target.fraction === shooter.fraction : false,
fraction: shooter ? shooter.fraction : 'NONE'
});
addPlayersIfNotExists([shooter, target]);
}
/**
* BUDGET
*/
if (line.includes('Budget')) {
else if (line.includes('Budget')) {
stats.clean.push(line);
const budg = line.split(' ');
if (line.includes('Endbudget')) {
@ -79,7 +76,7 @@ const parseWarLog = (lineArray, war) => {
/**
* FLAG
*/
if (line.includes('Fahne')) {
else if (line.includes('Fahne')) {
stats.clean.push(line);
const playerName = line.substring(line.lastIndexOf('t von ') + 6, line.lastIndexOf(' :OPT LOG END'));
const flagFraction = line.includes('NATO Flagge') ? 'BLUFOR' : 'OPFOR';
@ -97,7 +94,7 @@ const parseWarLog = (lineArray, war) => {
/**
* POINTS
*/
if (line.includes('Punkte')) {
else if (line.includes('Punkte')) {
stats.clean.push(line);
const pt = line.split(' ');
@ -114,7 +111,7 @@ const parseWarLog = (lineArray, war) => {
/**
* RESPAWN
*/
if (line.includes('Respawn')) {
else if (line.includes('Respawn')) {
stats.clean.push(line);
const resp = line.split(' ');
const playerName = line.substring(line.lastIndexOf('Spieler:') + 9, line.lastIndexOf('-') - 1);
@ -124,7 +121,7 @@ const parseWarLog = (lineArray, war) => {
/**
* REVIVE
*/
if (line.includes('Revive')) {
else if (line.includes('Revive')) {
stats.clean.push(line);
const stabilized = !!line.includes('stabilisiert');
const medicName = line.substring(line.lastIndexOf('wurde von ') + 10,
@ -141,14 +138,12 @@ const parseWarLog = (lineArray, war) => {
patient: patient.name,
fraction: medic.fraction
});
addPlayersIfNotExists([medic, patient]);
}
/**
* TRANSPORT
*/
if (line.includes('Transport ||')) {
else if (line.includes('Transport ||')) {
stats.clean.push(line);
const driverString = line.substring(line.lastIndexOf('wurde von ') + 10, line.lastIndexOf(' eingeflogen'));
const driver = getPlayerAndFractionFromString(driverString);
@ -164,8 +159,14 @@ const parseWarLog = (lineArray, war) => {
fraction: driver.fraction,
distance: distance
});
}
addPlayersIfNotExists([driver, passenger]);
/**
* PLAYERS
*/
else if (line.includes('Fraktionsübersicht ||')) {
const playerString = line.substring(line.lastIndexOf('Fraktionsübersicht || ') + 22, line.lastIndexOf(' :OPT LOG END'));
addPlayerIfNotExists(playerString)
}
});