1
0
mirror of synced 2024-12-05 03:27:57 +01:00

fix lock friend stamp

This commit is contained in:
ghkkk090 2022-08-31 23:31:16 +07:00
parent bd2d615a3e
commit a243e49015
4 changed files with 101 additions and 32 deletions

View File

@ -169,8 +169,10 @@ export default class CarModule extends Module {
let opponentTarget = await prisma.carStampTarget.findMany({ let opponentTarget = await prisma.carStampTarget.findMany({
where:{ where:{
stampTargetCarId: body.carId, stampTargetCarId: body.carId,
locked: false,
recommended: true, recommended: true,
},
orderBy:{
locked: 'desc'
} }
}) })
@ -252,7 +254,7 @@ export default class CarModule extends Module {
// Stamp or Challenger // Stamp or Challenger
challenger: carsChallengers[0] || null, challenger: carsChallengers[0] || null,
challengerReturnCount: returnCount || null, challengerReturnCount: returnCount || null,
numOfChallengers: carsChallengers.length || null, numOfChallengers: carsChallengers.length + 1 || null,
// OCM Challenge Top 1 // OCM Challenge Top 1
opponentGhost: ghostCarsNo1 || null, opponentGhost: ghostCarsNo1 || null,

View File

@ -78,8 +78,11 @@ export default class GhostModule extends Module {
let stampTargets = await prisma.carStampTarget.findMany({ let stampTargets = await prisma.carStampTarget.findMany({
where: { where: {
stampTargetCarId: body.carId, stampTargetCarId: body.carId,
locked: false recommended: true
} },
orderBy:{
locked: 'desc'
}
}); });
if(stampTargets) if(stampTargets)
@ -180,8 +183,11 @@ export default class GhostModule extends Module {
let stampTargets = await prisma.carStampTarget.findMany({ let stampTargets = await prisma.carStampTarget.findMany({
where: { where: {
stampTargetCarId: body.carId, stampTargetCarId: body.carId,
locked: false recommended: true
} },
orderBy:{
locked: 'asc'
}
}); });
if(stampTargets) if(stampTargets)

View File

@ -188,6 +188,7 @@ export default class TerminalModule extends Module {
// Get the query from the request // Get the query from the request
let query = req.query; let query = req.query;
let cars;
// Check the query limit // Check the query limit
let queryLimit = 10 let queryLimit = 10
@ -197,9 +198,9 @@ export default class TerminalModule extends Module {
} }
// Check the last played place id // Check the last played place id
let queryLastPlayedPlaceId = 1; if(query.last_played_place_id)
if(query.limit)
{ {
let queryLastPlayedPlaceId = 1;
let getLastPlayedPlaceId = await prisma.placeList.findFirst({ let getLastPlayedPlaceId = await prisma.placeList.findFirst({
where:{ where:{
placeId: String(query.last_played_place_id) placeId: String(query.last_played_place_id)
@ -208,30 +209,46 @@ export default class TerminalModule extends Module {
if(getLastPlayedPlaceId) if(getLastPlayedPlaceId)
{ {
queryLastPlayedPlaceId = getLastPlayedPlaceId.id queryLastPlayedPlaceId = getLastPlayedPlaceId.id;
} }
}
// Get all of the cars matching the query cars = await prisma.car.findMany({
let cars = await prisma.car.findMany({ take: queryLimit,
take: queryLimit, where: {
where: { lastPlayedPlaceId: queryLastPlayedPlaceId
OR:[ },
{ include:{
name: { gtWing: true,
startsWith: String(query.name) 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<cars.length; i++) for(let i=0; i<cars.length; i++)
{ {
@ -995,6 +1012,50 @@ export default class TerminalModule extends Module {
}) })
// Lock Stamp Target
app.post('/method/lock_stamp_target', async (req, res) => {
// 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) => { app.post('/method/load_unreceived_user_items', async (req, res) => {

View File

@ -165,11 +165,11 @@ export async function shuttleReturnStamp(body: wm.protobuf.SaveGameResultRequest
carId: rgResult.opponents![i].carId, carId: rgResult.opponents![i].carId,
stampTargetCarId: body.carId, stampTargetCarId: body.carId,
returnCount: returnCount, returnCount: returnCount,
locked: true, locked: false,
recommended: 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({ await prisma.carStampTarget.update({
where:{ where:{
@ -217,7 +217,7 @@ export async function shuttleReturnStamp(body: wm.protobuf.SaveGameResultRequest
if(stampReturned) 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({ await prisma.carStampTarget.update({
where:{ where:{