Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const parsers$ = INFERNO_DEMOS.map(DEMO_FILE => {
let attacks = [];
let plants = [];
let demo = new demofile.DemoFile();
let getTeam = (player) => {
if (_.includes(demo.teams[demofile.TEAM_CTS].members.map(p => p.userId), player.userId)) {
return "CT";
}
return "T";
};
// Wait for the first round, we don't care about the warm-up.
let gameStarted = false;
demo.gameEvents.on("round_start", e => {
console.log(`=== ROUND #${demo.gameRules.roundsPlayed} STARTED IN ${DEMO_FILE} ===`);
gameStarted = true;
});
// Record bomb plant position and information
const parsers$ = GAME_DEMOS.map(DEMO_FILE => {
let playerPositions = {};
let demo = new demofile.DemoFile();
let getTeam = (player) => {
if (_.includes(demo.teams[demofile.TEAM_CTS].members.map(p => p && p.userId), player.userId)) {
return "CT";
}
return "T";
};
// Wait for the first round, we don't care about the warm-up.
let gameStarted = false;
let lastRoundNumber = -1;
demo.gameEvents.on("round_start", e => {
if (demo.gameRules.roundsPlayed > lastRoundNumber) {
console.log(`=== ROUND #${demo.gameRules.roundsPlayed} STARTED IN ${DEMO_FILE} ===`);
demo.players
.filter(player => player.isAlive)
// It's not perfect, but we can find the attacker with reasonable accuracy by finding the closest player to inflictorWorldPos.
const attacker = _.minBy(demo.players, p => {
return distance3(p.position, e.msg.inflictorWorldPos);
});
if (victim && attacker && victim.index !== attacker.index
&& attacker.isAlive && distance3(attacker.position, e.msg.inflictorWorldPos) < 50) {
const victimTeam = getTeam(victim);
const attackerTeam = getTeam(attacker);
const amount = e.msg.amount;
const weapon = attacker.weapon.className;
// console.log(`${attacker.name} (${attackerTeam}) attacked ${victim.name} (${victimTeam}) for ${amount} damage with ${weapon}`);
attacks.push({
time: demo.currentTime,
round: demo.gameRules.roundsPlayed,
score: {
T: demo.teams[demofile.TEAM_TERRORISTS].score,
CT: demo.teams[demofile.TEAM_CTS].score,
},
attacker: {
pos: attacker.position,
team: attackerTeam,
name: attacker.name,
},
victim: {
pos: victim.position,
team: victimTeam,
name: victim.name,
},
amount: amount,
weapon: weapon,
});
}
const parsers = UNPARSED_DEMOS_BATCH.map(DEMO_FILE => {
const demo = new demofile.DemoFile();
const gameStarts$ = fromEvent(demo.gameEvents, 'round_start').pipe(
rxop.first(),
);
const gameEnds$ = fromEvent(demo, 'end').pipe(
rxop.first(),
);
// Some demos have round_end not round_officially_ended. Some are the other way around.
// So we'll use both and do the best we can with that.
let lastRoundScore = {};
const roundEndsWinner$ = fromEvent(demo.gameEvents, 'round_end').pipe(
rxop.filter(e => (e.winner === demofile.TEAM_TERRORISTS || e.winner === demofile.TEAM_CTS) && e.reason < 11),
rxop.map(e => {
if (e.winner === demofile.TEAM_TERRORISTS) return {winner: 'T'};
else if (e.winner === demofile.TEAM_CTS) return {winner: 'CT'};
return new Promise((resolve, reject) => {
let demo = new DemoFile();
demo.on("end", () => resolve(result));
demo.gameEvents.on("player_death", (event: any) => {
const victim = demo.entities.getByUserId(event.userid);
const attacker = demo.entities.getByUserId(event.attacker);
pushDeathPoint(result.deathPoints, victim, result.mapData);
pushDeathPoint(result.killPoints, attacker, result.mapData);
});
demo.on("start", async () => {
console.log(`Parsing ${demo.header.mapName}...`);
const overlayInfo = await parseOverlayInformation(csgoDirectory, demo.header.mapName);
result.mapData = {
const parsers = UNPARSED_DEMOS_BATCH.map(DEMO_FILE => {
const demo = new demofile.DemoFile();
let C4_TIMER;
const gameStarts$ = fromEvent(demo.gameEvents, "round_start").pipe(
rxop.first(),
rxop.tap(() => {
C4_TIMER = demo.conVars.vars.mp_c4timer
? parseFloat(demo.conVars.vars.mp_c4timer)
: 40;
})
);
const gameEnds$ = fromEvent(demo, "end").pipe(rxop.first());
const plants$ = fromEvent(demo.gameEvents, "bomb_planted").pipe(
rxop.map(e => ({ ...e, time: demo.currentTime }))
);
const defuses$ = fromEvent(demo.gameEvents, "bomb_defused").pipe(
let getTeam = (player) => {
if (_.includes(demo.teams[demofile.TEAM_CTS].members.map(p => p.userId), player.userId)) {
return "CT";
}
return "T";
};
rxop.map(e => {
if (e.winner === demofile.TEAM_TERRORISTS) return {winner: 'T'};
else if (e.winner === demofile.TEAM_CTS) return {winner: 'CT'};
}),
);
let getTeam = (player) => {
if (_.includes(demo.teams[demofile.TEAM_CTS].members.map(p => p && p.userId), player.userId)) {
return "CT";
}
return "T";
};
rxop.filter(e => (e.winner === demofile.TEAM_TERRORISTS || e.winner === demofile.TEAM_CTS) && e.reason < 11),
rxop.map(e => {