diff --git a/.gitignore b/.gitignore index 71d3f09..fe49650 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,6 @@ dist/ cert.pfx key.pem config.json -ecosystem.config.js \ No newline at end of file +package-lock.json +ecosystem.config.js +prisma/public.sql \ No newline at end of file diff --git a/prisma/migrations/20220720050238_caritem/migration.sql b/prisma/migrations/20220720050238_caritem/migration.sql new file mode 100644 index 0000000..6a6e517 --- /dev/null +++ b/prisma/migrations/20220720050238_caritem/migration.sql @@ -0,0 +1,9 @@ +-- DropIndex +DROP INDEX "CarItem_carId_key"; + +-- AlterTable +ALTER TABLE "Car" ALTER COLUMN "stLoseBits" SET DEFAULT 0; + +-- AlterTable +ALTER TABLE "CarItem" ADD COLUMN "dbId" SERIAL NOT NULL, +ADD CONSTRAINT "CarItem_pkey" PRIMARY KEY ("dbId"); diff --git a/src/modules/game.ts b/src/modules/game.ts index a378c6e..2a56451 100644 --- a/src/modules/game.ts +++ b/src/modules/game.ts @@ -16,71 +16,88 @@ export default class GameModule extends Module { carId: body.carId } }); + let storyLose: boolean = false; switch (body.gameMode) { case wm.wm.protobuf.GameMode.MODE_STORY: { - let maxConsecutiveWins = car!.stConsecutiveWinsMax; - if (maxConsecutiveWins < body.stResult!.stConsecutiveWins!) { - maxConsecutiveWins = body.stResult!.stConsecutiveWins!; - } - let divcount = body.stResult?.stClearDivCount; - let saveEx: any = {}; - if (divcount !== null && divcount !== undefined && divcount !== 0) { - console.log(body.stResult?.stClearDivCount); - saveEx.stClearDivCount = divcount; - } else { - saveEx.stClearDivCount = car?.stClearDivCount; - } - if (body.stResult?.stClearBits !== null && body.stResult?.stClearBits !== undefined) { - saveEx.stClearBits = body.stResult?.stClearBits; - } else { - saveEx.stClearBits = car?.stClearBits; - } - if (body.stResult?.stPlayCount !== null && body.stResult?.stPlayCount !== undefined) { - saveEx.stPlayCount = body.stResult?.stPlayCount!; - } else { - saveEx.stPlayCount = car?.stPlayCount; - } - if (body.stResult?.stClearCount !== null && body.stResult?.stClearCount !== undefined) { - saveEx.stClearCount = body.stResult?.stClearCount!; - } else { - saveEx.stClearCount = car?.stClearCount; - } - if (body.stResult?.stLoseBits !== null && body.stResult?.stLoseBits !== undefined) { - let actualLoseBits = BigInt(0); - if (body.stResult?.stLoseBits! instanceof Long) { - actualLoseBits = actualLoseBits | BigInt(body.stResult?.stLoseBits.high); - actualLoseBits = actualLoseBits << BigInt(32); - actualLoseBits = actualLoseBits | BigInt(body.stResult?.stLoseBits.low); - saveEx.stLoseBits = actualLoseBits; + if (!(body.retired)) { + let maxConsecutiveWins = car!.stConsecutiveWinsMax; + if (maxConsecutiveWins < body.stResult!.stConsecutiveWins!) { + maxConsecutiveWins = body.stResult!.stConsecutiveWins!; + } + let divcount = body.stResult?.stClearDivCount; + let saveEx: any = {}; + if (body.stResult?.stLoseBits !== null && body.stResult?.stLoseBits !== undefined) { + let actualLoseBits = BigInt(0); + if (body.stResult?.stLoseBits! instanceof Long) { + actualLoseBits = actualLoseBits | BigInt(body.stResult?.stLoseBits.high); + actualLoseBits = actualLoseBits << BigInt(32); + actualLoseBits = actualLoseBits | BigInt(body.stResult?.stLoseBits.low); + saveEx.stLoseBits = Number(actualLoseBits); + if(saveEx.stLoseBits > 0){ + storyLose = true; + } + } + } else { + saveEx.stLoseBits = car?.stLoseBits; + } + if (divcount !== null && divcount !== undefined && divcount !== 0) { + console.log(body.stResult?.stClearDivCount); + saveEx.stClearDivCount = divcount; + } else { + saveEx.stClearDivCount = car?.stClearDivCount; + } + if (body.stResult?.stClearBits !== null && body.stResult?.stClearBits !== undefined && storyLose !== true) { + saveEx.stClearBits = body.stResult?.stClearBits; + } else { + saveEx.stClearBits = car?.stClearBits; + } + if (body.stResult?.stPlayCount !== null && body.stResult?.stPlayCount !== undefined) { + saveEx.stPlayCount = body.stResult?.stPlayCount!; + } else { + saveEx.stPlayCount = car?.stPlayCount; + } + if (body.stResult?.stClearCount !== null && body.stResult?.stClearCount !== undefined && body.stResult?.stClearCount !== 0) { + saveEx.stClearCount = body.stResult?.stClearCount!; + } else { + saveEx.stClearCount = car?.stClearCount; + } + if (body.stResult?.stConsecutiveWins !== null && body.stResult?.stConsecutiveWins !== undefined) { + saveEx.stConsecutiveWins = body.stResult?.stConsecutiveWins!; + } else { + saveEx.stConsecutiveWins = car?.stConsecutiveWins; + } + if (body.stResult?.tuningPoint !== null && body.stResult?.tuningPoint !== undefined) { + saveEx.tuningPoints = body.stResult?.tuningPoint!; + } else { + saveEx.tuningPoints = car?.tuningPoints; + } + if (body.stResult?.stCompleted_100Episodes !== null && body.stResult?.stCompleted_100Episodes !== undefined) { + saveEx.stCompleted100Episodes = body.stResult?.stCompleted_100Episodes!; + } else { + saveEx.stCompleted100Episodes = car?.stCompleted100Episodes; + } + console.log(saveEx); + let c = await prisma.car.update({ + where: { + carId: body.carId + }, + data: saveEx + }); + console.log('-------'); + console.log(c); + + for(let i=0; i