diff --git a/prisma/migrations/20220805024317_car_path_and_tuning/migration.sql b/prisma/migrations/20220805024317_car_path_and_tuning/migration.sql new file mode 100644 index 0000000..003d3ef --- /dev/null +++ b/prisma/migrations/20220805024317_car_path_and_tuning/migration.sql @@ -0,0 +1,18 @@ +-- AlterTable +ALTER TABLE "Car" ALTER COLUMN "stLoseBits" SET DEFAULT 0; + +-- CreateTable +CREATE TABLE "CarPathandTuning" ( + "dbId" SERIAL NOT NULL, + "carId" INTEGER NOT NULL, + "area" INTEGER NOT NULL DEFAULT 0, + "ramp" INTEGER NOT NULL DEFAULT 0, + "path" INTEGER NOT NULL DEFAULT 0, + "tunePower" INTEGER NOT NULL DEFAULT 17, + "tuneHandling" INTEGER NOT NULL DEFAULT 17, + + CONSTRAINT "CarPathandTuning_pkey" PRIMARY KEY ("dbId") +); + +-- AddForeignKey +ALTER TABLE "CarPathandTuning" ADD CONSTRAINT "CarPathandTuning_carId_fkey" FOREIGN KEY ("carId") REFERENCES "Car"("carId") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/migrations/20220805033246_car_path_and_tuning_2/migration.sql b/prisma/migrations/20220805033246_car_path_and_tuning_2/migration.sql new file mode 100644 index 0000000..4d2f2a3 --- /dev/null +++ b/prisma/migrations/20220805033246_car_path_and_tuning_2/migration.sql @@ -0,0 +1,5 @@ +-- AlterTable +ALTER TABLE "Car" ALTER COLUMN "stLoseBits" SET DEFAULT 0; + +-- AlterTable +ALTER TABLE "CarPathandTuning" ADD COLUMN "lastPlayedAt" INTEGER NOT NULL DEFAULT 0; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 0dca4a4..8930875 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -133,6 +133,7 @@ model Car { CarCrown CarCrown[] GhostTrail GhostTrail[] GhostBattleRecord GhostBattleRecord[] + CarPathandTuning CarPathandTuning[] } model CarGTWing { @@ -260,3 +261,15 @@ model GhostBattleRecord { playedAt Int @default(0) playedShopName String @default("Bayshore") } + +model CarPathandTuning { + dbId Int @id @default(autoincrement()) + car Car @relation(fields: [carId], references: [carId]) + carId Int + area Int @default(0) + ramp Int @default(0) + path Int @default(0) + tunePower Int @default(17) + tuneHandling Int @default(17) + lastPlayedAt Int @default(0) +} diff --git a/src/modules/game.ts b/src/modules/game.ts index 5ac9c82..aed5575 100644 --- a/src/modules/game.ts +++ b/src/modules/game.ts @@ -3,7 +3,7 @@ import { Module } from "../module"; import * as wm from "../wmmt/wm.proto"; import * as wmsrv from "../wmmt/service.proto"; import { prisma } from ".."; -import { Car, User } from "@prisma/client"; +import { Car, CarPathandTuning, User } from "@prisma/client"; import { Config } from "../config"; import Long from "long"; import { userInfo } from "os"; @@ -891,11 +891,41 @@ export default class GameModule extends Module { } }); } - await prisma.ghostTrail.create({ data: saveEx }); + + let cPaT_count = await prisma.carPathandTuning.findFirst({ + where:{ + carId: saveEx.carId, + area: saveEx.area, + }, + orderBy: { + lastPlayedAt: 'desc' + } + }); + + if(cPaT_count){ + let cPaTdbId = cPaT_count.dbId; + await prisma.ghostTrail.delete({ + where: { + dbId: cPaTdbId + } + }); + } + await prisma.carPathandTuning.create({ + data: { + carId: saveEx.carId, + area: saveEx.area, + ramp: saveEx.ramp, + path: saveEx.path, + tunePower: saveEx.tunePower, + tuneHandling: saveEx.tuneHandling, + lastPlayedAt: saveEx.playedAt + } + }); + if(crownBattles === true){ await prisma.carCrown.update({ where: { @@ -2436,6 +2466,8 @@ export default class GameModule extends Module { if(!(ghostOpponentCar)){ ghostOpponentCar = await prisma.car.findFirst({}); ghostOpponentCar!.name = 'GUEST'; + ghostOpponentCar!.manufacturer = 5; + ghostOpponentCar!.model = 27; ghostOpponentCar!.visualModel = 29; } ghostOpponentCar!.regionId = 1; @@ -2460,6 +2492,8 @@ export default class GameModule extends Module { if(!(ghostOpponentCar2)){ ghostOpponentCar2 = await prisma.car.findFirst({}); ghostOpponentCar2!.name = 'GUEST'; + ghostOpponentCar2!.manufacturer = 5; + ghostOpponentCar2!.model = 27; ghostOpponentCar2!.visualModel = 29; } ghostOpponentCar2!.regionId = 1; @@ -2481,6 +2515,8 @@ export default class GameModule extends Module { if(!(ghostOpponentCar3)){ ghostOpponentCar3 = await prisma.car.findFirst({}); ghostOpponentCar3!.name = 'GUEST'; + ghostOpponentCar3!.manufacturer = 5; + ghostOpponentCar3!.model = 27; ghostOpponentCar3!.visualModel = 29; } ghostOpponentCar3!.regionId = 1; @@ -2493,7 +2529,6 @@ export default class GameModule extends Module { result: ghostHistoryData![i].opponent3Result! })); } - list_ghostHistoryData.push(wm.wm.protobuf.LoadGameHistoryResponse.GhostBattleRecord.create({ carSetting: carSetings, @@ -2526,7 +2561,6 @@ export default class GameModule extends Module { }) app.post('/method/update_user_session', (req, res) => { - // Get the request body // let body = wm.wm.protobuf.UpdateUserSessionRequest.decode(req.body); let msg = { @@ -2995,9 +3029,52 @@ export default class GameModule extends Module { app.post('/method/load_paths_and_tunings', async (req, res) => { let body = wm.wm.protobuf.LoadPathsAndTuningsRequest.decode(req.body); - console.log(body); + let carTbyP: wm.wm.protobuf.LoadPathsAndTuningsResponse.CarTuningsByPath[] = []; + for(let j=0; j<14; j++){ + let carTuning: wm.wm.protobuf.CarTuning[] = []; + let pathAndTuning: CarPathandTuning | null; + let carTbyP_ramp = Math.floor(Math.random() * 10); + let carTbyP_path = Math.floor(Math.random() * 10); + for(let i=0; i