diff --git a/src/modules/cars.ts b/src/modules/cars.ts index 94d5d0e..5367016 100644 --- a/src/modules/cars.ts +++ b/src/modules/cars.ts @@ -536,6 +536,8 @@ export default class CarModule extends Module { // Car update data data = { name: common.sanitizeInput(cars.name), + manufacturer: common.sanitizeInput(cars.manufacturer), + model: common.sanitizeInput(cars.model), visualModel: common.sanitizeInput(cars.visualModel), customColor: common.sanitizeInput(cars.customColor), wheel: common.sanitizeInput(cars.wheel), diff --git a/src/modules/resource.ts b/src/modules/resource.ts index f78571e..1c166cb 100644 --- a/src/modules/resource.ts +++ b/src/modules/resource.ts @@ -332,27 +332,28 @@ export default class ResourceModule extends Module { // Get the crown holder data let car_crown = await prisma.carCrown.findMany({ orderBy: { - area: 'asc' - } + area: 'asc' + }, + distinct: ['area'] }); // Crown holder data available if(car_crown.length !== 0) { - let counter = 0; + let counter = 0; // Loop GID_RUNAREA for(let i=0; i<19; i++) { - // 14 - 16 are dummy area, 17 is C1 Closed - if(i >= 14) + // 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){ - + if(car_crown[counter].area === i) + { // Get user's data let car = await prisma.car.findFirst({ where: { @@ -364,12 +365,6 @@ export default class ResourceModule extends Module { } }); - // If regionId is 0 or not set, game will crash after defeating the ghost - if(car!.regionId === 0) - { - car!.regionId = i + 1; // Change car region id - } - // Set the tunePower and tuneHandling used when capturing ghost crown car!.tunePower = car_crown[counter].tunePower; car!.tuneHandling = car_crown[counter].tuneHandling; @@ -394,48 +389,98 @@ export default class ResourceModule extends Module { } // Push the car data to the crown holder data - list_crown.push(wmsrv.wm.protobuf.Crown.create({ - carId: car_crown[counter].carId, - area: car_crown[counter].area, // GID_RUNAREA_C1 - GID_RUNAREA_TURNPIKE & GID_RUNAREA_HIROSHIMA - unlockAt: car_crown[counter].playedAt, - car: car! - - })); + // 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! + }); - if(counter < car_crown.length-1){ + // 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{ - + else + { // Push the default data by the game to the crown holder data - list_crown.push(wmsrv.wm.protobuf.Crown.create({ - carId: i, - area: i, // GID_RUNAREA_C1 - GID_RUNAREA_TURNPIKE & GID_RUNAREA_HIROSHIMA - unlockAt: 0, - })); + // 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, + })); + } } } } // There is no user's crown holder data available - else{ - + else + { // Loop GID_RUNAREA - for(let i=0; i<19; i++) + for(let i=0; i<14; i++) { - // 14 - 16 are dummy area, 17 is C1 Closed - if(i >= 14) + // 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 - list_crown.push(wmsrv.wm.protobuf.Crown.create({ - carId: i, - area: i, // GID_RUNAREA_C1 - GID_RUNAREA_TURNPIKE & GID_RUNAREA_HIROSHIMA - unlockAt: 0, - })); + // 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, + })); + } } } diff --git a/src/util/games/story.ts b/src/util/games/story.ts index 1dde625..d4f6830 100644 --- a/src/util/games/story.ts +++ b/src/util/games/story.ts @@ -15,9 +15,12 @@ export async function saveStoryResult(body: wm.protobuf.SaveGameResultRequest, c // If the game was not retired / timed out if (!(body.retired || body.timeup)) { + console.log('Game not retired / timed out, continuing ...') + console.log(body); + // Get the story result for the car let storyResult = body?.stResult; - let stLoseBits = 0; + let stLoseBits; // storyResult is set if (storyResult) @@ -54,6 +57,12 @@ export async function saveStoryResult(body: wm.protobuf.SaveGameResultRequest, c } } + // Calling check step function (BASE_PATH/src/util/games/games_util/check_step.ts) + let check_steps = await check_step.checkCurrentStep(body); + + // Set the ghost level to the correct level + data.ghostLevel = check_steps.ghostLevel; + // Check if clearBits is not null, and not lose the story if(storyResult.stClearBits !== null && storyResult.stClearBits !== undefined) { @@ -63,19 +72,19 @@ export async function saveStoryResult(body: wm.protobuf.SaveGameResultRequest, c } } - // Calling check step function (BASE_PATH/src/util/games/games_util/check_step.ts) - let check_steps = await check_step.checkCurrentStep(body); - - // Set the ghost level to the correct level - data.ghostLevel = check_steps.ghostLevel; - - // Update the car properties - await prisma.car.update({ - where: { - carId: body.carId - }, - data: data - }); + + if(data.stClearCount || stLoseBits) + { + console.log('Updating story data'); + + // Update the car properties + await prisma.car.update({ + where: { + carId: body.carId + }, + data: data + }); + } } } } \ No newline at end of file