diff --git a/src/modules/cars.ts b/src/modules/cars.ts index 9175806..d58488a 100644 --- a/src/modules/cars.ts +++ b/src/modules/cars.ts @@ -169,8 +169,10 @@ export default class CarModule extends Module { let opponentTarget = await prisma.carStampTarget.findMany({ where:{ stampTargetCarId: body.carId, - locked: false, recommended: true, + }, + orderBy:{ + locked: 'desc' } }) @@ -252,7 +254,7 @@ export default class CarModule extends Module { // Stamp or Challenger challenger: carsChallengers[0] || null, challengerReturnCount: returnCount || null, - numOfChallengers: carsChallengers.length || null, + numOfChallengers: carsChallengers.length + 1 || null, // OCM Challenge Top 1 opponentGhost: ghostCarsNo1 || null, diff --git a/src/modules/ghost.ts b/src/modules/ghost.ts index 587010b..25b19d5 100644 --- a/src/modules/ghost.ts +++ b/src/modules/ghost.ts @@ -78,8 +78,11 @@ export default class GhostModule extends Module { let stampTargets = await prisma.carStampTarget.findMany({ where: { stampTargetCarId: body.carId, - locked: false - } + recommended: true + }, + orderBy:{ + locked: 'desc' + } }); if(stampTargets) @@ -180,8 +183,11 @@ export default class GhostModule extends Module { let stampTargets = await prisma.carStampTarget.findMany({ where: { stampTargetCarId: body.carId, - locked: false - } + recommended: true + }, + orderBy:{ + locked: 'asc' + } }); if(stampTargets) diff --git a/src/modules/terminal.ts b/src/modules/terminal.ts index 2880c3a..ea8e4d6 100644 --- a/src/modules/terminal.ts +++ b/src/modules/terminal.ts @@ -188,6 +188,7 @@ export default class TerminalModule extends Module { // Get the query from the request let query = req.query; + let cars; // Check the query limit let queryLimit = 10 @@ -197,9 +198,9 @@ export default class TerminalModule extends Module { } // Check the last played place id - let queryLastPlayedPlaceId = 1; - if(query.limit) + if(query.last_played_place_id) { + let queryLastPlayedPlaceId = 1; let getLastPlayedPlaceId = await prisma.placeList.findFirst({ where:{ placeId: String(query.last_played_place_id) @@ -208,30 +209,46 @@ export default class TerminalModule extends Module { if(getLastPlayedPlaceId) { - queryLastPlayedPlaceId = getLastPlayedPlaceId.id + queryLastPlayedPlaceId = getLastPlayedPlaceId.id; } - } - // Get all of the cars matching the query - let cars = await prisma.car.findMany({ - take: queryLimit, - where: { - OR:[ - { - name: { - startsWith: String(query.name) + cars = await prisma.car.findMany({ + take: queryLimit, + where: { + lastPlayedPlaceId: queryLastPlayedPlaceId + }, + include:{ + gtWing: true, + lastPlayedPlace: true + } + }); + } + else + { + // Get all of the cars matching the query + cars = await prisma.car.findMany({ + take: queryLimit, + where: { + OR:[ + { + name: { + startsWith: String(query.name) + } + }, + { + name: { + endsWith: String(query.name) + } } - }, - { - lastPlayedPlaceId: queryLastPlayedPlaceId - } - ] - }, - include:{ - gtWing: true, - lastPlayedPlace: true - } - }); + ] + + }, + include:{ + gtWing: true, + lastPlayedPlace: true + } + }); + } for(let i=0; i { + + // car_id, target_cars[] + let body = wm.wm.protobuf.LockStampTargetRequest.decode(req.body); + + // Unlock all of the stamp targets for the car + await prisma.carStampTarget.updateMany({ + where: { + stampTargetCarId: body.carId + }, + data: { + locked: false + } + }); + + // Loop over all of the locked stamp targets + for(let targetCar of body.targetCars) + { + // Lock the stamp target for the given car + + // This should only occur once, however + // the relationship is not strictly 1:1 + await prisma.carStampTarget.updateMany({ + where: { + carId: targetCar, + stampTargetCarId: body.carId + }, + data: { + locked: true + } + }); + } + + // Encode the response + let message = wm.wm.protobuf.LoadStampTargetResponse.encode({ + error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS, + }); + + // Send the response to the client + common.sendResponse(message, res); + }); + + /* app.post('/method/load_unreceived_user_items', async (req, res) => { diff --git a/src/util/ghost/ghost_stamp.ts b/src/util/ghost/ghost_stamp.ts index 542fb65..e890c30 100644 --- a/src/util/ghost/ghost_stamp.ts +++ b/src/util/ghost/ghost_stamp.ts @@ -165,11 +165,11 @@ export async function shuttleReturnStamp(body: wm.protobuf.SaveGameResultRequest carId: rgResult.opponents![i].carId, stampTargetCarId: body.carId, returnCount: returnCount, - locked: true, + locked: false, recommended: false } - console.log(`Updating car ${rgResult.opponents![i].carId} vs ${body.carId} stamp entry and locking it`); + console.log(`Updating car ${rgResult.opponents![i].carId} vs ${body.carId} stamp entry and remove it from your recommendation`); await prisma.carStampTarget.update({ where:{ @@ -217,7 +217,7 @@ export async function shuttleReturnStamp(body: wm.protobuf.SaveGameResultRequest if(stampReturned) { - console.log(`Stamp returned to ${rgResult.opponents![i].carId}, unlocking it so opponents can fight your ghost`); + console.log(`Stamp returned to ${rgResult.opponents![i].carId}, recommend it so opponents can fight your ghost`); await prisma.carStampTarget.update({ where:{