diff --git a/src/util/common.ts b/src/util/common.ts index db84cde..d8b6c15 100644 --- a/src/util/common.ts +++ b/src/util/common.ts @@ -45,4 +45,8 @@ export function getBigIntFromLong(n: Long) export function sanitizeInput(value: any){ return (value == null || value == undefined) ? undefined : value; +} + +export function sanitizeInputNotZero(value: any){ + return (value !== null && value !== undefined && value !== 0) ? value : undefined; } \ No newline at end of file diff --git a/src/util/games/story.ts b/src/util/games/story.ts index ec2ed05..e3de2e3 100644 --- a/src/util/games/story.ts +++ b/src/util/games/story.ts @@ -23,19 +23,19 @@ export async function saveStoryResult(body: wm.protobuf.SaveGameResultRequest, c { // Story update data let data : any = { - stClearDivCount: common.sanitizeInput(storyResult.stClearDivCount), + stClearDivCount: common.sanitizeInputNotZero(storyResult.stClearDivCount), stPlayCount: common.sanitizeInput(storyResult.stPlayCount), - stClearCount: common.sanitizeInput(storyResult.stClearCount), + stClearCount: common.sanitizeInputNotZero(storyResult.stClearCount), stConsecutiveWins: common.sanitizeInput(storyResult.stConsecutiveWins), tuningPoints: common.sanitizeInput(storyResult.tuningPoint), stCompleted100Episodes: common.sanitizeInput(storyResult.stCompleted_100Episodes), } // If the current consecutive wins is greater than the previous max - if (body.stResult!.stConsecutiveWins! > car!.stConsecutiveWinsMax) + if (storyResult.stConsecutiveWins! > car!.stConsecutiveWinsMax) { // Update the maximum consecutive wins; - data.stConsecutiveWinsMax = body.stResult!.stConsecutiveWins!; + data.stConsecutiveWinsMax = storyResult.stConsecutiveWins; } // If the lose bits are set, and are long data diff --git a/src/util/games/versus.ts b/src/util/games/versus.ts index e02204b..9c08149 100644 --- a/src/util/games/versus.ts +++ b/src/util/games/versus.ts @@ -3,53 +3,39 @@ import { prisma } from "../.."; // Import Proto import { wm } from "../../wmmt/wm.proto"; +// Import Util +import * as common from "../common"; + // Save versus battle result -export async function saveVersusBattleResult(body: wm.protobuf.SaveGameResultRequest) +export async function saveVersusBattleResult(body: wm.protobuf.SaveGameResultRequest, car: any) { if (!(body.retired)) { // Get the vs result for the car let vsResult = body?.vsResult; - // storyResult is set + // vs result is set if (vsResult) { - // Check if vsTripleStarMedals is not 0 - let vsTripleStarMedals = undefined; - if(vsResult.vsTripleStarMedals && vsResult.vsTripleStarMedals !== 0){ - vsTripleStarMedals = vsResult.vsTripleStarMedals!; - } - - // Check if vsDoubleStarMedals is not 0 - let vsDoubleStarMedals = undefined; - if(vsResult.vsDoubleStarMedals && vsResult.vsDoubleStarMedals !== 0){ - vsDoubleStarMedals = vsResult.vsDoubleStarMedals!; - } - - // Check if vsSingleStarMedals is not 0 - let vsSingleStarMedals = undefined; - if(vsResult.vsSingleStarMedals && vsResult.vsSingleStarMedals !== 0){ - vsSingleStarMedals = vsResult.vsSingleStarMedals!; - } - - // Check if vsPlainMedals is not 0 - let vsPlainMedals = undefined; - if(vsResult.vsPlainMedals && vsResult.vsPlainMedals !== 0){ - vsPlainMedals = vsResult.vsPlainMedals!; - } - // vs result update data let data : any = { - vsPlayCount: vsResult.vsPlayCount || undefined, - vsBurstCount: vsResult.vsBurstCount || undefined, - vsStarCount: vsResult.vsStarCount || undefined, - vsCoolOrWild: vsResult.vsCoolOrWild || undefined, - vsSmoothOrRough: vsResult.vsSmoothOrRough || undefined, - vsTripleStarMedals: vsTripleStarMedals || undefined, - vsDoubleStarMedals: vsDoubleStarMedals || undefined, - vsSingleStarMedals: vsSingleStarMedals || undefined, - vsPlainMedals: vsPlainMedals || undefined, + vsPlayCount: common.sanitizeInput(vsResult.vsPlayCount), + vsBurstCount: common.sanitizeInput(vsResult.vsBurstCount), + vsStarCount: common.sanitizeInput(vsResult.vsStarCount), + vsCoolOrWild: common.sanitizeInput(vsResult.vsCoolOrWild), + vsSmoothOrRough: common.sanitizeInput(vsResult.vsSmoothOrRough), + vsTripleStarMedals: common.sanitizeInputNotZero(vsResult.vsTripleStarMedals), + vsDoubleStarMedals: common.sanitizeInputNotZero(vsResult.vsDoubleStarMedals), + vsSingleStarMedals: common.sanitizeInputNotZero(vsResult.vsSingleStarMedals), + vsPlainMedals: common.sanitizeInputNotZero(vsResult.vsPlainMedals), + } + + // If the current versus star count is greater than the maximum + if (data.vsStarCount && (car.vsStarCountMax < data.vsStarCount)) + { + // Update the maximum versus star count + data.vsStarCountMax = data.vsStarCount; } await prisma.car.update({