adding resources
This commit is contained in:
@@ -6,17 +6,19 @@ namespace LocationsApi.Services;
|
||||
public class LocationService
|
||||
{
|
||||
private readonly IMongoCollection<Location> _locations;
|
||||
private readonly ResourceService _resources;
|
||||
private readonly int _homeMinDistance;
|
||||
private readonly int _homeSearchRadius;
|
||||
private readonly int _visibilityDepth;
|
||||
|
||||
public LocationService(IConfiguration cfg)
|
||||
public LocationService(IConfiguration cfg, ResourceService resources)
|
||||
{
|
||||
var connectionString = cfg["MongoDB:ConnectionString"] ?? "mongodb://127.0.0.1:27017";
|
||||
var databaseName = cfg["MongoDB:DatabaseName"] ?? "territory-autobattler";
|
||||
var client = new MongoClient(connectionString);
|
||||
var database = client.GetDatabase(databaseName);
|
||||
_locations = database.GetCollection<Location>("Locations");
|
||||
_resources = resources;
|
||||
_homeMinDistance = int.TryParse(cfg["World:HomeMinDistance"], out var minDistance) ? Math.Max(1, minDistance) : 8;
|
||||
_homeSearchRadius = int.TryParse(cfg["World:HomeSearchRadius"], out var searchRadius) ? Math.Max(_homeMinDistance, searchRadius) : 80;
|
||||
_visibilityDepth = int.TryParse(cfg["World:VisibilityDepth"], out var visibilityDepth) ? Math.Max(0, visibilityDepth) : 3;
|
||||
@@ -117,6 +119,7 @@ public class LocationService
|
||||
var existingHome = await GetHomeAsync(username);
|
||||
if (existingHome is not null)
|
||||
{
|
||||
await _resources.EnsureAsync(username);
|
||||
return existingHome;
|
||||
}
|
||||
|
||||
@@ -138,6 +141,7 @@ public class LocationService
|
||||
var home = await TryCreateHomeAsync(username, candidate.q, candidate.r);
|
||||
if (home is not null)
|
||||
{
|
||||
await _resources.EnsureAsync(username);
|
||||
return home;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user