Save vehicles and magazine on kill log (CC-36)

pull/37/head
HardiReady 2018-06-17 11:52:43 +02:00
parent 026a3611a6
commit 07a6822920
4 changed files with 74 additions and 35 deletions

View File

@ -43,6 +43,9 @@
+ `BLUFOR` + `BLUFOR`
+ `OPFOR` + `OPFOR`
+ `NONE` + `NONE`
+ shooterVehicle: `FV-720 Mora` (string, optional) - vehicle in whiock the shooting player sat
+ targetVehicle: `Ifrit-GMG` (string, optional) - vehicle in which the target player sat
+ magazine: `30 mm APFSDS` (string, optional) - magazine name used to execute the kill
#LogRespawn (Log) #LogRespawn (Log)
## Properties ## Properties
@ -84,3 +87,5 @@
+ `HEAVY` + `HEAVY`
+ `AIR` + `AIR`
+ `UNKNOWN` + `UNKNOWN`
+ shooterVehicle: `FV-720 Mora` (string, optional) - vehicle in whiock the shooting player sat
+ magazine: `30 mm APFSDS` (string, optional) - magazine name used to execute the kill

View File

@ -24,6 +24,15 @@ const LogKillSchema = new Schema({
type: Boolean, type: Boolean,
required: true, required: true,
}, },
magazine: {
type: String,
},
shooterVehicle: {
type: String,
},
targetVehicle: {
type: String,
},
fraction: { fraction: {
type: String, type: String,
enum: ['BLUFOR', 'OPFOR', 'NONE'], enum: ['BLUFOR', 'OPFOR', 'NONE'],

View File

@ -33,6 +33,12 @@ const LogVehicleKillSchema = new Schema({
enum: ['LIGHT', 'HEAVY', 'AIR', 'UNKNOWN'], enum: ['LIGHT', 'HEAVY', 'AIR', 'UNKNOWN'],
required: true, required: true,
}, },
magazine: {
type: String,
},
shooterVehicle: {
type: String,
},
}, { }, {
collection: 'logVehicle', collection: 'logVehicle',
}); });

View File

@ -17,9 +17,9 @@ const vehicleNameEndRegex = /\s\(\w+:/;
const sideRegex = /(side:\s(.*?)\))/; const sideRegex = /(side:\s(.*?)\))/;
// const magazineRegex = /(magazine:\s(.*?)\))/; const magazineRegex = /(magazine:\s(.*?)\))/;
// const vehicleRegex = /(vehicle:\s(.*?)\))/; const vehicleRegex = /(vehicle:\s(.*?)\))/;
const categoryRegex = /(category:\s(.*?)\))/; const categoryRegex = /(category:\s(.*?)\))/;
@ -51,7 +51,7 @@ const parseWarLog = (lineArray, war) => {
]; ];
const addPlayerIfNotExists = (inputPlayer, steamUUID) => { const addPlayerIfNotExists = (inputPlayer, steamUUID) => {
const player = getPlayerAndFractionFromString(inputPlayer); const player = getPlayerInfoFromString(inputPlayer);
if (player && player.name && player.fraction && !playerArrayContains(stats.players, player)) { if (player && player.name && player.fraction && !playerArrayContains(stats.players, player)) {
player['warId'] = war._id; player['warId'] = war._id;
player['steamUUID'] = steamUUID; player['steamUUID'] = steamUUID;
@ -74,7 +74,7 @@ const parseWarLog = (lineArray, war) => {
stats.clean.push(line); stats.clean.push(line);
const shooterString = line.substring(line.lastIndexOf(' von: ') + 6, line.search(/$/) - 1); const shooterString = line.substring(line.lastIndexOf(' von: ') + 6, line.search(/$/) - 1);
const shooter = getPlayerAndFractionFromString(shooterString); const shooter = getPlayerInfoFromString(shooterString);
if (line.includes('Fahrzeug:')) { if (line.includes('Fahrzeug:')) {
const targetString = line.substring(line.lastIndexOf(' --- Fahrzeug: ') + 15, line.lastIndexOf(' von:')); const targetString = line.substring(line.lastIndexOf(' --- Fahrzeug: ') + 15, line.lastIndexOf(' von:'));
@ -93,19 +93,36 @@ const parseWarLog = (lineArray, war) => {
} else { } else {
vehicleKill.shooter = shooter ? shooter.name : null; vehicleKill.shooter = shooter ? shooter.name : null;
} }
if (shooter.magazine) {
vehicleKill.magazine = shooter.magazine;
}
if (shooter.vehicle) {
vehicleKill.shooterVehicle = shooter.vehicle;
}
stats.vehicles.push(vehicleKill); stats.vehicles.push(vehicleKill);
} }
} else { } else {
const targetString = line.substring(line.lastIndexOf(' --- Einheit: ') + 14, line.lastIndexOf(' von:')); const targetString = line.substring(line.lastIndexOf(' --- Einheit: ') + 14, line.lastIndexOf(' von:'));
const target = getPlayerAndFractionFromString(targetString); const target = getPlayerInfoFromString(targetString);
stats.kills.push({ const kill = {
war: war._id, war: war._id,
time: getFullTimeDate(war.date, line.split(WHITESPACE)[5]), time: getFullTimeDate(war.date, line.split(WHITESPACE)[5]),
shooter: shooter ? shooter.name : null, shooter: shooter ? shooter.name : null,
target: target ? target.name : null, target: target ? target.name : null,
friendlyFire: shooter ? target.fraction === shooter.fraction : false, friendlyFire: shooter ? target.fraction === shooter.fraction : false,
fraction: shooter ? shooter.fraction : 'NONE', fraction: shooter ? shooter.fraction : 'NONE',
}); };
if (shooter.magazine) {
kill.magazine = shooter.magazine;
}
if (shooter.vehicle) {
kill.shooterVehicle = shooter.vehicle;
}
if (target.vehicle) {
kill.targetVehicle = target.vehicle;
}
stats.kills.push(kill);
} }
} else if (line.includes('(Budget)')) { } else if (line.includes('(Budget)')) {
/** /**
@ -173,9 +190,9 @@ const parseWarLog = (lineArray, war) => {
const stabilized = !!line.includes('stabilisiert."'); const stabilized = !!line.includes('stabilisiert."');
const medicName = line.substring(line.lastIndexOf('wurde von ') + 10, const medicName = line.substring(line.lastIndexOf('wurde von ') + 10,
line.lastIndexOf(stabilized ? ' stabilisiert' : ' wiederbelebt')); line.lastIndexOf(stabilized ? ' stabilisiert' : ' wiederbelebt'));
const medic = getPlayerAndFractionFromString(medicName); const medic = getPlayerInfoFromString(medicName);
const patientName = line.substring(line.lastIndexOf('--- ') + 4, line.lastIndexOf(' wurde von')); const patientName = line.substring(line.lastIndexOf('--- ') + 4, line.lastIndexOf(' wurde von'));
const patient = getPlayerAndFractionFromString(patientName); const patient = getPlayerInfoFromString(patientName);
stats.revive.push({ stats.revive.push({
war: war._id, war: war._id,
@ -191,9 +208,9 @@ const parseWarLog = (lineArray, war) => {
*/ */
stats.clean.push(line); stats.clean.push(line);
const driverString = line.substring(line.lastIndexOf('wurde von ') + 10, line.lastIndexOf(' eingeflogen')); const driverString = line.substring(line.lastIndexOf('wurde von ') + 10, line.lastIndexOf(' eingeflogen'));
const driver = getPlayerAndFractionFromString(driverString); const driver = getPlayerInfoFromString(driverString);
const passengerString = line.substring(line.lastIndexOf('--- ') + 3, line.lastIndexOf(' wurde von')); const passengerString = line.substring(line.lastIndexOf('--- ') + 3, line.lastIndexOf(' wurde von'));
const passenger = getPlayerAndFractionFromString(passengerString); const passenger = getPlayerInfoFromString(passengerString);
const distance = parseInt(line.substring(line.lastIndexOf('eingeflogen (') + 13, line.lastIndexOf('m)') - 1)); const distance = parseInt(line.substring(line.lastIndexOf('eingeflogen (') + 13, line.lastIndexOf('m)') - 1));
stats.transport.push({ stats.transport.push({
@ -285,15 +302,20 @@ const getBudgetEntry = (budg, warId, warDate) => {
}; };
}; };
const getPlayerAndFractionFromString = (inputString) => { const getPlayerInfoFromString = (inputString) => {
const resPlayer = {};
const playerNameRegexMatch = playerNameRegex.exec(inputString); const playerNameRegexMatch = playerNameRegex.exec(inputString);
const sideMatch = sideRegex.exec(inputString); const sideMatch = sideRegex.exec(inputString);
// SINGLE PLAYER NAME // SINGLE PLAYER NAME
let name; let name;
if (playerNameRegexMatch && playerNameRegexMatch.length >= 2) { if (playerNameRegexMatch && playerNameRegexMatch.length >= 2) {
// NAME
name = playerNameRegexMatch[2].trim(); name = playerNameRegexMatch[2].trim();
// do not return player for 'Error: No unit'
if (!name && name === 'Error: No unit') {
return;
}
resPlayer.name = name;
} }
// ADDITIONAL PLAYER NAMES // ADDITIONAL PLAYER NAMES
let additionalPlayerMatch; let additionalPlayerMatch;
@ -317,34 +339,31 @@ const getPlayerAndFractionFromString = (inputString) => {
} }
} }
// const magazineMatch = magazineRegex.exec(inputString); if (side && side !== 'ENEMY') {
// const vehicleMatch = vehicleRegex.exec(inputString); resPlayer.fraction = side === 'WEST' ? 'BLUFOR' : 'OPFOR';
}
// if (magazineMatch && magazineMatch.length >= 3) {
// MAGAZINE // MAGAZINE
// console.log(magazineMatch[2]) const magazineMatch = magazineRegex.exec(inputString);
// } if (magazineMatch && magazineMatch.length >= 3) {
let magazine = magazineMatch[2];
if (new RegExp('\\(.*$').test(magazine)) {
magazine = magazine.concat(')');
}
resPlayer.magazine = magazine;
}
// if (vehicleMatch && vehicleMatch.length >= 3 && vehicleMatch[2]) {
// let vehicle = vehicleMatch[2];
// if (new RegExp("\\(.*$").test(vehicle)) {
// vehicle = vehicle.concat(")");
// }
// VEHICLE // VEHICLE
// console.log(vehicle) const vehicleMatch = vehicleRegex.exec(inputString);
// } if (vehicleMatch && vehicleMatch.length >= 3 && vehicleMatch[2]) {
let vehicle = vehicleMatch[2];
let fraction; if (new RegExp('\\(.*$').test(vehicle)) {
if (side) { vehicle = vehicle.concat(')');
fraction = side !== 'ENEMY' ? side === 'WEST' ? }
'BLUFOR' : 'OPFOR' : resPlayer.vehicle = vehicle;
undefined;
} }
// do not return player for 'Error: No unit' return resPlayer;
if (name && name !== 'Error: No unit') {
return {name: name, fraction: fraction};
}
}; };
const getVehicleAndFractionFromString = (nameClassFractionString) => { const getVehicleAndFractionFromString = (nameClassFractionString) => {