返回提交历史
Modified
src/services/statsService.ts
+25
-8
Modified
src/types/statTypes.ts
+3
-0
XFEstudio/XFESpaceNinjaServer
fix(stats): handle eidolon capture (#1190)
Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1190 Reviewed-by: Sainan <sainan@calamity.inc> Co-authored-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com> Co-committed-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com>
ae9a98ca
代码差异
2 个文件
+28
-8
@@ -104,14 +104,16 @@ export const updateStats = async (playerStats: TStatsDatabaseDocument, payload:
104
104
case "FIRE_WEAPON":
105
105
case "HIT_ENTITY_ITEM":
106
106
case "HEADSHOT_ITEM":
107
case "KILL_ENEMY_ITEM": {
107
case "KILL_ENEMY_ITEM":
108
case "KILL_ASSIST_ITEM": {
108
109
playerStats.Weapons ??= [];
109
110
const statKey = {
110
111
FIRE_WEAPON: "fired",
111
112
HIT_ENTITY_ITEM: "hits",
112
113
HEADSHOT_ITEM: "headshots",
113
KILL_ENEMY_ITEM: "kills"
114
}[category] as "fired" | "hits" | "headshots" | "kills";
114
KILL_ENEMY_ITEM: "kills",
115
KILL_ASSIST_ITEM: "assists"
116
}[category] as "fired" | "hits" | "headshots" | "kills" | "assists";
115
117
116
118
for (const [type, count] of Object.entries(data as IUploadEntry)) {
117
119
const weapon = playerStats.Weapons.find(element => element.type === type);
@@ -129,19 +131,33 @@ export const updateStats = async (playerStats: TStatsDatabaseDocument, payload:
129
131
130
132
case "KILL_ENEMY":
131
133
case "EXECUTE_ENEMY":
132
case "HEADSHOT": {
134
case "HEADSHOT":
135
case "KILL_ASSIST": {
133
136
playerStats.Enemies ??= [];
134
137
const enemyStatKey = {
135
138
KILL_ENEMY: "kills",
136
139
EXECUTE_ENEMY: "executions",
137
HEADSHOT: "headshots"
138
}[category] as "kills" | "executions" | "headshots";
140
HEADSHOT: "headshots",
141
KILL_ASSIST: "assists"
142
}[category] as "kills" | "executions" | "headshots" | "assists";
139
143
140
144
for (const [type, count] of Object.entries(data as IUploadEntry)) {
141
145
const enemy = playerStats.Enemies.find(element => element.type === type);
142
146
if (enemy) {
143
enemy[enemyStatKey] ??= 0;
144
enemy[enemyStatKey] += count;
147
if (category === "KILL_ENEMY") {
148
enemy.kills ??= 0;
149
const captureCount = (actionData["CAPTURE_ENEMY"] as IUploadEntry)?.[type];
150
if (captureCount) {
151
enemy.kills += Math.max(count - captureCount, 0);
152
enemy.captures ??= 0;
153
enemy.captures += captureCount;
154
} else {
155
enemy.kills += count;
156
}
157
} else {
158
enemy[enemyStatKey] ??= 0;
159
enemy[enemyStatKey] += count;
160
}
145
161
} else {
146
162
const newEnemy: IEnemy = { type: type };
147
163
newEnemy[enemyStatKey] = count;
@@ -394,6 +410,7 @@ const ignoredCategories = [
394
410
"PRE_DIE_ITEM",
395
411
"GEAR_USED",
396
412
"DIE_ITEM",
413
"CAPTURE_ENEMY", // handled in KILL_ENEMY
397
414
398
415
// timers action
399
416
"IN_SHIP_TIME",
@@ -44,6 +44,7 @@ export interface IEnemy {
44
44
kills?: number;
45
45
assists?: number;
46
46
deaths?: number;
47
captures?: number;
47
48
}
48
49
49
50
export interface IMission {
@@ -126,6 +127,8 @@ export interface IStatsAdd {
126
127
DIE_ITEM?: IUploadEntry;
127
128
EXECUTE_ENEMY?: IUploadEntry;
128
129
EXECUTE_ENEMY_ITEM?: IUploadEntry;
130
KILL_ASSIST?: IUploadEntry;
131
KILL_ASSIST_ITEM?: IUploadEntry;
129
132
}
130
133
131
134
export interface IUploadEntry {