fix captures not being tracked for a new enemy
This commit is contained in:
parent
71c96f248d
commit
d41ce64267
@ -147,26 +147,24 @@ export const updateStats = async (accountOwnerId: string, payload: IStatsUpdate)
|
||||
)[category];
|
||||
|
||||
for (const [type, count] of Object.entries(data as IUploadEntry)) {
|
||||
const enemy = playerStats.Enemies.find(element => element.type === type);
|
||||
if (enemy) {
|
||||
if (category === "KILL_ENEMY") {
|
||||
enemy.kills ??= 0;
|
||||
const captureCount = (actionData as IStatsAdd)["CAPTURE_ENEMY"]?.[type];
|
||||
if (captureCount) {
|
||||
enemy.kills += Math.max(count - captureCount, 0);
|
||||
enemy.captures ??= 0;
|
||||
enemy.captures += captureCount;
|
||||
} else {
|
||||
enemy.kills += count;
|
||||
}
|
||||
let enemy = playerStats.Enemies.find(element => element.type === type);
|
||||
if (!enemy) {
|
||||
enemy = { type: type };
|
||||
playerStats.Enemies.push(enemy);
|
||||
}
|
||||
if (category === "KILL_ENEMY") {
|
||||
enemy.kills ??= 0;
|
||||
const captureCount = (actionData as IStatsAdd)["CAPTURE_ENEMY"]?.[type];
|
||||
if (captureCount) {
|
||||
enemy.kills += Math.max(count - captureCount, 0);
|
||||
enemy.captures ??= 0;
|
||||
enemy.captures += captureCount;
|
||||
} else {
|
||||
enemy[enemyStatKey] ??= 0;
|
||||
enemy[enemyStatKey] += count;
|
||||
enemy.kills += count;
|
||||
}
|
||||
} else {
|
||||
const newEnemy: IEnemy = { type: type };
|
||||
newEnemy[enemyStatKey] = count;
|
||||
playerStats.Enemies.push(newEnemy);
|
||||
enemy[enemyStatKey] ??= 0;
|
||||
enemy[enemyStatKey] += count;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user