From 1e310c9afab9815527e573d3fa82d1c82e7aed22 Mon Sep 17 00:00:00 2001 From: Adrian Kunz Date: Tue, 6 Aug 2024 13:28:47 +0200 Subject: [PATCH] fix: Disallow building ships with build_time=0 and document that --- src/job/job-logic.service.ts | 6 +++++- src/job/job.schema.ts | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/job/job-logic.service.ts b/src/job/job-logic.service.ts index d5377e2..d85b35d 100644 --- a/src/job/job-logic.service.ts +++ b/src/job/job-logic.service.ts @@ -111,9 +111,13 @@ export class JobLogicService { throw new BadRequestException('Ship type and fleet id are required for this job type.'); } const ship = SHIP_TYPES[dto.ship as ShipTypeName] ?? notFound(dto.ship as ShipTypeName); + const time = this.empireLogicService.getShipTime(empire, ship); + if (!time) { + throw new BadRequestException('This ship type is not unlocked yet (build_time=0).'); + } return { ...this.empireLogicService.getShipCost(empire, ship), - time: this.empireLogicService.getShipTime(empire, ship), + time, }; } case JobType.TRAVEL: { diff --git a/src/job/job.schema.ts b/src/job/job.schema.ts index cd320e0..d5a2e37 100644 --- a/src/job/job.schema.ts +++ b/src/job/job.schema.ts @@ -98,7 +98,9 @@ export class Job extends GlobalSchema { @Prop({type: String}) @ApiPropertyOptional({ example: 'explorer', - description: 'Ship type name for the job. Required for type=ship.', + description: 'Ship type name for the job. Required for type=ship.\n\n' + + 'Note that if the ship type build_time variable is 0 for this empire, the ship cannot be built.\n' + + 'In this case, a technology is required to unlock the ship type.', enum: SHIP_NAMES, }) @ValidateIf((job, value) => value || job.type === JobType.SHIP)