1
0
mirror of https://github.com/shiroikitsu8/Bayshore_6r_legacy.git synced 2024-11-28 01:11:00 +01:00

update randomize search by name

This commit is contained in:
Shiroi Kitsu 2023-03-15 20:19:16 +07:00
parent 522a60957b
commit 16232c0083

View File

@ -186,7 +186,9 @@ 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; let cars: wm.wm.protobuf.Car[] = [];
let car;
let arr = [];
// Check the query limit // Check the query limit
let queryLimit = 10 let queryLimit = 10
@ -210,22 +212,23 @@ export default class TerminalModule extends Module {
queryLastPlayedPlaceId = getLastPlayedPlaceId.id; queryLastPlayedPlaceId = getLastPlayedPlaceId.id;
} }
cars = await prisma.car.findMany({ car = await prisma.car.findMany({
take: queryLimit,
where: { where: {
lastPlayedPlaceId: queryLastPlayedPlaceId lastPlayedPlaceId: queryLastPlayedPlaceId
}, },
include:{ include:{
gtWing: true, gtWing: true,
lastPlayedPlace: true lastPlayedPlace: true
},
orderBy: {
carId: "asc"
} }
}); });
} }
else else
{ {
// Get all of the cars matching the query // Get all of the cars matching the query
cars = await prisma.car.findMany({ car = await prisma.car.findMany({
take: queryLimit,
where: { where: {
OR:[ OR:[
{ {
@ -244,10 +247,50 @@ export default class TerminalModule extends Module {
include:{ include:{
gtWing: true, gtWing: true,
lastPlayedPlace: true lastPlayedPlace: true
},
orderBy: {
carId: "asc"
} }
}); });
} }
if(car.length > 0)
{
if(car.length < queryLimit)
{
queryLimit = car.length;
}
// Choose the user's car data randomly to appear
while(arr.length < queryLimit)
{
// Randomize pick
let random: number = 1;
// Randomize it 5 times
for(let i=0; i<5; i++)
{
random = Math.floor(Math.random() * car.length);
}
// Try randomize it again if it's 1
if(random === 1)
{
random = Math.floor(Math.random() * car.length);
}
if(arr.indexOf(random) === -1)
{
// Push current number to array
arr.push(random);
cars.push(wm.wm.protobuf.Car.create({
...car[random]
}));
}
}
}
let msg = { let msg = {
hitCount: cars.length, hitCount: cars.length,
cars: cars cars: cars