diff --git a/prisma/migrations/20250608120100_item_check/migration.sql b/prisma/migrations/20250608120100_item_check/migration.sql new file mode 100644 index 0000000..73ed770 --- /dev/null +++ b/prisma/migrations/20250608120100_item_check/migration.sql @@ -0,0 +1,11 @@ +/* + Warnings: + + - You are about to drop the column `type` on the `UserItem` table. All the data in the column will be lost. + +*/ +-- AlterTable +ALTER TABLE "CarItem" ADD COLUMN "earnedAt" INTEGER NOT NULL DEFAULT 0; + +-- AlterTable +ALTER TABLE "UserItem" DROP COLUMN "type"; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index f3e96e8..7a9a8f7 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -48,7 +48,6 @@ model UserItem { itemId Int User User @relation(fields: [userId], references: [id]) userId Int - type Int @default(0) earnedAt Int @default(0) } @@ -174,6 +173,7 @@ model CarItem { category Int itemId Int amount Int + earnedAt Int @default(0) } model CarSettings { diff --git a/src/modules/cars.ts b/src/modules/cars.ts index ab2634d..5cf8b95 100644 --- a/src/modules/cars.ts +++ b/src/modules/cars.ts @@ -218,14 +218,26 @@ export default class CarModule { { console.log('Car Item reward available, continuing ...'); for(let i=0; i 1) { + let duplicateIds = existingItems.slice(1).map(item => item.dbId); + await prisma.carItem.deleteMany({ + where: { + dbId: { in: duplicateIds } + } + }); + } + } } } @@ -39,13 +67,6 @@ export async function getItem(body: wm.protobuf.SaveGameResultRequest) console.log('User Item reward available, continuing ...'); for(let i=0; i 14) + if(i >= 14) { i = 18; // GID_RUNAREA_HIROSHIMA } @@ -138,10 +138,10 @@ export async function getCrownList() else { // Loop GID_RUNAREA - for(let i=0; i<19; i++) + for(let i=0; i<15; i++) // set to loop 14 times is enough { // After Kobe is Hiroshima then Fukuoka and the rest - if(i > 14) + if(i >= 14) { i = 18; // GID_RUNAREA_HIROSHIMA } diff --git a/src/modules/terminal.ts b/src/modules/terminal.ts index e3deefd..c668c1d 100644 --- a/src/modules/terminal.ts +++ b/src/modules/terminal.ts @@ -59,15 +59,27 @@ export default class TerminalModule { // Item is returned if (item) { - // Insert the item into the car items - await prisma.carItem.create({ - data: { - carId: body.carId, - category: item.category, - itemId: item.itemId, - amount: 1 - } - }); + let itemCheck = await prisma.carItem.findFirst({ + where: { + carId: body.carId, + category: item.category, + itemId: item.itemId, + amount: 1 + } + }); + + if (!itemCheck){ + // Insert the item into the car items + await prisma.carItem.create({ + data: { + carId: body.carId, + category: item.category, + itemId: item.itemId, + amount: 1, + earnedAt: Math.floor(new Date().getTime() / 1000) + } + }); + } // Delete the accepted item await prisma.userItem.delete({ @@ -88,7 +100,7 @@ export default class TerminalModule { } // Encode the response - let message = wm.wm.protobuf.LoadBookmarksResponse.encode(msg); + let message = wm.wm.protobuf.ReceiveUserItemsResponse.encode(msg); // Send the response to the client common.sendResponse(message, res, req.rawHeaders); @@ -314,7 +326,7 @@ export default class TerminalModule { let user = await prisma.user.findFirst({ where: { id: body.userId - }, + } }); if(user) @@ -336,7 +348,6 @@ export default class TerminalModule { }); // If the car order was modified - // Update the car order in the table if (body.carOrder.length > 0) { @@ -526,8 +537,7 @@ export default class TerminalModule { data: { userId: body.userId, category: scratchSquare.category, - itemId: scratchSquare.itemId, - type: 1, // Scratch item + itemId: scratchSquare.itemId, earnedAt: date } }); @@ -682,13 +692,13 @@ export default class TerminalModule { }, { periodId: 'desc' - } + } ], include:{ car: true }, distinct: ["carId"], - take: 100 + take: 150 }); let numOfParticipantsLength = [{ count: 0 }]; @@ -885,7 +895,7 @@ export default class TerminalModule { car: true }, distinct: ["carId"], - take: 25 + take: 150 }); let numOfParticipantsLength = [{ count: 0 }]; diff --git a/src/modules/terminal/check_car.ts b/src/modules/terminal/check_car.ts index d719db1..79a80ea 100644 --- a/src/modules/terminal/check_car.ts +++ b/src/modules/terminal/check_car.ts @@ -6,129 +6,131 @@ export async function checkScratchCar(userId: number, visualModel: number) { let checkUserItem: any; - if(visualModel === 55) // R2 + switch (visualModel) { - 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 = []; + case 55: // R2 + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 4 + } + }) + break; + + case 73: // Corolla + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 3 + } + }) + break; + + case 98: // HIACE Van + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 1 + } + }) + break; + + case 26: // Pajero Evolution + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 2 + } + }) + break; + + case 118: // GT-R Nismo + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 5 + } + }) + break; + + case 119: // Z34 Nismo + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 6 + } + }) + break; + + case 72: // Aristo Taxi + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 16 + } + }) + break; + + case 11: // Atenza Taxi + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 17 + } + }) + break; + + case 66: // Celsior Taxi + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 18 + } + }) + break; + + case 75: // HIACE Wagon + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 19 + } + }) + break; + + case 132: // GT-R Pure Edition + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 20 + } + }) + break; + + case 129: // NSX-R + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 21 + } + }) + break; + + default: + checkUserItem = []; + break; } // Check if user item is available or not diff --git a/src/modules/terminal/scratch.ts b/src/modules/terminal/scratch.ts index 4eba9cf..2763503 100644 --- a/src/modules/terminal/scratch.ts +++ b/src/modules/terminal/scratch.ts @@ -428,8 +428,14 @@ export async function getScratchItemList (userId: number, date: number) // Get all of the user's scratch items from the database let scratchUserItems = await prisma.userItem.findMany({ where: { - userId: userId, - type: 1 // Scratch Item + userId: userId, + category: { // switch to category instead of type + in: [ + 201, // wm.wm.protobuf.ItemCategory.CAT_CAR_TICKET + 26, // wm.wm.protobuf.ItemCategory.CAT_RIVAL_MARKER + 25 // wm.wm.protobuf.ItemCategory.CAT_WINDOW_DECORATION + ] + } } }); diff --git a/src/modules/users.ts b/src/modules/users.ts index c45371f..b995758 100644 --- a/src/modules/users.ts +++ b/src/modules/users.ts @@ -181,8 +181,7 @@ export default class UserModule { data: { userId: user.id, category: wm.wm.protobuf.ItemCategory.CAT_CAR_TICKET_FREE, - itemId: 5, - type: Number(0) // Car Ticket + itemId: 5, } }); } @@ -286,14 +285,19 @@ export default class UserModule { let tickets = await prisma.userItem.findMany({ where: { userId: user.id, - type: 0 + category: { + in: [ + 203, // wm.wm.protobuf.ItemCategory.CAT_CAR_TICKET_FREE + 201 // wm.wm.protobuf.ItemCategory.CAT_CAR_TICKET + ] + } }, select: { itemId: true, category: true, - userItemId: true + userItemId: true } - }) + }); // Error handling if windowStickerString and windowStickerFont is undefined or null @@ -666,15 +670,20 @@ export default class UserModule { // Get all of the user's tickets let tickets = await prisma.userItem.findMany({ where: { - userId: body.userId, - type: 0 + userId: body.userId, + category: { + in: [ + 203, // wm.wm.protobuf.ItemCategory.CAT_CAR_TICKET_FREE + 201 // wm.wm.protobuf.ItemCategory.CAT_CAR_TICKET + ] + } }, select: { itemId: true, category: true, userItemId: true } - }) + }); // TODO: Add notices to config let notice = (Config.getConfig().notices || []); diff --git a/src/modules/util/meter_reward.ts b/src/modules/util/meter_reward.ts index c144334..a7e07e0 100644 --- a/src/modules/util/meter_reward.ts +++ b/src/modules/util/meter_reward.ts @@ -20,93 +20,45 @@ export async function giveMeterRewards(body: wm.protobuf.SaveGameResultRequest) itemId: { in: [2, 3, 5, 6, 29, 30, 31, 32, 33 ,34] }, // Except story meter }, }, - /*where: { - itemId: { notIn: [2, 3, 5, 6, 29, 30, 31, 32, 33 ,34] }, - },*/ }) let itemIdVal = 0; - if(carItemCount === 0){ - itemIdVal = 1; // Namco Meter - } - else if(carItemCount === 1){ - itemIdVal = 4; // Special Meter - } - else if(carItemCount === 2){ - itemIdVal = 7; // Metal 1 (Black) - } - else if(carItemCount === 3){ - itemIdVal = 8; // Metal 2 (Red) - } - else if(carItemCount === 4){ - itemIdVal = 9; // Cyber 1 (Blue) - } - else if(carItemCount === 5){ - itemIdVal = 10; // Cyber 2 (Red) - } - else if(carItemCount === 6){ - itemIdVal = 11; // Aluminium 1 (Blue) - } - else if(carItemCount === 7){ - itemIdVal = 12; // Aluminium 1 (Red) - } - else if(carItemCount === 8){ - itemIdVal = 13; // Jungle 1 (Green) - } - else if(carItemCount === 9){ - itemIdVal = 14; // Jungle 2 (Brown) - } - else if(carItemCount === 10){ - itemIdVal = 15; // Dessert 1 (Red) - } - else if(carItemCount === 11){ - itemIdVal = 16; // Dessert 2 (Brown) - } - else if(carItemCount === 12){ - itemIdVal = 17; // Pirate 1 (Red) - } - else if(carItemCount === 13){ - itemIdVal = 18; // Pirate 2 (Blue) - } - else if(carItemCount === 14){ - itemIdVal = 19; // Fire Pattern 1 (Red) - } - else if(carItemCount === 15){ - itemIdVal = 20; // Fire Pattern 2 (Blue) - } - else if(carItemCount === 16){ - itemIdVal = 21; // Silver Access - } - else if(carItemCount === 17){ - itemIdVal = 22; // Gold Access - } - else if(carItemCount === 18){ - itemIdVal = 23; // Steampunk 1 (Gold) - } - else if(carItemCount === 19){ - itemIdVal = 24; // Steampunk 2 (Green) - } - else if(carItemCount === 20){ - itemIdVal = 25; // Dragon 1 (Gold) - } - else if(carItemCount === 21){ - itemIdVal = 26; // Dragon 2 (Blue) - } - else if(carItemCount === 22){ - itemIdVal = 27; // Light Line 1 (Blue) - } - else if(carItemCount === 23){ - itemIdVal = 28; // Light Line 2 (Orange) + switch (carItemCount) + { + case 0: + itemIdVal = 1; // Namco Meter + break; + + case 1: + itemIdVal = 4; // Special Meter + break; + + default: + if (carItemCount >= 2 && carItemCount <= 23) { + itemIdVal = carItemCount + 5; // Metal 1 (Black) to Light Line 2 (Orange) + } } if(itemIdVal !== 0){ - console.log(`carID ${body.carId} do n*100 play, continue give reward... meter ID ${itemIdVal}`); - await prisma.carItem.create({ - data: { + let itemCheck = await prisma.carItem.findFirst({ + where: { carId: body.carId, category: 15, itemId: itemIdVal, amount: 1 } }); - } + + if (!itemCheck) { + console.log(`carID ${body.carId} do n*100 play, continue give reward... meter ID ${itemIdVal}`); + await prisma.carItem.create({ + data: { + carId: body.carId, + category: 15, + itemId: itemIdVal, + amount: 1, + earnedAt: Math.floor(new Date().getTime() / 1000) + } + }); + } + } } \ No newline at end of file