From 488f530df192d7f34ff938eb1cd1921293f35858 Mon Sep 17 00:00:00 2001 From: ghkkk090 <108461408+ghkkk090@users.noreply.github.com> Date: Thu, 4 Aug 2022 19:14:26 +0700 Subject: [PATCH] ghost battle history --- .../migration.sql | 30 +++ prisma/schema.prisma | 24 +++ src/modules/game.ts | 187 +++++++++++++++++- src/modules/startup.ts | 3 +- 4 files changed, 240 insertions(+), 4 deletions(-) create mode 100644 prisma/migrations/20220804052450_ghost_battle_record/migration.sql diff --git a/prisma/migrations/20220804052450_ghost_battle_record/migration.sql b/prisma/migrations/20220804052450_ghost_battle_record/migration.sql new file mode 100644 index 0000000..d22d79d --- /dev/null +++ b/prisma/migrations/20220804052450_ghost_battle_record/migration.sql @@ -0,0 +1,30 @@ +-- AlterTable +ALTER TABLE "Car" ALTER COLUMN "stLoseBits" SET DEFAULT 0; + +-- CreateTable +CREATE TABLE "GhostBattleRecord" ( + "dbId" SERIAL NOT NULL, + "carId" INTEGER NOT NULL, + "tunePower" INTEGER NOT NULL DEFAULT 0, + "tuneHandling" INTEGER NOT NULL DEFAULT 0, + "opponent1CarId" INTEGER NOT NULL, + "opponent1Result" INTEGER NOT NULL, + "opponent1TunePower" INTEGER NOT NULL, + "opponent1TuneHandling" INTEGER NOT NULL, + "opponent2CarId" INTEGER, + "opponent2Result" INTEGER, + "opponent2TunePower" INTEGER, + "opponent2TuneHandling" INTEGER, + "opponent3CarId" INTEGER, + "opponent3Result" INTEGER, + "opponent3TunePower" INTEGER, + "opponent3TuneHandling" INTEGER, + "area" INTEGER NOT NULL DEFAULT 0, + "playedAt" INTEGER NOT NULL DEFAULT 0, + "playedShopName" TEXT NOT NULL DEFAULT 'Bayshore', + + CONSTRAINT "GhostBattleRecord_pkey" PRIMARY KEY ("dbId") +); + +-- AddForeignKey +ALTER TABLE "GhostBattleRecord" ADD CONSTRAINT "GhostBattleRecord_carId_fkey" FOREIGN KEY ("carId") REFERENCES "Car"("carId") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 81bcbd8..0dca4a4 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -132,6 +132,7 @@ model Car { TimeAttackRecord TimeAttackRecord[] CarCrown CarCrown[] GhostTrail GhostTrail[] + GhostBattleRecord GhostBattleRecord[] } model CarGTWing { @@ -236,3 +237,26 @@ model GhostTrail { tuneHandling Int @default(0) crownBattle Boolean @default(false) } + +model GhostBattleRecord { + dbId Int @id @default(autoincrement()) + car Car @relation(fields: [carId], references: [carId]) + carId Int + tunePower Int @default(0) + tuneHandling Int @default(0) + opponent1CarId Int + opponent1Result Int + opponent1TunePower Int + opponent1TuneHandling Int + opponent2CarId Int? + opponent2Result Int? + opponent2TunePower Int? + opponent2TuneHandling Int? + opponent3CarId Int? + opponent3Result Int? + opponent3TunePower Int? + opponent3TuneHandling Int? + area Int @default(0) + playedAt Int @default(0) + playedShopName String @default("Bayshore") +} diff --git a/src/modules/game.ts b/src/modules/game.ts index 7f8e5ae..5ac9c82 100644 --- a/src/modules/game.ts +++ b/src/modules/game.ts @@ -399,6 +399,92 @@ export default class GameModule extends Module { } } } + + let saveExGhostHistory: any = {}; + if (body.car?.carId !== null && body.car?.carId !== undefined) { + saveExGhostHistory.carId = body.car?.carId!; + } + if (body.car?.tunePower !== null && body.car?.tunePower !== undefined) { + saveExGhostHistory.tunePower = body.car?.tunePower!; + } + if (body.car?.tuneHandling !== null && body.car?.tuneHandling !== undefined) { + saveExGhostHistory.tuneHandling = body.car?.tuneHandling!; + } + for(let i=0; i= 0 && body.rgResult?.path <= 9){ // GID_PATH_C1 + saveExGhostHistory.area = Number(0); + } + else if(body.rgResult?.path >= 10 && body.rgResult?.path <= 15){ // GID_PATH_N9 + saveExGhostHistory.area = Number(1); + } + else if(body.rgResult?.path >= 16 && body.rgResult?.path <= 17){ // GID_PATH_WTEAST + saveExGhostHistory.area = Number(2); + } + else if(body.rgResult?.path >= 18 && body.rgResult?.path <= 19){ // GID_PATH_WT_UP_DOWN + saveExGhostHistory.area = Number(3); + } + else if(body.rgResult?.path >= 20 && body.rgResult?.path <= 26){ // GID_PATH_WG + saveExGhostHistory.area = Number(4); + } + else if(body.rgResult?.path >= 27 && body.rgResult?.path <= 33){ // GID_PATH_KG + saveExGhostHistory.area = Number(5); + } + else if(body.rgResult?.path >= 34 && body.rgResult?.path <= 37){ // GID_PATH_YS + saveExGhostHistory.area = Number(6); + } + else if(body.rgResult?.path >= 38 && body.rgResult?.path <= 48){ // GID_PATH_KG_SHINYAMASHITA_MINATOMIRAI + saveExGhostHistory.area = Number(7); + } + else if(body.rgResult?.path === 49){ // GID_PATH_NGR + saveExGhostHistory.area = Number(8); + } + else if(body.rgResult?.path >= 50 && body.rgResult?.path <= 53){ // GID_PATH_OS + saveExGhostHistory.area = Number(9); + } + else if(body.rgResult?.path >= 54 && body.rgResult?.path <= 55){ // GID_PATH_KB + saveExGhostHistory.area = Number(10); + } + else if(body.rgResult?.path >= 58 && body.rgResult?.path <= 61){ // GID_PATH_FK + saveExGhostHistory.area = Number(11); + } + else if(body.rgResult?.path >= 62 && body.rgResult?.path <= 63){ // GID_PATH_HK + saveExGhostHistory.area = Number(12); + } + else if(body.rgResult?.path >= 64 && body.rgResult?.path <= 65){ // GID_PATH_TP + saveExGhostHistory.area = Number(13); + } + else if(body.rgResult?.path >= 56 && body.rgResult?.path <= 57){ // GID_PATH_HS + saveExGhostHistory.area = Number(18); + } + } + saveExGhostHistory.playedShopName = 'Bayshore'; + + await prisma.ghostBattleRecord.create({ + data: saveExGhostHistory + }); } break; } @@ -2323,12 +2409,109 @@ export default class GameModule extends Module { })); } + let ghostHistoryData = await prisma.ghostBattleRecord.findMany({ + where: { + carId: body.carId + }, + orderBy: { + playedAt: 'asc' + }, + take: 3 + }); + + let list_ghostHistoryData: wm.wm.protobuf.LoadGameHistoryResponse.GhostBattleRecord[] = []; + for(let i=0; i