diff --git a/prisma/migrations/20220729074502_car_crown/migration.sql b/prisma/migrations/20220729074502_car_crown/migration.sql new file mode 100644 index 0000000..36bc7d1 --- /dev/null +++ b/prisma/migrations/20220729074502_car_crown/migration.sql @@ -0,0 +1,17 @@ +-- AlterTable +ALTER TABLE "Car" ALTER COLUMN "stLoseBits" SET DEFAULT 0; + +-- CreateTable +CREATE TABLE "CarCrown" ( + "dbId" SERIAL NOT NULL, + "carId" INTEGER NOT NULL, + "area" INTEGER NOT NULL, + "ramp" INTEGER NOT NULL, + "path" INTEGER NOT NULL, + "trail" BIGINT NOT NULL DEFAULT 0, + + CONSTRAINT "CarCrown_pkey" PRIMARY KEY ("dbId") +); + +-- AddForeignKey +ALTER TABLE "CarCrown" ADD CONSTRAINT "CarCrown_carId_fkey" FOREIGN KEY ("carId") REFERENCES "Car"("carId") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/migrations/20220729075651_car_crown_unique/migration.sql b/prisma/migrations/20220729075651_car_crown_unique/migration.sql new file mode 100644 index 0000000..38d3e47 --- /dev/null +++ b/prisma/migrations/20220729075651_car_crown_unique/migration.sql @@ -0,0 +1,14 @@ +/* + Warnings: + + - A unique constraint covering the columns `[area]` on the table `CarCrown` will be added. If there are existing duplicate values, this will fail. + +*/ +-- AlterTable +ALTER TABLE "Car" ALTER COLUMN "stLoseBits" SET DEFAULT 0; + +-- AlterTable +ALTER TABLE "CarCrown" ALTER COLUMN "trail" SET DEFAULT 0; + +-- CreateIndex +CREATE UNIQUE INDEX "CarCrown_area_key" ON "CarCrown"("area"); diff --git a/prisma/migrations/20220729075837_car_crown_playedat/migration.sql b/prisma/migrations/20220729075837_car_crown_playedat/migration.sql new file mode 100644 index 0000000..176d1fa --- /dev/null +++ b/prisma/migrations/20220729075837_car_crown_playedat/migration.sql @@ -0,0 +1,6 @@ +-- AlterTable +ALTER TABLE "Car" ALTER COLUMN "stLoseBits" SET DEFAULT 0; + +-- AlterTable +ALTER TABLE "CarCrown" ADD COLUMN "playedAt" INTEGER NOT NULL DEFAULT 0, +ALTER COLUMN "trail" SET DEFAULT 0; diff --git a/prisma/migrations/20220729080554_car_crown_tune/migration.sql b/prisma/migrations/20220729080554_car_crown_tune/migration.sql new file mode 100644 index 0000000..88456ad --- /dev/null +++ b/prisma/migrations/20220729080554_car_crown_tune/migration.sql @@ -0,0 +1,14 @@ +/* + Warnings: + + - Added the required column `tuneHandling` to the `CarCrown` table without a default value. This is not possible if the table is not empty. + - Added the required column `tunePower` to the `CarCrown` table without a default value. This is not possible if the table is not empty. + +*/ +-- AlterTable +ALTER TABLE "Car" ALTER COLUMN "stLoseBits" SET DEFAULT 0; + +-- AlterTable +ALTER TABLE "CarCrown" ADD COLUMN "tuneHandling" INTEGER NOT NULL, +ADD COLUMN "tunePower" INTEGER NOT NULL, +ALTER COLUMN "trail" SET DEFAULT 0; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index b0851e3..e7cdc0c 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -130,18 +130,19 @@ model Car { carStateDbId Int @unique state CarState @relation(fields: [carStateDbId], references: [dbId]) TimeAttackRecord TimeAttackRecord[] + CarCrown CarCrown[] } model CarGTWing { dbId Int @id @default(autoincrement()) car Car? - pillar Int @default(0) - pillarMaterial Int @default(0) - mainWing Int @default(0) - mainWingColor Int @default(0) - wingTip Int @default(0) - material Int @default(0) + pillar Int @default(0) + pillarMaterial Int @default(0) + mainWing Int @default(0) + mainWingColor Int @default(0) + wingTip Int @default(0) + material Int @default(0) } model CarItem { @@ -199,3 +200,16 @@ model TimeAttackRecord { tunePower Int @default(0) // Car Power tuneHandling Int @default(0) // Car Handling } + +model CarCrown { + dbId Int @id @default(autoincrement()) + car Car @relation(fields: [carId], references: [carId]) + carId Int + area Int @unique + ramp Int + path Int + trail BigInt @default(0) + playedAt Int @default(0) + tunePower Int + tuneHandling Int +} diff --git a/src/modules/game.ts b/src/modules/game.ts index c83f713..0a62009 100644 --- a/src/modules/game.ts +++ b/src/modules/game.ts @@ -10,6 +10,7 @@ import { userInfo } from "os"; import { config } from "dotenv"; import * as scratch from "../util/scratch"; import { envelopeItemTypeToDataCategory } from "@sentry/utils"; +import path from "path"; export default class GameModule extends Module { register(app: Application): void { @@ -21,7 +22,6 @@ export default class GameModule extends Module { carId: body.carId } }); - console.log(body); let storyLose: boolean = false; switch (body.gameMode) { case wm.wm.protobuf.GameMode.MODE_STORY: @@ -297,6 +297,102 @@ export default class GameModule extends Module { }, data: saveEx }); + + if (body.rgResult?.acquireCrown !== false || body.rgResult?.acquireCrown !== null && body.rgResult?.acquireCrown !== undefined) { + let saveExCrown: any = {}; + saveExCrown.carId = body.carId; + if(body.rgResult?.path !== null && body.rgResult?.path !== undefined){ + if(body.rgResult?.path >= 0 && body.rgResult?.path <= 9){ // GID_PATH_C1 + saveExCrown.area = Number(0); + saveExCrown.ramp = Number(Math.floor(Math.random() * 4)); + } + else if(body.rgResult?.path >= 10 && body.rgResult?.path <= 15){ // GID_PATH_N9 + saveExCrown.area = Number(1); + saveExCrown.ramp = Number(Math.floor(Math.random() * 2) + 4); + } + else if(body.rgResult?.path >= 16 && body.rgResult?.path <= 17){ // GID_PATH_WTEAST + saveExCrown.area = Number(2); + saveExCrown.ramp = Number(Math.floor(Math.random() * 2) + 6); + } + else if(body.rgResult?.path >= 18 && body.rgResult?.path <= 19){ // GID_PATH_WT_UP_DOWN + saveExCrown.area = Number(3); + saveExCrown.ramp = Number(Math.floor(Math.random() * 2) + 8); + } + else if(body.rgResult?.path >= 20 && body.rgResult?.path <= 26){ // GID_PATH_WG + saveExCrown.area = Number(4); + saveExCrown.ramp = Number(Math.floor(Math.random() * 4) + 10); + } + else if(body.rgResult?.path >= 27 && body.rgResult?.path <= 33){ // GID_PATH_KG + saveExCrown.area = Number(5); + saveExCrown.ramp = Number(Math.floor(Math.random() * 4) + 14); + } + else if(body.rgResult?.path >= 34 && body.rgResult?.path <= 37){ // GID_PATH_YS + saveExCrown.area = Number(6); + saveExCrown.ramp = Number(Math.floor(Math.random() * 3) + 18); + } + else if(body.rgResult?.path >= 38 && body.rgResult?.path <= 48){ // GID_PATH_KG_SHINYAMASHITA_MINATOMIRAI + saveExCrown.area = Number(7); + saveExCrown.ramp = Number(Math.floor(Math.random() * 4) + 21); + } + else if(body.rgResult?.path === 49){ // GID_PATH_NGR + saveExCrown.area = Number(8); + saveExCrown.ramp = Number(25); + } + else if(body.rgResult?.path >= 50 && body.rgResult?.path <= 53){ // GID_PATH_OS + saveExCrown.area = Number(9); + saveExCrown.ramp = Number(26); + } + else if(body.rgResult?.path >= 54 && body.rgResult?.path <= 55){ // GID_PATH_KB + saveExCrown.area = Number(10); + saveExCrown.ramp = Number(Math.floor(Math.random() * 2) + 27); + } + else if(body.rgResult?.path >= 58 && body.rgResult?.path <= 61){ // GID_PATH_FK + saveExCrown.area = Number(11); + saveExCrown.ramp = Number(Math.floor(Math.random() * 4) + 29); + } + else if(body.rgResult?.path >= 62 && body.rgResult?.path <= 63){ // GID_PATH_HK + saveExCrown.area = Number(12); + saveExCrown.ramp = Number(Math.floor(Math.random() * 2) + 33); + } + else if(body.rgResult?.path >= 64 && body.rgResult?.path <= 65){ // GID_PATH_TP + saveExCrown.area = Number(13); + saveExCrown.ramp = Number(Math.floor(Math.random() * 2) + 35); + } + else if(body.rgResult?.path >= 56 && body.rgResult?.path <= 57){ // GID_PATH_KB + saveExCrown.area = Number(18); + saveExCrown.ramp = Number(Math.floor(Math.random() * 2) + 27); + } + + saveExCrown.path = body.rgResult?.path!; + } + if(body?.playedAt !== null || body?.playedAt !== undefined){ + saveExCrown.playedAt = body?.playedAt!; + } + saveExCrown.trail = Number(1); //wtf is this lmao + saveExCrown.tunePower = body.car!.tunePower!; + saveExCrown.tuneHandling = body.car!.tuneHandling!; + + let carCrowns = await prisma.carCrown.count({ + where: { + carId: body.carId, + area: saveExCrown.area + } + }); + if(carCrowns !== 0){ + let areaVal = Number(saveExCrown.area); + await prisma.carCrown.update({ + where: { + area: areaVal + }, + data: saveExCrown + }); + } + else{ + await prisma.carCrown.create({ + data: saveExCrown + }); + } + } } break; } @@ -431,94 +527,94 @@ export default class GameModule extends Module { // Every n*100 play give reward let giveMeterReward = Config.getConfig().gameOptions.giveMeterReward; if(giveMeterReward === 1 && body.playCount % 100 === 0){ - let carItemCount = await prisma.carItem.findMany({ + let carItemCount = await prisma.carItem.count({ where: { carId: body.carId, category: 15, itemId: { - lte: 28, + lte: 34, gte: 1, }, + NOT: { + itemId: { in: [2, 3, 5, 6, 29, 30, 31, 32, 33 ,34] }, + }, }, + /*where: { + itemId: { notIn: [2, 3, 5, 6, 29, 30, 31, 32, 33 ,34] }, + },*/ }) - let sqlVal = 0; - for(let i=0; i