From 28e75762ad83b169663d63305642d74256950a0b Mon Sep 17 00:00:00 2001 From: ghkkk090 <108461408+ghkkk090@users.noreply.github.com> Date: Mon, 15 Aug 2022 15:05:43 +0700 Subject: [PATCH] alpha ocm --- OCM Event Query Example.txt | 16 +- .../20220815062807_car_country/migration.sql | 3 + prisma/schema.prisma | 1 + src/modules/ghost_ocm.ts | 6 +- src/util/games/ghost_ocm.ts | 200 ++++++++++++++---- 5 files changed, 173 insertions(+), 53 deletions(-) create mode 100644 prisma/migrations/20220815062807_car_country/migration.sql diff --git a/OCM Event Query Example.txt b/OCM Event Query Example.txt index 6e8155f..6156fe4 100644 --- a/OCM Event Query Example.txt +++ b/OCM Event Query Example.txt @@ -3,7 +3,7 @@ INSERT INTO "public"."OCMEvent" VALUES (dbId, competitionId, qualifyingPeriodStartAt, qualifyingPeriodCloseAt, competitionStartAt, competitionCloseAt, competitionEndAt, lengthOfPeriod, lengthOfInterval, area, minigamePattern); // Query Example -INSERT INTO "public"."OCMEvent" VALUES (1, 4, 1659286800, 1660064400, 1660150800, 1660928400, 1661792400, 86400, 0, 0, 1); +INSERT INTO "public"."OCMEvent" VALUES (1, 1, 1659312000, 1660420740, 1660420800, 1661446800, 1661792400, 86400, 0, 0, 1); // CompetitionId Reference : BASE_PATH\src\util\games\games_util\ghost_ocm_area.ts @@ -20,7 +20,7 @@ lengthOfInterval = idk what this is (maybe interval for each period) area = course area, not really important tbh.. set to 0 still works fine minigamePattern = idk the correct value - +---PLEASE DON'T CHANGE THE TIMETAMPS AFTER YOU SET YOURS OCM EVENT.. DO IT BEFORE YOU RUN THE QUERY--- ######################## OCMPeriod TABLE ######################## @@ -31,14 +31,14 @@ INSERT INTO "public"."OCMPeriod" VALUES (dbId, competitionDbId, competitionId, p // Description competitionId = OCM Event number (connected to OCMEvent table) -periodId = idk how to explain this... +periodId = idk how to explain this... how many period available for main draw startAt = start timestamp (datetime) of each period closeAt = end timestamp (datetime) of each period -// periodId formula (idk if this is correct) : +// periodId (idk if this is correct) : 1. x = competitionStartAt + lengthOfPeriod -2. if x is still less than competitionCloseAt, periodId = 1 +2. if x is still less than competitionCloseAt, periodId = 1 (startAt = competitionStartAt, closeAt = x) 3. competitionStartAt = x + lengthOfInterval -4. do the count again (no 1) -5. if x is still less than competitionCloseAt, periodId = periodId + 1 (in this case is periodId = 2) -6. do it again until x is more than or same like competitionCloseAt (better make it same like competitionCloseAt) \ No newline at end of file +4. if x is still less than competitionCloseAt, periodId = periodId + 1 (in this case is periodId = 2) +5. do the count again (no 1) +6. do it again until x is more than or same like competitionCloseAt (for last period, better make it same like competitionCloseAt) \ No newline at end of file diff --git a/prisma/migrations/20220815062807_car_country/migration.sql b/prisma/migrations/20220815062807_car_country/migration.sql new file mode 100644 index 0000000..b760b8c --- /dev/null +++ b/prisma/migrations/20220815062807_car_country/migration.sql @@ -0,0 +1,3 @@ +-- AlterTable +ALTER TABLE "Car" ADD COLUMN "country" TEXT NOT NULL DEFAULT 'JPN', +ALTER COLUMN "stLoseBits" SET DEFAULT 0; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index afd6c20..6fcdd7f 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -61,6 +61,7 @@ model Car { name String manufacturer Int regionId Int @default(0) + country String @default("JPN") model Int visualModel Int customColor Int @default(0) diff --git a/src/modules/ghost_ocm.ts b/src/modules/ghost_ocm.ts index fca0b12..7e3bd92 100644 --- a/src/modules/ghost_ocm.ts +++ b/src/modules/ghost_ocm.ts @@ -473,7 +473,7 @@ export default class GhostModule extends Module { // Generate default S660 car data cars = wm.wm.protobuf.Car.create({ - carId: 999999999, + carId: 999999999, // Don't change this name: 'S660', regionId: 18, // IDN (福井) manufacturer: 12, // HONDA @@ -497,12 +497,12 @@ export default class GhostModule extends Module { rivalMarker: 32, aura: 551, windowSticker: true, - windowStickerString: 'BAYSHORE', // GGWP + windowStickerString: 'BAYSHORE', windowStickerFont: 0, title: 'You don\'t have S660? LMAO', level: 65, // SSSSS lastPlayedAt: checkGhostTrail!.playedAt, - + country: 'GLB' }); // Set Ghost stuff Value diff --git a/src/util/games/ghost_ocm.ts b/src/util/games/ghost_ocm.ts index 60ebb70..7208ed8 100644 --- a/src/util/games/ghost_ocm.ts +++ b/src/util/games/ghost_ocm.ts @@ -15,7 +15,7 @@ export async function ocmTallying(body: wm.protobuf.LoadGhostCompetitionInfoRequ if(periodId === 0) { - console.log('Tallying'); + console.log('Tallying data from Qualifying'); // Get user that playing OCM qualifying day let gbRecordTally = await prisma.oCMGhostBattleRecord.findMany({ @@ -39,7 +39,7 @@ export async function ocmTallying(body: wm.protobuf.LoadGhostCompetitionInfoRequ // Get the Top 1 Advantage if(top1advantage === null) { - top1advantage = gbRecordTally[i].result + top1advantage = gbRecordTally[i].result; let getTrail = await prisma.oCMGhostTrail.findFirst({ where:{ @@ -106,6 +106,8 @@ export async function ocmTallying(body: wm.protobuf.LoadGhostCompetitionInfoRequ }); if(i === 0){ + console.log('Making OCM Top 1 Ghost Data'); + // Create Top 1 ghost data await prisma.oCMTop1Ghost.create({ data: data @@ -116,10 +118,11 @@ export async function ocmTallying(body: wm.protobuf.LoadGhostCompetitionInfoRequ } else { + console.log('Tallying data from previous Period'); + // Get user that playing OCM qualifying day - let gbRecordTally = await prisma.oCMGhostBattleRecord.findMany({ + let OCMTally = await prisma.oCMTally.findMany({ where:{ - ocmMainDraw: true, competitionId: body.competitionId, periodId: periodId }, @@ -129,42 +132,98 @@ export async function ocmTallying(body: wm.protobuf.LoadGhostCompetitionInfoRequ }); // gbRecordTally is set - if(gbRecordTally) + if(OCMTally) { - let top1advantage = 0; - for(let i=0; i 0) { - gbRecordTally[i].result = top1advantage + Math.abs(gbRecordTally[i].result); - } + if(OCMTally[i].result <= 0) + { + currentResult = top1advantage + Math.abs(OCMTally[i].result); - // Get current Result after calculated - let currentResult = top1advantage - gbRecordTally[i].result + currentResult = -Math.abs(currentResult); + } + else + { + currentResult = OCMTally[i].result - top1advantage; + } + } + else + { + currentResult = top1advantage + Math.abs(OCMTally[i].result); + + currentResult = -Math.abs(currentResult); + } // Moving data to OCM Tally let data : any = { - carId: gbRecordTally[i].carId, + carId: OCMTally[i].carId, result: currentResult, - tunePower: gbRecordTally[i].tunePower, - tuneHandling: gbRecordTally[i].tuneHandling, + tunePower: OCMTally[i].tunePower, + tuneHandling: OCMTally[i].tuneHandling, competitionId: body.competitionId, - periodId: periodId + periodId: periodId + 1 } - // Create the data - await prisma.oCMTally.create({ - data: data + let checkOCMTally = await prisma.oCMTally.findFirst({ + where: { + carId: OCMTally[i].carId, + competitionId: body.competitionId, + } }); + if(checkOCMTally) + { + // Update the tally data + await prisma.oCMTally.update({ + where:{ + dbId: checkOCMTally?.dbId + }, + data: data + }); + } + + if(i === 0){ + console.log('Making OCM Top 1 Ghost Data'); + // Create Top 1 ghost data await prisma.oCMTop1Ghost.create({ data: data @@ -177,10 +236,11 @@ export async function ocmTallying(body: wm.protobuf.LoadGhostCompetitionInfoRequ // OCM is ended else { + console.log('Tallying data for end of OCM'); + // Get user that playing OCM qualifying day - let gbRecordTally = await prisma.oCMGhostBattleRecord.findMany({ + let OCMTally = await prisma.oCMTally.findMany({ where:{ - ocmMainDraw: true, competitionId: body.competitionId, periodId: periodId }, @@ -190,42 +250,98 @@ export async function ocmTallying(body: wm.protobuf.LoadGhostCompetitionInfoRequ }); // gbRecordTally is set - if(gbRecordTally) + if(OCMTally) { - let top1advantage = 0; - for(let i=0; i 0) { - gbRecordTally[i].result = top1advantage + Math.abs(gbRecordTally[i].result); - } + if(OCMTally[i].result <= 0) + { + currentResult = top1advantage + Math.abs(OCMTally[i].result); - // Get current Result after calculated - let currentResult = top1advantage - gbRecordTally[i].result + currentResult = -Math.abs(currentResult); + } + else + { + currentResult = OCMTally[i].result - top1advantage; + } + } + else + { + currentResult = top1advantage + Math.abs(OCMTally[i].result); + + currentResult = -Math.abs(currentResult); + } // Moving data to OCM Tally let data : any = { - carId: gbRecordTally[i].carId, + carId: OCMTally[i].carId, result: currentResult, - tunePower: gbRecordTally[i].tunePower, - tuneHandling: gbRecordTally[i].tuneHandling, + tunePower: OCMTally[i].tunePower, + tuneHandling: OCMTally[i].tuneHandling, competitionId: body.competitionId, - periodId: periodId + periodId: periodId + 1 } - // Create the data - await prisma.oCMTally.create({ - data: data + let checkOCMTally = await prisma.oCMTally.findFirst({ + where: { + carId: OCMTally[i].carId, + competitionId: body.competitionId, + } }); + if(checkOCMTally) + { + // Update the tally data + await prisma.oCMTally.update({ + where:{ + dbId: checkOCMTally?.dbId + }, + data: data + }); + } + + if(i === 0){ + console.log('Making OCM Top 1 Ghost Data'); + // Create Top 1 ghost data await prisma.oCMTop1Ghost.create({ data: data