1
0
mirror of synced 2025-02-21 21:00:13 +01:00

Merge pull request #28 from ghkkk090/master

ocm hall of fame
This commit is contained in:
Luna 2022-08-18 11:21:51 +01:00 committed by GitHub
commit 317f96e0bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 320 additions and 70 deletions

View File

@ -0,0 +1,15 @@
-- AlterTable
ALTER TABLE "Car" ALTER COLUMN "stLoseBits" SET DEFAULT 0;
-- CreateTable
CREATE TABLE "GhostRegisteredFromTerminal" (
"dbId" SERIAL NOT NULL,
"carId" INTEGER NOT NULL,
"competitionId" INTEGER,
"opponentCarId" INTEGER NOT NULL,
CONSTRAINT "GhostRegisteredFromTerminal_pkey" PRIMARY KEY ("dbId")
);
-- AddForeignKey
ALTER TABLE "GhostRegisteredFromTerminal" ADD CONSTRAINT "GhostRegisteredFromTerminal_carId_fkey" FOREIGN KEY ("carId") REFERENCES "Car"("carId") ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@ -137,11 +137,12 @@ model Car {
GhostBattleRecord GhostBattleRecord[]
CarPathandTuning CarPathandTuning[]
OCMGhostBattleRecord OCMGhostBattleRecord[]
OCMTally OCMTally[]
OCMTop1Ghost OCMTop1Ghost[]
OCMGhostTrail OCMGhostTrail[]
OCMPlayRecord OCMPlayRecord[]
OCMGhostBattleRecord OCMGhostBattleRecord[]
OCMTally OCMTally[]
OCMTop1Ghost OCMTop1Ghost[]
OCMGhostTrail OCMGhostTrail[]
OCMPlayRecord OCMPlayRecord[]
GhostRegisteredFromTerminal GhostRegisteredFromTerminal[]
}
model CarGTWing {
@ -385,4 +386,12 @@ model OCMPeriod {
periodId Int
startAt Int
closeAt Int
}
model GhostRegisteredFromTerminal {
dbId Int @id @default(autoincrement())
car Car @relation(fields: [carId], references: [carId])
carId Int
competitionId Int?
opponentCarId Int
}

View File

@ -50,12 +50,31 @@ export default class CarModule extends Module {
// Get current / previous active OCM Event
let ocmEventDate = await prisma.oCMEvent.findFirst({
where:{
competitionEndAt:
{
lte: date // competitionEndAt less than current date
}
},
where: {
OR: [
{
// qualifyingPeriodStartAt is less than current date
qualifyingPeriodStartAt: { lte: date },
// qualifyingPeriodCloseAt is greater than current date
qualifyingPeriodCloseAt: { gte: date },
},
{
// competitionStartAt is less than current date
competitionStartAt: { lte: date },
// competitionCloseAt is greater than current date
competitionCloseAt: { gte: date },
},
{
// competitionCloseAt is less than current date
competitionCloseAt: { lte: date },
// competitionEndAt is greater than current date
competitionEndAt: {gte: date },
}
],
},
orderBy: [
{
dbId: 'desc'
@ -65,72 +84,99 @@ export default class CarModule extends Module {
},
],
});
// Declare GhostCompetitionSchedule
let pastEvent = 0;
if(!(ocmEventDate))
{
ocmEventDate = await prisma.oCMEvent.findFirst({
orderBy: [
{
dbId: 'desc'
},
{
competitionEndAt: 'desc',
},
],
});
pastEvent = 1;
}
// Current / previous OCM Event is found
let ghostCarsNo1;
let trailIdNo1: number = 0;
if(ocmEventDate)
{
let pastDay = date - ocmEventDate.competitionEndAt
if(pastDay < 604800)
// Get Previous Top 1 OCM
if(pastDay < 604800 && pastEvent === 1)
{
let getNo1OCM = await prisma.oCMTally.findFirst({
let checkRegisteredGhost = await prisma.ghostRegisteredFromTerminal.findFirst({
where:{
competitionId: ocmEventDate.competitionId,
periodId: 999999999
},
orderBy:{
result: 'desc'
carId: body.carId
}
});
if(getNo1OCM)
if(checkRegisteredGhost)
{
let carId = getNo1OCM.carId
// Get Car Data
let cars = await prisma.car.findFirst({
let getNo1OCM = await prisma.oCMTally.findFirst({
where:{
carId: carId
},
include:{
gtWing: true
}
});
// Get Place
let playedPlace = wm.wm.protobuf.Place.create({
placeId: 'JPN0123',
shopName: Config.getConfig().shopName,
regionId: 18,
country: 'JPN'
});
// Get Ghost Trail
let ghostTrailNo1 = await prisma.oCMTop1GhostTrail.findFirst({
where:{
carId: carId,
competitionId: ocmEventDate.competitionId,
periodId: 999999999
},
orderBy:{
competitionId: 'desc'
}
});
trailIdNo1 = ghostTrailNo1!.dbId;
if(getNo1OCM)
{
let carId = getNo1OCM.carId
ghostCarsNo1 = wm.wm.protobuf.GhostCar.create({
car: {
...cars!,
lastPlayedPlace: playedPlace
},
area: ghostTrailNo1!.area,
ramp: ghostTrailNo1!.ramp,
path: ghostTrailNo1!.path,
nonhuman: false,
type: wm.wm.protobuf.GhostType.GHOST_NORMAL,
trailId: trailIdNo1
});
// Get Car Data
let cars = await prisma.car.findFirst({
where:{
carId: carId
},
include:{
gtWing: true
}
});
// Get Place
let playedPlace = wm.wm.protobuf.Place.create({
placeId: 'JPN0123',
shopName: Config.getConfig().shopName,
regionId: 18,
country: 'JPN'
});
// Get Ghost Trail
let ghostTrailNo1 = await prisma.oCMTop1GhostTrail.findFirst({
where:{
carId: carId,
competitionId: ocmEventDate.competitionId,
periodId: 999999999
}
});
trailIdNo1 = ghostTrailNo1!.dbId;
ghostCarsNo1 = wm.wm.protobuf.GhostCar.create({
car: {
...cars!,
lastPlayedPlace: playedPlace
},
area: ghostTrailNo1!.area,
ramp: ghostTrailNo1!.ramp,
path: ghostTrailNo1!.path,
nonhuman: false,
type: wm.wm.protobuf.GhostType.GHOST_NORMAL,
trailId: trailIdNo1
});
}
}
}
}

View File

@ -356,6 +356,8 @@ export default class GhostModule extends Module {
where: {
OR: [
{
competitionId: competition_id,
// qualifyingPeriodStartAt is less than current date
qualifyingPeriodStartAt: { lte: date },
@ -363,6 +365,8 @@ export default class GhostModule extends Module {
qualifyingPeriodCloseAt: { gte: date },
},
{
competitionId: competition_id,
// competitionStartAt is less than current date
competitionStartAt: { lte: date },
@ -370,6 +374,8 @@ export default class GhostModule extends Module {
competitionCloseAt: { gte: date },
},
{
competitionId: competition_id,
// competitionCloseAt is less than current date
competitionCloseAt: { lte: date },

View File

@ -60,6 +60,7 @@ export default class StartupModule extends Module {
],
});
let pastEvent = 0;
if(!(ocmEventDate))
{
ocmEventDate = await prisma.oCMEvent.findFirst({
@ -72,10 +73,13 @@ export default class StartupModule extends Module {
},
],
});
pastEvent = 1;
}
// Declare GhostCompetitionSchedule
let compeSch;
let competitionSchedule;
let lastCompetitionId: number = 0;
if(ocmEventDate)
{
let pastDay = date - ocmEventDate.competitionEndAt
@ -83,7 +87,7 @@ export default class StartupModule extends Module {
if(pastDay < 604800)
{
// Creating GhostCompetitionSchedule
compeSch = wm.wm.protobuf.GhostCompetitionSchedule.create({
competitionSchedule = wm.wm.protobuf.GhostCompetitionSchedule.create({
// OCM Competition ID (1 = C1 (Round 16), 4 = Nagoya (Round 19), 8 = Hiroshima (Round 21))
competitionId: ocmEventDate.competitionId,
@ -116,6 +120,11 @@ export default class StartupModule extends Module {
minigamePatternId: ocmEventDate.minigamePatternId
});
}
if(pastEvent === 1 && pastDay < 604800)
{
lastCompetitionId = ocmEventDate.competitionId
}
}
// Response data
@ -133,7 +142,8 @@ export default class StartupModule extends Module {
pluses: 0,
releaseAt: 0 // idk what this is
},
competitionSchedule: compeSch || null // OCM Event Available or not
latestCompetitionId: lastCompetitionId || null,
competitionSchedule: competitionSchedule || null // OCM Event Available or not
}
// Encode the response

View File

@ -520,6 +520,7 @@ export default class TerminalModule extends Module {
// Terminal OCM Ranking
app.post('/method/load_ghost_competition_ranking', async (req, res) => {
// Get the information from the request
let body = wm.wm.protobuf.LoadGhostCompetitionRankingRequest.decode(req.body);
@ -876,6 +877,7 @@ export default class TerminalModule extends Module {
}
else
{
// Response data
msg = {
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
numOfParticipants: 0,
@ -888,5 +890,83 @@ export default class TerminalModule extends Module {
// Send the response to the client
common.sendResponse(message, res);
})
}
// Recieve user items
app.post('/method/register_opponent_ghost', async (req, res) => {
// Get the information from the request
let body = wm.wm.protobuf.RegisterOpponentGhostRequest.decode(req.body);
let ocmEventDate = await prisma.oCMEvent.findFirst({
orderBy: [
{
dbId: 'desc'
},
{
competitionEndAt: 'desc',
},
],
});
if(ocmEventDate)
{
let checkRegisteredGhost = await prisma.ghostRegisteredFromTerminal.findFirst({
where:{
carId: body.carId
}
});
let getNo1OCM = await prisma.oCMTally.findFirst({
where:{
competitionId: ocmEventDate.competitionId,
periodId: 999999999
},
orderBy:{
competitionId: 'desc'
}
});
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
let msg = {
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
}
// Encode the response
let message = wm.wm.protobuf.RegisterOpponentGhostResponse.encode(msg);
// Send the response to the client
common.sendResponse(message, res);
})
}
}

View File

@ -462,6 +462,39 @@ export default class UserModule extends Module {
}
}
}
if(!ocmEventDate)
{
let ocmEventDate = await prisma.oCMEvent.findFirst({
orderBy: [
{
dbId: 'desc'
},
{
competitionEndAt: 'desc',
},
],
});
if(ocmEventDate)
{
let pastDay = date - ocmEventDate.competitionEndAt;
if(pastDay < 604800)
{
let checkRegisteredGhost = await prisma.ghostRegisteredFromTerminal.findFirst({
where:{
carId: user.cars[i].carId
}
});
if(checkRegisteredGhost)
{
carStates[i].hasOpponentGhost = true;
}
}
}
}
}
// Participated to OCM Event

View File

@ -22,9 +22,6 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ
// Set ghost mode play to true for saving the ghost trail later
ghostModePlay = true;
// Set update new trail to true for updating the user's ghost trail after playing OCM ghost battle mode later
updateNewTrail = true;
// Get the ghost result for the car
let ghostResult = body?.rgResult;
@ -115,6 +112,7 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ
switch (body.rgResult!.selectionMethod)
{
// Ghost Battle by Level
case wmproto.wm.protobuf.GhostSelectionMethod.GHOST_SELECT_BY_LEVEL:
{
console.log('Normal Ghost Mode Found');
@ -127,6 +125,58 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ
break;
}
// Ghost Battle by Name
case wmproto.wm.protobuf.GhostSelectionMethod.GHOST_SEARCH_BY_NAME:
{
console.log('Normal Ghost Mode Found');
ghost_historys = await ghost_history.saveGhostHistory(body);
// Update the updateNewTrail value
updateNewTrail = ghost_historys.updateNewTrail;
break;
}
// Ghost Battle by Region
case wmproto.wm.protobuf.GhostSelectionMethod.GHOST_SEARCH_BY_REGION:
{
console.log('Normal Ghost Mode Found');
ghost_historys = await ghost_history.saveGhostHistory(body);
// Update the updateNewTrail value
updateNewTrail = ghost_historys.updateNewTrail;
break;
}
// Ghost Battle from History
case wmproto.wm.protobuf.GhostSelectionMethod.GHOST_SELECT_FROM_HISTORY:
{
console.log('Normal Ghost Mode Found');
ghost_historys = await ghost_history.saveGhostHistory(body);
// Update the updateNewTrail value
updateNewTrail = ghost_historys.updateNewTrail;
break;
}
// Ghost Battle by Shop
case wmproto.wm.protobuf.GhostSelectionMethod.GHOST_SEARCH_BY_SHOP:
{
console.log('Normal Ghost Mode Found');
ghost_historys = await ghost_history.saveGhostHistory(body);
// Update the updateNewTrail value
updateNewTrail = ghost_historys.updateNewTrail;
break;
}
// Crown Ghost Battle Mode
case wmproto.wm.protobuf.GhostSelectionMethod.GHOST_SELECT_CROWN_MATCH:
{
@ -265,13 +315,13 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ
});
}
}
ghost_historys = await ghost_history.saveGhostHistory(body);
// Update the updateNewTrail value
updateNewTrail = ghost_historys.updateNewTrail;
}
ghost_historys = await ghost_history.saveGhostHistory(body);
// Update the updateNewTrail value
updateNewTrail = ghost_historys.updateNewTrail;
break;
}
@ -279,6 +329,7 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ
case wmproto.wm.protobuf.GhostSelectionMethod.GHOST_COMPETITION:
{
console.log('OCM Ghost Mode Found');
OCMModePlay = true;
let saveExOCM: any = {};
saveExOCM.carId = body.carId;

View File

@ -7,7 +7,7 @@ import { wm } from "../../wmmt/wm.proto";
// Save versus battle result
export async function saveVersusBattleResult(body: wm.protobuf.SaveGameResultRequest)
{
if (!(body.retired || body.timeup))
if (!(body.retired))
{
// Get the vs result for the car
let vsResult = body?.vsResult;