{"size": 1157, "ext": "js", "max_stars_repo_path": "parser-games-log/src/bypassParser/makers/makeKillsInGameByPlayer.js", "max_stars_repo_name": "rogeriomq/test-immail", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "parser-games-log/src/bypassParser/makers/makeKillsInGameByPlayer.js", "max_issues_repo_name": "rogeriomq/test-immail", "max_issues_repo_issues_event_min_datetime": "2021-03-10T16:15:55.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T03:49:22.000Z", "max_forks_repo_path": "parser-games-log/src/bypassParser/makers/makeKillsInGameByPlayer.js", "max_forks_repo_name": "rogeriomq/test-immail", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 4, "max_forks_count": null, "avg_line_length": 36.15625, "max_line_length": 104, "alphanum_fraction": 0.7173725151}
const extractPlayerKilledByWorld = (line) => {
  const [playerName, killByMean] = line.split(' killed ')[1].split(' by ')

  return [playerName, killByMean]
}

const extractPlayerNameKiller = (line) => {
  const lineSplited = line.split(' killed ')
  const playerName = lineSplited[0].split(': ')[2]
  const killByMean = lineSplited[1].split(' by ')[1]

  return [playerName, killByMean]
}

const makeKillsInGameByPlayer = (line, state) => {
  state.actualGame.total_kills++
  // decreases kill when killed by <world>
  if(line.includes('<world>')) {
    const [playerName, killByMean] = extractPlayerKilledByWorld(line)
    // counter minus one kill.
    state.actualGame.kills[playerName] = (state.actualGame.kills[playerName] || 0) - 1
    state.actualGame.kills_by_means[killByMean] = (state.actualGame.kills_by_means[killByMean] || 0) + 1
    return
  }

  const [playerName, killByMean] = extractPlayerNameKiller(line)
  state.actualGame.kills[playerName] = (state.actualGame.kills[playerName] || 0) + 1
  state.actualGame.kills_by_means[killByMean] = (state.actualGame.kills_by_means[killByMean] || 0) + 1
}

module.exports = makeKillsInGameByPlayer
