diff --git a/src/modules/cars/functions.ts b/src/modules/cars/functions.ts index f76d430..ac815ee 100644 --- a/src/modules/cars/functions.ts +++ b/src/modules/cars/functions.ts @@ -63,7 +63,7 @@ export async function getCar(carId: number) if (car!.ghostLevel > 12) { if(car!.rgWinCount > 1000) - { + { car!.ghostLevel = 11; await prisma.car.update({ @@ -76,7 +76,7 @@ export async function getCar(carId: number) }); } else - { + { car!.ghostLevel = 10; await prisma.car.update({ diff --git a/src/modules/game.ts b/src/modules/game.ts index 811135a..7834a24 100644 --- a/src/modules/game.ts +++ b/src/modules/game.ts @@ -239,7 +239,8 @@ export default class GameModule extends Module { // Check retire crown let getCarCrown = await prisma.carCrownDetect.findFirst({ where:{ - carId: body.carId + carId: body.carId, + playedAt: body.playedAt, } }); diff --git a/src/modules/game/ghost.ts b/src/modules/game/ghost.ts index c2d3887..db5e358 100644 --- a/src/modules/game/ghost.ts +++ b/src/modules/game/ghost.ts @@ -8,7 +8,6 @@ import wmproto from "../../wmmt/wm.proto"; import * as common from "../util/common"; import * as ghost_history from "../ghost/ghost_history"; import * as ghost_stamp from "../ghost/ghost_stamp"; -import * as carFunctions from "../cars/functions"; // Save ghost battle result export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequest, car: any) @@ -306,32 +305,76 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ // Crown holder data available if(carCrowns) { - // Crown Finish Status - await prisma.carCrownDetect.create({ - data:{ + // Look For Existing Car Record Based On Area + let areaRecord = await prisma.carCrownDetect.findFirst({ + where: { carId: body.carId, - status: 'finish', - area: carCrowns.area, - ramp: carCrowns.ramp, - path: carCrowns.path, - playedAt: carCrowns.playedAt, - tunePower: carCrowns.tunePower, - tuneHandling: carCrowns.tuneHandling + area: area } }); - // Update it to the new one - await prisma.carCrown.update({ - where: { - dbId: carCrowns.dbId - }, - data: { - ...dataCrown, - area: area, - ramp: ramp, - path: path - } - }); + // Record exist, update it + if(areaRecord) + { + // Update the record to Crown Finish Status + await prisma.carCrownDetect.update({ + where: { + id: areaRecord.id + }, + data: { + carId: body.carId, + status: 'finish', + area: carCrowns.area, + ramp: carCrowns.ramp, + path: carCrowns.path, + playedAt: carCrowns.playedAt, + tunePower: carCrowns.tunePower, + tuneHandling: carCrowns.tuneHandling + } + }); + + // Update it to the new one + await prisma.carCrown.update({ + where: { + dbId: carCrowns.dbId + }, + data: { + ...dataCrown, + area: area, + ramp: ramp, + path: path + } + }); + } + else + { + // Crown Finish Status + await prisma.carCrownDetect.create({ + data:{ + carId: body.carId, + status: 'finish', + area: carCrowns.area, + ramp: carCrowns.ramp, + path: carCrowns.path, + playedAt: carCrowns.playedAt, + tunePower: carCrowns.tunePower, + tuneHandling: carCrowns.tuneHandling + } + }); + + // Update it to the new one + await prisma.carCrown.update({ + where: { + dbId: carCrowns.dbId + }, + data: { + ...dataCrown, + area: area, + ramp: ramp, + path: path + } + }); + } } // Crown holder data not available or still default crown holder data else @@ -684,7 +727,8 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ await prisma.carCrownDetect.create({ data:{ carId: body.carId, - status: 'retire' + status: 'retire', + playedAt: body.playedAt } }); } diff --git a/src/modules/game/versus.ts b/src/modules/game/versus.ts index 78fbdc2..0c80130 100644 --- a/src/modules/game/versus.ts +++ b/src/modules/game/versus.ts @@ -5,7 +5,6 @@ import { wm } from "../../wmmt/wm.proto"; // Import Util import * as common from "../util/common"; -import * as carFunctions from "../cars/functions"; // Save versus battle result @@ -15,7 +14,7 @@ export async function saveVersusBattleResult(body: wm.protobuf.SaveGameResultReq { // Get the car let cars = body?.car; - + // Get the vs result for the car let vsResult = body?.vsResult;