From 427c7539af4449acfd39b82590cf7701c15056df Mon Sep 17 00:00:00 2001 From: ghkkk090 Date: Sat, 3 Sep 2022 19:37:54 +0700 Subject: [PATCH] fix terminal scratch immediately pick up car --- src/modules/cars.ts | 5 ++ src/util/terminal/check_car.ts | 150 +++++++++++++++++++++++++++++++++ 2 files changed, 155 insertions(+) create mode 100644 src/util/terminal/check_car.ts diff --git a/src/modules/cars.ts b/src/modules/cars.ts index d58488a..0ebafe3 100644 --- a/src/modules/cars.ts +++ b/src/modules/cars.ts @@ -11,6 +11,7 @@ import * as wm from "../wmmt/wm.proto"; // Import Util import * as common from "../util/common"; import * as scratch from "../util/scratch"; +import * as terminal from "../util/terminal/check_car"; export default class CarModule extends Module { @@ -275,6 +276,7 @@ export default class CarModule extends Module { // Get the request body for the create car request let body = wm.wm.protobuf.CreateCarRequest.decode(req.body); + console.log(body); // Get the current date/time (unix epoch) let date = Math.floor(new Date().getTime() / 1000) @@ -408,6 +410,9 @@ export default class CarModule extends Module { { // Car is fully tuned tune = 2; + + // Check if created car is from terminal scratch car + await terminal.checkScratchCar(body.userId, body.car.visualModel!) } // User item not used, but car has 600 HP by default else if (body.car && diff --git a/src/util/terminal/check_car.ts b/src/util/terminal/check_car.ts new file mode 100644 index 0000000..2493c1b --- /dev/null +++ b/src/util/terminal/check_car.ts @@ -0,0 +1,150 @@ +import { prisma } from "../.."; + +// Sends the server response to the client +export async function checkScratchCar(userId: number, visualModel: number) +{ + let checkUserItem: any; + + if(visualModel === 55) // R2 + { + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 4 + } + }) + } + else if(visualModel === 73) // Corolla + { + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 3 + } + }) + } + else if(visualModel === 98) // HIACE Van + { + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 1 + } + }) + } + else if(visualModel === 26) // Pajero Evolution + { + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 2 + } + }) + } + else if(visualModel === 118) // GT-R Nismo + { + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 5 + } + }) + } + else if(visualModel === 119) // Z34 Nismo + { + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 6 + } + }) + } + else if(visualModel === 72) // Aristo Taxi + { + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 16 + } + }) + } + else if(visualModel === 11) // Atenza Taxi + { + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 17 + } + }) + } + else if(visualModel === 66) // Celsior Taxi + { + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 18 + } + }) + } + else if(visualModel === 75) // HIACE Wagon + { + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 19 + } + }) + } + else if(visualModel === 132) // GT-R Pure Edition + { + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 20 + } + }) + } + else if(visualModel === 129) // NSX-R + { + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 21 + } + }) + } + else + { + checkUserItem = []; + } + + // Check if user item is available or not + if(checkUserItem.length > 0) + { + for(let i=0; i