From 43777cc690f66ab8043958f0df01ea9aad49ce87 Mon Sep 17 00:00:00 2001 From: Shiroi Kitsu <108461408+shiroikitsu8@users.noreply.github.com> Date: Tue, 17 Jan 2023 22:47:53 +0700 Subject: [PATCH] more random --- src/modules/cars.ts | 33 +++++++++++++++++++++++++++++++-- src/modules/game.ts | 21 --------------------- src/modules/ghost.ts | 37 ++++++++++++++++++++++--------------- src/modules/ghost_ocm.ts | 13 ------------- src/modules/resource.ts | 2 +- src/modules/terminal.ts | 9 --------- 6 files changed, 54 insertions(+), 61 deletions(-) diff --git a/src/modules/cars.ts b/src/modules/cars.ts index 0521d90..93c3d60 100644 --- a/src/modules/cars.ts +++ b/src/modules/cars.ts @@ -129,7 +129,19 @@ export default class CarModule extends Module { console.log('Challengers Available'); // Randomize pick - let random: number = MersenneTwister.int(0, opponentTargetCount - 1); + let random: number = 1; + + // Randomize it 5 times + for(let i=0; i<5; i++) + { + random = MersenneTwister.int(0, opponentTargetCount - 1); // array 0 until max - 1 + } + + // Try randomize it again if it's 1 + if(random === 1) + { + random = MersenneTwister.int(0, opponentTargetCount - 1); // array 0 until max - 1 + } // Check opponents target let opponentTarget = await prisma.carStampTarget.findMany({ @@ -399,7 +411,24 @@ export default class CarModule extends Module { // Randomize regionId let regionId: number = 18; - regionId = MersenneTwister.int(1, 47); + + // Randomize it 5 times + for(let i=0; i<5; i++) + { + regionId = MersenneTwister.int(1, 47); + } + + // Try randomize it again if it's 1 + if(regionId === 1) + { + regionId = MersenneTwister.int(1, 47); + } + + // Error handling if regionId is above 47 + if(regionId > 47) + { + regionId = 47 + } // Default car values let carInsert = { diff --git a/src/modules/game.ts b/src/modules/game.ts index fac67fd..d619878 100644 --- a/src/modules/game.ts +++ b/src/modules/game.ts @@ -136,12 +136,6 @@ export default class GameModule extends Module { } } - // Check region id is 0 - if(body.car!.regionId! === 0) - { - body.car!.regionId = MersenneTwister.int(1, 47); - } - // Check playet at timestamp let timestamps = 0; if(body.car?.lastPlayedAt !== undefined && body.car?.lastPlayedAt !== null) @@ -436,11 +430,6 @@ export default class GameModule extends Module { ghostOpponentCar!.country = 'GLB'; } - if(ghostOpponentCar!.regionId === 0) - { - ghostOpponentCar!.regionId = MersenneTwister.int(1, 47); - } - // Get Opponent 1 tune ghostOpponentCar!.tunePower = ghostHistoryData![i].opponent1TunePower!; ghostOpponentCar!.tuneHandling = ghostHistoryData![i].opponent1TuneHandling!; @@ -478,11 +467,6 @@ export default class GameModule extends Module { ghostOpponentCar2!.country = 'GLB'; } - if(ghostOpponentCar!.regionId === 0) - { - ghostOpponentCar2!.regionId = MersenneTwister.int(1, 47); - } - // Get Opponent 2 tune ghostOpponentCar2!.tunePower = ghostHistoryData![i].opponent2TunePower!; ghostOpponentCar2!.tuneHandling = ghostHistoryData![i].opponent2TuneHandling!; @@ -517,11 +501,6 @@ export default class GameModule extends Module { ghostOpponentCar3!.country = 'GLB'; } - if(ghostOpponentCar!.regionId === 0) - { - ghostOpponentCar3!.regionId = MersenneTwister.int(1, 47); - } - // Get Opponent 3 tune ghostOpponentCar3!.tunePower = ghostHistoryData![i].opponent3TunePower!; ghostOpponentCar3!.tuneHandling = ghostHistoryData![i].opponent3TuneHandling!; diff --git a/src/modules/ghost.ts b/src/modules/ghost.ts index 57f2550..105215b 100644 --- a/src/modules/ghost.ts +++ b/src/modules/ghost.ts @@ -357,18 +357,31 @@ export default class GhostModule extends Module { // Choose the user's car data randomly to appear while(arr.length < maxNumber) { - // Pick random car Id - let randomNumber = MersenneTwister.int(0, car.length-1); + // Randomize pick + let random: number = 1; + + // Randomize it 5 times + for(let i=0; i<5; i++) + { + random = MersenneTwister.int(0, car.length - 1); // array 0 until max - 1 + } + + // Try randomize it again if it's 1 + if(random === 1) + { + random = MersenneTwister.int(0, car.length - 1); // array 0 until max - 1 + } - if(arr.indexOf(randomNumber) === -1) + + if(arr.indexOf(random) === -1) { // Push current number to array - arr.push(randomNumber); + arr.push(random); // Check if ghost trail for certain car is available let ghost_trails = await prisma.ghostTrail.findFirst({ where: { - carId: car[randomNumber].carId, + carId: car[random].carId, area: body.area, crownBattle: false }, @@ -377,31 +390,25 @@ export default class GhostModule extends Module { } }); - // If regionId is 0 or not set, game will crash after defeating the ghost - if(car[randomNumber]!.regionId === 0) - { - car[randomNumber].regionId = MersenneTwister.int(1, 47); - } - // Push user's car data without ghost trail if(!(ghost_trails)) { lists_ghostcar.push(wm.wm.protobuf.GhostCar.create({ - car: car[randomNumber] + car: car[random] })); } // Push user's car data with ghost trail else { // Set the tunePower used when playing certain area - car[randomNumber].tunePower = ghost_trails!.tunePower; + car[random].tunePower = ghost_trails!.tunePower; // Set the tuneHandling used when playing certain area - car[randomNumber].tuneHandling = ghost_trails!.tuneHandling; + car[random].tuneHandling = ghost_trails!.tuneHandling; // Push data to Ghost car proto lists_ghostcar.push(wm.wm.protobuf.GhostCar.create({ - car: car[randomNumber], + car: car[random], nonhuman: false, type: wm.wm.protobuf.GhostType.GHOST_NORMAL, trailId: ghost_trails!.dbId! diff --git a/src/modules/ghost_ocm.ts b/src/modules/ghost_ocm.ts index 05893b7..b9a861e 100644 --- a/src/modules/ghost_ocm.ts +++ b/src/modules/ghost_ocm.ts @@ -2,7 +2,6 @@ import { Application } from "express"; import { Module } from "module"; import { prisma } from ".."; import { Config } from "../config"; -let MersenneTwister = require('chancer'); // Import Proto import * as wm from "../wmmt/wm.proto"; @@ -487,12 +486,6 @@ export default class GhostModule extends Module { } }); - // If regionId is 0 or not set, game will crash after defeating the ghost - if(cars!.regionId === 0) - { - cars!.regionId = MersenneTwister.int(1, 47); - } - // Set the tunePower used when playing ghost crown cars!.tunePower = ocmTallyRecord!.tunePower; @@ -609,12 +602,6 @@ export default class GhostModule extends Module { } }); - // If regionId is 0 or not set, game will crash after defeating the ghost - if(cars!.regionId === 0) - { - cars!.regionId = MersenneTwister.int(1, 47); - } - // Set the tunePower used when playing ghost crown cars!.tunePower = ocmTallyRecord!.tunePower; diff --git a/src/modules/resource.ts b/src/modules/resource.ts index f5a6a5c..6c4a4ee 100644 --- a/src/modules/resource.ts +++ b/src/modules/resource.ts @@ -1,4 +1,4 @@ -import e, { Application } from "express"; +import { Application } from "express"; import { Module } from "module"; import { Config } from "../config"; import { prisma } from ".."; diff --git a/src/modules/terminal.ts b/src/modules/terminal.ts index 3b1b885..128fb99 100644 --- a/src/modules/terminal.ts +++ b/src/modules/terminal.ts @@ -3,7 +3,6 @@ import { Config } from "../config"; import { Module } from "module"; import { prisma } from ".."; import { Car } from "@prisma/client"; -let MersenneTwister = require('chancer'); // Import Proto import * as wm from "../wmmt/wm.proto"; @@ -248,14 +247,6 @@ export default class TerminalModule extends Module { } }); } - - for(let i=0; i