1
0
mirror of synced 2025-02-08 07:18:12 +01:00

change how to read challengers for faster loading

This commit is contained in:
Shiroi Kitsu 2022-11-20 19:16:33 +07:00
parent d6411c8150
commit e6faa157cd
2 changed files with 60 additions and 52 deletions

View File

@ -99,7 +99,7 @@ export default class CarModule extends Module {
} }
// Check opponents target // Check opponents target
let opponentTarget = await prisma.carStampTarget.findMany({ let opponentTargetCount = await prisma.carStampTarget.count({
where:{ where:{
stampTargetCarId: body.carId, stampTargetCarId: body.carId,
recommended: true, recommended: true,
@ -108,59 +108,69 @@ export default class CarModule extends Module {
locked: 'desc' locked: 'desc'
} }
}) })
let carsChallengers;
let carsChallengers: wm.wm.protobuf.ChallengerCar[] = [];
let returnCount = 1; let returnCount = 1;
if(opponentTarget.length > 0)
if(opponentTargetCount > 0)
{ {
console.log('Challengers Available'); console.log('Challengers Available');
for(let i=0; i<opponentTarget.length; i++) // Randomize pick
{ let random: number = Math.floor(Math.random() * opponentTargetCount);
// Get all of the friend cars for the carId provided
let challengers = await prisma.carChallenger.findFirst({ // Check opponents target
where: { let opponentTarget = await prisma.carStampTarget.findMany({
challengerCarId: opponentTarget[0].carId, where:{
carId: body.carId stampTargetCarId: body.carId,
}, recommended: true,
orderBy:{ },
id: 'desc' orderBy:{
} locked: 'desc'
}); },
skip: random,
take: 1,
});
if(challengers) // Get all of the friend cars for the carId provided
{ let challengers = await prisma.carChallenger.findFirst({
returnCount = opponentTarget[0].returnCount; where: {
challengerCarId: opponentTarget[0].carId,
let carTarget = await prisma.car.findFirst({ carId: body.carId
where:{ },
carId: challengers.challengerCarId orderBy:{
}, id: 'desc'
include:{
gtWing: true,
lastPlayedPlace: true
}
})
let result = 0;
if(challengers.result > 0)
{
result = -Math.abs(challengers.result);
}
else{
result = Math.abs(challengers.result);
}
carsChallengers.push(
wm.wm.protobuf.ChallengerCar.create({
car: carTarget!,
stamp: challengers.stamp,
result: result,
area: challengers.area
})
);
} }
});
if(challengers)
{
returnCount = opponentTarget[0].returnCount;
let carTarget = await prisma.car.findFirst({
where:{
carId: challengers.challengerCarId
},
include:{
gtWing: true,
lastPlayedPlace: true
}
})
let result = 0;
if(challengers.result > 0)
{
result = -Math.abs(challengers.result);
}
else{
result = Math.abs(challengers.result);
}
carsChallengers = wm.wm.protobuf.ChallengerCar.create({
car: carTarget!,
stamp: challengers.stamp,
result: result,
area: challengers.area
});
} }
} }
@ -185,9 +195,9 @@ export default class CarModule extends Module {
announceEventModePrize: true, announceEventModePrize: true,
// Stamp or Challenger // Stamp or Challenger
challenger: carsChallengers[0] || null, challenger: carsChallengers || null,
challengerReturnCount: returnCount || null, challengerReturnCount: returnCount || null,
numOfChallengers: carsChallengers.length + 1 || null, numOfChallengers: opponentTargetCount + 1 || null,
// OCM Challenge Top 1 // OCM Challenge Top 1
opponentGhost: opponentGhost || null, opponentGhost: opponentGhost || null,
@ -208,7 +218,6 @@ export default class CarModule extends Module {
// Get the request body for the create car request // Get the request body for the create car request
let body = wm.wm.protobuf.CreateCarRequest.decode(req.body); let body = wm.wm.protobuf.CreateCarRequest.decode(req.body);
console.log(body);
// Get the current date/time (unix epoch) // Get the current date/time (unix epoch)
let date = Math.floor(new Date().getTime() / 1000) let date = Math.floor(new Date().getTime() / 1000)

View File

@ -16,7 +16,6 @@ export async function saveStoryResult(body: wm.protobuf.SaveGameResultRequest, c
if (!(body.retired || body.timeup)) if (!(body.retired || body.timeup))
{ {
console.log('Game not retired / timed out, continuing ...') console.log('Game not retired / timed out, continuing ...')
console.log(body);
// Get the story result for the car // Get the story result for the car
let storyResult = body?.stResult; let storyResult = body?.stResult;