move ??= outside for loop
This commit is contained in:
parent
3098d3290f
commit
8492720fd0
@ -62,8 +62,8 @@ export const uploadStats = async (playerStats: TStatsDatabaseDocument, payload:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (SCAN) {
|
if (SCAN) {
|
||||||
|
playerStats.Scans ??= [];
|
||||||
for (const [key, scans] of Object.entries(SCAN)) {
|
for (const [key, scans] of Object.entries(SCAN)) {
|
||||||
playerStats.Scans ??= [];
|
|
||||||
const scan = playerStats.Scans.find(element => element.type === key);
|
const scan = playerStats.Scans.find(element => element.type === key);
|
||||||
if (scan) {
|
if (scan) {
|
||||||
scan.scans ??= 0;
|
scan.scans ??= 0;
|
||||||
@ -75,8 +75,8 @@ export const uploadStats = async (playerStats: TStatsDatabaseDocument, payload:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (USE_ABILITY) {
|
if (USE_ABILITY) {
|
||||||
|
playerStats.Abilities ??= [];
|
||||||
for (const [key, used] of Object.entries(USE_ABILITY)) {
|
for (const [key, used] of Object.entries(USE_ABILITY)) {
|
||||||
playerStats.Abilities ??= [];
|
|
||||||
const ability = playerStats.Abilities.find(element => element.type === key);
|
const ability = playerStats.Abilities.find(element => element.type === key);
|
||||||
if (ability) {
|
if (ability) {
|
||||||
ability.used ??= 0;
|
ability.used ??= 0;
|
||||||
@ -88,8 +88,8 @@ export const uploadStats = async (playerStats: TStatsDatabaseDocument, payload:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (FIRE_WEAPON) {
|
if (FIRE_WEAPON) {
|
||||||
|
playerStats.Weapons ??= [];
|
||||||
for (const [key, fired] of Object.entries(FIRE_WEAPON)) {
|
for (const [key, fired] of Object.entries(FIRE_WEAPON)) {
|
||||||
playerStats.Weapons ??= [];
|
|
||||||
const weapon = playerStats.Weapons.find(element => element.type === key);
|
const weapon = playerStats.Weapons.find(element => element.type === key);
|
||||||
if (weapon) {
|
if (weapon) {
|
||||||
weapon.fired ??= 0;
|
weapon.fired ??= 0;
|
||||||
@ -101,8 +101,8 @@ export const uploadStats = async (playerStats: TStatsDatabaseDocument, payload:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (HIT_ENTITY_ITEM) {
|
if (HIT_ENTITY_ITEM) {
|
||||||
|
playerStats.Weapons ??= [];
|
||||||
for (const [key, hits] of Object.entries(HIT_ENTITY_ITEM)) {
|
for (const [key, hits] of Object.entries(HIT_ENTITY_ITEM)) {
|
||||||
playerStats.Weapons ??= [];
|
|
||||||
const weapon = playerStats.Weapons.find(element => element.type === key);
|
const weapon = playerStats.Weapons.find(element => element.type === key);
|
||||||
if (weapon) {
|
if (weapon) {
|
||||||
weapon.hits ??= 0;
|
weapon.hits ??= 0;
|
||||||
@ -114,8 +114,8 @@ export const uploadStats = async (playerStats: TStatsDatabaseDocument, payload:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (HEADSHOT_ITEM) {
|
if (HEADSHOT_ITEM) {
|
||||||
|
playerStats.Weapons ??= [];
|
||||||
for (const [key, headshots] of Object.entries(HEADSHOT_ITEM)) {
|
for (const [key, headshots] of Object.entries(HEADSHOT_ITEM)) {
|
||||||
playerStats.Weapons ??= [];
|
|
||||||
const weapon = playerStats.Weapons.find(element => element.type === key);
|
const weapon = playerStats.Weapons.find(element => element.type === key);
|
||||||
if (weapon) {
|
if (weapon) {
|
||||||
weapon.headshots ??= 0;
|
weapon.headshots ??= 0;
|
||||||
@ -127,8 +127,8 @@ export const uploadStats = async (playerStats: TStatsDatabaseDocument, payload:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (KILL_ENEMY_ITEM) {
|
if (KILL_ENEMY_ITEM) {
|
||||||
|
playerStats.Weapons ??= [];
|
||||||
for (const [key, kills] of Object.entries(KILL_ENEMY_ITEM)) {
|
for (const [key, kills] of Object.entries(KILL_ENEMY_ITEM)) {
|
||||||
playerStats.Weapons ??= [];
|
|
||||||
const weapon = playerStats.Weapons.find(element => element.type === key);
|
const weapon = playerStats.Weapons.find(element => element.type === key);
|
||||||
if (weapon) {
|
if (weapon) {
|
||||||
weapon.kills ??= 0;
|
weapon.kills ??= 0;
|
||||||
@ -140,8 +140,8 @@ export const uploadStats = async (playerStats: TStatsDatabaseDocument, payload:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (KILL_ENEMY) {
|
if (KILL_ENEMY) {
|
||||||
|
playerStats.Enemies ??= [];
|
||||||
for (const [key, kills] of Object.entries(KILL_ENEMY)) {
|
for (const [key, kills] of Object.entries(KILL_ENEMY)) {
|
||||||
playerStats.Enemies ??= [];
|
|
||||||
const enemy = playerStats.Enemies.find(element => element.type === key);
|
const enemy = playerStats.Enemies.find(element => element.type === key);
|
||||||
if (enemy) {
|
if (enemy) {
|
||||||
enemy.kills ??= 0;
|
enemy.kills ??= 0;
|
||||||
@ -153,8 +153,8 @@ export const uploadStats = async (playerStats: TStatsDatabaseDocument, payload:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (EXECUTE_ENEMY) {
|
if (EXECUTE_ENEMY) {
|
||||||
|
playerStats.Enemies ??= [];
|
||||||
for (const [key, executions] of Object.entries(EXECUTE_ENEMY)) {
|
for (const [key, executions] of Object.entries(EXECUTE_ENEMY)) {
|
||||||
playerStats.Enemies ??= [];
|
|
||||||
const enemy = playerStats.Enemies.find(element => element.type === key);
|
const enemy = playerStats.Enemies.find(element => element.type === key);
|
||||||
if (enemy) {
|
if (enemy) {
|
||||||
enemy.executions ??= 0;
|
enemy.executions ??= 0;
|
||||||
@ -166,8 +166,8 @@ export const uploadStats = async (playerStats: TStatsDatabaseDocument, payload:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (HEADSHOT) {
|
if (HEADSHOT) {
|
||||||
|
playerStats.Enemies ??= [];
|
||||||
for (const [key, headshots] of Object.entries(HEADSHOT)) {
|
for (const [key, headshots] of Object.entries(HEADSHOT)) {
|
||||||
playerStats.Enemies ??= [];
|
|
||||||
const enemy = playerStats.Enemies.find(element => element.type === key);
|
const enemy = playerStats.Enemies.find(element => element.type === key);
|
||||||
if (enemy) {
|
if (enemy) {
|
||||||
enemy.headshots ??= 0;
|
enemy.headshots ??= 0;
|
||||||
@ -179,10 +179,10 @@ export const uploadStats = async (playerStats: TStatsDatabaseDocument, payload:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (DIE) {
|
if (DIE) {
|
||||||
|
playerStats.Enemies ??= [];
|
||||||
for (const [key, deaths] of Object.entries(DIE)) {
|
for (const [key, deaths] of Object.entries(DIE)) {
|
||||||
playerStats.Deaths ??= 0;
|
playerStats.Deaths ??= 0;
|
||||||
playerStats.Deaths += deaths;
|
playerStats.Deaths += deaths;
|
||||||
playerStats.Enemies ??= [];
|
|
||||||
const enemy = playerStats.Enemies.find(element => element.type === key);
|
const enemy = playerStats.Enemies.find(element => element.type === key);
|
||||||
if (enemy) {
|
if (enemy) {
|
||||||
enemy.deaths ??= 0;
|
enemy.deaths ??= 0;
|
||||||
@ -221,8 +221,8 @@ export const uploadStats = async (playerStats: TStatsDatabaseDocument, payload:
|
|||||||
const { EQUIP_WEAPON, CURRENT_MISSION_TIME, CIPHER_TIME } = payload.timers;
|
const { EQUIP_WEAPON, CURRENT_MISSION_TIME, CIPHER_TIME } = payload.timers;
|
||||||
|
|
||||||
if (EQUIP_WEAPON) {
|
if (EQUIP_WEAPON) {
|
||||||
|
playerStats.Weapons ??= [];
|
||||||
for (const [key, equipTime] of Object.entries(EQUIP_WEAPON)) {
|
for (const [key, equipTime] of Object.entries(EQUIP_WEAPON)) {
|
||||||
playerStats.Weapons ??= [];
|
|
||||||
const weapon = playerStats.Weapons.find(element => element.type === key);
|
const weapon = playerStats.Weapons.find(element => element.type === key);
|
||||||
if (weapon) {
|
if (weapon) {
|
||||||
weapon.equipTime ??= 0;
|
weapon.equipTime ??= 0;
|
||||||
@ -248,8 +248,8 @@ export const uploadStats = async (playerStats: TStatsDatabaseDocument, payload:
|
|||||||
const { WEAPON_XP, MISSION_SCORE } = payload.max;
|
const { WEAPON_XP, MISSION_SCORE } = payload.max;
|
||||||
|
|
||||||
if (WEAPON_XP) {
|
if (WEAPON_XP) {
|
||||||
|
playerStats.Weapons ??= [];
|
||||||
for (const [key, xp] of Object.entries(WEAPON_XP)) {
|
for (const [key, xp] of Object.entries(WEAPON_XP)) {
|
||||||
playerStats.Weapons ??= [];
|
|
||||||
const weapon = playerStats.Weapons.find(element => element.type === key);
|
const weapon = playerStats.Weapons.find(element => element.type === key);
|
||||||
if (weapon) {
|
if (weapon) {
|
||||||
weapon.xp = xp;
|
weapon.xp = xp;
|
||||||
@ -260,8 +260,8 @@ export const uploadStats = async (playerStats: TStatsDatabaseDocument, payload:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (MISSION_SCORE) {
|
if (MISSION_SCORE) {
|
||||||
|
playerStats.Missions ??= [];
|
||||||
for (const [key, highScore] of Object.entries(MISSION_SCORE)) {
|
for (const [key, highScore] of Object.entries(MISSION_SCORE)) {
|
||||||
playerStats.Missions ??= [];
|
|
||||||
const mission = playerStats.Missions.find(element => element.type === key);
|
const mission = playerStats.Missions.find(element => element.type === key);
|
||||||
if (mission) {
|
if (mission) {
|
||||||
mission.highScore = highScore;
|
mission.highScore = highScore;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user