mersenne twister
This commit is contained in:
parent
7e926445fb
commit
ad677d92a2
@ -31,7 +31,8 @@
|
|||||||
"@sentry/node": "^7.7.0",
|
"@sentry/node": "^7.7.0",
|
||||||
"@sentry/tracing": "^7.7.0",
|
"@sentry/tracing": "^7.7.0",
|
||||||
"@types/pem": "^1.9.6",
|
"@types/pem": "^1.9.6",
|
||||||
"body-parser": "^1.20.0",
|
"body-parser": "^1.20.1",
|
||||||
|
"chancer": "^2.0.2",
|
||||||
"dotenv": "^16.0.1",
|
"dotenv": "^16.0.1",
|
||||||
"express": "^4.18.1",
|
"express": "^4.18.1",
|
||||||
"form-urlencoded": "^6.0.6",
|
"form-urlencoded": "^6.0.6",
|
||||||
|
@ -4,6 +4,7 @@ import { Module } from "module";
|
|||||||
import { prisma } from "..";
|
import { prisma } from "..";
|
||||||
import { User } from "@prisma/client";
|
import { User } from "@prisma/client";
|
||||||
import Long from "long";
|
import Long from "long";
|
||||||
|
let MersenneTwister = require('chancer');
|
||||||
|
|
||||||
// Import Proto
|
// Import Proto
|
||||||
import * as wm from "../wmmt/wm.proto";
|
import * as wm from "../wmmt/wm.proto";
|
||||||
@ -49,9 +50,6 @@ export default class CarModule extends Module {
|
|||||||
// Convert the database lose bits to a Long
|
// Convert the database lose bits to a Long
|
||||||
let longLoseBits = Long.fromString(car!.stLoseBits.toString());
|
let longLoseBits = Long.fromString(car!.stLoseBits.toString());
|
||||||
|
|
||||||
// Get current date
|
|
||||||
let date = Math.floor(new Date().getTime() / 1000);
|
|
||||||
|
|
||||||
// Get Registered Target
|
// Get Registered Target
|
||||||
let getTarget = await prisma.ghostRegisteredFromTerminal.findFirst({
|
let getTarget = await prisma.ghostRegisteredFromTerminal.findFirst({
|
||||||
where:{
|
where:{
|
||||||
@ -61,6 +59,7 @@ export default class CarModule extends Module {
|
|||||||
let opponentGhost;
|
let opponentGhost;
|
||||||
let opponentTrailId;
|
let opponentTrailId;
|
||||||
let opponentCompetitionId;
|
let opponentCompetitionId;
|
||||||
|
let registeredTarget: boolean = false;
|
||||||
|
|
||||||
if(getTarget)
|
if(getTarget)
|
||||||
{
|
{
|
||||||
@ -104,85 +103,95 @@ export default class CarModule extends Module {
|
|||||||
opponentTrailId = Number(getTargetTrail!.dbId);
|
opponentTrailId = Number(getTargetTrail!.dbId);
|
||||||
opponentCompetitionId = Number(getTarget.competitionId);
|
opponentCompetitionId = Number(getTarget.competitionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registeredTarget = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check opponents target
|
// Check opponents stamp target
|
||||||
let opponentTargetCount = await prisma.carStampTarget.count({
|
// Will skip this if user's have Hall of Fame ghost registered
|
||||||
where:{
|
|
||||||
stampTargetCarId: body.carId,
|
|
||||||
recommended: true,
|
|
||||||
},
|
|
||||||
orderBy:{
|
|
||||||
locked: 'desc'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
let carsChallengers;
|
let carsChallengers;
|
||||||
let returnCount = 1;
|
let returnCount = 0;
|
||||||
|
let opponentTargetCount = 0;
|
||||||
if(opponentTargetCount > 0)
|
if(registeredTarget === false)
|
||||||
{
|
{
|
||||||
console.log('Challengers Available');
|
opponentTargetCount = await prisma.carStampTarget.count({
|
||||||
|
|
||||||
// Randomize pick
|
|
||||||
let random: number = Math.floor(Math.random() * opponentTargetCount);
|
|
||||||
|
|
||||||
// Check opponents target
|
|
||||||
let opponentTarget = await prisma.carStampTarget.findMany({
|
|
||||||
where:{
|
where:{
|
||||||
stampTargetCarId: body.carId,
|
stampTargetCarId: body.carId,
|
||||||
recommended: true,
|
recommended: true,
|
||||||
},
|
},
|
||||||
orderBy:{
|
orderBy:{
|
||||||
locked: 'desc'
|
locked: 'desc'
|
||||||
},
|
|
||||||
skip: random,
|
|
||||||
take: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Get all of the friend cars for the carId provided
|
|
||||||
let challengers = await prisma.carChallenger.findFirst({
|
|
||||||
where: {
|
|
||||||
challengerCarId: opponentTarget[0].carId,
|
|
||||||
carId: body.carId
|
|
||||||
},
|
|
||||||
orderBy:{
|
|
||||||
id: 'desc'
|
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
if(challengers)
|
returnCount = 1;
|
||||||
|
|
||||||
|
if(opponentTargetCount > 0)
|
||||||
{
|
{
|
||||||
returnCount = opponentTarget[0].returnCount;
|
console.log('Challengers Available');
|
||||||
|
|
||||||
let carTarget = await prisma.car.findFirst({
|
// Randomize pick
|
||||||
|
let random: number = MersenneTwister.int(0, opponentTargetCount);
|
||||||
|
|
||||||
|
// Check opponents target
|
||||||
|
let opponentTarget = await prisma.carStampTarget.findMany({
|
||||||
where:{
|
where:{
|
||||||
carId: challengers.challengerCarId
|
stampTargetCarId: body.carId,
|
||||||
|
recommended: true,
|
||||||
},
|
},
|
||||||
include:{
|
orderBy:{
|
||||||
gtWing: true,
|
locked: 'desc'
|
||||||
lastPlayedPlace: true
|
},
|
||||||
}
|
skip: random,
|
||||||
})
|
take: 1,
|
||||||
|
|
||||||
let result = 0;
|
|
||||||
if(challengers.result > 0)
|
|
||||||
{
|
|
||||||
result = -Math.abs(challengers.result);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
result = Math.abs(challengers.result);
|
|
||||||
}
|
|
||||||
|
|
||||||
carsChallengers = wm.wm.protobuf.ChallengerCar.create({
|
|
||||||
car: carTarget!,
|
|
||||||
stamp: challengers.stamp,
|
|
||||||
result: result,
|
|
||||||
area: challengers.area
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Get all of the friend cars for the carId provided
|
||||||
|
let challengers = await prisma.carChallenger.findFirst({
|
||||||
|
where: {
|
||||||
|
challengerCarId: opponentTarget[0].carId,
|
||||||
|
carId: body.carId
|
||||||
|
},
|
||||||
|
orderBy:{
|
||||||
|
id: 'desc'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if(challengers)
|
||||||
|
{
|
||||||
|
returnCount = opponentTarget[0].returnCount;
|
||||||
|
|
||||||
|
let carTarget = await prisma.car.findFirst({
|
||||||
|
where:{
|
||||||
|
carId: challengers.challengerCarId
|
||||||
|
},
|
||||||
|
include:{
|
||||||
|
gtWing: true,
|
||||||
|
lastPlayedPlace: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
let result = 0;
|
||||||
|
if(challengers.result > 0)
|
||||||
|
{
|
||||||
|
result = -Math.abs(challengers.result);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
result = Math.abs(challengers.result);
|
||||||
|
}
|
||||||
|
|
||||||
|
carsChallengers = wm.wm.protobuf.ChallengerCar.create({
|
||||||
|
car: carTarget!,
|
||||||
|
stamp: challengers.stamp,
|
||||||
|
result: result,
|
||||||
|
area: challengers.area
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Response data
|
// Response data
|
||||||
let msg = {
|
let msg = {
|
||||||
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
|
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
|
||||||
@ -391,11 +400,8 @@ export default class CarModule extends Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Randomize regionId
|
// Randomize regionId
|
||||||
let randomRegionId: number = 18;
|
let regionId: number = 18;
|
||||||
for(let i=0; i<5; i++)
|
regionId = MersenneTwister.int(1, 47);
|
||||||
{
|
|
||||||
randomRegionId = Math.floor(Math.random() * 47) + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default car values
|
// Default car values
|
||||||
let carInsert = {
|
let carInsert = {
|
||||||
@ -412,7 +418,7 @@ export default class CarModule extends Module {
|
|||||||
carSettingsDbId: settings.dbId,
|
carSettingsDbId: settings.dbId,
|
||||||
carStateDbId: state.dbId,
|
carStateDbId: state.dbId,
|
||||||
carGTWingDbId: gtWing.dbId,
|
carGTWingDbId: gtWing.dbId,
|
||||||
regionId: randomRegionId,
|
regionId: regionId,
|
||||||
lastPlayedAt: date,
|
lastPlayedAt: date,
|
||||||
lastPlayedPlaceId: 1, // Server Default
|
lastPlayedPlaceId: 1, // Server Default
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import e, { Application } from "express";
|
import { Application } from "express";
|
||||||
import { Module } from "../module";
|
import { Module } from "../module";
|
||||||
import { prisma } from "..";
|
import { prisma } from "..";
|
||||||
import { Config } from "../config";
|
import { Config } from "../config";
|
||||||
|
let MersenneTwister = require('chancer');
|
||||||
|
|
||||||
// Import Proto
|
// Import Proto
|
||||||
import * as wm from "../wmmt/wm.proto";
|
import * as wm from "../wmmt/wm.proto";
|
||||||
@ -138,8 +139,7 @@ export default class GameModule extends Module {
|
|||||||
// Check region id is 0
|
// Check region id is 0
|
||||||
if(body.car!.regionId! === 0)
|
if(body.car!.regionId! === 0)
|
||||||
{
|
{
|
||||||
let randomRegionId = Math.floor(Math.random() * 47) + 1;
|
body.car!.regionId = MersenneTwister.int(1, 47);
|
||||||
body.car!.regionId = randomRegionId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check playet at timestamp
|
// Check playet at timestamp
|
||||||
@ -256,7 +256,7 @@ export default class GameModule extends Module {
|
|||||||
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
|
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
|
||||||
|
|
||||||
// Set session for saving ghost trail Ghost Battle Mode or Crown Ghost Battle Mode
|
// Set session for saving ghost trail Ghost Battle Mode or Crown Ghost Battle Mode
|
||||||
ghostSessionId: Math.floor(Math.random() * 100) + 1
|
ghostSessionId: MersenneTwister.int(1, 100)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// OCM Battle game mode is completed
|
// OCM Battle game mode is completed
|
||||||
@ -266,7 +266,7 @@ export default class GameModule extends Module {
|
|||||||
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
|
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
|
||||||
|
|
||||||
// Set session for saving ghost trail OCM Ghost Battle Mode
|
// Set session for saving ghost trail OCM Ghost Battle Mode
|
||||||
ghostSessionId: Math.floor(Math.random() * 100) + 101
|
ghostSessionId: MersenneTwister.int(101, 200)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Story mode or TA mode is completed
|
// Story mode or TA mode is completed
|
||||||
@ -438,8 +438,7 @@ export default class GameModule extends Module {
|
|||||||
|
|
||||||
if(ghostOpponentCar!.regionId === 0)
|
if(ghostOpponentCar!.regionId === 0)
|
||||||
{
|
{
|
||||||
let randomRegionId = Math.floor(Math.random() * 47) + 1;
|
ghostOpponentCar!.regionId = MersenneTwister.int(1, 47);
|
||||||
ghostOpponentCar!.regionId = randomRegionId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Opponent 1 tune
|
// Get Opponent 1 tune
|
||||||
@ -481,8 +480,7 @@ export default class GameModule extends Module {
|
|||||||
|
|
||||||
if(ghostOpponentCar!.regionId === 0)
|
if(ghostOpponentCar!.regionId === 0)
|
||||||
{
|
{
|
||||||
let randomRegionId = Math.floor(Math.random() * 47) + 1;
|
ghostOpponentCar2!.regionId = MersenneTwister.int(1, 47);
|
||||||
ghostOpponentCar2!.regionId = randomRegionId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Opponent 2 tune
|
// Get Opponent 2 tune
|
||||||
@ -521,8 +519,7 @@ export default class GameModule extends Module {
|
|||||||
|
|
||||||
if(ghostOpponentCar!.regionId === 0)
|
if(ghostOpponentCar!.regionId === 0)
|
||||||
{
|
{
|
||||||
let randomRegionId = Math.floor(Math.random() * 47) + 1;
|
ghostOpponentCar3!.regionId = MersenneTwister.int(1, 47);
|
||||||
ghostOpponentCar3!.regionId = randomRegionId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Opponent 3 tune
|
// Get Opponent 3 tune
|
||||||
|
@ -4,6 +4,7 @@ import { prisma } from "..";
|
|||||||
import { CarPathandTuning } from "@prisma/client";
|
import { CarPathandTuning } from "@prisma/client";
|
||||||
import Long from "long";
|
import Long from "long";
|
||||||
import { Config } from "../config";
|
import { Config } from "../config";
|
||||||
|
let MersenneTwister = require('chancer');
|
||||||
|
|
||||||
// Import Proto
|
// Import Proto
|
||||||
import * as wm from "../wmmt/wm.proto";
|
import * as wm from "../wmmt/wm.proto";
|
||||||
@ -357,7 +358,7 @@ export default class GhostModule extends Module {
|
|||||||
while(arr.length < maxNumber)
|
while(arr.length < maxNumber)
|
||||||
{
|
{
|
||||||
// Pick random car Id
|
// Pick random car Id
|
||||||
let randomNumber: number = Math.floor(Math.random() * car.length);
|
let randomNumber = MersenneTwister.int(0, maxNumber-1);
|
||||||
if(arr.indexOf(randomNumber) === -1)
|
if(arr.indexOf(randomNumber) === -1)
|
||||||
{
|
{
|
||||||
// Push current number to array
|
// Push current number to array
|
||||||
@ -378,8 +379,7 @@ export default class GhostModule extends Module {
|
|||||||
// If regionId is 0 or not set, game will crash after defeating the ghost
|
// If regionId is 0 or not set, game will crash after defeating the ghost
|
||||||
if(car[randomNumber]!.regionId === 0)
|
if(car[randomNumber]!.regionId === 0)
|
||||||
{
|
{
|
||||||
let randomRegionId = Math.floor(Math.random() * 47) + 1;
|
car[randomNumber].regionId = MersenneTwister.int(1, 47);
|
||||||
car[randomNumber].regionId = randomRegionId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Push user's car data without ghost trail
|
// Push user's car data without ghost trail
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { Application } from "express";
|
import { Application } from "express";
|
||||||
import { Module } from "module";
|
import { Module } from "module";
|
||||||
import { prisma } from "..";
|
import { prisma } from "..";
|
||||||
import { Car, CarGTWing } from "@prisma/client";
|
|
||||||
import { Config } from "../config";
|
import { Config } from "../config";
|
||||||
|
let MersenneTwister = require('chancer');
|
||||||
|
|
||||||
// Import Proto
|
// Import Proto
|
||||||
import * as wm from "../wmmt/wm.proto";
|
import * as wm from "../wmmt/wm.proto";
|
||||||
@ -423,7 +423,7 @@ export default class GhostModule extends Module {
|
|||||||
ocmEventDate = await prisma.oCMEvent.findFirst({
|
ocmEventDate = await prisma.oCMEvent.findFirst({
|
||||||
orderBy: [
|
orderBy: [
|
||||||
{
|
{
|
||||||
competitionId: 'desc'
|
dbId: 'desc'
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -492,8 +492,7 @@ export default class GhostModule extends Module {
|
|||||||
// If regionId is 0 or not set, game will crash after defeating the ghost
|
// If regionId is 0 or not set, game will crash after defeating the ghost
|
||||||
if(cars!.regionId === 0)
|
if(cars!.regionId === 0)
|
||||||
{
|
{
|
||||||
let randomRegionId = Math.floor(Math.random() * 47) + 1;
|
cars!.regionId = MersenneTwister.int(1, 47);
|
||||||
cars!.regionId = randomRegionId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the tunePower used when playing ghost crown
|
// Set the tunePower used when playing ghost crown
|
||||||
@ -615,8 +614,7 @@ export default class GhostModule extends Module {
|
|||||||
// If regionId is 0 or not set, game will crash after defeating the ghost
|
// If regionId is 0 or not set, game will crash after defeating the ghost
|
||||||
if(cars!.regionId === 0)
|
if(cars!.regionId === 0)
|
||||||
{
|
{
|
||||||
let randomRegionId = Math.floor(Math.random() * 47) + 1;
|
cars!.regionId = MersenneTwister.int(1, 47);
|
||||||
cars!.regionId = randomRegionId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the tunePower used when playing ghost crown
|
// Set the tunePower used when playing ghost crown
|
||||||
@ -647,7 +645,7 @@ export default class GhostModule extends Module {
|
|||||||
|
|
||||||
|
|
||||||
let ocmEventDate = await prisma.oCMEvent.findFirst({
|
let ocmEventDate = await prisma.oCMEvent.findFirst({
|
||||||
where: {
|
where:{
|
||||||
competitionId: competition_id
|
competitionId: competition_id
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -706,7 +704,6 @@ 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,
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
import { Application } from "express";
|
import e, { Application } from "express";
|
||||||
import {Module} from "module";
|
import { Module } from "module";
|
||||||
import { Config } from "../config";
|
import { Config } from "../config";
|
||||||
import { prisma } from "..";
|
import { prisma } from "..";
|
||||||
|
import path from 'path';
|
||||||
|
let MersenneTwister = require('chancer');
|
||||||
|
|
||||||
// Import Proto
|
// Import Proto
|
||||||
import * as wm from "../wmmt/wm.proto";
|
import * as wm from "../wmmt/wm.proto";
|
||||||
@ -49,22 +51,6 @@ 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().placeId),
|
|
||||||
shopName: Config.getConfig().shopName,
|
|
||||||
country: Config.getConfig().country
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Encode the response
|
// Encode the response
|
||||||
let message = wm.wm.protobuf.PlaceList.encode({places});
|
let message = wm.wm.protobuf.PlaceList.encode({places});
|
||||||
@ -147,8 +133,8 @@ export default class ResourceModule extends Module {
|
|||||||
result: resultTime,
|
result: resultTime,
|
||||||
name: 'GUEST',
|
name: 'GUEST',
|
||||||
regionId: 1, // Hokkaido
|
regionId: 1, // Hokkaido
|
||||||
model: Math.floor(Math.random() * 50), // Randomizing GUEST Car data
|
model: MersenneTwister.int(0, 50), // Randomizing GUEST Car data
|
||||||
visualModel: Math.floor(Math.random() * 100), // Randomizing GUEST Car data
|
visualModel: MersenneTwister.int(0, 100), // Randomizing GUEST Car data
|
||||||
defaultColor: 0,
|
defaultColor: 0,
|
||||||
tunePower: 0,
|
tunePower: 0,
|
||||||
tuneHandling: 0,
|
tuneHandling: 0,
|
||||||
@ -185,8 +171,8 @@ export default class ResourceModule extends Module {
|
|||||||
result: resulttime,
|
result: resulttime,
|
||||||
name: 'GUEST',
|
name: 'GUEST',
|
||||||
regionId: 1, // Hokkaido
|
regionId: 1, // Hokkaido
|
||||||
model: Math.floor(Math.random() * 50), // Randomizing GUEST Car data
|
model: MersenneTwister.int(0, 50), // Randomizing GUEST Car data
|
||||||
visualModel: Math.floor(Math.random() * 100), // Randomizing GUEST Car data
|
visualModel: MersenneTwister.int(0, 100), // Randomizing GUEST Car data
|
||||||
defaultColor: 0,
|
defaultColor: 0,
|
||||||
tunePower: 0,
|
tunePower: 0,
|
||||||
tuneHandling: 0,
|
tuneHandling: 0,
|
||||||
@ -249,8 +235,8 @@ export default class ResourceModule extends Module {
|
|||||||
result: 0,
|
result: 0,
|
||||||
name: 'GUEST',
|
name: 'GUEST',
|
||||||
regionId: 1, // Hokkaido
|
regionId: 1, // Hokkaido
|
||||||
model: Math.floor(Math.random() * 50), // Randomizing GUEST Car data
|
model: MersenneTwister.int(0, 50), // Randomizing GUEST Car data
|
||||||
visualModel: Math.floor(Math.random() * 100), // Randomizing GUEST Car data
|
visualModel: MersenneTwister.int(0, 100), // Randomizing GUEST Car data
|
||||||
defaultColor: 0,
|
defaultColor: 0,
|
||||||
tunePower: 0,
|
tunePower: 0,
|
||||||
tuneHandling: 0,
|
tuneHandling: 0,
|
||||||
@ -312,8 +298,8 @@ export default class ResourceModule extends Module {
|
|||||||
result: 0,
|
result: 0,
|
||||||
name: 'GUEST',
|
name: 'GUEST',
|
||||||
regionId: 1, // Hokkaido
|
regionId: 1, // Hokkaido
|
||||||
model: Math.floor(Math.random() * 50), // Randomizing GUEST Car data
|
model: MersenneTwister.int(0, 50), // Randomizing GUEST Car data
|
||||||
visualModel: Math.floor(Math.random() * 100), // Randomizing GUEST Car data
|
visualModel: MersenneTwister.int(0, 100), // Randomizing GUEST Car data
|
||||||
defaultColor: 0,
|
defaultColor: 0,
|
||||||
tunePower: 0,
|
tunePower: 0,
|
||||||
tuneHandling: 0,
|
tuneHandling: 0,
|
||||||
@ -415,7 +401,6 @@ export default class ResourceModule extends Module {
|
|||||||
car: car!
|
car: car!
|
||||||
});
|
});
|
||||||
|
|
||||||
// Push it after Kobe
|
|
||||||
list_crown.splice(11, 0, listCrown);
|
list_crown.splice(11, 0, listCrown);
|
||||||
}
|
}
|
||||||
// GID_RUNAREA_C1 - GID_RUNAREA_TURNPIKE
|
// GID_RUNAREA_C1 - GID_RUNAREA_TURNPIKE
|
||||||
@ -448,7 +433,6 @@ export default class ResourceModule extends Module {
|
|||||||
unlockAt: 0,
|
unlockAt: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Push it after Kobe
|
|
||||||
list_crown.splice(11, 0, listCrown);
|
list_crown.splice(11, 0, listCrown);
|
||||||
}
|
}
|
||||||
// GID_RUNAREA_C1 - GID_RUNAREA_TURNPIKE
|
// GID_RUNAREA_C1 - GID_RUNAREA_TURNPIKE
|
||||||
@ -512,18 +496,35 @@ export default class ResourceModule extends Module {
|
|||||||
common.sendResponse(message, res);
|
common.sendResponse(message, res);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.use("/static", e.static(
|
||||||
|
path.join(__dirname, '..', '..', 'static'),
|
||||||
|
{ cacheControl: false }
|
||||||
|
));
|
||||||
|
|
||||||
|
|
||||||
app.get('/resource/file_list', async (req, res) => {
|
app.get('/resource/file_list', async (req, res) => {
|
||||||
|
|
||||||
console.log('file_list');
|
console.log('file_list');
|
||||||
|
|
||||||
// TODO: Actual stuff here
|
// TODO: Actual stuff here
|
||||||
// This is literally just bare-bones so the shit boots
|
// This is literally just bare-bones so the shit boots
|
||||||
|
let files: wm.wm.protobuf.FileList.FileInfo[] = [];
|
||||||
|
|
||||||
|
files.push(wm.wm.protobuf.FileList.FileInfo.create({
|
||||||
|
fileId: 1,
|
||||||
|
fileType: wm.wm.protobuf.FileType.FILE_PROMOTION_ANNOUNCEMENT,
|
||||||
|
fileSize: 383791,
|
||||||
|
url: 'https://'+Config.getConfig().serverIp+':9002/static/000002-bayshore.bin',
|
||||||
|
sha1sum: Buffer.from('F1A1AF6F7273F2BA5189CDB15165028B56E022E6', "hex"),
|
||||||
|
notBefore: 0,
|
||||||
|
notAfter: 2147483647,
|
||||||
|
}));
|
||||||
|
|
||||||
// Response data
|
// Response data
|
||||||
let msg = {
|
let msg = {
|
||||||
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
|
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
|
||||||
files: null,
|
files: files,
|
||||||
interval: null
|
interval: 2
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode the response
|
// Encode the response
|
||||||
@ -533,6 +534,7 @@ export default class ResourceModule extends Module {
|
|||||||
common.sendResponse(message, res);
|
common.sendResponse(message, res);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
app.get('/resource/ghost_list', async (req, res) => {
|
app.get('/resource/ghost_list', async (req, res) => {
|
||||||
|
|
||||||
console.log('ghost_list');
|
console.log('ghost_list');
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Application } from "express";
|
import { Application } from "express";
|
||||||
import {Module} from "module";
|
import { Module } from "module";
|
||||||
import { prisma } from "..";
|
import { prisma } from "..";
|
||||||
|
|
||||||
// Import Proto
|
// Import Proto
|
||||||
|
@ -3,6 +3,7 @@ import { Config } from "../config";
|
|||||||
import { Module } from "module";
|
import { Module } from "module";
|
||||||
import { prisma } from "..";
|
import { prisma } from "..";
|
||||||
import { Car } from "@prisma/client";
|
import { Car } from "@prisma/client";
|
||||||
|
let MersenneTwister = require('chancer');
|
||||||
|
|
||||||
// Import Proto
|
// Import Proto
|
||||||
import * as wm from "../wmmt/wm.proto";
|
import * as wm from "../wmmt/wm.proto";
|
||||||
@ -252,8 +253,7 @@ export default class TerminalModule extends Module {
|
|||||||
{
|
{
|
||||||
if(cars[i].regionId === 0)
|
if(cars[i].regionId === 0)
|
||||||
{
|
{
|
||||||
let randomRegionId = Math.floor(Math.random() * 47) + 1;
|
cars[i].regionId = MersenneTwister.int(1, 47);
|
||||||
cars[i].regionId = randomRegionId;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -900,52 +900,66 @@ export default class TerminalModule extends Module {
|
|||||||
common.sendResponse(message, res);
|
common.sendResponse(message, res);
|
||||||
})
|
})
|
||||||
|
|
||||||
// Recieve user items
|
|
||||||
|
// Register Opponent Ghost
|
||||||
app.post('/method/register_opponent_ghost', async (req, res) => {
|
app.post('/method/register_opponent_ghost', async (req, res) => {
|
||||||
|
|
||||||
// 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);
|
||||||
|
|
||||||
// Check if target is already registered
|
let ocmEventDate = await prisma.oCMEvent.findFirst({
|
||||||
let checkOpponent = await prisma.ghostRegisteredFromTerminal.findFirst({
|
orderBy: {
|
||||||
where:{
|
competitionEndAt: 'desc',
|
||||||
carId: body.carId,
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get Target Car ID
|
if(ocmEventDate)
|
||||||
let ghostCompetitionTarget = await prisma.oCMTop1Ghost.findFirst({
|
|
||||||
where:{
|
|
||||||
competitionId: body.specialGhostId,
|
|
||||||
},
|
|
||||||
orderBy:{
|
|
||||||
periodId: 'desc'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Target not yet registerted
|
|
||||||
if(!(checkOpponent))
|
|
||||||
{
|
{
|
||||||
await prisma.ghostRegisteredFromTerminal.create({
|
let checkRegisteredGhost = await prisma.ghostRegisteredFromTerminal.findFirst({
|
||||||
data:{
|
|
||||||
carId: body.carId,
|
|
||||||
competitionId: body.specialGhostId,
|
|
||||||
opponentCarId: ghostCompetitionTarget!.carId
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
await prisma.ghostRegisteredFromTerminal.update({
|
|
||||||
where:{
|
where:{
|
||||||
dbId: checkOpponent.dbId
|
carId: body.carId
|
||||||
},
|
|
||||||
data:{
|
|
||||||
carId: body.carId,
|
|
||||||
competitionId: body.specialGhostId,
|
|
||||||
opponentCarId: ghostCompetitionTarget!.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
|
// Response data
|
||||||
@ -1007,25 +1021,6 @@ export default class TerminalModule extends Module {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Save Screenshoot
|
|
||||||
app.post('/method/save_screenshot', async (req, res) => {
|
|
||||||
|
|
||||||
// Get the information from the request
|
|
||||||
let body = wm.wm.protobuf.SaveScreenshotRequest.decode(req.body);
|
|
||||||
|
|
||||||
// Response data
|
|
||||||
let msg = {
|
|
||||||
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Encode the response
|
|
||||||
let message = wm.wm.protobuf.SaveScreenshotResponse.encode(msg);
|
|
||||||
|
|
||||||
// Send the response to the client
|
|
||||||
common.sendResponse(message, res);
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
app.post('/method/load_unreceived_user_items', async (req, res) => {
|
app.post('/method/load_unreceived_user_items', async (req, res) => {
|
||||||
|
|
||||||
@ -1045,6 +1040,24 @@ export default class TerminalModule extends Module {
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
app.post('/method/save_screenshot', async (req, res) => {
|
||||||
|
|
||||||
|
// Get the information from the request
|
||||||
|
let body = wm.wm.protobuf.SaveScreenshotRequest.decode(req.body);
|
||||||
|
|
||||||
|
// Response data
|
||||||
|
let msg = {
|
||||||
|
error: wmsrv.wm.protobuf.ErrorCode.ERR_SUCCESS,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Encode the response
|
||||||
|
let message = wmsrv.wm.protobuf.SaveScreenshotResponse.encode(msg);
|
||||||
|
|
||||||
|
// Send the response to the client
|
||||||
|
common.sendResponse(message, res);
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
app.post('/method/check_item_receivable_cars', async (req, res) => {
|
app.post('/method/check_item_receivable_cars', async (req, res) => {
|
||||||
|
|
||||||
// Get the information from the request
|
// Get the information from the request
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import e, { Application } from "express";
|
import { Application } from "express";
|
||||||
import { Config } from "../config";
|
import { Config } from "../config";
|
||||||
import { Module } from "module";
|
import { Module } from "module";
|
||||||
import { prisma } from "..";
|
import { prisma } from "..";
|
||||||
@ -484,33 +484,27 @@ export default class UserModule extends Module {
|
|||||||
if(!ocmEventDate)
|
if(!ocmEventDate)
|
||||||
{
|
{
|
||||||
let ocmEventDate = await prisma.oCMEvent.findFirst({
|
let ocmEventDate = await prisma.oCMEvent.findFirst({
|
||||||
orderBy:
|
orderBy: {
|
||||||
{
|
|
||||||
competitionEndAt: 'desc',
|
competitionEndAt: 'desc',
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if(ocmEventDate)
|
if(ocmEventDate)
|
||||||
{
|
{
|
||||||
let pastDay = date - ocmEventDate.competitionEndAt;
|
let checkRegisteredGhost = await prisma.ghostRegisteredFromTerminal.findFirst({
|
||||||
|
where:{
|
||||||
|
carId: user.cars[i].carId,
|
||||||
|
competitionId: ocmEventDate.competitionId
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if(pastDay < 604800)
|
if(checkRegisteredGhost)
|
||||||
{
|
{
|
||||||
let checkRegisteredGhost = await prisma.ghostRegisteredFromTerminal.findFirst({
|
carStates[i].hasOpponentGhost = true;
|
||||||
where:{
|
}
|
||||||
carId: user.cars[i].carId,
|
else
|
||||||
competitionId: ocmEventDate.competitionId
|
{
|
||||||
}
|
carStates[i].hasOpponentGhost = false;
|
||||||
});
|
|
||||||
|
|
||||||
if(checkRegisteredGhost)
|
|
||||||
{
|
|
||||||
carStates[i].hasOpponentGhost = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
carStates[i].hasOpponentGhost = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
39
yarn.lock
39
yarn.lock
@ -1271,7 +1271,7 @@ bluebird@^3.7.2:
|
|||||||
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
|
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
|
||||||
integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==
|
integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==
|
||||||
|
|
||||||
body-parser@1.20.0, body-parser@^1.20.0:
|
body-parser@1.20.0:
|
||||||
version "1.20.0"
|
version "1.20.0"
|
||||||
resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.20.0.tgz#3de69bd89011c11573d7bfee6a64f11b6bd27cc5"
|
resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.20.0.tgz#3de69bd89011c11573d7bfee6a64f11b6bd27cc5"
|
||||||
integrity sha512-DfJ+q6EPcGKZD1QWUjSpqp+Q7bDQTsQIF4zfUAtZ6qk+H/3/QRhg9CEp39ss+/T2vw0+HaidC0ecJj/DRLIaKg==
|
integrity sha512-DfJ+q6EPcGKZD1QWUjSpqp+Q7bDQTsQIF4zfUAtZ6qk+H/3/QRhg9CEp39ss+/T2vw0+HaidC0ecJj/DRLIaKg==
|
||||||
@ -1289,6 +1289,24 @@ body-parser@1.20.0, body-parser@^1.20.0:
|
|||||||
type-is "~1.6.18"
|
type-is "~1.6.18"
|
||||||
unpipe "1.0.0"
|
unpipe "1.0.0"
|
||||||
|
|
||||||
|
body-parser@^1.20.1:
|
||||||
|
version "1.20.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.20.1.tgz#b1812a8912c195cd371a3ee5e66faa2338a5c668"
|
||||||
|
integrity sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==
|
||||||
|
dependencies:
|
||||||
|
bytes "3.1.2"
|
||||||
|
content-type "~1.0.4"
|
||||||
|
debug "2.6.9"
|
||||||
|
depd "2.0.0"
|
||||||
|
destroy "1.2.0"
|
||||||
|
http-errors "2.0.0"
|
||||||
|
iconv-lite "0.4.24"
|
||||||
|
on-finished "2.4.1"
|
||||||
|
qs "6.11.0"
|
||||||
|
raw-body "2.5.1"
|
||||||
|
type-is "~1.6.18"
|
||||||
|
unpipe "1.0.0"
|
||||||
|
|
||||||
brace-expansion@^1.1.7:
|
brace-expansion@^1.1.7:
|
||||||
version "1.1.11"
|
version "1.1.11"
|
||||||
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
|
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
|
||||||
@ -1342,6 +1360,13 @@ chalk@^4.0.0:
|
|||||||
ansi-styles "^4.1.0"
|
ansi-styles "^4.1.0"
|
||||||
supports-color "^7.1.0"
|
supports-color "^7.1.0"
|
||||||
|
|
||||||
|
chancer@^2.0.2:
|
||||||
|
version "2.0.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/chancer/-/chancer-2.0.2.tgz#20b5e6a2009a2987a639f64d93670532ac6f4868"
|
||||||
|
integrity sha512-MFRbifjvvkHTTDyWtDDv5tWhRyFfR6ZvWVuRxdMnycaGFipjn5MHZC593MTuhNZatyQlys1eAfW+eUX4L2eJpA==
|
||||||
|
dependencies:
|
||||||
|
mersenne-twister "^1.0.1"
|
||||||
|
|
||||||
charenc@0.0.2:
|
charenc@0.0.2:
|
||||||
version "0.0.2"
|
version "0.0.2"
|
||||||
resolved "https://registry.yarnpkg.com/charenc/-/charenc-0.0.2.tgz#c0a1d2f3a7092e03774bfa83f14c0fc5790a8667"
|
resolved "https://registry.yarnpkg.com/charenc/-/charenc-0.0.2.tgz#c0a1d2f3a7092e03774bfa83f14c0fc5790a8667"
|
||||||
@ -1939,6 +1964,11 @@ merge-descriptors@1.0.1:
|
|||||||
resolved "https://registry.yarnpkg.com/merge-descriptors/-/merge-descriptors-1.0.1.tgz#b00aaa556dd8b44568150ec9d1b953f3f90cbb61"
|
resolved "https://registry.yarnpkg.com/merge-descriptors/-/merge-descriptors-1.0.1.tgz#b00aaa556dd8b44568150ec9d1b953f3f90cbb61"
|
||||||
integrity sha512-cCi6g3/Zr1iqQi6ySbseM1Xvooa98N0w31jzUYrXPX2xqObmFGHJ0tQ5u74H3mVh7wLouTseZyYIq39g8cNp1w==
|
integrity sha512-cCi6g3/Zr1iqQi6ySbseM1Xvooa98N0w31jzUYrXPX2xqObmFGHJ0tQ5u74H3mVh7wLouTseZyYIq39g8cNp1w==
|
||||||
|
|
||||||
|
mersenne-twister@^1.0.1:
|
||||||
|
version "1.1.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/mersenne-twister/-/mersenne-twister-1.1.0.tgz#f916618ee43d7179efcf641bec4531eb9670978a"
|
||||||
|
integrity sha512-mUYWsMKNrm4lfygPkL3OfGzOPTR2DBlTkBNHM//F6hGp8cLThY897crAlk3/Jo17LEOOjQUrNAx6DvgO77QJkA==
|
||||||
|
|
||||||
methods@~1.1.2:
|
methods@~1.1.2:
|
||||||
version "1.1.2"
|
version "1.1.2"
|
||||||
resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"
|
resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"
|
||||||
@ -2253,6 +2283,13 @@ qs@6.10.3:
|
|||||||
dependencies:
|
dependencies:
|
||||||
side-channel "^1.0.4"
|
side-channel "^1.0.4"
|
||||||
|
|
||||||
|
qs@6.11.0:
|
||||||
|
version "6.11.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/qs/-/qs-6.11.0.tgz#fd0d963446f7a65e1367e01abd85429453f0c37a"
|
||||||
|
integrity sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==
|
||||||
|
dependencies:
|
||||||
|
side-channel "^1.0.4"
|
||||||
|
|
||||||
range-parser@~1.2.1:
|
range-parser@~1.2.1:
|
||||||
version "1.2.1"
|
version "1.2.1"
|
||||||
resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.1.tgz#3cf37023d199e1c24d1a55b84800c2f3e6468031"
|
resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.1.tgz#3cf37023d199e1c24d1a55b84800c2f3e6468031"
|
||||||
|
Loading…
Reference in New Issue
Block a user