From 3e4efb603f996888d894b23777f140e51622b973 Mon Sep 17 00:00:00 2001 From: anthonyng43 Date: Tue, 30 Dec 2025 23:41:33 +0800 Subject: [PATCH 1/4] force detection fix --- src/modules/game.ts | 17 ++++++++++++++--- src/modules/game/ghost.ts | 20 ++++++++++++-------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/modules/game.ts b/src/modules/game.ts index 1893d65..2c4a8e6 100644 --- a/src/modules/game.ts +++ b/src/modules/game.ts @@ -267,13 +267,15 @@ export default class GameModule { // Perform the save screenshot request for the car await gameFunction.saveScreenshot(body); - if (body.imageType == 7) + if (body.imageType == 1) { + if (body.ghostMetadata!.opponents!.length > 1) return // skip check if is opponent is more than 1 // Check obtained crown let getCarCrown = await prisma.carCrownDetect.findFirst({ where:{ carId: body.carId, - playedAt: body.playedAt + area: body.ghostMetadata?.area, + opponentCarId: body.ghostMetadata?.opponents![0].carId } }); @@ -283,7 +285,7 @@ export default class GameModule { { let timestamp = body.playedAt - body.timestamp; - if(timestamp <= 30) + if(timestamp <= 60) { console.log('Crown Force Finish Detected'); @@ -359,6 +361,15 @@ export default class GameModule { } }); } + else + { + // Delete after legit check + await prisma.carCrownDetect.delete({ + where: { + id: getCarCrown.id + } + }); + } } } } diff --git a/src/modules/game/ghost.ts b/src/modules/game/ghost.ts index 161ee97..a2bcd4b 100644 --- a/src/modules/game/ghost.ts +++ b/src/modules/game/ghost.ts @@ -323,10 +323,12 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ data: { carId: body.carId, status: 'finish', - area: area, - ramp: ramp, - path: path, - ...dataCrown + area: carCrowns.area, + ramp: carCrowns.ramp, + path: carCrowns.path, + playedAt: carCrowns.playedAt, + tunePower: carCrowns.tunePower, + tuneHandling: carCrowns.tuneHandling } }); @@ -350,10 +352,12 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ data: { carId: body.carId, status: 'finish', - area: area, - ramp: ramp, - path: path, - ...dataCrown + area: carCrowns.area, + ramp: carCrowns.ramp, + path: carCrowns.path, + playedAt: carCrowns.playedAt, + tunePower: carCrowns.tunePower, + tuneHandling: carCrowns.tuneHandling } }); From d1015daa92b0fc58ec273ddb13448b0c25542f05 Mon Sep 17 00:00:00 2001 From: anthonyng43 Date: Thu, 15 Jan 2026 23:42:45 +0800 Subject: [PATCH 2/4] ocm hof, secret cars, notice for config --- config.example.json | 3 ++- src/modules/cars/functions.ts | 5 +---- src/modules/game/functions.ts | 10 +++++----- src/modules/game/ghost.ts | 4 ++-- src/modules/game/story.ts | 2 +- src/modules/game/time_attack.ts | 2 +- src/modules/game/versus.ts | 2 +- src/modules/ghost.ts | 25 ++++++++---------------- src/modules/ghost/functions.ts | 2 +- src/modules/ghost_ocm.ts | 33 ++++++++++++++++---------------- src/modules/startup/functions.ts | 6 ++++-- src/modules/terminal.ts | 8 ++++---- src/modules/users.ts | 2 +- 13 files changed, 48 insertions(+), 56 deletions(-) diff --git a/config.example.json b/config.example.json index 8f8ac9a..e183016 100644 --- a/config.example.json +++ b/config.example.json @@ -16,5 +16,6 @@ "revisionCheck": 1, "enableScreenshot": 0, "ghostTrailAutodeleteDays": 0 - } + }, + "notices": [] } \ No newline at end of file diff --git a/src/modules/cars/functions.ts b/src/modules/cars/functions.ts index ae0bc0f..45ee180 100644 --- a/src/modules/cars/functions.ts +++ b/src/modules/cars/functions.ts @@ -721,10 +721,7 @@ export async function checkCreatedCar(body: wm.protobuf.CreateCarRequest, car: a 126, // DIABLO 130, // JW5 131, // AP2 - 133, // PS13 - 137, // NDERC - 138, // UF31 - 139, // GS130 + 133 // PS13 ]; let carVisualModelWithoutItem = [ diff --git a/src/modules/game/functions.ts b/src/modules/game/functions.ts index e2ae8df..295b24b 100644 --- a/src/modules/game/functions.ts +++ b/src/modules/game/functions.ts @@ -328,8 +328,8 @@ export async function getGhostBattleRecord(body: wm.protobuf.LoadGameHistoryRequ }); // If opponent is default ghost or random ghost - if(!(ghostOpponentCar)) - { + if(!ghostOpponentCar) + { ghostOpponentCar = await prisma.car.findFirst({}); ghostOpponentCar!.name = 'S660'; ghostOpponentCar!.manufacturer = 12; @@ -366,7 +366,7 @@ export async function getGhostBattleRecord(body: wm.protobuf.LoadGameHistoryRequ }); // If opponent is default ghost or random ghost - if(!(ghostOpponentCar2)) + if(!ghostOpponentCar2) { ghostOpponentCar2 = await prisma.car.findFirst({}); ghostOpponentCar2!.name = 'S660'; @@ -401,8 +401,8 @@ export async function getGhostBattleRecord(body: wm.protobuf.LoadGameHistoryRequ }); // If opponent is default ghost or random ghost - if(!(ghostOpponentCar3)) - { + if(!ghostOpponentCar3) + { ghostOpponentCar3 = await prisma.car.findFirst({}); ghostOpponentCar3!.name = 'S660'; ghostOpponentCar3!.manufacturer = 12; diff --git a/src/modules/game/ghost.ts b/src/modules/game/ghost.ts index a2bcd4b..619c6c3 100644 --- a/src/modules/game/ghost.ts +++ b/src/modules/game/ghost.ts @@ -18,7 +18,7 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ let OCMModePlay: boolean = false; // If the game was not retired / timed out - if (!(body.retired || body.timeup)) + if (!body.retired || !body.timeup) { console.log('Saving Ghost Battle Result'); @@ -730,7 +730,7 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ export async function deleteGhostTrail(body: wm.protobuf.SaveGameResultRequest, ghostTrailDays: number) { // if is not retired or time up - if (!(body.retired || body.timeup)) + if (!body.retired || !body.timeup) { // if n days of ghost trail is set if(ghostTrailDays != 0) diff --git a/src/modules/game/story.ts b/src/modules/game/story.ts index bbffb0c..9cd8b7e 100644 --- a/src/modules/game/story.ts +++ b/src/modules/game/story.ts @@ -13,7 +13,7 @@ import * as check_step from "./games_util/check_step"; export async function saveStoryResult(body: wm.protobuf.SaveGameResultRequest, car: any) { // If the game was not retired / timed out - if (!(body.retired || body.timeup)) + if (!body.retired || !body.timeup) { console.log('Game not retired / timed out, continuing ...') diff --git a/src/modules/game/time_attack.ts b/src/modules/game/time_attack.ts index e5c29c4..3f356f5 100644 --- a/src/modules/game/time_attack.ts +++ b/src/modules/game/time_attack.ts @@ -10,7 +10,7 @@ export async function saveTimeAttackResult(body: wm.protobuf.SaveGameResultReque let cheatedTime: boolean = false; // If the game was not retired / timed out - if (!(body.retired || body.timeup)) + if (!body.retired || !body.timeup) { console.log('Game not retired / timed out, continuing ...') diff --git a/src/modules/game/versus.ts b/src/modules/game/versus.ts index 961e9e8..d252e75 100644 --- a/src/modules/game/versus.ts +++ b/src/modules/game/versus.ts @@ -10,7 +10,7 @@ import * as common from "../util/common"; // Save versus battle result export async function saveVersusBattleResult(body: wm.protobuf.SaveGameResultRequest, car: any) { - if (!(body.retired)) + if (!body.retired) { // Get the car let cars = body?.car; diff --git a/src/modules/ghost.ts b/src/modules/ghost.ts index 00535d9..6b81a6d 100644 --- a/src/modules/ghost.ts +++ b/src/modules/ghost.ts @@ -74,25 +74,16 @@ export default class GhostModule { } }); - if(getUserId) + if(getUserId?.userBanned) { - if(getUserId.userBanned === false) - { - // Encode the response - let message = wm.wm.protobuf.LoadGhostBattleInfoResponse.encode(msg); + return res.status(500); + } - // Send the response to the client - common.sendResponse(message, res, req.rawHeaders); - } - } - else - { - // Encode the response - let message = wm.wm.protobuf.LoadGhostBattleInfoResponse.encode(msg); + // Encode the response + let message = wm.wm.protobuf.LoadGhostBattleInfoResponse.encode(msg); - // Send the response to the client - common.sendResponse(message, res, req.rawHeaders); - } + // Send the response to the client + common.sendResponse(message, res, req.rawHeaders); }) @@ -326,7 +317,7 @@ export default class GhostModule { else if(actualSessionId > 0 && actualSessionId < 101) { // Check if it is crown ghost battle or not (crown ghost battle don't have time, driveData, trendBinaryByArea, trendBinaryByCar, trendBinaryByUser value from request body) - if(!(body.trendBinaryByArea) && !(body.trendBinaryByCar) && !(body.trendBinaryByUser)) + if(!body.trendBinaryByArea && !body.trendBinaryByCar && !body.trendBinaryByUser) { console.log('Crown Ghost Battle Game found'); diff --git a/src/modules/ghost/functions.ts b/src/modules/ghost/functions.ts index cfbd0a8..d03703c 100644 --- a/src/modules/ghost/functions.ts +++ b/src/modules/ghost/functions.ts @@ -253,7 +253,7 @@ export async function getGhostCar(car: any, area: number, ramp: number, path: nu } // Push user's car data without ghost trail - if(!(ghost_trails)) + if(!ghost_trails) { lists_ghostcar.push(wmproto.wm.protobuf.GhostCar.create({ car: car[random] diff --git a/src/modules/ghost_ocm.ts b/src/modules/ghost_ocm.ts index 3e46071..4f3bc35 100644 --- a/src/modules/ghost_ocm.ts +++ b/src/modules/ghost_ocm.ts @@ -400,26 +400,28 @@ export default class GhostModule { let pathVal: number = OCMArea.pathVal; // Get url query parameter (period_id) - let period_id = Number(req.query.period_id); + let period_id = Number(req.query.period_id); // Get current date let date = Math.floor(new Date().getTime() / 1000); // Get currently active OCM event - let ocmEventDate = await prisma.oCMEvent.findFirst({ + let ocmEventDate = await prisma.oCMEvent.findFirst({ where: { + // competitionId + competitionId: competition_id // qualifyingPeriodStartAt is less than current date - qualifyingPeriodStartAt: { lte: date }, + // qualifyingPeriodStartAt: { lte: date }, // competitionEndAt is greater than current date - competitionEndAt: { gte: date }, + // competitionEndAt: { gte: date }, }, orderBy:{ competitionId: 'desc' } }); - if(!(ocmEventDate)) + if(!ocmEventDate) { ocmEventDate = await prisma.oCMEvent.findFirst({ orderBy:{ @@ -432,7 +434,7 @@ export default class GhostModule { let ghostCars: wm.wm.protobuf.GhostCar; let ghostTypes; let cars: wm.wm.protobuf.ICar | null; - let playedPlace = wm.wm.protobuf.Place.create({ + let playedPlace = wm.wm.protobuf.Place.create({ placeId: Config.getConfig().placeId, regionId: Config.getConfig().regionId, shopName: Config.getConfig().shopName, @@ -460,7 +462,7 @@ export default class GhostModule { }); // Get Top 1 qualifying ghost trail id - let checkGhostTrail = await prisma.oCMTop1GhostTrail.findFirst({ + let checkGhostTrail = await prisma.oCMTop1GhostTrail.findFirst({ where:{ carId: ocmTallyRecord!.carId, competitionId: ocmEventDate!.competitionId, @@ -473,7 +475,7 @@ export default class GhostModule { // Top 1 OCM Ghost trail data available if(checkGhostTrail) - { + { // Get the Top 1 OCM car data cars = await prisma.car.findFirst({ where:{ @@ -502,10 +504,10 @@ export default class GhostModule { } // Current date is OCM qualifying day else if(ocmEventDate!.qualifyingPeriodStartAt < date && ocmEventDate!.qualifyingPeriodCloseAt > date) - { + { console.log('OCM Qualifying Day'); - // Get the default ghost trail + // Get the default ghost trail let checkGhostTrail = await prisma.oCMTop1GhostTrail.findFirst({ where:{ carId: 999999999, @@ -561,7 +563,7 @@ export default class GhostModule { ghostTypes = wm.wm.protobuf.GhostType.GHOST_NORMAL; } else if(ocmEventDate!.competitionCloseAt < date && ocmEventDate!.competitionEndAt > date) - { + { // TODO: Actual stuff here // This is literally just bare-bones so the shit boots } @@ -577,7 +579,7 @@ export default class GhostModule { }, orderBy:{ result: 'desc' - }, + } }); // Get Top 1 qualifying ghost trail id @@ -588,12 +590,12 @@ export default class GhostModule { }, orderBy:{ playedAt: 'desc' - }, + } }); // Top 1 OCM Ghost trail data available if(checkGhostTrail) - { + { // Get the Top 1 OCM car data cars = await prisma.car.findFirst({ where:{ @@ -606,7 +608,7 @@ export default class GhostModule { }); // Set the tunePower used when playing ghost crown - cars!.tunePower = ocmTallyRecord!.tunePower; + cars!.tunePower = ocmTallyRecord!.tunePower; // Set the tuneHandling used when playing ghost crown cars!.tuneHandling = ocmTallyRecord!.tuneHandling; @@ -631,7 +633,6 @@ export default class GhostModule { cars!.lastPlayedPlace!.shopName = checkShopName.playedShopName; } - let ocmEventDate = await prisma.oCMEvent.findFirst({ where:{ competitionId: competition_id diff --git a/src/modules/startup/functions.ts b/src/modules/startup/functions.ts index 950faa2..b89f84d 100644 --- a/src/modules/startup/functions.ts +++ b/src/modules/startup/functions.ts @@ -43,7 +43,7 @@ export async function competitionSchedule(date: any, competitionId: any) // Currently no Active Competition (OCM) Event.. Getting Previous Competition (OCM) Event let pastEvent = 0; - if(!(ghostCompetitionSchedule)) + if(!ghostCompetitionSchedule) { ghostCompetitionSchedule = await prisma.oCMEvent.findFirst({ orderBy:{ @@ -96,6 +96,9 @@ export async function competitionSchedule(date: any, competitionId: any) // idk what this is minigamePatternId: ghostCompetitionSchedule.minigamePatternId }); + + // hof menu while OCM is ongoing + lastCompetitionId = ghostCompetitionSchedule.competitionId -1; } // It's previous Competition (OCM) event @@ -112,7 +115,6 @@ export async function competitionSchedule(date: any, competitionId: any) competitionId: 'desc' } }); - lastCompetitionId = lastScheduleCompetitionId?.competitionId || 0; } diff --git a/src/modules/terminal.ts b/src/modules/terminal.ts index 8b6f5f8..de21314 100644 --- a/src/modules/terminal.ts +++ b/src/modules/terminal.ts @@ -650,7 +650,7 @@ export default class TerminalModule { }); // Declare GhostCompetitionSchedule - let compeSch; + let compeSch; let msg: any; if(ocmEventDate) @@ -794,7 +794,7 @@ export default class TerminalModule { })); } - if(!(ownRecords)) + if(!ownRecords) { let ocmPersonalRank = [{ result: 0, position: 0 }]; @@ -991,7 +991,7 @@ export default class TerminalModule { })); } - if(!(ownRecords)) + if(!ownRecords) { let ocmPersonalRank = [{ result: 0, position: 0 }]; @@ -1091,7 +1091,7 @@ export default class TerminalModule { } }); - if(!(checkRegisteredGhost)) + if(!checkRegisteredGhost) { await prisma.ghostRegisteredFromTerminal.create({ data:{ diff --git a/src/modules/users.ts b/src/modules/users.ts index b995758..4880fa3 100644 --- a/src/modules/users.ts +++ b/src/modules/users.ts @@ -685,7 +685,7 @@ export default class UserModule { } }); - // TODO: Add notices to config + // Get notices from config let notice = (Config.getConfig().notices || []); // Create the notice window objects From 625e3e62fa4af76411817f481b9c6ded7137d0b0 Mon Sep 17 00:00:00 2001 From: anthonyng43 Date: Tue, 24 Feb 2026 00:59:57 +0800 Subject: [PATCH 3/4] abit undo of lines and cleaup --- src/modules/game/ghost.ts | 4 ++-- src/modules/game/story.ts | 2 +- src/modules/game/time_attack.ts | 2 +- src/modules/ghost/ghost_history.ts | 2 +- src/modules/ghost/ghost_stamp.ts | 2 +- src/modules/startup/functions.ts | 4 +++- src/modules/users.ts | 2 +- 7 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/modules/game/ghost.ts b/src/modules/game/ghost.ts index 619c6c3..65583aa 100644 --- a/src/modules/game/ghost.ts +++ b/src/modules/game/ghost.ts @@ -18,7 +18,7 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ let OCMModePlay: boolean = false; // If the game was not retired / timed out - if (!body.retired || !body.timeup) + if (!(body.retired || body.timeup)) { console.log('Saving Ghost Battle Result'); @@ -730,7 +730,7 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ export async function deleteGhostTrail(body: wm.protobuf.SaveGameResultRequest, ghostTrailDays: number) { // if is not retired or time up - if (!body.retired || !body.timeup) + if (!(body.retired || body.timeup)) { // if n days of ghost trail is set if(ghostTrailDays != 0) diff --git a/src/modules/game/story.ts b/src/modules/game/story.ts index 9cd8b7e..7493007 100644 --- a/src/modules/game/story.ts +++ b/src/modules/game/story.ts @@ -13,7 +13,7 @@ import * as check_step from "./games_util/check_step"; export async function saveStoryResult(body: wm.protobuf.SaveGameResultRequest, car: any) { // If the game was not retired / timed out - if (!body.retired || !body.timeup) + if (!(body.retired || body.timeup)) { console.log('Game not retired / timed out, continuing ...') diff --git a/src/modules/game/time_attack.ts b/src/modules/game/time_attack.ts index 3f356f5..f1e974a 100644 --- a/src/modules/game/time_attack.ts +++ b/src/modules/game/time_attack.ts @@ -10,7 +10,7 @@ export async function saveTimeAttackResult(body: wm.protobuf.SaveGameResultReque let cheatedTime: boolean = false; // If the game was not retired / timed out - if (!body.retired || !body.timeup) + if (!(body.retired || body.timeup)) { console.log('Game not retired / timed out, continuing ...') diff --git a/src/modules/ghost/ghost_history.ts b/src/modules/ghost/ghost_history.ts index c61bcb5..4b39d48 100644 --- a/src/modules/ghost/ghost_history.ts +++ b/src/modules/ghost/ghost_history.ts @@ -232,7 +232,7 @@ export async function saveOCMGhostHistory(body: wm.protobuf.SaveGameResultReques }); // Period ID not found - if(!(OCM_periodId)) + if(!OCM_periodId) { OCM_periodId = await prisma.oCMPeriod.findFirst({ where:{ diff --git a/src/modules/ghost/ghost_stamp.ts b/src/modules/ghost/ghost_stamp.ts index 2405f3b..9e6ff3b 100644 --- a/src/modules/ghost/ghost_stamp.ts +++ b/src/modules/ghost/ghost_stamp.ts @@ -91,7 +91,7 @@ export async function sendStamp(body: wm.protobuf.SaveGameResultRequest) }) // No record found - if(!(stampTarget)) + if(!stampTarget) { console.log('Creating new stamp entry'); diff --git a/src/modules/startup/functions.ts b/src/modules/startup/functions.ts index b89f84d..a8879f4 100644 --- a/src/modules/startup/functions.ts +++ b/src/modules/startup/functions.ts @@ -98,7 +98,9 @@ export async function competitionSchedule(date: any, competitionId: any) }); // hof menu while OCM is ongoing - lastCompetitionId = ghostCompetitionSchedule.competitionId -1; + if(ghostCompetitionSchedule.competitionId > 1) { + lastCompetitionId = ghostCompetitionSchedule.competitionId -1; + } } // It's previous Competition (OCM) event diff --git a/src/modules/users.ts b/src/modules/users.ts index 4880fa3..0c30527 100644 --- a/src/modules/users.ts +++ b/src/modules/users.ts @@ -63,7 +63,7 @@ export default class UserModule { transferState: wm.wm.protobuf.TransferState.NOT_REGISTERED, }; - if (!body.cardChipId || !body.accessCode) + if (!(body.cardChipId || body.accessCode)) { msg.error = wm.wm.protobuf.ErrorCode.ERR_USER_SUCCEEDED; From 431bb27ee2313d2e5b5c7db5381470ff023498ec Mon Sep 17 00:00:00 2001 From: anthonyng43 Date: Fri, 6 Mar 2026 00:37:54 +0800 Subject: [PATCH 4/4] proper terminal scratch --- src/modules/terminal.ts | 94 +++++++++++++++++++++++++++------ src/modules/terminal/scratch.ts | 10 +++- src/modules/users.ts | 29 +++------- 3 files changed, 93 insertions(+), 40 deletions(-) diff --git a/src/modules/terminal.ts b/src/modules/terminal.ts index de21314..a9040c9 100644 --- a/src/modules/terminal.ts +++ b/src/modules/terminal.ts @@ -21,7 +21,18 @@ export default class TerminalModule { // Get the request body for the load terminal information request let body = wm.wm.protobuf.LoadTerminalInformationRequest.decode(req.body); + // Get the current date/time (unix epoch) + let date = Math.floor(new Date().getTime() / 1000) + + // Get user + let user = await prisma.user.findFirst({ + where: { + id: body.userId + } + }); + let prizeReceivable = false; + let freeScratched = true; // Get all of the user's items from the database let userItems = await prisma.userItem.findMany({ @@ -41,6 +52,12 @@ export default class TerminalModule { if (userItems.length > 0) { prizeReceivable = true; } + // If a day has passed, allow the user to scratch again + freeScratched = scratch.dayPassedBool( + new Date(date*1000), // Todays date + new Date(user!.lastScratched*1000) // Last Scratched date + ); + // Response data let msg = { error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS, @@ -49,7 +66,7 @@ export default class TerminalModule { needToSeeTransferred: false }, announceFeature: false, - freeScratched: true, + freeScratched: freeScratched, availableTickets: userItems, } @@ -511,8 +528,65 @@ export default class TerminalModule { // Get the information from the request let body = wm.wm.protobuf.SaveScratchSheetRequest.decode(req.body); - // Get the current date/time (unix epoch) - let date = Math.floor(new Date().getTime() / 1000) + let user = await prisma.user.findFirst({ + where: { + id: body.userId + } + }); + + // Skip update last scratched timestamp if is from tutorial + if (user?.tutorials[23] != false) { + // Update the last scratched timestamp + await prisma.user.update({ + where: { + id: body.userId + }, + data: { + lastScratched: body.timestamp + } + }); + } + + if (user!.tutorials[23] != true) { + // Get the number of scratch cards for the user + let scratchSheetCount = await prisma.scratchSheet.count({ + where: { + userId: user!.id + } + }); + + // If the user has no scratch sheets + if (scratchSheetCount === 0) + { + console.log("Generating first sheet ..."); + + // Generate a new scratch sheet for the user + await scratch.generateScratchSheet(user!.id, Number(1)); + + // Set the current scratch sheet to 1 + await prisma.user.update({ + where: { + id: user!.id + }, + data: { + currentSheet: Number(1) + } + }); + } + + // Set terminal scratch tutorial to true + user!.tutorials[23] = true; + + // Update the tutorial + await prisma.user.update({ + where: { + id: body.userId + }, + data: { + tutorials: user!.tutorials + } + }); + } // Get all of the scratch sheets for the user let scratchSheets = await prisma.scratchSheet.findMany({ @@ -548,7 +622,7 @@ export default class TerminalModule { let earnedItem = wm.wm.protobuf.UserItem.create({ category: scratchSquare.category, itemId: scratchSquare.itemId, - earnedAt: date + earnedAt: body.timestamp }); try // Attempt to update scratch sheet @@ -559,7 +633,7 @@ export default class TerminalModule { userId: body.userId, category: scratchSquare.category, itemId: scratchSquare.itemId, - earnedAt: date + earnedAt: body.timestamp } }); @@ -572,16 +646,6 @@ export default class TerminalModule { earned: true } }); - - // Update the last scratched timestamp - await prisma.user.update({ - where: { - id: body.userId - }, - data: { - lastScratched: date - } - }); // If the box we uncovered is the car... hehe boi if (scratchSquare.category === 201) diff --git a/src/modules/terminal/scratch.ts b/src/modules/terminal/scratch.ts index c750f6d..6a82d1f 100644 --- a/src/modules/terminal/scratch.ts +++ b/src/modules/terminal/scratch.ts @@ -348,6 +348,13 @@ export function dayPassed(a: Date, b: Date) return daysSinceEpoch(a) > daysSinceEpoch(b) ? 0 : 1; } +// Get the days passed between dates as boolean +export function dayPassedBool(a: Date, b: Date) +{ + // Return true if a day has passed since the last scratch, false otherwise + return daysSinceEpoch(a) > daysSinceEpoch(b) ? false : true; +} + // Async function for generating a new scratch sheet export async function generateScratchSheet (userId: number, sheetNo: number) { @@ -361,7 +368,6 @@ export async function generateScratchSheet (userId: number, sheetNo: number) switch(scratchType) { // More options maybe added in the future - case 0: // Same as actual game (randomised after last set) // If the sheet number has associated data @@ -373,7 +379,7 @@ export async function generateScratchSheet (userId: number, sheetNo: number) else // Sheet is out of range { // Generate a random (standard) scratch sheet - // scratchItems = getRandomScratchSheet(sheetNo-1); + scratchItems = getRandomScratchSheet(sheetNo-1); } break; diff --git a/src/modules/users.ts b/src/modules/users.ts index 0c30527..4233dde 100644 --- a/src/modules/users.ts +++ b/src/modules/users.ts @@ -207,31 +207,14 @@ export default class UserModule { } // Get the number of scratch cards for the user - let scratchSheetCount = await prisma.scratchSheet.count({ - where: { - userId: user!.id - } - }) - - console.log("Current sheet count: ", scratchSheetCount); - - // If the user has no scratch sheets - if (scratchSheetCount === 0) - { - console.log("Generating first sheet ..."); - - // Generate a new scratch sheet for the user - await scratch.generateScratchSheet(user!.id, Number(1)); - - // Set the current scratch sheet to 1 - await prisma.user.update({ + if (user.tutorials[23] === true) { + let scratchSheetCount = await prisma.scratchSheet.count({ where: { - id: user!.id - }, - data: { - currentSheet: Number(1) + userId: user!.id } - }); + }) + + console.log("Current sheet count: ", scratchSheetCount); } // If the car order array has not been created