forked from OpenWF/SpaceNinjaServer
		
	fix(stats): captures not being tracked for a new enemy (#1728)
Reviewed-on: OpenWF/SpaceNinjaServer#1728 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									5eecf11b1a
								
							
						
					
					
						commit
						8afb515231
					
				@ -1,6 +1,5 @@
 | 
				
			|||||||
import { Stats, TStatsDatabaseDocument } from "@/src/models/statsModel";
 | 
					import { Stats, TStatsDatabaseDocument } from "@/src/models/statsModel";
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
    IEnemy,
 | 
					 | 
				
			||||||
    IStatsAdd,
 | 
					    IStatsAdd,
 | 
				
			||||||
    IStatsMax,
 | 
					    IStatsMax,
 | 
				
			||||||
    IStatsSet,
 | 
					    IStatsSet,
 | 
				
			||||||
@ -137,34 +136,34 @@ export const updateStats = async (accountOwnerId: string, payload: IStatsUpdate)
 | 
				
			|||||||
                        case "HEADSHOT":
 | 
					                        case "HEADSHOT":
 | 
				
			||||||
                        case "KILL_ASSIST": {
 | 
					                        case "KILL_ASSIST": {
 | 
				
			||||||
                            playerStats.Enemies ??= [];
 | 
					                            playerStats.Enemies ??= [];
 | 
				
			||||||
                            const enemyStatKey = {
 | 
					                            const enemyStatKey = (
 | 
				
			||||||
                                KILL_ENEMY: "kills",
 | 
					                                {
 | 
				
			||||||
                                EXECUTE_ENEMY: "executions",
 | 
					                                    KILL_ENEMY: "kills",
 | 
				
			||||||
                                HEADSHOT: "headshots",
 | 
					                                    EXECUTE_ENEMY: "executions",
 | 
				
			||||||
                                KILL_ASSIST: "assists"
 | 
					                                    HEADSHOT: "headshots",
 | 
				
			||||||
                            }[category] as "kills" | "executions" | "headshots" | "assists";
 | 
					                                    KILL_ASSIST: "assists"
 | 
				
			||||||
 | 
					                                } as const
 | 
				
			||||||
 | 
					                            )[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;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user