Skip to content

Commit

Permalink
fix: Don't delete colonizer before other checks are complete
Browse files Browse the repository at this point in the history
  • Loading branch information
Clashsoft committed Aug 8, 2024
1 parent 596e2c2 commit 1ba9e67
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/job/job.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {ShipService} from '../ship/ship.service';
import {SystemService} from '../system/system.service';
import {ResourceName} from '../game-logic/resources';
import {SystemLogicService} from '../system/system-logic.service';
import {Ship} from '../ship/ship.schema';

@Injectable()
@EventRepository()
Expand All @@ -38,6 +39,7 @@ export class JobService extends MongooseRepository<Job> {

async createJob(dto: CreateJobDto, empire: EmpireDocument, system?: SystemDocument): Promise<Job | null> {
// Check fleet access
let shipToDelete: Ship | undefined;
if (dto.type === JobType.UPGRADE) {
if (!system) {
throw new NotFoundException('System not found.');
Expand All @@ -50,8 +52,7 @@ export class JobService extends MongooseRepository<Job> {
this.jobLogicService.checkFleet('explorer', fleets, ships);
} else if (system.upgrade === 'explored') {
// check and delete colonizer
const ship = this.jobLogicService.checkFleet('colonizer', fleets, ships);
await this.shipService.deleteOne(ship._id);
shipToDelete = this.jobLogicService.checkFleet('colonizer', fleets, ships);
}
}
}
Expand Down Expand Up @@ -82,6 +83,8 @@ export class JobService extends MongooseRepository<Job> {
// Deduct resources from the empire
this.empireLogicService.deductResources(empire, cost);

shipToDelete && await this.shipService.deleteOne(shipToDelete._id);

const jobData: Omit<Job, keyof GlobalSchema> = {
empire: empire._id,
game: empire.game,
Expand Down

0 comments on commit 1ba9e67

Please sign in to comment.