1
0
mirror of synced 2025-02-01 12:18:01 +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
let opponentTarget = await prisma.carStampTarget.findMany({
let opponentTargetCount = await prisma.carStampTarget.count({
where:{
stampTargetCarId: body.carId,
recommended: true,
@ -108,16 +108,29 @@ export default class CarModule extends Module {
locked: 'desc'
}
})
let carsChallengers: wm.wm.protobuf.ChallengerCar[] = [];
let carsChallengers;
let returnCount = 1;
if(opponentTarget.length > 0)
if(opponentTargetCount > 0)
{
console.log('Challengers Available');
for(let i=0; i<opponentTarget.length; i++)
{
// Randomize pick
let random: number = Math.floor(Math.random() * opponentTargetCount);
// Check opponents target
let opponentTarget = await prisma.carStampTarget.findMany({
where:{
stampTargetCarId: body.carId,
recommended: true,
},
orderBy:{
locked: 'desc'
},
skip: random,
take: 1,
});
// Get all of the friend cars for the carId provided
let challengers = await prisma.carChallenger.findFirst({
where: {
@ -152,15 +165,12 @@ export default class CarModule extends Module {
result = Math.abs(challengers.result);
}
carsChallengers.push(
wm.wm.protobuf.ChallengerCar.create({
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,
// Stamp or Challenger
challenger: carsChallengers[0] || null,
challenger: carsChallengers || null,
challengerReturnCount: returnCount || null,
numOfChallengers: carsChallengers.length + 1 || null,
numOfChallengers: opponentTargetCount + 1 || null,
// OCM Challenge Top 1
opponentGhost: opponentGhost || null,
@ -208,7 +218,6 @@ 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)

View File

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