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

fix crown battle saving

This commit is contained in:
ghkkk090 2022-07-29 16:13:21 +07:00
parent 67fb4b2e04
commit 28c1f8289e
7 changed files with 272 additions and 106 deletions

View File

@ -0,0 +1,17 @@
-- AlterTable
ALTER TABLE "Car" ALTER COLUMN "stLoseBits" SET DEFAULT 0;
-- CreateTable
CREATE TABLE "CarCrown" (
"dbId" SERIAL NOT NULL,
"carId" INTEGER NOT NULL,
"area" INTEGER NOT NULL,
"ramp" INTEGER NOT NULL,
"path" INTEGER NOT NULL,
"trail" BIGINT NOT NULL DEFAULT 0,
CONSTRAINT "CarCrown_pkey" PRIMARY KEY ("dbId")
);
-- AddForeignKey
ALTER TABLE "CarCrown" ADD CONSTRAINT "CarCrown_carId_fkey" FOREIGN KEY ("carId") REFERENCES "Car"("carId") ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@ -0,0 +1,14 @@
/*
Warnings:
- A unique constraint covering the columns `[area]` on the table `CarCrown` will be added. If there are existing duplicate values, this will fail.
*/
-- AlterTable
ALTER TABLE "Car" ALTER COLUMN "stLoseBits" SET DEFAULT 0;
-- AlterTable
ALTER TABLE "CarCrown" ALTER COLUMN "trail" SET DEFAULT 0;
-- CreateIndex
CREATE UNIQUE INDEX "CarCrown_area_key" ON "CarCrown"("area");

View File

@ -0,0 +1,6 @@
-- AlterTable
ALTER TABLE "Car" ALTER COLUMN "stLoseBits" SET DEFAULT 0;
-- AlterTable
ALTER TABLE "CarCrown" ADD COLUMN "playedAt" INTEGER NOT NULL DEFAULT 0,
ALTER COLUMN "trail" SET DEFAULT 0;

View File

@ -0,0 +1,14 @@
/*
Warnings:
- Added the required column `tuneHandling` to the `CarCrown` table without a default value. This is not possible if the table is not empty.
- Added the required column `tunePower` to the `CarCrown` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "Car" ALTER COLUMN "stLoseBits" SET DEFAULT 0;
-- AlterTable
ALTER TABLE "CarCrown" ADD COLUMN "tuneHandling" INTEGER NOT NULL,
ADD COLUMN "tunePower" INTEGER NOT NULL,
ALTER COLUMN "trail" SET DEFAULT 0;

View File

@ -130,18 +130,19 @@ model Car {
carStateDbId Int @unique
state CarState @relation(fields: [carStateDbId], references: [dbId])
TimeAttackRecord TimeAttackRecord[]
CarCrown CarCrown[]
}
model CarGTWing {
dbId Int @id @default(autoincrement())
car Car?
pillar Int @default(0)
pillarMaterial Int @default(0)
mainWing Int @default(0)
mainWingColor Int @default(0)
wingTip Int @default(0)
material Int @default(0)
pillar Int @default(0)
pillarMaterial Int @default(0)
mainWing Int @default(0)
mainWingColor Int @default(0)
wingTip Int @default(0)
material Int @default(0)
}
model CarItem {
@ -199,3 +200,16 @@ model TimeAttackRecord {
tunePower Int @default(0) // Car Power
tuneHandling Int @default(0) // Car Handling
}
model CarCrown {
dbId Int @id @default(autoincrement())
car Car @relation(fields: [carId], references: [carId])
carId Int
area Int @unique
ramp Int
path Int
trail BigInt @default(0)
playedAt Int @default(0)
tunePower Int
tuneHandling Int
}

View File

@ -10,6 +10,7 @@ import { userInfo } from "os";
import { config } from "dotenv";
import * as scratch from "../util/scratch";
import { envelopeItemTypeToDataCategory } from "@sentry/utils";
import path from "path";
export default class GameModule extends Module {
register(app: Application): void {
@ -21,7 +22,6 @@ export default class GameModule extends Module {
carId: body.carId
}
});
console.log(body);
let storyLose: boolean = false;
switch (body.gameMode) {
case wm.wm.protobuf.GameMode.MODE_STORY:
@ -297,6 +297,102 @@ export default class GameModule extends Module {
},
data: saveEx
});
if (body.rgResult?.acquireCrown !== false || body.rgResult?.acquireCrown !== null && body.rgResult?.acquireCrown !== undefined) {
let saveExCrown: any = {};
saveExCrown.carId = body.carId;
if(body.rgResult?.path !== null && body.rgResult?.path !== undefined){
if(body.rgResult?.path >= 0 && body.rgResult?.path <= 9){ // GID_PATH_C1
saveExCrown.area = Number(0);
saveExCrown.ramp = Number(Math.floor(Math.random() * 4));
}
else if(body.rgResult?.path >= 10 && body.rgResult?.path <= 15){ // GID_PATH_N9
saveExCrown.area = Number(1);
saveExCrown.ramp = Number(Math.floor(Math.random() * 2) + 4);
}
else if(body.rgResult?.path >= 16 && body.rgResult?.path <= 17){ // GID_PATH_WTEAST
saveExCrown.area = Number(2);
saveExCrown.ramp = Number(Math.floor(Math.random() * 2) + 6);
}
else if(body.rgResult?.path >= 18 && body.rgResult?.path <= 19){ // GID_PATH_WT_UP_DOWN
saveExCrown.area = Number(3);
saveExCrown.ramp = Number(Math.floor(Math.random() * 2) + 8);
}
else if(body.rgResult?.path >= 20 && body.rgResult?.path <= 26){ // GID_PATH_WG
saveExCrown.area = Number(4);
saveExCrown.ramp = Number(Math.floor(Math.random() * 4) + 10);
}
else if(body.rgResult?.path >= 27 && body.rgResult?.path <= 33){ // GID_PATH_KG
saveExCrown.area = Number(5);
saveExCrown.ramp = Number(Math.floor(Math.random() * 4) + 14);
}
else if(body.rgResult?.path >= 34 && body.rgResult?.path <= 37){ // GID_PATH_YS
saveExCrown.area = Number(6);
saveExCrown.ramp = Number(Math.floor(Math.random() * 3) + 18);
}
else if(body.rgResult?.path >= 38 && body.rgResult?.path <= 48){ // GID_PATH_KG_SHINYAMASHITA_MINATOMIRAI
saveExCrown.area = Number(7);
saveExCrown.ramp = Number(Math.floor(Math.random() * 4) + 21);
}
else if(body.rgResult?.path === 49){ // GID_PATH_NGR
saveExCrown.area = Number(8);
saveExCrown.ramp = Number(25);
}
else if(body.rgResult?.path >= 50 && body.rgResult?.path <= 53){ // GID_PATH_OS
saveExCrown.area = Number(9);
saveExCrown.ramp = Number(26);
}
else if(body.rgResult?.path >= 54 && body.rgResult?.path <= 55){ // GID_PATH_KB
saveExCrown.area = Number(10);
saveExCrown.ramp = Number(Math.floor(Math.random() * 2) + 27);
}
else if(body.rgResult?.path >= 58 && body.rgResult?.path <= 61){ // GID_PATH_FK
saveExCrown.area = Number(11);
saveExCrown.ramp = Number(Math.floor(Math.random() * 4) + 29);
}
else if(body.rgResult?.path >= 62 && body.rgResult?.path <= 63){ // GID_PATH_HK
saveExCrown.area = Number(12);
saveExCrown.ramp = Number(Math.floor(Math.random() * 2) + 33);
}
else if(body.rgResult?.path >= 64 && body.rgResult?.path <= 65){ // GID_PATH_TP
saveExCrown.area = Number(13);
saveExCrown.ramp = Number(Math.floor(Math.random() * 2) + 35);
}
else if(body.rgResult?.path >= 56 && body.rgResult?.path <= 57){ // GID_PATH_KB
saveExCrown.area = Number(18);
saveExCrown.ramp = Number(Math.floor(Math.random() * 2) + 27);
}
saveExCrown.path = body.rgResult?.path!;
}
if(body?.playedAt !== null || body?.playedAt !== undefined){
saveExCrown.playedAt = body?.playedAt!;
}
saveExCrown.trail = Number(1); //wtf is this lmao
saveExCrown.tunePower = body.car!.tunePower!;
saveExCrown.tuneHandling = body.car!.tuneHandling!;
let carCrowns = await prisma.carCrown.count({
where: {
carId: body.carId,
area: saveExCrown.area
}
});
if(carCrowns !== 0){
let areaVal = Number(saveExCrown.area);
await prisma.carCrown.update({
where: {
area: areaVal
},
data: saveExCrown
});
}
else{
await prisma.carCrown.create({
data: saveExCrown
});
}
}
}
break;
}
@ -431,94 +527,94 @@ export default class GameModule extends Module {
// Every n*100 play give reward
let giveMeterReward = Config.getConfig().gameOptions.giveMeterReward;
if(giveMeterReward === 1 && body.playCount % 100 === 0){
let carItemCount = await prisma.carItem.findMany({
let carItemCount = await prisma.carItem.count({
where: {
carId: body.carId,
category: 15,
itemId: {
lte: 28,
lte: 34,
gte: 1,
},
NOT: {
itemId: { in: [2, 3, 5, 6, 29, 30, 31, 32, 33 ,34] },
},
},
/*where: {
itemId: { notIn: [2, 3, 5, 6, 29, 30, 31, 32, 33 ,34] },
},*/
})
let sqlVal = 0;
for(let i=0; i<carItemCount.length; i++){
if(carItemCount[i].itemId !== 2 && carItemCount[i].itemId !== 3 && carItemCount[i].itemId !== 5 && carItemCount[i].itemId !== 6){
sqlVal = sqlVal + 1;
}
}
console.log('Number of owned reward meter : ' + carItemCount)
let itemIdVal = 0;
if(sqlVal === 0){
if(carItemCount === 0){
itemIdVal = 1;
}
else if(sqlVal === 1){
else if(carItemCount === 1){
itemIdVal = 4;
}
else if(sqlVal === 2){
else if(carItemCount === 2){
itemIdVal = 7;
}
else if(sqlVal === 3){
else if(carItemCount === 3){
itemIdVal = 8;
}
else if(sqlVal === 4){
else if(carItemCount === 4){
itemIdVal = 9;
}
else if(sqlVal === 5){
else if(carItemCount === 5){
itemIdVal = 10;
}
else if(sqlVal === 6){
else if(carItemCount === 6){
itemIdVal = 11;
}
else if(sqlVal === 7){
else if(carItemCount === 7){
itemIdVal = 12;
}
else if(sqlVal === 8){
else if(carItemCount === 8){
itemIdVal = 13;
}
else if(sqlVal === 9){
else if(carItemCount === 9){
itemIdVal = 14;
}
else if(sqlVal === 10){
else if(carItemCount === 10){
itemIdVal = 15;
}
else if(sqlVal === 11){
else if(carItemCount === 11){
itemIdVal = 16;
}
else if(sqlVal === 12){
else if(carItemCount === 12){
itemIdVal = 17;
}
else if(sqlVal === 13){
else if(carItemCount === 13){
itemIdVal = 18;
}
else if(sqlVal === 14){
else if(carItemCount === 14){
itemIdVal = 19;
}
else if(sqlVal === 15){
else if(carItemCount === 15){
itemIdVal = 20;
}
else if(sqlVal === 16){
else if(carItemCount === 16){
itemIdVal = 21;
}
else if(sqlVal === 17){
else if(carItemCount === 17){
itemIdVal = 22;
}
else if(sqlVal === 18){
else if(carItemCount === 18){
itemIdVal = 23;
}
else if(sqlVal === 19){
else if(carItemCount === 19){
itemIdVal = 24;
}
else if(sqlVal === 20){
else if(carItemCount === 20){
itemIdVal = 25;
}
else if(sqlVal === 21){
else if(carItemCount === 21){
itemIdVal = 26;
}
else if(sqlVal === 22){
else if(carItemCount === 22){
itemIdVal = 27;
}
else if(sqlVal === 23){
else if(carItemCount === 23){
itemIdVal = 28;
}
@ -1541,6 +1637,11 @@ export default class GameModule extends Module {
} else {
saveEx.auraMotif = car?.auraMotif;
}
if (body?.rgStamp !== null && body?.rgStamp !== undefined) {
saveEx.rgStamp = body?.rgStamp!;
} else {
saveEx.rgStamp = car?.rgStamp;
}
// Update the car info
@ -2221,7 +2322,7 @@ export default class GameModule extends Module {
rampVal = Math.floor(Math.random() * 2) + 35;
pathVal = Math.floor(Math.random() * 2) + 64;
}
//14 - 16 is dummy area
//14 - 16 are dummy area
else if(body.area === 17){ //GID_RUNAREA_C1_CLOSED
rampVal = Math.floor(Math.random() * 4);
pathVal = Math.floor(Math.random() * 10); //probably not correct
@ -2361,7 +2462,7 @@ export default class GameModule extends Module {
rampVal = Math.floor(Math.random() * 2) + 35;
pathVal = Math.floor(Math.random() * 2) + 64;
}
//14 - 16 is dummy area
//14 - 16 are dummy area
else if(pArea === 17){ //GID_RUNAREA_C1_CLOSED
rampVal = Math.floor(Math.random() * 4);
pathVal = Math.floor(Math.random() * 10); //probably not correct
@ -2370,7 +2471,7 @@ export default class GameModule extends Module {
rampVal = Math.floor(Math.random() * 2) + 37;
pathVal = Math.floor(Math.random() * 2) + 56;
}
let trails = new Uint8Array([1, 2, 3, 4]);
let trails = new Uint8Array([1, 2, 3, 4]); //wtf is this lmao
let msg = {
carId: pCarId,
area: pArea,

View File

@ -4,6 +4,7 @@ import { Config } from "../config";
import * as wm from "../wmmt/wm.proto";
import * as wmsrv from "../wmmt/service.proto";
import { prisma } from "..";
import { count } from "console";
export default class StartupModule extends Module {
register(app: Application): void {
@ -103,8 +104,8 @@ export default class StartupModule extends Module {
result: resulttime,
name: '',
regionId: 0,
model: Math.floor(Math.random() * 106) + 1,
visualModel: Math.floor(Math.random() * 106) + 1,
model: Math.floor(Math.random() * 50),
visualModel: Math.floor(Math.random() * 106),
defaultColor: 0,
tunePower: 0,
tuneHandling: 0,
@ -154,8 +155,8 @@ export default class StartupModule extends Module {
result: 0,
name: '',
regionId: 0,
model: Math.floor(Math.random() * 106) + 1,
visualModel: Math.floor(Math.random() * 106) + 1,
model: Math.floor(Math.random() * 50),
visualModel: Math.floor(Math.random() * 106),
defaultColor: 0,
tunePower: 0,
tuneHandling: 0,
@ -202,8 +203,8 @@ export default class StartupModule extends Module {
result: 0,
name: '',
regionId: 0,
model: Math.floor(Math.random() * 106) + 1,
visualModel: Math.floor(Math.random() * 106) + 1,
model: Math.floor(Math.random() * 50),
visualModel: Math.floor(Math.random() * 106),
defaultColor: 0,
tunePower: 0,
tuneHandling: 0,
@ -263,73 +264,72 @@ export default class StartupModule extends Module {
carId: 'asc'
}
});*/
let car_crown: wm.wm.protobuf.Car[] = [];
for(let i=29; i<31; i++){
car_crown.push(wm.wm.protobuf.Car.create({
carId: 99969+i,
userId: 99969+i,
regionId: 1,
name: '',
manufacturer: 5,
model: 27,
visualModel: i,
defaultColor: 0,
customColor: 0,
wheel: 0,
wheelColor: 0,
aero: 0,
bonnet: 0,
wing: 0,
mirror: 0,
neon: 0,
trunk: 0,
plate: 0,
plateColor: 0,
plateNumber: 0,
tunePower: 34,
tuneHandling: 34,
title: 'Bayshore',
level: 65,
windowSticker: true,
windowStickerString: '',
windowStickerFont: 0,
windowDecoration: 0,
rivalMarker: 0,
lastPlayedAt: 0,
aura: 0,
auraMotif: 0,
ghostLevel: 10,
country: 'JPN',
searchCode: 'JPN123'
}));
}
if(car_crown){
let car_crown = await prisma.carCrown.findMany({
orderBy: {
area: 'asc'
}
});
if(car_crown.length !== 0){
let counter = 0;
for(let i=0; i<14; i++){
if(i % 2 === 0){
if(car_crown[counter].area === i){
let car = await prisma.car.findFirst({
where: {
carId: car_crown[counter].carId
},
include: {
gtWing: true
}
});
car!.aura = 0;
car!.tunePower = car_crown[counter].tunePower;
car!.tuneHandling = car_crown[counter].tuneHandling;
list_crown.push(wmsrv.wm.protobuf.Crown.create({
carId: car_crown[0]!.carId,
area: i,
carId: car_crown[counter].carId,
area: car_crown[counter].area, // GID_RUNAREA_C1 - GID_RUNAREA_TURNPIKE
unlockAt: car_crown[counter].playedAt,
car: car
}));
if(counter < car_crown.length-1){
counter++;
}
}
else{
list_crown.push(wmsrv.wm.protobuf.Crown.create({
carId: i,
area: i, // GID_RUNAREA_C1 - GID_RUNAREA_TURNPIKE
unlockAt: 0,
car: car_crown[0]
}));
}
}
for(let i=0; i<car_crown.length; i++){
if(car_crown[counter].area === 18){
let car = await prisma.car.findFirst({
where: {
carId: car_crown[counter].carId
},
include: {
gtWing: true
}
});
car!.aura = 0;
list_crown.push(wmsrv.wm.protobuf.Crown.create({
carId: 18,
area: 18, // GID_RUNAREA_HIROSHIMA
unlockAt: 0,
car: car
}));
}
else{
list_crown.push(wmsrv.wm.protobuf.Crown.create({
carId: car_crown[1]!.carId,
area: i,
carId: 18,
area: 18, // GID_RUNAREA_HIROSHIMA
unlockAt: 0,
car: car_crown[1]
}));
}
}
list_crown.push(wmsrv.wm.protobuf.Crown.create({
carId: car_crown[0]!.carId,
area: 18,
unlockAt: 0,
car: car_crown[0]
}));
}
else{
for(let i=0; i<14; i++){
@ -344,7 +344,7 @@ export default class StartupModule extends Module {
area: 18, // GID_RUNAREA_HIROSHIMA
unlockAt: 0,
}));
}
}
let msg = {
crowns: list_crown