feat: wire HuntingController/HuntingModule and enrich current-location with monster pool
Registers HuntingModule (POST /api/hunts) into the DI graph alongside its new entities, and adds possibleMonsters (enabled LocationMonster pool, weight-descending, empty when hunting is disabled) to WorldService.getCurrentLocation. Also updates the pre-existing DB-less app.e2e-spec.ts to override HuntingModule the same way the other feature modules already are, since it now needs a real DataSource.
This commit is contained in:
@@ -2,6 +2,7 @@ import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Character } from '../characters/entities/character.entity';
|
||||
import { LocationMonster } from '../monsters/entities/location-monster.entity';
|
||||
import { TravelService } from '../travel/travel.service';
|
||||
import { LocationConnection } from './entities/location-connection.entity';
|
||||
|
||||
@@ -30,6 +31,7 @@ export interface CurrentLocationResponse {
|
||||
huntingEnabled: boolean;
|
||||
artworkPath: string;
|
||||
connections: CurrentLocationConnection[];
|
||||
possibleMonsters: string[];
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
@@ -40,6 +42,8 @@ export class WorldService {
|
||||
private readonly characters: Repository<Character>,
|
||||
@InjectRepository(LocationConnection)
|
||||
private readonly connections: Repository<LocationConnection>,
|
||||
@InjectRepository(LocationMonster)
|
||||
private readonly locationMonsters: Repository<LocationMonster>,
|
||||
) {}
|
||||
|
||||
async getCurrentLocation(
|
||||
@@ -61,6 +65,10 @@ export class WorldService {
|
||||
});
|
||||
const location = character.currentLocation;
|
||||
|
||||
const possibleMonsters = location.huntingEnabled
|
||||
? await this.getPossibleMonsters(location.id)
|
||||
: [];
|
||||
|
||||
return {
|
||||
id: location.id,
|
||||
key: location.key,
|
||||
@@ -84,9 +92,19 @@ export class WorldService {
|
||||
travelDurationSeconds: connection.travelDurationSeconds,
|
||||
danger: this.toDangerRating(connection.ambushChance),
|
||||
})),
|
||||
possibleMonsters,
|
||||
};
|
||||
}
|
||||
|
||||
private async getPossibleMonsters(locationId: string): Promise<string[]> {
|
||||
const pool = await this.locationMonsters.find({
|
||||
where: { locationId, enabled: true },
|
||||
relations: { monster: true },
|
||||
order: { weight: 'DESC' },
|
||||
});
|
||||
return pool.map((entry) => entry.monster.name);
|
||||
}
|
||||
|
||||
private toDangerRating(ambushChance: string): 'LOW' | 'HIGH' {
|
||||
return Number(ambushChance) <= 0.05 ? 'LOW' : 'HIGH';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user