From 4a5e9adeb9baddba02835d7192aa59fe5358c598 Mon Sep 17 00:00:00 2001 From: Shiroi Kitsu <108461408+shiroikitsu8@users.noreply.github.com> Date: Mon, 20 Mar 2023 15:28:06 +0700 Subject: [PATCH] trying to fix terminal scratch --- config.example.json | 2 +- src/modules/terminal.ts | 26 ++++++++++++++++---------- src/modules/terminal/scratch.ts | 5 +++-- src/modules/users.ts | 18 +++++++++--------- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/config.example.json b/config.example.json index 025e00f..27867ed 100644 --- a/config.example.json +++ b/config.example.json @@ -10,7 +10,7 @@ "grantFullTuneTicketToNewUsers": 5, "giftCarsFullyTuned": 0, "scratchEnabled": 1, - "scratchType": 1, + "scratchType": 0, "giveMeterReward": 0, "newCardsBanned": 0, "enableScreenshot": 0 diff --git a/src/modules/terminal.ts b/src/modules/terminal.ts index c76619a..673510b 100644 --- a/src/modules/terminal.ts +++ b/src/modules/terminal.ts @@ -482,13 +482,6 @@ export default class TerminalModule extends Module { // Get the current date/time (unix epoch) let date = Math.floor(new Date().getTime() / 1000) - // Get all of the info for the user - let user = await prisma.user.findFirst({ - where: { - id: body.userId - } - }); - // Get all of the scratch sheets for the user let scratchSheets = await prisma.scratchSheet.findMany({ where: { @@ -559,11 +552,24 @@ export default class TerminalModule extends Module { } }); - // If the box we uncovered is the car - if (scratchSquare.category == 201) + // If the box we uncovered is the car... hehe boi + if (scratchSquare.category === 201) { + // Get user last scratch sheet number + let lastUserSheet = await prisma.scratchSheet.findFirst({ + where:{ + userId: body.userId + }, + orderBy:{ + sheetNo: 'desc' + } + }); + + // Last scratch sheet plus 1 + let targetSheet:number = Number(lastUserSheet?.sheetNo) + 1 || Number(body.targetSheet) + 1; + // Generate a new scratch sheet for the user - await scratch.generateScratchSheet(body.userId, body.targetSheet + 1) + await scratch.generateScratchSheet(body.userId, targetSheet); } } catch (error) // Failed to update scratch sheet diff --git a/src/modules/terminal/scratch.ts b/src/modules/terminal/scratch.ts index 884f0b4..4eba9cf 100644 --- a/src/modules/terminal/scratch.ts +++ b/src/modules/terminal/scratch.ts @@ -294,13 +294,14 @@ function shuffleScratchSheet (array: number[][]) // 1 Random Scratch Car // 25 Random Scratch Stickers // 24 Random Scratch Versus Markers -function getRandomScratchSheet (carId: number) +function getRandomScratchSheet (sheetNo: number) { // Scratch items list let items : number[][] = []; + let sheetNumber:number = Number(sheetNo % scratchCars.length); // Add the scratch car for the given index - items.push([201, scratchCars[carId % scratchCars.length]]); + items.push([201, scratchCars[sheetNumber]]); // Add the random scratch stickers diff --git a/src/modules/users.ts b/src/modules/users.ts index 1f1569c..b5d4ea1 100644 --- a/src/modules/users.ts +++ b/src/modules/users.ts @@ -123,9 +123,9 @@ export default class UserModule extends Module { false, // TUTORIAL_ID_UNUSED_17 = 17, false, // TUTORIAL_ID_UNUSED_18 = 18, false, // TUTORIAL_ID_UNUSED_19 = 19, - false, // TUTORIAL_ID_GHOST_STAMP = 20, - false, // TUTORIAL_ID_GHOST_STAMP_DECLINED = 21, - false, // TUTORIAL_ID_GHOST_STAMP_FRIENDS = 22, + true, // TUTORIAL_ID_GHOST_STAMP = 20, + true, // TUTORIAL_ID_GHOST_STAMP_DECLINED = 21, + true, // TUTORIAL_ID_GHOST_STAMP_FRIENDS = 22, false, // TUTORIAL_ID_TERMINAL_SCRATCH = 23, false, // TUTORIAL_ID_TURN_SCRATCH_SHEET = 24, false, // TUTORIAL_ID_INVITE_FRIEND_CAMPAIGN = 25, @@ -159,7 +159,7 @@ export default class UserModule extends Module { } }); - console.log('user made') + console.log('user made'); if (!user) { @@ -179,7 +179,7 @@ export default class UserModule extends Module { userId: user.id, category: wm.wm.protobuf.ItemCategory.CAT_CAR_TICKET_FREE, itemId: 5, - type: 0 // Car Ticket + type: Number(0) // Car Ticket } }); } @@ -211,15 +211,15 @@ export default class UserModule extends Module { } }) - console.log("Current sheet count:", scratchSheetCount); + console.log("Current sheet count: ", scratchSheetCount); // If the user has no scratch sheets - if (scratchSheetCount == 0) + if (scratchSheetCount === 0) { console.log("Generating first sheet ..."); // Generate a new scratch sheet for the user - await scratch.generateScratchSheet(user!.id, 1); + await scratch.generateScratchSheet(user!.id, Number(1)); // Set the current scratch sheet to 1 await prisma.user.update({ @@ -227,7 +227,7 @@ export default class UserModule extends Module { id: user!.id }, data: { - currentSheet: 1 + currentSheet: Number(1) } }); }