返回提交历史
Modified
src/services/statsService.ts
+23
-24
XFEstudio/SpaceNinjaServer
fix(stats): captures not being tracked for a new enemy (#1728)
Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1728 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
8afb5152
代码差异
1 个文件
+23
-24
@@ -1,6 +1,5 @@
1
1
import { Stats, TStatsDatabaseDocument } from "@/src/models/statsModel";
2
2
import {
3
IEnemy,
4
3
IStatsAdd,
5
4
IStatsMax,
6
5
IStatsSet,
@@ -137,34 +136,34 @@ export const updateStats = async (accountOwnerId: string, payload: IStatsUpdate)
137
136
case "HEADSHOT":
138
137
case "KILL_ASSIST": {
139
138
playerStats.Enemies ??= [];
140
const enemyStatKey = {
141
KILL_ENEMY: "kills",
142
EXECUTE_ENEMY: "executions",
143
HEADSHOT: "headshots",
144
KILL_ASSIST: "assists"
145
}[category] as "kills" | "executions" | "headshots" | "assists";
139
const enemyStatKey = (
140
{
141
KILL_ENEMY: "kills",
142
EXECUTE_ENEMY: "executions",
143
HEADSHOT: "headshots",
144
KILL_ASSIST: "assists"
145
} as const
146
)[category];
146
147
147
148
for (const [type, count] of Object.entries(data as IUploadEntry)) {
148
const enemy = playerStats.Enemies.find(element => element.type === type);
149
if (enemy) {
150
if (category === "KILL_ENEMY") {
151
enemy.kills ??= 0;
152
const captureCount = (actionData as IStatsAdd)["CAPTURE_ENEMY"]?.[type];
153
if (captureCount) {
154
enemy.kills += Math.max(count - captureCount, 0);
155
enemy.captures ??= 0;
156
enemy.captures += captureCount;
157
} else {
158
enemy.kills += count;
159
}
149
let enemy = playerStats.Enemies.find(element => element.type === type);
150
if (!enemy) {
151
enemy = { type: type };
152
playerStats.Enemies.push(enemy);
153
}
154
if (category === "KILL_ENEMY") {
155
enemy.kills ??= 0;
156
const captureCount = (actionData as IStatsAdd)["CAPTURE_ENEMY"]?.[type];
157
if (captureCount) {
158
enemy.kills += Math.max(count - captureCount, 0);
159
enemy.captures ??= 0;
160
enemy.captures += captureCount;
160
161
} else {
161
enemy[enemyStatKey] ??= 0;
162
enemy[enemyStatKey] += count;
162
enemy.kills += count;
163
163
}
164
164
} else {
165
const newEnemy: IEnemy = { type: type };
166
newEnemy[enemyStatKey] = count;
167
playerStats.Enemies.push(newEnemy);
165
enemy[enemyStatKey] ??= 0;
166
enemy[enemyStatKey] += count;
168
167
}
169
168
}
170
169
break;