void AddSessionWeapon(EventLog newEvent) { Weapon newWeapon = new Weapon(); Weapon oldWeapon = new Weapon(); oldWeapon.Initialize(); newWeapon.Initialize(); newWeapon.name = newEvent.method; newWeapon.kills += newEvent.IsKill() ? 1 : 0; newWeapon.headShots += newEvent.headshot ? 1 : 0; // Add to total deaths. if (m_sessionStarted) { if (!newEvent.IsKill()) { UpdateOverallStats(0, 0, 1); } // Update overall stats. Should only be called once overall stats have been set initially. // *Additionally it will not update a weapon not found in the All Weapons section. else { // * Testing with always updating stats regardless of if weapon was used previously. //if (m_weaponsUpdated && IsWeaponInAllWeapons(newWeapon.name)) //{ // Do not give kills or headshots for team kills. if(newEvent.faction != m_userFaction) UpdateOverallStats(newWeapon.kills, newWeapon.headShots, 0); //} } } // Add session weapon stats unless this event was a death or team kill. if(!newEvent.death && newEvent.faction != m_userFaction) AddSessionWeapon(newWeapon, oldWeapon); }
async Task AddSessionWeapon(EventLog newEvent) { Weapon newWeapon = new Weapon(); Weapon oldWeapon = new Weapon(); oldWeapon.Initialize(); newWeapon.Initialize(); if (newEvent.isVehicle) { newWeapon.id = "0"; newWeapon.vehicleId = newEvent.methodID; } else newWeapon.id = newEvent.methodID; newWeapon.name = await GetItemName(GetBestWeaponID(newWeapon)); newWeapon.kills += newEvent.IsKill() ? 1 : 0; newWeapon.headShots += newEvent.headshot ? 1 : 0; // Add to total deaths. if (m_sessionStarted || m_countEvents) { if (!newEvent.IsKill()) { UpdateOverallStats(0, 0, 1); } // Update overall stats. Should only be called once overall stats have been set initially. else { // Do not give kills or headshots for team kills. // TODO: If you kill someone that is so brand new that even their ID does not come through, // the defender will be null. So if the defender is null then a kill is currently counted. However, // the defender might be a team mate. The only fix I know of is to keep track of this and check it // occasionally and reverse the kill once the name is resolved and same faction is discovered. if (newEvent.defender == null || (newEvent.defender != null && newEvent.defender.faction != m_player.faction)) UpdateOverallStats(newWeapon.kills, newWeapon.headShots, 0); } } // Add session weapon stats unless this event was a death or team kill. if (!newEvent.death && (newEvent.defender == null || (newEvent.defender != null && newEvent.defender.faction != m_player.faction))) await AddSessionWeapon(newWeapon, oldWeapon); }