detect force finish
This commit is contained in:
parent
32cc93c227
commit
8f3be6b168
21
prisma/migrations/20230330051225_test_ff/migration.sql
Normal file
21
prisma/migrations/20230330051225_test_ff/migration.sql
Normal file
@ -0,0 +1,21 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Car" ALTER COLUMN "stLoseBits" SET DEFAULT 0;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "FileList" ALTER COLUMN "filePath" DROP DEFAULT;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "CarCrownDetect" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"carId" INTEGER NOT NULL,
|
||||
"status" TEXT NOT NULL DEFAULT '',
|
||||
"area" INTEGER,
|
||||
"ramp" INTEGER,
|
||||
"path" INTEGER,
|
||||
"trail" BYTEA,
|
||||
"playedAt" INTEGER,
|
||||
"tunePower" INTEGER,
|
||||
"tuneHandling" INTEGER,
|
||||
|
||||
CONSTRAINT "CarCrownDetect_pkey" PRIMARY KEY ("id")
|
||||
);
|
5
prisma/migrations/20230330053201_test_ff_2/migration.sql
Normal file
5
prisma/migrations/20230330053201_test_ff_2/migration.sql
Normal file
@ -0,0 +1,5 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Car" ALTER COLUMN "stLoseBits" SET DEFAULT 0;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "CarCrownDetect" ADD COLUMN "opponentCarId" INTEGER;
|
@ -446,5 +446,19 @@ model FileList {
|
||||
sha1sum String
|
||||
notBefore Int
|
||||
notAfter Int
|
||||
filePath String @default("")
|
||||
filePath String
|
||||
}
|
||||
|
||||
model CarCrownDetect {
|
||||
id Int @id @default(autoincrement())
|
||||
carId Int
|
||||
status String @default("")
|
||||
area Int?
|
||||
ramp Int?
|
||||
path Int?
|
||||
trail Bytes?
|
||||
playedAt Int?
|
||||
tunePower Int?
|
||||
tuneHandling Int?
|
||||
opponentCarId Int?
|
||||
}
|
@ -236,6 +236,99 @@ export default class GameModule extends Module {
|
||||
// Perform the save screenshot request for the car
|
||||
await gameFunction.saveScreenshot(body);
|
||||
|
||||
// Check retire crown
|
||||
let getCarCrown = await prisma.carCrownDetect.findFirst({
|
||||
where:{
|
||||
carId: body.carId
|
||||
}
|
||||
});
|
||||
|
||||
if(getCarCrown)
|
||||
{
|
||||
if(getCarCrown.status === 'retire')
|
||||
{
|
||||
await prisma.carCrownDetect.delete({
|
||||
where:{
|
||||
id: getCarCrown.id
|
||||
}
|
||||
});
|
||||
}
|
||||
else if(getCarCrown.status === 'finish')
|
||||
{
|
||||
let timestamp = body.playedAt - body.timestamp;
|
||||
|
||||
if(timestamp <= 120)
|
||||
{
|
||||
// Update the user status
|
||||
await prisma.carCrownDetect.update({
|
||||
where:{
|
||||
id: getCarCrown.id
|
||||
},
|
||||
data:{
|
||||
status: 'forcefinish'
|
||||
}
|
||||
});
|
||||
|
||||
// Restore the old crown
|
||||
await prisma.carCrown.update({
|
||||
where:{
|
||||
area: getCarCrown.area!
|
||||
},
|
||||
data:{
|
||||
carId: getCarCrown.opponentCarId!,
|
||||
area: getCarCrown.area!,
|
||||
ramp: getCarCrown.ramp!,
|
||||
path: getCarCrown.path!,
|
||||
playedAt: getCarCrown.playedAt!,
|
||||
tunePower: getCarCrown.tunePower!,
|
||||
tuneHandling: getCarCrown.tuneHandling!,
|
||||
}
|
||||
});
|
||||
|
||||
await prisma.ghostTrail.updateMany({
|
||||
where:{
|
||||
area: getCarCrown.area!,
|
||||
crownBattle: true
|
||||
},
|
||||
data:{
|
||||
carId: getCarCrown.opponentCarId!,
|
||||
area: getCarCrown.area!,
|
||||
ramp: getCarCrown.ramp!,
|
||||
path: getCarCrown.path!,
|
||||
playedAt: getCarCrown.playedAt!,
|
||||
tunePower: getCarCrown.tunePower!,
|
||||
tuneHandling: getCarCrown.tuneHandling!,
|
||||
trail: getCarCrown.trail!
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Banned the user
|
||||
let getUserId = await prisma.car.findFirst({
|
||||
where:{
|
||||
carId: body.carId
|
||||
},
|
||||
select:{
|
||||
userId: true
|
||||
}
|
||||
})
|
||||
|
||||
if(getUserId)
|
||||
{
|
||||
await prisma.user.update({
|
||||
where:{
|
||||
id: getUserId.userId
|
||||
},
|
||||
data:{
|
||||
userBanned: true
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Response data
|
||||
let msg = {
|
||||
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
|
||||
|
@ -200,6 +200,9 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ
|
||||
|
||||
// Declare data
|
||||
let dataCrown : any;
|
||||
let area = 0;
|
||||
let ramp = 0;
|
||||
let path = 0;
|
||||
|
||||
// ghostResultCrown is set
|
||||
if (ghostResultCrown)
|
||||
@ -219,9 +222,6 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ
|
||||
}
|
||||
|
||||
// Get the area id and ramp id
|
||||
let area = 0;
|
||||
let ramp = 0;
|
||||
let path = 0;
|
||||
if(body.rgResult?.path)
|
||||
{
|
||||
if(body.rgResult?.path >= 0 && body.rgResult?.path <= 9){ // GID_PATH_C1
|
||||
@ -289,20 +289,33 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ
|
||||
}
|
||||
|
||||
// Get the available crown holder data
|
||||
let carCrowns = await prisma.carCrown.count({
|
||||
let carCrowns = await prisma.carCrown.findFirst({
|
||||
where: {
|
||||
area: area
|
||||
}
|
||||
});
|
||||
|
||||
// Crown holder data available
|
||||
if(carCrowns !== 0)
|
||||
if(carCrowns)
|
||||
{
|
||||
// Crown Finish Status
|
||||
await prisma.carCrownDetect.create({
|
||||
data:{
|
||||
carId: body.carId,
|
||||
status: 'finish',
|
||||
area: carCrowns.area,
|
||||
ramp: carCrowns.ramp,
|
||||
path: carCrowns.path,
|
||||
playedAt: carCrowns.playedAt,
|
||||
tunePower: carCrowns.tunePower,
|
||||
tuneHandling: carCrowns.tuneHandling
|
||||
}
|
||||
});
|
||||
|
||||
// Update it to the new one
|
||||
let areaVal = Number(area);
|
||||
await prisma.carCrown.update({
|
||||
where: {
|
||||
area: areaVal
|
||||
dbId: carCrowns.dbId
|
||||
},
|
||||
data: {
|
||||
...dataCrown,
|
||||
@ -661,8 +674,15 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ
|
||||
// Retiring Crown Mode
|
||||
else if(body.rgResult!.selectionMethod === wmproto.wm.protobuf.GhostSelectionMethod.GHOST_SELECT_CROWN_MATCH)
|
||||
{
|
||||
// TODO
|
||||
console.log('Crown Ghost Mode Found but Retiring');
|
||||
|
||||
// Crown Finish Status
|
||||
await prisma.carCrownDetect.create({
|
||||
data:{
|
||||
carId: body.carId,
|
||||
status: 'retire'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Return the value to 'BASE_PATH/src/modules/game.ts'
|
||||
|
@ -64,11 +64,31 @@ export default class GhostModule extends Module {
|
||||
stampReturnStats: car?.stampSheet || null,
|
||||
};
|
||||
|
||||
// Encode the response
|
||||
let message = wm.wm.protobuf.LoadGhostBattleInfoResponse.encode(msg);
|
||||
let getUserId = await prisma.user.findFirst({
|
||||
where:{
|
||||
id: car!.userId
|
||||
}
|
||||
});
|
||||
|
||||
// Send the response to the client
|
||||
common.sendResponse(message, res, req.rawHeaders[5], req.rawHeaders[7]);
|
||||
if(getUserId)
|
||||
{
|
||||
if(getUserId.userBanned === false)
|
||||
{
|
||||
// Encode the response
|
||||
let message = wm.wm.protobuf.LoadGhostBattleInfoResponse.encode(msg);
|
||||
|
||||
// Send the response to the client
|
||||
common.sendResponse(message, res, req.rawHeaders[5], req.rawHeaders[7]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Encode the response
|
||||
let message = wm.wm.protobuf.LoadGhostBattleInfoResponse.encode(msg);
|
||||
|
||||
// Send the response to the client
|
||||
common.sendResponse(message, res, req.rawHeaders[5], req.rawHeaders[7]);
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
@ -218,6 +218,16 @@ export async function saveCrownGhostTrail(body: wm.protobuf.RegisterGhostTrailRe
|
||||
console.log('Crown Trail history found');
|
||||
console.log('Updating crown trail to the newest trail');
|
||||
|
||||
await prisma.carCrownDetect.updateMany({
|
||||
where:{
|
||||
carId: ghostResult.car.carId!
|
||||
},
|
||||
data: {
|
||||
trail: gtCount.trail,
|
||||
opponentCarId: gtCount.carId
|
||||
}
|
||||
})
|
||||
|
||||
// Update the data
|
||||
await prisma.ghostTrail.update({
|
||||
where: {
|
||||
|
Loading…
Reference in New Issue
Block a user