randomizer
This commit is contained in:
parent
9395f1f4f0
commit
035410daec
@ -138,18 +138,37 @@ export async function getOpponentsTarget(carId: number, registeredargetAvailable
|
|||||||
|
|
||||||
// Randomize pick
|
// Randomize pick
|
||||||
let random: number = 1;
|
let random: number = 1;
|
||||||
|
let randomArray: number[] = [];
|
||||||
|
let maxNumber = 5;
|
||||||
|
|
||||||
|
if(opponentTargetCount < 5)
|
||||||
|
{
|
||||||
|
maxNumber = opponentTargetCount;
|
||||||
|
}
|
||||||
|
|
||||||
// Randomize it 5 times
|
// Randomize it 5 times
|
||||||
for(let i=0; i<5; i++)
|
while(randomArray.length < 5)
|
||||||
{
|
{
|
||||||
random = Math.floor(Math.random() * opponentTargetCount);
|
// Pick random car Id
|
||||||
|
random = Math.floor(Math.random() * opponentTargetCount + 0.9);
|
||||||
|
|
||||||
|
// Try randomize it again if it's 0, and fix if more than car length
|
||||||
|
if(random < 1 || random >= opponentTargetCount)
|
||||||
|
{
|
||||||
|
random = Math.floor(Math.random() * opponentTargetCount + 0.9);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try randomize it again if it's 1
|
// Random Number not yet selected
|
||||||
if(random === 1)
|
if(randomArray.indexOf(random) === -1)
|
||||||
{
|
{
|
||||||
random = Math.floor(Math.random() * opponentTargetCount);
|
// Push current number to array
|
||||||
|
randomArray.push(random);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pick the array number
|
||||||
|
let pickRandom = Math.floor(Math.random() * randomArray.length + 0.9);
|
||||||
|
random = randomArray[pickRandom];
|
||||||
|
|
||||||
// Check opponents target
|
// Check opponents target
|
||||||
let opponentTarget = await prisma.carStampTarget.findMany({
|
let opponentTarget = await prisma.carStampTarget.findMany({
|
||||||
@ -157,9 +176,14 @@ export async function getOpponentsTarget(carId: number, registeredargetAvailable
|
|||||||
stampTargetCarId: carId,
|
stampTargetCarId: carId,
|
||||||
recommended: true,
|
recommended: true,
|
||||||
},
|
},
|
||||||
orderBy:{
|
orderBy: [
|
||||||
locked: 'desc'
|
{
|
||||||
|
id: 'asc'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
recommended: 'desc'
|
||||||
|
}
|
||||||
|
],
|
||||||
skip: random,
|
skip: random,
|
||||||
take: 1,
|
take: 1,
|
||||||
});
|
});
|
||||||
@ -205,6 +229,12 @@ export async function getOpponentsTarget(carId: number, registeredargetAvailable
|
|||||||
result = Math.abs(carChallengers.result);
|
result = Math.abs(carChallengers.result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Error handling if regionId is below 1 or above 47
|
||||||
|
if(carTarget!.regionId < 1 || carTarget!.regionId > 47)
|
||||||
|
{
|
||||||
|
carTarget!.regionId = Math.floor(Math.random() * 10) + 10;
|
||||||
|
}
|
||||||
|
|
||||||
// Push the data
|
// Push the data
|
||||||
challenger = wmproto.wm.protobuf.ChallengerCar.create({
|
challenger = wmproto.wm.protobuf.ChallengerCar.create({
|
||||||
car: carTarget,
|
car: carTarget,
|
||||||
@ -322,26 +352,33 @@ export async function createCar(body: wm.protobuf.CreateCarRequest)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Randomize regionId
|
// Randomize pick
|
||||||
let regionId: number = 18;
|
let random: number = 1;
|
||||||
|
let randomArray: number[] = [];
|
||||||
|
|
||||||
// Randomize it 5 times
|
// Randomize it 5 times
|
||||||
for(let i=0; i<5; i++)
|
while(randomArray.length < 5)
|
||||||
{
|
{
|
||||||
regionId = Math.floor(Math.random() * 47) + 1;
|
// Pick random car Id
|
||||||
|
random = Math.floor(Math.random() * 47 + 0.9) + 1;
|
||||||
|
|
||||||
|
// Try randomize it again if it's 0, and fix if more than car length
|
||||||
|
if(random < 1 || random > 47)
|
||||||
|
{
|
||||||
|
random = Math.floor(Math.random() * 47 + 0.9) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try randomize it again if it's 1
|
// Random Number not yet selected
|
||||||
if(regionId === 1)
|
if(randomArray.indexOf(random) === -1)
|
||||||
{
|
{
|
||||||
regionId = Math.floor(Math.random() * 47) + 1;
|
// Push current number to array
|
||||||
|
randomArray.push(random);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error handling if regionId is below 1 or above 47
|
// Pick the array number
|
||||||
if(regionId < 1 || regionId > 47)
|
let pickRandom = Math.floor(Math.random() * randomArray.length + 0.9);
|
||||||
{
|
random = randomArray[pickRandom];
|
||||||
regionId = Math.floor(Math.random() * 10) + 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default car values
|
// Default car values
|
||||||
let carInsert = {
|
let carInsert = {
|
||||||
@ -358,7 +395,7 @@ export async function createCar(body: wm.protobuf.CreateCarRequest)
|
|||||||
carSettingsDbId: settings.dbId,
|
carSettingsDbId: settings.dbId,
|
||||||
carStateDbId: state.dbId,
|
carStateDbId: state.dbId,
|
||||||
carGTWingDbId: gtWing.dbId,
|
carGTWingDbId: gtWing.dbId,
|
||||||
regionId: regionId,
|
regionId: random,
|
||||||
lastPlayedAt: date,
|
lastPlayedAt: date,
|
||||||
lastPlayedPlaceId: 1, // Server Default
|
lastPlayedPlaceId: 1, // Server Default
|
||||||
};
|
};
|
||||||
|
@ -195,7 +195,6 @@ export async function saveOCMGhostHistory(body: wm.protobuf.SaveGameResultReques
|
|||||||
where:{
|
where:{
|
||||||
carId: saveExGhostHistory.carId,
|
carId: saveExGhostHistory.carId,
|
||||||
ocmMainDraw: saveExGhostHistory.ocmMainDraw,
|
ocmMainDraw: saveExGhostHistory.ocmMainDraw,
|
||||||
area: saveExGhostHistory.area,
|
|
||||||
competitionId: ocmEventDate!.competitionId,
|
competitionId: ocmEventDate!.competitionId,
|
||||||
periodId: 0
|
periodId: 0
|
||||||
}
|
}
|
||||||
@ -207,7 +206,7 @@ export async function saveOCMGhostHistory(body: wm.protobuf.SaveGameResultReques
|
|||||||
if(countGBR)
|
if(countGBR)
|
||||||
{
|
{
|
||||||
// Check if the newest advantage distance is bigger than the older advantage distance
|
// Check if the newest advantage distance is bigger than the older advantage distance
|
||||||
if(countGBR!.result < saveExGhostHistory.result)
|
if(countGBR.result < saveExGhostHistory.result)
|
||||||
{
|
{
|
||||||
console.log('OCM Ghost Tally found');
|
console.log('OCM Ghost Tally found');
|
||||||
|
|
||||||
@ -217,7 +216,6 @@ export async function saveOCMGhostHistory(body: wm.protobuf.SaveGameResultReques
|
|||||||
// Get OCM Period ID
|
// Get OCM Period ID
|
||||||
let OCM_periodId = await prisma.oCMPeriod.findFirst({
|
let OCM_periodId = await prisma.oCMPeriod.findFirst({
|
||||||
where:{
|
where:{
|
||||||
competitionDbId: ocmEventDate!.dbId,
|
|
||||||
competitionId: ocmEventDate!.competitionId,
|
competitionId: ocmEventDate!.competitionId,
|
||||||
startAt:
|
startAt:
|
||||||
{
|
{
|
||||||
@ -248,7 +246,6 @@ export async function saveOCMGhostHistory(body: wm.protobuf.SaveGameResultReques
|
|||||||
let getGBR = await prisma.oCMGhostBattleRecord.findFirst({
|
let getGBR = await prisma.oCMGhostBattleRecord.findFirst({
|
||||||
where:{
|
where:{
|
||||||
carId: saveExGhostHistory.carId,
|
carId: saveExGhostHistory.carId,
|
||||||
area: saveExGhostHistory.area,
|
|
||||||
competitionId: ocmEventDate!.competitionId,
|
competitionId: ocmEventDate!.competitionId,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -323,7 +320,7 @@ export async function saveOCMGhostHistory(body: wm.protobuf.SaveGameResultReques
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
console.log('OCM Ghost Battle Record not found');
|
console.log('OCM Ghost Battle Record not found');
|
||||||
console.log('Creating new OOCM Ghost Battle Record entry');
|
console.log('Creating new OCM Ghost Battle Record entry');
|
||||||
|
|
||||||
// Current date is OCM Main Draw
|
// Current date is OCM Main Draw
|
||||||
if(ocmEventDate!.competitionStartAt < date && ocmEventDate!.competitionCloseAt > date)
|
if(ocmEventDate!.competitionStartAt < date && ocmEventDate!.competitionCloseAt > date)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user