diff --git a/src/modules/cars/functions.ts b/src/modules/cars/functions.ts index 7b10554..49bf907 100644 --- a/src/modules/cars/functions.ts +++ b/src/modules/cars/functions.ts @@ -216,7 +216,7 @@ export async function getOpponentsTarget(carId: number, registeredargetAvailable } // Get Number of Challengers - numOfChallengers = opponentTarget.length + 1; + numOfChallengers = opponentTargetCount + 1; } } diff --git a/src/modules/game/ghost.ts b/src/modules/game/ghost.ts index c6448e5..77edf95 100644 --- a/src/modules/game/ghost.ts +++ b/src/modules/game/ghost.ts @@ -6,8 +6,8 @@ import wmproto from "../../wmmt/wm.proto"; // Import Util import * as common from "../util/common"; -import * as ghost_history from "../../util/ghost/ghost_history"; -import * as ghost_stamp from "../../util/ghost/ghost_stamp"; +import * as ghost_history from "../ghost/ghost_history"; +import * as ghost_stamp from "../ghost/ghost_stamp"; // Save ghost battle result export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequest, car: any) diff --git a/src/modules/ghost.ts b/src/modules/ghost.ts index 129286c..2381ff2 100644 --- a/src/modules/ghost.ts +++ b/src/modules/ghost.ts @@ -3,7 +3,6 @@ import { Module } from "module"; import { prisma } from ".."; import { CarPathandTuning } from "@prisma/client"; import Long from "long"; -import { Config } from "../config"; // Import Proto import * as wm from "../wmmt/wm.proto"; @@ -11,9 +10,10 @@ import * as wmsrv from "../wmmt/service.proto"; // Import Util import * as common from "./util/common"; -import * as ghost_save_trail from "../util/ghost/ghost_save_trail"; -import * as ghost_trail from "../util/ghost/ghost_trail"; -import * as ghost_area from "../util/ghost/ghost_area"; +import * as ghostFunctions from "./ghost/functions"; +import * as ghost_save_trail from "./ghost/ghost_save_trail"; +import * as ghost_trail from "./ghost/ghost_util/ghost_trail"; +import * as ghost_area from "./ghost/ghost_util/ghost_area"; export default class GhostModule extends Module { @@ -33,152 +33,35 @@ export default class GhostModule extends Module { gtWing: true, lastPlayedPlace: true } - }) + }); - // Car History - let findChallenger = await prisma.carChallenger.findMany({ - where: { - challengerCarId: body.carId - }, - orderBy:{ - lastPlayedAt: 'desc' - }, - take: 10 - }) + // Get Challenged Opponent History + let getStampTargets = await ghostFunctions.getOpponentHistory(body.carId); + let opponentHistory = getStampTargets.opponentHistory; - let carsHistory: wm.wm.protobuf.Car[] = []; - if(findChallenger.length > 0) - { - for(let i=0; i 0) - { - result = -Math.abs(challengers[i].result); - } - else{ - result = Math.abs(challengers[i].result); - } - - carsChallenger.push( - wm.wm.protobuf.ChallengerCar.create({ - car: carTarget!, - stamp: challengers[i].stamp, - result: result, - area: challengers[i].area - }) - ); - } - } + // Get Stamp Target + let getStampTarget = await ghostFunctions.getStampTarget(body.carId); + let stampTarget = getStampTarget.stampTarget; + + // Get Challengers + let getChallengers = await ghostFunctions.getChallengers(body.carId); + let challengers = getChallengers.challengers; // Response data let msg = { error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS, - stampTargetCars: carsStamp || null, - challengers: carsChallenger || null, - stampSheetCount: car!.stampSheetCount, + + // Challengers + challengers: challengers || null, + stampTargetCars: stampTarget || null, + + // History + history: opponentHistory || null, + + // Stamp + stampSheetCount: car?.stampSheetCount || 0, stampSheet: car?.stampSheet || null, stampReturnStats: car?.stampSheet || null, - history: carsHistory || null, }; // Encode the response @@ -193,93 +76,21 @@ export default class GhostModule extends Module { app.post('/method/load_stamp_target', async (req, res) => { // Get the request body for the load stamp target request - let body = wm.wm.protobuf.LoadStampTargetRequest.decode(req.body); + let body = wm.wm.protobuf.LoadStampTargetRequest.decode(req.body); - let carsStamp: wm.wm.protobuf.StampTargetCar[] = []; - let carsChallenger: wm.wm.protobuf.ChallengerCar[] = []; + // Get Stamp Target + let getStampTarget = await ghostFunctions.getStampTarget(body.carId); + let stampTarget = getStampTarget.stampTarget; - // Get all of the friend cars for the carId provided - let stampTargets = await prisma.carStampTarget.findMany({ - where: { - stampTargetCarId: body.carId, - recommended: true - }, - orderBy:{ - locked: 'asc' - } - }); - - if(stampTargets) - { - for(let i=0; i 0) - { - result = -Math.abs(challengers[i].result); - } - else{ - result = Math.abs(challengers[i].result); - } - - carsChallenger.push( - wm.wm.protobuf.ChallengerCar.create({ - car: carTarget!, - stamp: challengers[i].stamp, - result: result, - area: challengers[i].area - }) - ); - } - } + // Get Challengers + let getChallengers = await ghostFunctions.getChallengers(body.carId); + let challengers = getChallengers.challengers; // Response data let msg = { error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS, - cars: carsStamp, - challengers: carsChallenger + cars: stampTarget, + challengers: challengers }; // Encode the response @@ -290,7 +101,7 @@ export default class GhostModule extends Module { }) - // Ghost Mode + // Search Cars by Level app.post('/method/search_cars_by_level', async (req, res) => { // Get the request body for the search cars by level request @@ -326,221 +137,36 @@ export default class GhostModule extends Module { }); } - // Randomizing the starting ramp and path based on selected area - let rampVal = 0; - let pathVal = 0; - // Get the ramp and path id let ghost_areas = await ghost_area.GhostArea(body.area); // Set the value - rampVal = ghost_areas.rampVal; - pathVal = ghost_areas.pathVal; + let rampVal = ghost_areas.rampVal; + let pathVal = ghost_areas.pathVal; - // Empty list of ghost car records - let lists_ghostcar: wm.wm.protobuf.GhostCar[] = []; - let arr = []; - let maxNumber = 0; - - // If all user car data available is more than 10 for certain level - if(car.length > 10) - { - maxNumber = 10 // Limit to 10 (game default) - } - // If no more than 10 - else - { - maxNumber = car.length; - } - - // Choose the user's car data randomly to appear - while(arr.length < maxNumber) - { - // Randomize pick - let random: number = 1; - - // Randomize it 5 times - for(let i=0; i<5; i++) - { - random = Math.floor(Math.random() * car.length); - } - - // Try randomize it again if it's 1 - if(random === 1) - { - random = Math.floor(Math.random() * car.length); - } - - - if(arr.indexOf(random) === -1) - { - // Push current number to array - arr.push(random); - - // Check if ghost trail for certain car is available - let ghost_trails = await prisma.ghostTrail.findFirst({ - where: { - carId: car[random].carId, - area: body.area, - crownBattle: false - }, - orderBy: { - playedAt: 'desc' - } - }); - - // Push user's car data without ghost trail - if(!(ghost_trails)) - { - lists_ghostcar.push(wm.wm.protobuf.GhostCar.create({ - car: car[random] - })); - } - // Push user's car data with ghost trail - else - { - // Set the tunePower used when playing certain area - car[random].tunePower = ghost_trails!.tunePower; - - // Set the tuneHandling used when playing certain area - car[random].tuneHandling = ghost_trails!.tuneHandling; - - // Push data to Ghost car proto - lists_ghostcar.push(wm.wm.protobuf.GhostCar.create({ - car: car[random], - nonhuman: false, - type: wm.wm.protobuf.GhostType.GHOST_NORMAL, - trailId: ghost_trails!.dbId! - })); - } - } - } + // Get Ghost Car + let getGhostCar = await ghostFunctions.getGhostCar(car, body.area, rampVal, pathVal); + 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(car.length < 1) - { - // Get current date - let date = Math.floor(new Date().getTime() / 1000); - - let playedPlace = wm.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(body.ghostLevel === 1) - { - tunePowerDefault = 1; - tuneHandlingDefault = 4; - } - else if(body.ghostLevel === 2) - { - tunePowerDefault = 5; - tuneHandlingDefault = 5; - } - else if(body.ghostLevel === 3) - { - tunePowerDefault = 8; - tuneHandlingDefault = 7; - } - else if(body.ghostLevel === 4) - { - tunePowerDefault = 10; - tuneHandlingDefault = 10; - } - else if(body.ghostLevel === 5) - { - tunePowerDefault = 15; - tuneHandlingDefault = 10; - } - else if(body.ghostLevel === 6) - { - tunePowerDefault = 18; - tuneHandlingDefault = 10; - } - else if(body.ghostLevel === 7) - { - tunePowerDefault = 20; - tuneHandlingDefault = 10; - } - else if(body.ghostLevel === 8) - { - tunePowerDefault = 21; - tuneHandlingDefault = 10; - } - else if(body.ghostLevel === 9) - { - tunePowerDefault = 22; - tuneHandlingDefault = 10; - } - else if(body.ghostLevel === 10) - { - tunePowerDefault = 24; - tuneHandlingDefault = 10; - } - else if(body.ghostLevel === 11) - { - tunePowerDefault = 24; - tuneHandlingDefault = 24; - } - - // Generate default S660 car data - car = wm.wm.protobuf.Car.create({ - carId: 999999999, // Don't change this - name: 'S660', - regionId: body.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: 'BAYSHORE', - 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(wm.wm.protobuf.GhostCar.create({ - car: car, - nonhuman: true, - type: wm.wm.protobuf.GhostType.GHOST_DEFAULT, - })); - } - - // else{} have car list + let checkGhostSearchByRegion = await ghostFunctions.checkGhostSearchByRegion(car, body.ghostLevel, body.regionId); + lists_ghostcar = checkGhostSearchByRegion.lists_ghostcar; } // Response data let msg = { error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS, + + // Area Value ramp: rampVal, path: pathVal, + + // Ghost Car List ghosts: lists_ghostcar, + + // Ghost Selection Method selectionMethod: Number(wm.wm.protobuf.GhostSelectionMethod.GHOST_SELECT_BY_LEVEL) }; @@ -581,7 +207,8 @@ export default class GhostModule extends Module { // ---Get the user and opponent ghost trail data--- let ghostType: number = wm.wm.protobuf.GhostType.GHOST_NORMAL; let lists_binarydriveData; - if(ghost_trails?.driveData !== null && ghost_trails?.driveData !== undefined){ + if(ghost_trails?.driveData !== null && ghost_trails?.driveData !== undefined) + { lists_binarydriveData = wm.wm.protobuf.BinaryData.create({ data: ghost_trails!.driveData!, mergeSerial: ghost_trails!.driveDMergeSerial! @@ -589,7 +216,8 @@ export default class GhostModule extends Module { } let lists_binaryByArea - if(ghost_trails?.trendBinaryByArea !== null && ghost_trails?.trendBinaryByArea !== undefined){ + if(ghost_trails?.trendBinaryByArea !== null && ghost_trails?.trendBinaryByArea !== undefined) + { lists_binaryByArea = wm.wm.protobuf.BinaryData.create({ data: ghost_trails!.trendBinaryByArea!, mergeSerial: ghost_trails!.byAreaMergeSerial! @@ -597,7 +225,8 @@ export default class GhostModule extends Module { } let lists_binaryByCar - if(ghost_trails?.trendBinaryByCar !== null && ghost_trails?.trendBinaryByCar !== undefined){ + if(ghost_trails?.trendBinaryByCar !== null && ghost_trails?.trendBinaryByCar !== undefined) + { lists_binaryByCar = wm.wm.protobuf.BinaryData.create({ data: ghost_trails!.trendBinaryByCar!, mergeSerial: ghost_trails!.byCarMergeSerial! @@ -605,7 +234,8 @@ export default class GhostModule extends Module { } let lists_binaryByUser - if(ghost_trails?.trendBinaryByUser !== null && ghost_trails?.trendBinaryByUser !== undefined){ + if(ghost_trails?.trendBinaryByUser !== null && ghost_trails?.trendBinaryByUser !== undefined) + { lists_binaryByUser = wm.wm.protobuf.BinaryData.create({ data: ghost_trails!.trendBinaryByUser!, mergeSerial: ghost_trails!.byUserMergeSerial! @@ -656,6 +286,7 @@ export default class GhostModule extends Module { actualSessionId = common.getBigIntFromLong(body.ghostSessionId); } + // ----------------------------------------------------------------------------------------- // OCM game mode session id if(actualSessionId > 100 && actualSessionId < 201) { @@ -686,6 +317,7 @@ export default class GhostModule extends Module { await ghost_save_trail.savePathAndTuning(body); } } + // ----------------------------------------------------------------------------------------- // Response data let msg = { diff --git a/src/modules/ghost/functions.ts b/src/modules/ghost/functions.ts index e69de29..9f5f68f 100644 --- a/src/modules/ghost/functions.ts +++ b/src/modules/ghost/functions.ts @@ -0,0 +1,367 @@ +import { Config } from "../../config"; +import { prisma } from "../.."; + +// Import Proto +import * as wmproto from "../../wmmt/wm.proto"; + +// Get Challenged Opponent History +export async function getOpponentHistory(carId: number) +{ + // Car History + let findChallenger = await prisma.carChallenger.findMany({ + where: { + challengerCarId: carId + }, + orderBy:{ + lastPlayedAt: 'desc' + }, + take: 10 + }) + let opponentHistory: wmproto.wm.protobuf.Car[] = []; + + if(findChallenger.length > 0) + { + for(let i=0; i 0) + { + result = -Math.abs(getChallengers[i].result); + } + else{ + result = Math.abs(getChallengers[i].result); + } + + challengers.push( + wmproto.wm.protobuf.ChallengerCar.create({ + car: carTarget!, + stamp: getChallengers[i].stamp, + result: result, + area: getChallengers[i].area + }) + ); + } + } + + return { challengers } +} + + +// Get Ghost Car +export async function getGhostCar(car: any, area: number, ramp: number, path: number) +{ + // Empty list of ghost car records + let lists_ghostcar: wmproto.wm.protobuf.GhostCar[] = []; + let arr = []; + let maxNumber = 0; + + // If all user car data available is more than 10 for certain level + if(car.length > 10) + { + maxNumber = 10 // Limit to 10 (game default) + } + // If no more than 10 + else + { + maxNumber = car.length; + } + + // Choose the user's car data randomly to appear + while(arr.length < maxNumber) + { + // Randomize pick + let random: number = 1; + + // Randomize it 5 times + for(let i=0; i<5; i++) + { + random = Math.floor(Math.random() * car.length); + } + + // Try randomize it again if it's 1 + if(random === 1) + { + random = Math.floor(Math.random() * car.length); + } + + + if(arr.indexOf(random) === -1) + { + // Push current number to array + arr.push(random); + + // Check if ghost trail for certain car is available + let ghost_trails = await prisma.ghostTrail.findFirst({ + where: { + carId: car[random].carId, + area: area, + crownBattle: false + }, + orderBy: { + playedAt: 'desc' + } + }); + + // Push user's car data without ghost trail + if(!(ghost_trails)) + { + lists_ghostcar.push(wmproto.wm.protobuf.GhostCar.create({ + car: car[random] + })); + } + // Push user's car data with ghost trail + else + { + // Set the tunePower used when playing certain area + car[random].tunePower = ghost_trails!.tunePower; + + // Set the tuneHandling used when playing certain area + car[random].tuneHandling = ghost_trails!.tuneHandling; + + // Push data to Ghost car proto + lists_ghostcar.push(wmproto.wm.protobuf.GhostCar.create({ + car: car[random], + nonhuman: false, + type: wmproto.wm.protobuf.GhostType.GHOST_NORMAL, + trailId: ghost_trails!.dbId! + })); + } + } + } + + return { lists_ghostcar } +} + + +// Check Ghost Car when using Search by Region +export async function checkGhostSearchByRegion(car: any, ghostLevel: number, regionId: number) +{ + let lists_ghostcar: any; + + if(car.length < 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: 'S660', + 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: 'BAYSHORE', + 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, + })); + } + + return { lists_ghostcar } +} \ No newline at end of file diff --git a/src/util/ghost/ghost_history.ts b/src/modules/ghost/ghost_history.ts similarity index 98% rename from src/util/ghost/ghost_history.ts rename to src/modules/ghost/ghost_history.ts index b738d8d..3b339e8 100644 --- a/src/util/ghost/ghost_history.ts +++ b/src/modules/ghost/ghost_history.ts @@ -4,9 +4,9 @@ import { Config } from "../../config"; import { wm } from "../../wmmt/wm.proto"; // Import Util -import * as common from "../../modules/util/common"; -import * as ghost_stamp from "../ghost/ghost_stamp"; -import * as ghost_get_area_from_path from "../ghost/ghost_util/ghost_get_area_from_path"; +import * as common from "../util/common"; +import * as ghost_stamp from "./ghost_stamp"; +import * as ghost_get_area_from_path from "./ghost_util/ghost_get_area_from_path"; // Save ghost history battle diff --git a/src/util/ghost/ghost_ocm.ts b/src/modules/ghost/ghost_ocm.ts similarity index 100% rename from src/util/ghost/ghost_ocm.ts rename to src/modules/ghost/ghost_ocm.ts diff --git a/src/util/ghost/ghost_save_trail.ts b/src/modules/ghost/ghost_save_trail.ts similarity index 100% rename from src/util/ghost/ghost_save_trail.ts rename to src/modules/ghost/ghost_save_trail.ts diff --git a/src/util/ghost/ghost_stamp.ts b/src/modules/ghost/ghost_stamp.ts similarity index 98% rename from src/util/ghost/ghost_stamp.ts rename to src/modules/ghost/ghost_stamp.ts index 6a1aee3..2805109 100644 --- a/src/util/ghost/ghost_stamp.ts +++ b/src/modules/ghost/ghost_stamp.ts @@ -4,7 +4,7 @@ import { prisma } from "../.."; import { wm } from "../../wmmt/wm.proto"; // Import Util -import * as ghost_get_area_from_path from "../ghost/ghost_util/ghost_get_area_from_path"; +import * as ghost_get_area_from_path from "./ghost_util/ghost_get_area_from_path"; export async function sendStamp(body: wm.protobuf.SaveGameResultRequest) diff --git a/src/util/ghost/ghost_area.ts b/src/modules/ghost/ghost_util/ghost_area.ts similarity index 100% rename from src/util/ghost/ghost_area.ts rename to src/modules/ghost/ghost_util/ghost_area.ts diff --git a/src/util/ghost/ghost_util/ghost_get_area_from_path.ts b/src/modules/ghost/ghost_util/ghost_get_area_from_path.ts similarity index 100% rename from src/util/ghost/ghost_util/ghost_get_area_from_path.ts rename to src/modules/ghost/ghost_util/ghost_get_area_from_path.ts diff --git a/src/util/ghost/ghost_ocm_area.ts b/src/modules/ghost/ghost_util/ghost_ocm_area.ts similarity index 97% rename from src/util/ghost/ghost_ocm_area.ts rename to src/modules/ghost/ghost_util/ghost_ocm_area.ts index 0ba680f..ccd39e2 100644 --- a/src/util/ghost/ghost_ocm_area.ts +++ b/src/modules/ghost/ghost_util/ghost_ocm_area.ts @@ -96,16 +96,10 @@ export async function OCMArea(competition_id: number) areaVal = 18; // GID_RAMP_HIROSHIMA_SHINONOME - //rampVal = 37; - - // GID_RAMP_HIROSHIMA_UJINA - rampVal = 38; + rampVal = 37; // GID_PATH_HS_SHINONOME - //pathVal = 56; - - // GID_PATH_HS_UJINA - pathVal = 57; + pathVal = 56; } // 8th - Hakone else if(competition_id === 9) diff --git a/src/util/ghost/ghost_trail.ts b/src/modules/ghost/ghost_util/ghost_trail.ts similarity index 99% rename from src/util/ghost/ghost_trail.ts rename to src/modules/ghost/ghost_util/ghost_trail.ts index 71be0fa..aa2cf55 100644 --- a/src/util/ghost/ghost_trail.ts +++ b/src/modules/ghost/ghost_util/ghost_trail.ts @@ -1,4 +1,4 @@ -import { prisma } from "../.."; +import { prisma } from "../../.."; // Import Proto import * as ghost_ocm_area from "./ghost_ocm_area"; diff --git a/src/modules/ghost_ocm.ts b/src/modules/ghost_ocm.ts index 0959aa9..6669832 100644 --- a/src/modules/ghost_ocm.ts +++ b/src/modules/ghost_ocm.ts @@ -8,8 +8,8 @@ import * as wm from "../wmmt/wm.proto"; // Import Util import * as common from "./util/common"; -import * as ghost_ocm from "../util/ghost/ghost_ocm"; -import * as ghost_ocm_area from "../util/ghost/ghost_ocm_area"; +import * as ghost_ocm from "./ghost/ghost_ocm"; +import * as ghost_ocm_area from "./ghost/ghost_util/ghost_ocm_area"; export default class GhostModule extends Module { diff --git a/src/modules/resource.ts b/src/modules/resource.ts index da77cdb..eef6913 100644 --- a/src/modules/resource.ts +++ b/src/modules/resource.ts @@ -10,6 +10,8 @@ import * as wmsrv from "../wmmt/service.proto"; // Import Util import * as common from "./util/common"; +import * as crown_list from "./resource/crown_list"; +import * as ranking from "./resource/ranking"; export default class ResourceModule extends Module { @@ -50,6 +52,22 @@ export default class ResourceModule extends Module { } }) } + else + { + if(checkPlaceList.shopName !== Config.getConfig().shopName) + { + await prisma.placeList.update({ + where:{ + id: checkPlaceList.id + }, + data:{ + regionId: Number(Config.getConfig().regionId), + shopName: Config.getConfig().shopName, + country: Config.getConfig().country + } + }) + } + } // Encode the response let message = wm.wm.protobuf.PlaceList.encode({places}); @@ -67,252 +85,16 @@ export default class ResourceModule extends Module { let lists: wmsrv.wm.protobuf.Ranking.List[] = []; // Get TA Ranking - for(let i=0; i<25; i++){ // GID_TACOURSE ID + let rankingTA = await ranking.getTimeAttackRanking(); + lists.push( ...rankingTA.lists ); - // Get the TA time per course - let ta_time = await prisma.timeAttackRecord.findMany({ - where: { - course: i - }, - orderBy: { - time: 'asc' - }, - take: 10, // Take top 10 - }); + // Get VS Outrun Ranking + let rankingVSOutrun = await ranking.getVSOutrunRanking(); + lists.push( ...rankingVSOutrun.lists ); - // TA time record by user is available for certain course - if(ta_time.length > 0){ - - // Empty list of ranking records for user time attack - let list_ta: wmsrv.wm.protobuf.Ranking.Entry[] = []; - - // Get the TA time data - for(let j=0; j 14) - { - i = 18; // GID_RUNAREA_HIROSHIMA - } - - // Crown holder for certain area available - if(car_crown[counter].area === i) - { - // Get user's data - let car = await prisma.car.findFirst({ - where: { - carId: car_crown[counter].carId - }, - include: { - gtWing: true, - lastPlayedPlace: true - } - }); - - // Set the tunePower and tuneHandling used when capturing ghost crown - car!.tunePower = car_crown[counter].tunePower; - car!.tuneHandling = car_crown[counter].tuneHandling; - - // Error handling if played At timestamp value is current date and timestamp is bigger than 9 July 2022 (using GMT+7 timestamp) - if(car_crown[counter].playedAt !== 0 && car_crown[counter].playedAt >= 1657299600) - { - // Acquired crown timestamp - 1 day - car!.lastPlayedAt = car_crown[counter].playedAt - 172800; - - // Acquired crown timestamp - 1 day - car_crown[counter].playedAt = car_crown[counter].playedAt - 172800; - } - // Error handling if played At timestamp value is 0 or timestamp is less than 9 July 2022 (using GMT+7 timestamp) - else if(car_crown[counter].playedAt === 0 || car_crown[counter].playedAt < 1657299600) - { - // Acquired crown timestamp become 9 July 2022 (using GMT+7 timestamp) - car!.lastPlayedAt = 1657299600; - - // Acquired crown timestamp become 9 July 2022 (using GMT+7 timestamp) - car_crown[counter].playedAt = 1657299600; - } - - // Push the car data to the crown holder data - // GID_RUNAREA_HIROSHIMA - if(car_crown[counter].area === 18) - { - let listCrown = wmsrv.wm.protobuf.Crown.create({ - carId: car_crown[counter].carId, - area: car_crown[counter].area, - unlockAt: car_crown[counter].playedAt, - car: car! - }); - - list_crown.splice(11, 0, listCrown); - } - // GID_RUNAREA_C1 - GID_RUNAREA_TURNPIKE - else - { - list_crown.push(wmsrv.wm.protobuf.Crown.create({ - carId: car_crown[counter].carId, - area: car_crown[counter].area, - unlockAt: car_crown[counter].playedAt, - car: car! - })); - } - - - if(counter < car_crown.length-1) - { - counter++; - } - } - // Crown holder for certain area not available - else - { - // Push the default data by the game to the crown holder data - // GID_RUNAREA_HIROSHIMA - if(i === 18) - { - let listCrown = wmsrv.wm.protobuf.Crown.create({ - carId: 999999999-i, - area: i, - unlockAt: 0, - }); - - list_crown.splice(11, 0, listCrown); - } - // GID_RUNAREA_C1 - GID_RUNAREA_TURNPIKE - else - { - list_crown.push(wmsrv.wm.protobuf.Crown.create({ - carId: 999999999-i, - area: i, - unlockAt: 0, - })); - } - } - } - } - // There is no user's crown holder data available - else - { - // Loop GID_RUNAREA - for(let i=0; i<19; i++) - { - // After Kobe is Hiroshima then Fukuoka and the rest - if(i > 14) - { - i = 18; // GID_RUNAREA_HIROSHIMA - } - - // Push the default data by the game to the crown holder data - // GID_RUNAREA_HIROSHIMA - if(i === 18) - { - let listCrown = wmsrv.wm.protobuf.Crown.create({ - carId: 999999999-i, - area: i, - unlockAt: 0, - }); - - // Push it after Kobe - list_crown.splice(11, 0, listCrown); - } - // GID_RUNAREA_C1 - GID_RUNAREA_TURNPIKE - else - { - list_crown.push(wmsrv.wm.protobuf.Crown.create({ - carId: 999999999-i, - area: i, - unlockAt: 0, - })); - } - } - } - - // Response data - let msg = { - crowns: list_crown - }; + // Get Crown List + let crown_lists = await crown_list.getCrownList(); + crowns.push( ...crown_lists.list_crown ); // Encode the response - let message = wmsrv.wm.protobuf.CrownList.encode(msg); + let message = wmsrv.wm.protobuf.CrownList.encode( {crowns} ); // Send the response to the client common.sendResponse(message, res); @@ -509,7 +137,6 @@ export default class ResourceModule extends Module { } }); - res.sendFile(path.resolve(paths!.filePath, req.params.filename), { cacheControl: false }); }); diff --git a/src/modules/resource/crown_list.ts b/src/modules/resource/crown_list.ts new file mode 100644 index 0000000..e494bd2 --- /dev/null +++ b/src/modules/resource/crown_list.ts @@ -0,0 +1,172 @@ +import { prisma } from "../.."; + +//Import Proto +import wmsrv from "../../wmmt/service.proto"; + + +// Get Crown List +export async function getCrownList() +{ + // Empty list of crown records + let list_crown: wmsrv.wm.protobuf.Crown[] = []; + + // Get the current date/time (unix epoch) + let date = Math.floor(new Date().getTime() / 1000); + + // Get the crown holder data + let car_crown = await prisma.carCrown.findMany({ + orderBy: { + area: 'asc' + }, + distinct: ['area'] + }); + + // Crown holder data available + if(car_crown.length !== 0) + { + let counter = 0; + + // Loop GID_RUNAREA + for(let i=0; i<19; i++) + { + // After Kobe is Hiroshima then Fukuoka and the rest + if(i > 14) + { + i = 18; // GID_RUNAREA_HIROSHIMA + } + + // Crown holder for certain area available + if(car_crown[counter].area === i) + { + // Get user's data + let car = await prisma.car.findFirst({ + where: { + carId: car_crown[counter].carId + }, + include: { + gtWing: true, + lastPlayedPlace: true + } + }); + + // Set the tunePower and tuneHandling used when capturing ghost crown + car!.tunePower = car_crown[counter].tunePower; + car!.tuneHandling = car_crown[counter].tuneHandling; + + // Error handling if played At timestamp value is current date and timestamp is bigger than 9 July 2022 (using GMT+7 timestamp) + if(car_crown[counter].playedAt !== 0 && car_crown[counter].playedAt >= 1657299600) + { + // Acquired crown timestamp - 1 day + car!.lastPlayedAt = car_crown[counter].playedAt - 172800; + + // Acquired crown timestamp - 1 day + car_crown[counter].playedAt = car_crown[counter].playedAt - 172800; + } + // Error handling if played At timestamp value is 0 or timestamp is less than 9 July 2022 (using GMT+7 timestamp) + else if(car_crown[counter].playedAt === 0 || car_crown[counter].playedAt < 1657299600) + { + // Acquired crown timestamp become 9 July 2022 (using GMT+7 timestamp) + car!.lastPlayedAt = 1657299600; + + // Acquired crown timestamp become 9 July 2022 (using GMT+7 timestamp) + car_crown[counter].playedAt = 1657299600; + } + + // Push the car data to the crown holder data + // GID_RUNAREA_HIROSHIMA + if(car_crown[counter].area === 18) + { + let listCrown = wmsrv.wm.protobuf.Crown.create({ + carId: car_crown[counter].carId, + area: car_crown[counter].area, + unlockAt: car_crown[counter].playedAt, + car: car! + }); + + // Push it after Kobe + list_crown.splice(11, 0, listCrown); + } + // GID_RUNAREA_C1 - GID_RUNAREA_TURNPIKE + else + { + list_crown.push(wmsrv.wm.protobuf.Crown.create({ + carId: car_crown[counter].carId, + area: car_crown[counter].area, + unlockAt: car_crown[counter].playedAt, + car: car! + })); + } + + + if(counter < car_crown.length-1) + { + counter++; + } + } + // Crown holder for certain area not available + else + { + // Push the default data by the game to the crown holder data + // GID_RUNAREA_HIROSHIMA + if(i === 18) + { + let listCrown = wmsrv.wm.protobuf.Crown.create({ + carId: 999999999-i, + area: i, + unlockAt: date - 1000, + }); + + // Push it after Kobe + list_crown.splice(11, 0, listCrown); + } + // GID_RUNAREA_C1 - GID_RUNAREA_TURNPIKE + else + { + list_crown.push(wmsrv.wm.protobuf.Crown.create({ + carId: 999999999-i, + area: i, + unlockAt: date - 1000, + })); + } + } + } + } + // There is no user's crown holder data available + else + { + // Loop GID_RUNAREA + for(let i=0; i<19; i++) + { + // After Kobe is Hiroshima then Fukuoka and the rest + if(i > 14) + { + i = 18; // GID_RUNAREA_HIROSHIMA + } + + // Push the default data by the game to the crown holder data + // GID_RUNAREA_HIROSHIMA + if(i === 18) + { + let listCrown = wmsrv.wm.protobuf.Crown.create({ + carId: 999999999-i, + area: i, + unlockAt: date - 1000, + }); + + // Push it after Kobe + list_crown.splice(11, 0, listCrown); + } + // GID_RUNAREA_C1 - GID_RUNAREA_TURNPIKE + else + { + list_crown.push(wmsrv.wm.protobuf.Crown.create({ + carId: 999999999-i, + area: i, + unlockAt: date - 1000, + })); + } + } + } + + return { list_crown } +} \ No newline at end of file diff --git a/src/modules/resource/ranking.ts b/src/modules/resource/ranking.ts new file mode 100644 index 0000000..148ac63 --- /dev/null +++ b/src/modules/resource/ranking.ts @@ -0,0 +1,279 @@ +import { prisma } from "../.."; + +//Import Proto +import * as wmsrv from "../../wmmt/service.proto"; + + +// Get TA Ranking +export async function getTimeAttackRanking() +{ + // Empty list ranking records + let lists: wmsrv.wm.protobuf.Ranking.List[] = []; + + // Get TA Ranking + for(let i=0; i<25; i++) // GID_TACOURSE ID + { + + // Get the TA time per course + let ta_time = await prisma.timeAttackRecord.findMany({ + where: { + course: i + }, + orderBy: { + time: 'asc' + }, + take: 10, // Take top 10 + }); + + // TA time record by user is available for certain course + if(ta_time.length > 0) + { + // Empty list of ranking records for user time attack + let list_ta: wmsrv.wm.protobuf.Ranking.Entry[] = []; + + // Get the TA time data + for(let j=0; j