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

Merge pull request #65 from shiroikitsu8/master

limit terminal ocm ranking to 150, fix ghost search by region, preven TA record more than 20 minutes
This commit is contained in:
Luna 2023-03-07 10:19:13 +00:00 committed by GitHub
commit fafb3490f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 324 additions and 242 deletions

View File

@ -23,7 +23,7 @@ export default class CarModule extends Module {
// Get the car (required data only) with the given id
let car = await carFunctions.getCar(body.carId);
// Get Challenger Data
// Get Registered HoF Data
let registeredTarget = await carFunctions.getRegisteredTarget(body.carId);
// Get Challenger Data

View File

@ -150,12 +150,12 @@ export async function getOpponentsTarget(carId: number, registeredargetAvailable
while(randomArray.length < maxNumber)
{
// Pick random car Id
random = Math.floor(Math.random() * opponentTargetCount + 0.9);
random = Math.floor(Math.random() * opponentTargetCount);
// 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);
random = Math.floor(Math.random() * opponentTargetCount);
}
// Random Number not yet selected
@ -167,7 +167,7 @@ export async function getOpponentsTarget(carId: number, registeredargetAvailable
}
// Pick the array number
let pickRandom = Math.floor(Math.random() * randomArray.length + 0.9);
let pickRandom = Math.floor(Math.random() * randomArray.length);
random = randomArray[pickRandom];
// Check opponents target
@ -360,12 +360,12 @@ export async function createCar(body: wm.protobuf.CreateCarRequest)
while(randomArray.length < 5)
{
// Pick random car Id
random = Math.floor(Math.random() * 47 + 0.9) + 1;
random = Math.floor(Math.random() * 47) + 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;
random = Math.floor(Math.random() * 47) + 1;
}
// Random Number not yet selected
@ -377,7 +377,7 @@ export async function createCar(body: wm.protobuf.CreateCarRequest)
}
// Pick the array number
let pickRandom = Math.floor(Math.random() * randomArray.length + 0.9);
let pickRandom = Math.floor(Math.random() * randomArray.length);
random = randomArray[pickRandom];
// Default car values

View File

@ -58,8 +58,8 @@ export async function saveTimeAttackResult(body: wm.protobuf.SaveGameResultReque
// Record already exists
if (currentRecord)
{
// If the existing record is faster, do not continue
if (body.taResult!.time < currentRecord.time)
// Current time record is faster than previous time record and time record is below 20 minutes
if (body.taResult!.time < currentRecord.time && body.taResult!.time < 1200000)
{
console.log('Updating time attack record...');

View File

@ -149,9 +149,9 @@ export default class GhostModule extends Module {
let lists_ghostcar = getGhostCar.lists_ghostcar;
// Check again if car list for that selected region is available of not
if(body.regionId !== null && body.regionId !== undefined && body.regionId !== 0)
if(body.regionId !== null && body.regionId !== undefined && body.regionId !== 0 && car.length < 1)
{
let checkGhostSearchByRegion = await ghostFunctions.checkGhostSearchByRegion(car, body.ghostLevel, body.regionId);
let checkGhostSearchByRegion = await ghostFunctions.checkGhostSearchByRegion(body.ghostLevel, body.regionId);
lists_ghostcar = checkGhostSearchByRegion.lists_ghostcar;
}

View File

@ -15,9 +15,10 @@ export async function getOpponentHistory(carId: number)
orderBy:{
lastPlayedAt: 'desc'
},
take: 10
})
take: 20
});
let opponentHistory: wmproto.wm.protobuf.Car[] = [];
let inserted = 0;
if(findChallenger.length > 0)
{
@ -30,22 +31,28 @@ export async function getOpponentHistory(carId: number)
include:{
gtWing: true,
lastPlayedPlace: true
},
orderBy: {
carId: 'asc'
},
take: 10
}
});
// Error handling if regionId is below 1 or above 47
if(car!.regionId < 1 || car!.regionId > 47)
if(car)
{
car!.regionId = Math.floor(Math.random() * 10) + 10;
// Error handling if regionId is below 1 or above 47
if(car!.regionId < 1 || car!.regionId > 47)
{
car!.regionId = Math.floor(Math.random() * 10) + 10;
}
opponentHistory.push(wmproto.wm.protobuf.Car.create({
...car!
}));
inserted++;
}
opponentHistory.push(wmproto.wm.protobuf.Car.create({
...car!
}))
if(inserted > 10)
{
break;
}
}
}
@ -64,7 +71,8 @@ export async function getStampTarget(carId: number)
},
orderBy:{
locked: 'desc'
}
},
take: 10
});
let stampTarget: wmproto.wm.protobuf.StampTargetCar[] = [];
@ -119,18 +127,21 @@ export async function getChallengers(carId: number)
let challengers: wmproto.wm.protobuf.ChallengerCar[] = [];
let arrChallengerCarId = [];
// Push beated carId to array
for(let i=0; i<checkBeatedCar.length; i++)
{
arrChallengerCarId.push(checkBeatedCar[i].carId);
}
// Find Opponent Challengers except beated car
let getChallengers = await prisma.carChallenger.findMany({
where: {
carId: carId,
NOT: {
challengerCarId: { in: arrChallengerCarId }, // Except beated challenger id
},
}
}
},
take: 10
});
if(getChallengers)
@ -270,122 +281,118 @@ export async function getGhostCar(car: any, area: number, ramp: number, path: nu
// Check Ghost Car when using Search by Region
export async function checkGhostSearchByRegion(car: any, ghostLevel: number, regionId: number)
export async function checkGhostSearchByRegion(ghostLevel: number, regionId: number)
{
let lists_ghostcar: any;
// Get current date
let date = Math.floor(new Date().getTime() / 1000);
let playedPlace = wmproto.wm.protobuf.Place.create({
placeId: Config.getConfig().placeId,
regionId: Config.getConfig().regionId,
shopName: Config.getConfig().shopName,
country: Config.getConfig().country
});
if(car.length < 1)
let tunePowerDefault = 0
let tuneHandlingDefault = 0;
if(ghostLevel === 1)
{
// Get current date
let date = Math.floor(new Date().getTime() / 1000);
let playedPlace = wmproto.wm.protobuf.Place.create({
placeId: Config.getConfig().placeId,
regionId: Config.getConfig().regionId,
shopName: Config.getConfig().shopName,
country: Config.getConfig().country
});
let tunePowerDefault = 0
let tuneHandlingDefault = 0;
if(ghostLevel === 1)
{
tunePowerDefault = 1;
tuneHandlingDefault = 4;
}
else if(ghostLevel === 2)
{
tunePowerDefault = 5;
tuneHandlingDefault = 5;
}
else if(ghostLevel === 3)
{
tunePowerDefault = 8;
tuneHandlingDefault = 7;
}
else if(ghostLevel === 4)
{
tunePowerDefault = 10;
tuneHandlingDefault = 10;
}
else if(ghostLevel === 5)
{
tunePowerDefault = 15;
tuneHandlingDefault = 10;
}
else if(ghostLevel === 6)
{
tunePowerDefault = 18;
tuneHandlingDefault = 10;
}
else if(ghostLevel === 7)
{
tunePowerDefault = 20;
tuneHandlingDefault = 10;
}
else if(ghostLevel === 8)
{
tunePowerDefault = 21;
tuneHandlingDefault = 10;
}
else if(ghostLevel === 9)
{
tunePowerDefault = 22;
tuneHandlingDefault = 10;
}
else if(ghostLevel === 10)
{
tunePowerDefault = 24;
tuneHandlingDefault = 10;
}
else if(ghostLevel === 11)
{
tunePowerDefault = 24;
tuneHandlingDefault = 24;
}
// Generate default S660 car data
car = wmproto.wm.protobuf.Car.create({
carId: 999999999, // Don't change this
name: '',
regionId: regionId, // IDN (福井)
manufacturer: 12, // HONDA
model: 105, // S660 [JW5]
visualModel: 130, // S660 [JW5]
defaultColor: 0,
customColor: 0,
wheel: 20,
wheelColor: 0,
aero: 0,
bonnet: 0,
wing: 0,
mirror: 0,
neon: 0,
trunk: 0,
plate: 0,
plateColor: 0,
plateNumber: 0,
tunePower: tunePowerDefault,
tuneHandling: tuneHandlingDefault,
rivalMarker: 32,
aura: 551,
windowSticker: true,
windowStickerString: '',
windowStickerFont: 0,
title: 'No Ghost for this Region',
level: 65, // SSSSS
lastPlayedAt: date,
country: 'JPN',
lastPlayedPlace: playedPlace
});
// Push data to Ghost car proto
lists_ghostcar.push(wmproto.wm.protobuf.GhostCar.create({
car: car,
nonhuman: true,
type: wmproto.wm.protobuf.GhostType.GHOST_DEFAULT,
}));
tunePowerDefault = 1;
tuneHandlingDefault = 4;
}
else if(ghostLevel === 2)
{
tunePowerDefault = 5;
tuneHandlingDefault = 5;
}
else if(ghostLevel === 3)
{
tunePowerDefault = 8;
tuneHandlingDefault = 7;
}
else if(ghostLevel === 4)
{
tunePowerDefault = 10;
tuneHandlingDefault = 10;
}
else if(ghostLevel === 5)
{
tunePowerDefault = 15;
tuneHandlingDefault = 10;
}
else if(ghostLevel === 6)
{
tunePowerDefault = 18;
tuneHandlingDefault = 10;
}
else if(ghostLevel === 7)
{
tunePowerDefault = 20;
tuneHandlingDefault = 10;
}
else if(ghostLevel === 8)
{
tunePowerDefault = 21;
tuneHandlingDefault = 10;
}
else if(ghostLevel === 9)
{
tunePowerDefault = 22;
tuneHandlingDefault = 10;
}
else if(ghostLevel === 10)
{
tunePowerDefault = 24;
tuneHandlingDefault = 10;
}
else if(ghostLevel === 11)
{
tunePowerDefault = 24;
tuneHandlingDefault = 24;
}
// Generate default S660 car data
let car = wmproto.wm.protobuf.Car.create({
carId: 999999999, // Don't change this
name: '',
regionId: regionId, // IDN (福井)
manufacturer: 12, // HONDA
model: 105, // S660 [JW5]
visualModel: 130, // S660 [JW5]
defaultColor: 0,
customColor: 0,
wheel: 20,
wheelColor: 0,
aero: 0,
bonnet: 0,
wing: 0,
mirror: 0,
neon: 0,
trunk: 0,
plate: 0,
plateColor: 0,
plateNumber: 0,
tunePower: tunePowerDefault,
tuneHandling: tuneHandlingDefault,
rivalMarker: 32,
aura: 551,
windowSticker: true,
windowStickerString: '',
windowStickerFont: 0,
title: 'No Ghost for this Region',
level: 65, // SSSSS
lastPlayedAt: date,
country: 'JPN',
lastPlayedPlace: playedPlace
});
// Push data to Ghost car proto
let lists_ghostcar: wmproto.wm.protobuf.GhostCar[] = [];
lists_ghostcar.push(wmproto.wm.protobuf.GhostCar.create({
car: car,
nonhuman: true,
type: wmproto.wm.protobuf.GhostType.GHOST_DEFAULT,
}));
return { lists_ghostcar }
}

View File

@ -588,10 +588,10 @@ export async function ocmGiveNamePlateReward(competitionId: number)
let participantLength = getCarParticipant.length;
// Participant is more than 100
if(participantLength > 100)
// Participant is more than certain number (100 is default)
if(participantLength > 25)
{
participantLength = 100
participantLength = 25;
}
// 16th - C1

View File

@ -101,7 +101,20 @@ export async function competitionSchedule(date: any, competitionId: any)
// It's previous Competition (OCM) event
if(pastEvent === 1)
{
lastCompetitionId = ghostCompetitionSchedule.competitionId;
// Get current date
let dates = Math.floor(new Date().getTime() / 1000);
let lastScheduleCompetitionId = await prisma.oCMEvent.findFirst({
where: {
competitionCloseAt: { lte: dates }
},
orderBy:{
competitionId: 'desc'
}
});
lastCompetitionId = lastScheduleCompetitionId?.competitionId || 0;
}
// Competition (OCM) Response Message

View File

@ -635,32 +635,36 @@ export default class TerminalModule extends Module {
periodId: 'desc'
}
],
include:{
car: true
},
distinct: ["carId"],
})
numOfParticipants = ocmParticipant.length;
periodId = 0;
let ranking = 0;
let maxNumber = 150;
if(ocmParticipant)
if(numOfParticipants < 151)
{
maxNumber = numOfParticipants;
}
if(numOfParticipants > 0)
{
periodId = ocmParticipant[0].periodId;
for(let i=0; i<ocmParticipant.length; i++)
for(let i=0; i<maxNumber; i++)
{
let cars = await prisma.car.findFirst({
where:{
carId: ocmParticipant[i].carId
},
include:{
gtWing: true,
lastPlayedPlace: true
}
});
let ocmGhostrecord = await prisma.oCMGhostBattleRecord.findFirst({
where:{
carId: ocmParticipant[0].carId,
competitionId: ocmEventDate!.competitionId,
},
select:{
playedShopName: true,
playedAt: true
}
});
@ -676,14 +680,14 @@ export default class TerminalModule extends Module {
rank: i + 1,
result: ocmParticipant[i].result,
carId: ocmParticipant[i].carId,
name: cars!.name,
regionId: cars!.regionId,
model: cars!.model,
visualModel: cars!.visualModel,
defaultColor: cars!.defaultColor,
title: cars!.title,
level: cars!.level,
windowStickerString: cars!.windowStickerString,
name: ocmParticipant[i].car.name,
regionId: ocmParticipant[i].car.regionId,
model: ocmParticipant[i].car.model,
visualModel: ocmParticipant[i].car.visualModel,
defaultColor: ocmParticipant[i].car.defaultColor,
title: ocmParticipant[i].car.title,
level: ocmParticipant[i].car.level,
windowStickerString: ocmParticipant[i].car.windowStickerString,
playedShopName: playedShopName,
playedAt: ocmGhostrecord!.playedAt
});
@ -696,18 +700,56 @@ export default class TerminalModule extends Module {
rank: i + 1,
result: ocmParticipant[i].result,
carId: ocmParticipant[i].carId,
name: cars!.name,
regionId: cars!.regionId,
model: cars!.model,
visualModel: cars!.visualModel,
defaultColor: cars!.defaultColor,
title: cars!.title,
level: cars!.level,
windowStickerString: cars!.windowStickerString,
name: ocmParticipant[i].car.name,
regionId: ocmParticipant[i].car.regionId,
model: ocmParticipant[i].car.model,
visualModel: ocmParticipant[i].car.visualModel,
defaultColor: ocmParticipant[i].car.defaultColor,
title: ocmParticipant[i].car.title,
level: ocmParticipant[i].car.level,
windowStickerString: ocmParticipant[i].car.windowStickerString,
playedShopName: playedShopName,
playedAt: ocmGhostrecord!.playedAt
}));
}
if(!(ownRecords))
{
for(let i=150; i<numOfParticipants; i++)
{
if(ocmParticipant[i].carId === body.carId)
{
let ocmGhostrecord = await prisma.oCMGhostBattleRecord.findFirst({
where:{
carId: body.carId,
competitionId: ocmEventDate!.competitionId,
},
select:{
playedAt: true
}
});
// User car setting
ownRecords = wm.wm.protobuf.LoadGhostCompetitionRankingResponse.Entry.create({
rank: i + 1,
result: ocmParticipant[i].result,
carId: ocmParticipant[i].carId,
name: ocmParticipant[i].car.name,
regionId: ocmParticipant[i].car.regionId,
model: ocmParticipant[i].car.model,
visualModel: ocmParticipant[i].car.visualModel,
defaultColor: ocmParticipant[i].car.defaultColor,
title: ocmParticipant[i].car.title,
level: ocmParticipant[i].car.level,
windowStickerString: ocmParticipant[i].car.windowStickerString,
playedShopName: playedShopName,
playedAt: ocmGhostrecord!.playedAt
});
break;
}
}
}
}
}
// Current date is OCM qualifying day
@ -721,27 +763,21 @@ export default class TerminalModule extends Module {
},
orderBy: {
result: 'desc'
}
},
include:{
car: true
},
distinct: ["carId"],
})
numOfParticipants = ocmParticipant.length;
periodId = 0;
let ranking = 0;
if(ocmParticipant)
if(numOfParticipants > 0)
{
for(let i=0; i<ocmParticipant.length; i++)
for(let i=0; i<numOfParticipants; i++)
{
let cars = await prisma.car.findFirst({
where:{
carId: ocmParticipant[i].carId
},
include:{
gtWing: true,
lastPlayedPlace: true
}
})
if(ocmParticipant[i].carId === body.carId && ranking === 0)
{
// User car setting
@ -749,37 +785,21 @@ export default class TerminalModule extends Module {
rank: i + 1,
result: ocmParticipant[i].result,
carId: ocmParticipant[i].carId,
name: cars!.name,
regionId: cars!.regionId,
model: cars!.model,
visualModel: cars!.visualModel,
defaultColor: cars!.defaultColor,
title: cars!.title,
level: cars!.level,
windowStickerString: cars!.windowStickerString,
playedShopName: ocmParticipant[i].playedShopName,
name: ocmParticipant[i].car.name,
regionId: ocmParticipant[i].car.regionId,
model: ocmParticipant[i].car.model,
visualModel: ocmParticipant[i].car.visualModel,
defaultColor: ocmParticipant[i].car.defaultColor,
title: ocmParticipant[i].car.title,
level: ocmParticipant[i].car.level,
windowStickerString: ocmParticipant[i].car.windowStickerString,
playedShopName: playedShopName,
playedAt: ocmParticipant[i].playedAt
});
ranking++;
break;
}
// Generate OCM Top Records
topRecords.push(wm.wm.protobuf.LoadGhostCompetitionRankingResponse.Entry.create({
rank: i + 1,
result: ocmParticipant[i].result,
carId: ocmParticipant[i].carId,
name: cars!.name,
regionId: cars!.regionId,
model: cars!.model,
visualModel: cars!.visualModel,
defaultColor: cars!.defaultColor,
title: cars!.title,
level: cars!.level,
windowStickerString: cars!.windowStickerString,
playedShopName: ocmParticipant[i].playedShopName,
playedAt: ocmParticipant[i].playedAt
}));
}
}
}
@ -795,31 +815,35 @@ export default class TerminalModule extends Module {
},
orderBy: {
result: 'desc'
}
},
include:{
car: true
},
distinct: ["carId"]
})
numOfParticipants = ocmParticipant.length;
periodId = 0;
let ranking = 0;
let maxNumber = 150;
if(ocmParticipant)
if(numOfParticipants < 151)
{
for(let i=0; i<ocmParticipant.length; i++)
{
let cars = await prisma.car.findFirst({
where:{
carId: ocmParticipant[i].carId
},
include:{
gtWing: true,
lastPlayedPlace: true
}
});
maxNumber = numOfParticipants;
}
if(numOfParticipants > 0)
{
for(let i=0; i<maxNumber; i++)
{
let ocmGhostrecord = await prisma.oCMGhostBattleRecord.findFirst({
where:{
carId: ocmParticipant[0].carId,
carId: ocmParticipant[i].carId,
competitionId: ocmEventDate!.competitionId,
},
select:{
playedShopName: true,
playedAt: true
}
});
@ -830,14 +854,14 @@ export default class TerminalModule extends Module {
rank: i + 1,
result: ocmParticipant[i].result,
carId: ocmParticipant[i].carId,
name: cars!.name,
regionId: cars!.regionId,
model: cars!.model,
visualModel: cars!.visualModel,
defaultColor: cars!.defaultColor,
title: cars!.title,
level: cars!.level,
windowStickerString: cars!.windowStickerString,
name: ocmParticipant[i].car.name,
regionId: ocmParticipant[i].car.regionId,
model: ocmParticipant[i].car.model,
visualModel: ocmParticipant[i].car.visualModel,
defaultColor: ocmParticipant[i].car.defaultColor,
title: ocmParticipant[i].car.title,
level: ocmParticipant[i].car.level,
windowStickerString: ocmParticipant[i].car.windowStickerString,
playedShopName: ocmGhostrecord!.playedShopName,
playedAt: ocmGhostrecord!.playedAt
});
@ -850,18 +874,56 @@ export default class TerminalModule extends Module {
rank: i + 1,
result: ocmParticipant[i].result,
carId: ocmParticipant[i].carId,
name: cars!.name,
regionId: cars!.regionId,
model: cars!.model,
visualModel: cars!.visualModel,
defaultColor: cars!.defaultColor,
title: cars!.title,
level: cars!.level,
windowStickerString: cars!.windowStickerString,
name: ocmParticipant[i].car.name,
regionId: ocmParticipant[i].car.regionId,
model: ocmParticipant[i].car.model,
visualModel: ocmParticipant[i].car.visualModel,
defaultColor: ocmParticipant[i].car.defaultColor,
title: ocmParticipant[i].car.title,
level: ocmParticipant[i].car.level,
windowStickerString: ocmParticipant[i].car.windowStickerString,
playedShopName: ocmGhostrecord!.playedShopName,
playedAt: ocmGhostrecord!.playedAt
}));
}
if(!(ownRecords))
{
for(let i=maxNumber; i<numOfParticipants; i++)
{
if(ocmParticipant[i].carId === body.carId)
{
let ocmGhostrecord = await prisma.oCMGhostBattleRecord.findFirst({
where:{
carId: body.carId,
competitionId: ocmEventDate!.competitionId,
},
select:{
playedAt: true
}
});
// User car setting
ownRecords = wm.wm.protobuf.LoadGhostCompetitionRankingResponse.Entry.create({
rank: i + 1,
result: ocmParticipant[i].result,
carId: ocmParticipant[i].carId,
name: ocmParticipant[i].car.name,
regionId: ocmParticipant[i].car.regionId,
model: ocmParticipant[i].car.model,
visualModel: ocmParticipant[i].car.visualModel,
defaultColor: ocmParticipant[i].car.defaultColor,
title: ocmParticipant[i].car.title,
level: ocmParticipant[i].car.level,
windowStickerString: ocmParticipant[i].car.windowStickerString,
playedShopName: playedShopName,
playedAt: ocmGhostrecord!.playedAt
});
break;
}
}
}
}
}

View File

@ -236,8 +236,8 @@ export default class UserModule extends Module {
if (user.carOrder.length > 0)
{
// Sort the player's car list using the car order property
user.cars = user.cars.sort(function(a, b){
user.cars = user.cars.sort(function(a, b)
{
// User, and both car IDs exist
if (user)
{