1
0
mirror of https://github.com/shiroikitsu8/Bayshore_6r_legacy.git synced 2025-03-01 22:40:25 +01:00

Merge pull request #46 from shiroikitsu8/master-asakura

trying to fix register ocm ghost from terminal
This commit is contained in:
Luna 2022-10-24 18:06:35 +01:00 committed by GitHub
commit ae624fd024
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 73 additions and 188 deletions

View File

@ -52,149 +52,49 @@ export default class CarModule extends Module {
// Get current date // Get current date
let date = Math.floor(new Date().getTime() / 1000); let date = Math.floor(new Date().getTime() / 1000);
// Get current / previous active OCM Event // Get Registered Target
let ocmEventDate = await prisma.oCMEvent.findFirst({ let getTarget = await prisma.ghostRegisteredFromTerminal.findFirst({
where: { where:{
// qualifyingPeriodStartAt is less than current date carId: body.carId
qualifyingPeriodStartAt: { lte: date }, }
});
// competitionEndAt is greater than current date let opponentGhost;
competitionEndAt: { gte: date }, let opponentTrailId;
}, let opponentCompetitionId;
orderBy: [
{
dbId: 'desc'
},
{
competitionEndAt: 'desc',
},
],
});
let pastEvent = 0; if(getTarget)
if(!(ocmEventDate)) {
{
ocmEventDate = await prisma.oCMEvent.findFirst({ let getTargetTrail = await prisma.oCMTop1GhostTrail.findFirst({
orderBy: [ where:{
{ carId: getTarget.opponentCarId,
dbId: 'desc' competitionId: Number(getTarget.competitionId)
}, }
{
competitionEndAt: 'desc',
},
],
}); });
pastEvent = 1; if(getTargetTrail)
} {
let getTargetCar = await prisma.car.findFirst({
// Current / previous OCM Event is found
let ghostCarsNo1;
let trailIdNo1: number = 0;
if(ocmEventDate)
{
let pastDay = date - ocmEventDate.competitionEndAt
// Get Previous Top 1 OCM
if(pastDay < 604800 && pastEvent === 1)
{
let checkRegisteredGhost = await prisma.ghostRegisteredFromTerminal.findFirst({
where:{ where:{
carId: body.carId carId: getTarget.opponentCarId
} }
}); });
if(checkRegisteredGhost) opponentGhost = wm.wm.protobuf.GhostCar.create({
{ car: {
console.log('OCM Ghost Registered From Terminal'); ...getTargetCar!,
tunePower: getTargetTrail!.tunePower,
let getNo1OCM = await prisma.oCMTally.findFirst({ tuneHandling: getTargetTrail!.tuneHandling,
where:{ },
competitionId: ocmEventDate.competitionId, area: getTargetTrail!.area,
periodId: 999999999 ramp: getTargetTrail!.ramp,
}, path: getTargetTrail!.path,
orderBy:{ nonhuman: false,
competitionId: 'desc' type: wm.wm.protobuf.GhostType.GHOST_NORMAL,
} trailId: getTargetTrail!.dbId
}); });
opponentTrailId = Number(getTargetTrail!.dbId);
if(getNo1OCM) opponentCompetitionId = Number(getTarget.competitionId);
{
console.log('Getting registered car data');
// Get Car Data
let cars = await prisma.car.findFirst({
where:{
carId: getNo1OCM.carId
},
include:{
gtWing: true,
lastPlayedPlace: true
}
});
// Get Ghost Trail
let ghostTrailNo1 = await prisma.oCMTop1GhostTrail.findFirst({
where:{
carId: getNo1OCM.carId,
competitionId: ocmEventDate.competitionId
},
orderBy:{
dbId: 'asc'
}
});
if(ghostTrailNo1)
{
console.log('Getting registered ghost trail');
trailIdNo1 = ghostTrailNo1.dbId;
ghostCarsNo1 = wm.wm.protobuf.GhostCar.create({
car: {
...cars!,
},
area: ghostTrailNo1.area,
ramp: ghostTrailNo1.ramp,
path: ghostTrailNo1.path,
nonhuman: false,
type: wm.wm.protobuf.GhostType.GHOST_NORMAL,
trailId: trailIdNo1
});
}
else
{
ghostTrailNo1 = await prisma.oCMGhostTrail.findFirst({
where:{
carId: getNo1OCM.carId,
competitionId: ocmEventDate.competitionId
},
orderBy:{
playedAt: 'desc'
}
});
if(ghostTrailNo1)
{
console.log('Getting registered ghost trail from other table');
trailIdNo1 = ghostTrailNo1.dbId;
ghostCarsNo1 = wm.wm.protobuf.GhostCar.create({
car: {
...cars!,
},
area: ghostTrailNo1.area,
ramp: ghostTrailNo1.ramp,
path: ghostTrailNo1.path,
nonhuman: false,
type: wm.wm.protobuf.GhostType.GHOST_NORMAL,
trailId: trailIdNo1
});
}
}
}
}
} }
} }
@ -290,9 +190,9 @@ export default class CarModule extends Module {
numOfChallengers: carsChallengers.length + 1 || null, numOfChallengers: carsChallengers.length + 1 || null,
// OCM Challenge Top 1 // OCM Challenge Top 1
opponentGhost: ghostCarsNo1 || null, opponentGhost: opponentGhost || null,
opponentTrailId: trailIdNo1 || null, opponentTrailId: opponentTrailId || null,
opponentCompetitionId: ocmEventDate?.competitionId || null opponentCompetitionId: opponentCompetitionId || null
}; };
// Generate the load car response message // Generate the load car response message
@ -635,6 +535,8 @@ export default class CarModule extends Module {
// Car update data // Car update data
data = { data = {
name: common.sanitizeInput(cars.name),
visualModel: common.sanitizeInput(cars.visualModel),
customColor: common.sanitizeInput(cars.customColor), customColor: common.sanitizeInput(cars.customColor),
wheel: common.sanitizeInput(cars.wheel), wheel: common.sanitizeInput(cars.wheel),
wheelColor: common.sanitizeInput(cars.wheelColor), wheelColor: common.sanitizeInput(cars.wheelColor),

View File

@ -706,6 +706,7 @@ export default class GhostModule extends Module {
let msg = { let msg = {
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS, error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
competitionId: competition_id, competitionId: competition_id,
specialGhostId: competition_id,
ghostCar: ghostCars!, ghostCar: ghostCars!,
trailId: ghostTrailId, trailId: ghostTrailId,
updatedAt: date, updatedAt: date,

View File

@ -906,64 +906,46 @@ export default class TerminalModule extends Module {
// Get the information from the request // Get the information from the request
let body = wm.wm.protobuf.RegisterOpponentGhostRequest.decode(req.body); let body = wm.wm.protobuf.RegisterOpponentGhostRequest.decode(req.body);
let ocmEventDate = await prisma.oCMEvent.findFirst({ // Check if target is already registered
orderBy: [ let checkOpponent = await prisma.ghostRegisteredFromTerminal.findFirst({
{ where:{
dbId: 'desc' carId: body.carId,
}, }
{
competitionEndAt: 'desc',
},
],
}); });
if(ocmEventDate) // Get Target Car ID
let ghostCompetitionTarget = await prisma.oCMTop1Ghost.findFirst({
where:{
competitionId: body.specialGhostId,
},
orderBy:{
periodId: 'desc'
}
});
// Target not yet registerted
if(!(checkOpponent))
{ {
let checkRegisteredGhost = await prisma.ghostRegisteredFromTerminal.findFirst({ await prisma.ghostRegisteredFromTerminal.create({
where:{ data:{
carId: body.carId carId: body.carId,
competitionId: body.specialGhostId,
opponentCarId: ghostCompetitionTarget!.carId
} }
}); });
}
let getNo1OCM = await prisma.oCMTally.findFirst({ else
{
await prisma.ghostRegisteredFromTerminal.update({
where:{ where:{
competitionId: ocmEventDate.competitionId, dbId: checkOpponent.dbId
periodId: 999999999
}, },
orderBy:{ data:{
competitionId: 'desc' carId: body.carId,
competitionId: body.specialGhostId,
opponentCarId: ghostCompetitionTarget!.carId
} }
}); });
if(!(checkRegisteredGhost))
{
await prisma.ghostRegisteredFromTerminal.create({
data:{
carId: body.carId,
competitionId: ocmEventDate!.competitionId,
opponentCarId: getNo1OCM!.carId
}
});
console.log('Creating new Register Ghost Opponent entry')
}
else
{
await prisma.ghostRegisteredFromTerminal.update({
where:{
dbId: checkRegisteredGhost.dbId
},
data:{
carId: body.carId,
competitionId: ocmEventDate!.competitionId,
opponentCarId: getNo1OCM!.carId
}
});
console.log('Updating Register Ghost Opponent entry')
}
} }
// Response data // Response data