fix captures not being tracked for a new enemy
Some checks failed
Build / build (push) Failing after 1m16s
Build / build (pull_request) Failing after 1m21s

This commit is contained in:
Sainan 2025-04-18 21:15:18 +02:00
parent 71c96f248d
commit d41ce64267

View File

@ -147,26 +147,24 @@ export const updateStats = async (accountOwnerId: string, payload: IStatsUpdate)
)[category]; )[category];
for (const [type, count] of Object.entries(data as IUploadEntry)) { for (const [type, count] of Object.entries(data as IUploadEntry)) {
const enemy = playerStats.Enemies.find(element => element.type === type); let enemy = playerStats.Enemies.find(element => element.type === type);
if (enemy) { if (!enemy) {
if (category === "KILL_ENEMY") { enemy = { type: type };
enemy.kills ??= 0; playerStats.Enemies.push(enemy);
const captureCount = (actionData as IStatsAdd)["CAPTURE_ENEMY"]?.[type]; }
if (captureCount) { if (category === "KILL_ENEMY") {
enemy.kills += Math.max(count - captureCount, 0); enemy.kills ??= 0;
enemy.captures ??= 0; const captureCount = (actionData as IStatsAdd)["CAPTURE_ENEMY"]?.[type];
enemy.captures += captureCount; if (captureCount) {
} else { enemy.kills += Math.max(count - captureCount, 0);
enemy.kills += count; enemy.captures ??= 0;
} enemy.captures += captureCount;
} else { } else {
enemy[enemyStatKey] ??= 0; enemy.kills += count;
enemy[enemyStatKey] += count;
} }
} else { } else {
const newEnemy: IEnemy = { type: type }; enemy[enemyStatKey] ??= 0;
newEnemy[enemyStatKey] = count; enemy[enemyStatKey] += count;
playerStats.Enemies.push(newEnemy);
} }
} }
break; break;