1
0
mirror of synced 2024-12-04 19:17:58 +01:00

Merge pull request #32 from ghkkk090/master

ocm fix ranking
This commit is contained in:
Luna 2022-08-21 23:43:42 +01:00 committed by GitHub
commit 068a6a4d1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 161 additions and 80 deletions

View File

@ -530,24 +530,24 @@ export default class CarModule extends Module {
{
// Car update data
data = {
customColor: cars.customColor || undefined,
wheel: cars.wheel || undefined,
wheelColor: cars.wheelColor || undefined,
aero: cars.aero || undefined,
bonnet: cars.bonnet || undefined,
wing: cars.wing || undefined,
mirror: cars.mirror || undefined,
neon: cars.neon || undefined,
trunk: cars.trunk || undefined,
plate: cars.plate || undefined,
plateColor: cars.plateColor || undefined,
plateNumber: cars.plateNumber || undefined,
windowSticker: cars.windowSticker || undefined,
windowDecoration: cars.windowDecoration || undefined,
rivalMarker: cars.rivalMarker || undefined,
aura: cars.aura || undefined,
auraMotif: cars.auraMotif || undefined,
rgStamp: body?.rgStamp! || undefined,
customColor: common.sanitizeInput(cars.customColor),
wheel: common.sanitizeInput(cars.wheel),
wheelColor: common.sanitizeInput(cars.wheelColor),
aero: common.sanitizeInput(cars.aero),
bonnet: common.sanitizeInput(cars.bonnet),
wing: common.sanitizeInput(cars.wing),
mirror: common.sanitizeInput(cars.mirror),
neon: common.sanitizeInput(cars.neon),
trunk: common.sanitizeInput(cars.trunk),
plate: common.sanitizeInput(cars.plate),
plateColor: common.sanitizeInput(cars.plateColor),
plateNumber: common.sanitizeInput(cars.plateNumber),
windowSticker: common.sanitizeInput(cars.windowSticker),
windowDecoration: common.sanitizeInput(cars.windowDecoration),
rivalMarker: common.sanitizeInput(cars.rivalMarker),
aura: common.sanitizeInput(cars.aura),
auraMotif: common.sanitizeInput(cars.auraMotif),
rgStamp: common.sanitizeInput(body.rgStamp),
}
// Update the car info
@ -634,12 +634,12 @@ export default class CarModule extends Module {
if (gtWing)
{
let dataGTWing : any = {
pillar: gtWing.pillar || undefined,
pillarMaterial: gtWing.pillarMaterial || undefined,
mainWing: gtWing.mainWing || undefined,
mainWingColor: gtWing.mainWingColor || undefined,
wingTip: gtWing.wingTip || undefined,
material: gtWing.material || undefined,
pillar: common.sanitizeInput(gtWing.pillar),
pillarMaterial: common.sanitizeInput(gtWing.pillarMaterial),
mainWing: common.sanitizeInput(gtWing.mainWing),
mainWingColor: common.sanitizeInput(gtWing.mainWingColor),
wingTip: common.sanitizeInput(gtWing.wingTip),
material: common.sanitizeInput(gtWing.material),
}
await prisma.carGTWing.update({

View File

@ -47,7 +47,7 @@ export default class GhostModule extends Module {
if(cars[i].regionId === 0)
{
let randomRegionId = Math.floor(Math.random() * 47) + 1;
cars[i].regionId = randomRegionId; // Change car region id to 1 (Hokkaido)
cars[i].regionId = randomRegionId;
}
}
// ----------------------
@ -210,7 +210,7 @@ export default class GhostModule extends Module {
if(car[randomNumber]!.regionId === 0)
{
let randomRegionId = Math.floor(Math.random() * 47) + 1;
car[randomNumber].regionId = randomRegionId; // Hokkaido
car[randomNumber].regionId = randomRegionId;
}
// Push user's car data without ghost trail

View File

@ -2,6 +2,7 @@ import { Application } from "express";
import { Module } from "module";
import { prisma } from "..";
import { Car, CarGTWing } from "@prisma/client";
import { Config } from "../config";
// Import Proto
import * as wm from "../wmmt/wm.proto";
@ -10,7 +11,6 @@ import * as wm from "../wmmt/wm.proto";
import * as common from "../util/common";
import * as ghost_ocm from "../util/games/ghost_ocm";
import * as ghost_ocm_area from "../util/games/games_util/ghost_ocm_area";
import { Config } from "../config";
export default class GhostModule extends Module {
@ -122,7 +122,7 @@ export default class GhostModule extends Module {
}
// Current date is OCM main draw
if(ocmEventDate!.competitionStartAt <= date && ocmEventDate!.competitionCloseAt >= date)
if(ocmEventDate!.competitionStartAt < date && ocmEventDate!.competitionCloseAt > date)
{
console.log('Current OCM Day : Competition Day / Main Draw');
@ -452,6 +452,20 @@ export default class GhostModule extends Module {
}
});
if(!(ocmEventDate))
{
ocmEventDate = await prisma.oCMEvent.findFirst({
orderBy: [
{
dbId: 'desc'
},
{
competitionEndAt: 'desc',
},
],
});
}
// Declare variable for Top 1 OCM Ghost
let ghostCars: wm.wm.protobuf.GhostCar;
let ghostTypes;
@ -468,10 +482,9 @@ export default class GhostModule extends Module {
// Current date is OCM main draw
if(ocmEventDate!.competitionStartAt < date && ocmEventDate!.competitionCloseAt > date)
{
{
console.log('OCM Competition Day / Main Draw');
// --- Tally (still not complete) ---
// Get Top 1 qualifying car data
let ocmTallyRecord = await prisma.oCMTop1Ghost.findFirst({
where:{
@ -487,6 +500,8 @@ export default class GhostModule extends Module {
let checkGhostTrail = await prisma.oCMTop1GhostTrail.findFirst({
where:{
carId: ocmTallyRecord!.carId,
competitionId: ocmEventDate!.competitionId,
periodId: period_id,
area: areaVal,
ramp: rampVal,
path: pathVal,
@ -495,7 +510,6 @@ export default class GhostModule extends Module {
playedAt: 'desc'
},
});
// ----------------------------------
// Top 1 OCM Ghost trail data available
if(checkGhostTrail)
@ -537,11 +551,12 @@ export default class GhostModule extends Module {
// Get the default ghost trail
let checkGhostTrail = await prisma.oCMTop1GhostTrail.findFirst({
where:{
carId: 999999999,
competitionId: ocmEventDate!.competitionId,
periodId: 0,
area: areaVal,
ramp: rampVal,
path: pathVal,
competitionId: ocmEventDate!.competitionId,
periodId: 0
path: pathVal
},
orderBy:{
playedAt: 'desc'
@ -586,6 +601,72 @@ export default class GhostModule extends Module {
ghostTrailId = checkGhostTrail!.dbId!;
ghostTypes = wm.wm.protobuf.GhostType.GHOST_NORMAL;
}
else if(ocmEventDate!.competitionCloseAt < date && ocmEventDate!.competitionEndAt > date)
{
// TODO: IDK
}
else
{
console.log('OCM has ended');
// Get Top 1 qualifying car data
let ocmTallyRecord = await prisma.oCMTop1Ghost.findFirst({
where:{
competitionId: competition_id,
periodId: 999999999
},
orderBy:{
result: 'desc'
},
});
// Get Top 1 qualifying ghost trail id
let checkGhostTrail = await prisma.oCMTop1GhostTrail.findFirst({
where:{
carId: ocmTallyRecord!.carId,
competitionId: ocmEventDate!.competitionId,
periodId: 999999999,
area: areaVal,
ramp: rampVal,
path: pathVal,
},
orderBy:{
playedAt: 'desc'
},
});
// Top 1 OCM Ghost trail data available
if(checkGhostTrail)
{
// Get the Top 1 OCM car data
cars = await prisma.car.findFirst({
where:{
carId: checkGhostTrail!.carId
},
include:{
gtWing: true
}
});
// If regionId is 0 or not set, game will crash after defeating the ghost
if(cars!.regionId === 0)
{
let randomRegionId = Math.floor(Math.random() * 47) + 1;
cars!.regionId = randomRegionId;
}
// Set the tunePower used when playing ghost crown
cars!.tunePower = ocmTallyRecord!.tunePower;
// Set the tuneHandling used when playing ghost crown
cars!.tuneHandling = ocmTallyRecord!.tuneHandling;
// Set Ghost stuff Value
cars!.lastPlayedAt = checkGhostTrail.playedAt
ghostTrailId = checkGhostTrail.dbId!;
ghostTypes = wm.wm.protobuf.GhostType.GHOST_NORMAL;
}
}
// Push the Top 1 OCM ghost car data
ghostCars = wm.wm.protobuf.GhostCar.create({

View File

@ -356,15 +356,8 @@ export default class UserModule extends Module {
for(let j=0; j<ocmTallyRecord.length; j++)
{
if(carStates[i].dbId === ocmTallyRecord[j].carId)
{
carStates[i].eventJoined = true;
carStates[i].competitionState = wm.wm.protobuf.GhostCompetitionParticipantState.COMPETITION_QUALIFIED
}
if(carStates[i].dbId === ocmTallyRecord[j].carId && j === 0)
{
carStates[i].competitionState = wm.wm.protobuf.GhostCompetitionParticipantState.COMPETITION_WON
}
carStates[i].eventJoined = true;
carStates[i].competitionState = wm.wm.protobuf.GhostCompetitionParticipantState.COMPETITION_QUALIFIED
}
}
// Current date is OCM qualifying day
@ -433,15 +426,10 @@ export default class UserModule extends Module {
// Get OCM Data
let ocmTallyRecord = await prisma.oCMTally.findMany({
where:{
competitionId: ocmEventDate!.competitionId
competitionId: ocmEventDate!.competitionId,
periodId: 999999999
},
orderBy: [
{
competitionId: 'desc',
},
{
periodId: 'desc',
},
{
result: 'desc',
},

View File

@ -41,4 +41,8 @@ export function getBigIntFromLong(n: Long)
// Return the finished value
return Number(bigInt);
}
export function sanitizeInput(value: any){
return (value == null || value == undefined) ? undefined : value;
}

View File

@ -9,6 +9,7 @@ export async function saveGhostHistory(body: wm.protobuf.SaveGameResultRequest)
{
console.log('Saving Ghost Battle History');
let updateNewTrail: boolean = true;
let saveExGhostHistory: any = {};
if (body.car?.carId !== null && body.car?.carId !== undefined) {
@ -132,6 +133,9 @@ export async function saveGhostHistory(body: wm.protobuf.SaveGameResultRequest)
await prisma.ghostBattleRecord.create({
data: saveExGhostHistory
});
// Return the value to 'BASE_PATH/src/util/games/ghost.ts'
return { updateNewTrail }
}

View File

@ -3,8 +3,10 @@ import { prisma } from "../..";
// Import Proto
import { wm } from "../../wmmt/wm.proto";
import wmproto from "../../wmmt/wm.proto";
import * as ghost_history from "../games/games_util/ghost_history";
// Import Util
import * as common from "../../util/common";
import * as ghost_history from "../games/games_util/ghost_history";
// Save ghost battle result
export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequest, car: any)
@ -34,10 +36,10 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ
{
// Ghost update data
dataGhost = {
rgRegionMapScore: ghostResult.rgRegionMapScore || undefined,
rgPlayCount: ghostResult.rgPlayCount || undefined,
dressupLevel: ghostResult.dressupLevel || undefined,
dressupPoint: ghostResult.dressupPoint || undefined,
rgRegionMapScore: common.sanitizeInput(ghostResult.rgRegionMapScore),
rgPlayCount: common.sanitizeInput(ghostResult.rgPlayCount),
dressupLevel: common.sanitizeInput(ghostResult.dressupLevel),
dressupPoint: common.sanitizeInput(ghostResult.dressupPoint),
}
}
@ -62,18 +64,18 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ
// Car update data
dataCar = {
wheel: cars.wheel || undefined,
wheelColor: cars.wheelColor || undefined,
aero: cars.aero || undefined,
bonnet: cars.bonnet || undefined,
wing: cars.wing || undefined,
mirror: cars.mirror || undefined,
neon: cars.neon || undefined,
trunk: cars.trunk || undefined,
plate: cars.plate || undefined,
plateColor: cars.plateColor || undefined,
plateNumber: cars.plateNumber || undefined,
ghostLevel: cars.ghostLevel || undefined,
wheel: common.sanitizeInput(cars.wheel),
wheelColor: common.sanitizeInput(cars.wheelColor),
aero: common.sanitizeInput(cars.aero),
bonnet: common.sanitizeInput(cars.bonnet),
wing: common.sanitizeInput(cars.wing),
mirror: common.sanitizeInput(cars.mirror),
neon: common.sanitizeInput(cars.neon),
trunk: common.sanitizeInput(cars.trunk),
plate: common.sanitizeInput(cars.plate),
plateColor: common.sanitizeInput(cars.plateColor),
plateNumber: common.sanitizeInput(cars.plateNumber),
ghostLevel: common.sanitizeInput(cars.ghostLevel),
}
}
@ -205,9 +207,9 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ
// Ghost Crown update data
dataCrown = {
carId: carId,
playedAt: body.playedAt || undefined,
tunePower: body.car?.tunePower || undefined,
tuneHandling: body.car?.tuneHandling || undefined,
playedAt: common.sanitizeInput(body.playedAt),
tunePower: common.sanitizeInput(body.car?.tunePower),
tuneHandling: common.sanitizeInput(body.car?.tuneHandling),
}
// Get the area id and ramp id

View File

@ -388,7 +388,10 @@ export async function ocmCompetitionDay(body: wm.protobuf.LoadGhostCompetitionIn
currentRank = i + 1;
isQualified = true;
}
topresult.push(ocmTallyRecord[i].carId);
else
{
topresult.push(ocmTallyRecord[i].result);
}
}
// Mini game braking point

View File

@ -23,12 +23,12 @@ export async function saveStoryResult(body: wm.protobuf.SaveGameResultRequest, c
{
// Story update data
let data : any = {
stClearDivCount: storyResult.stClearDivCount || undefined,
stPlayCount: storyResult.stPlayCount || undefined,
stClearCount: storyResult.stClearCount || undefined,
stConsecutiveWins: storyResult.stConsecutiveWins || undefined,
tuningPoints: storyResult.tuningPoint || 0,
stCompleted100Episodes: storyResult.stCompleted_100Episodes || undefined,
stClearDivCount: common.sanitizeInput(storyResult.stClearDivCount),
stPlayCount: common.sanitizeInput(storyResult.stPlayCount),
stClearCount: common.sanitizeInput(storyResult.stClearCount),
stConsecutiveWins: common.sanitizeInput(storyResult.stConsecutiveWins),
tuningPoints: common.sanitizeInput(storyResult.tuningPoint),
stCompleted100Episodes: common.sanitizeInput(storyResult.stCompleted_100Episodes),
}
// If the current consecutive wins is greater than the previous max
@ -53,8 +53,7 @@ export async function saveStoryResult(body: wm.protobuf.SaveGameResultRequest, c
}
// Check if clearBits is not null, and not lose the story
if (storyResult.stClearBits !== null && storyResult.stClearBits !== undefined
&& data.stLoseBits === 0)
if (common.sanitizeInput(storyResult.stClearBits) && data.stLoseBits === 0)
{
data.stClearBits = storyResult.stClearBits;
}

View File

@ -1,2 +1,2 @@
node dist
yarn dev
pause