Expanded LocationControler implementation
This commit is contained in:
@@ -1,12 +1,33 @@
|
||||
using Core.Annotations;
|
||||
using Core.Models.Eft.Common;
|
||||
using Core.Models.Eft.Common.Tables;
|
||||
using Core.Models.Eft.Location;
|
||||
using Core.Services;
|
||||
using Core.Utils.Cloners;
|
||||
using ILogger = Core.Models.Utils.ILogger;
|
||||
|
||||
namespace Core.Controllers;
|
||||
|
||||
[Injectable]
|
||||
public class LocationController
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly DatabaseService _databaseService;
|
||||
private readonly AirdropService _airdropService;
|
||||
private readonly JsonCloner _cloner;
|
||||
|
||||
public LocationController(
|
||||
ILogger logger,
|
||||
DatabaseService databaseService,
|
||||
AirdropService airdropService,
|
||||
JsonCloner cloner)
|
||||
{
|
||||
_logger = logger;
|
||||
_databaseService = databaseService;
|
||||
_airdropService = airdropService;
|
||||
_cloner = cloner;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle client/locations
|
||||
/// Get all maps base location properties without loot data
|
||||
@@ -15,7 +36,32 @@ public class LocationController
|
||||
/// <returns>LocationsGenerateAllResponse</returns>
|
||||
public LocationsGenerateAllResponse GenerateAll(string sessionId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var locationsFromDb = _databaseService.GetLocations();
|
||||
var maps = locationsFromDb.GetDictionary();
|
||||
|
||||
// keyed by _id location property
|
||||
var locationResult = new Dictionary<string, LocationBase>();
|
||||
|
||||
foreach (var location in maps)
|
||||
{
|
||||
var mapBase = location.Value?.Base;
|
||||
if (mapBase == null)
|
||||
{
|
||||
_logger.Debug($"Map: {location} has no base json file, skipping generation");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Clear out loot array
|
||||
mapBase.Loot = [];
|
||||
// Add map base data to dictionary
|
||||
locationResult.Add(mapBase.IdField, mapBase);
|
||||
}
|
||||
|
||||
return new LocationsGenerateAllResponse
|
||||
{
|
||||
Locations = locationResult,
|
||||
Paths = locationsFromDb.Base.Paths
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -25,6 +71,11 @@ public class LocationController
|
||||
/// <returns></returns>
|
||||
public GetAirdropLootResponse GetAirDropLoot(GetAirdropLootRequest request)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (request.ContainerId is not null)
|
||||
{
|
||||
return this._airdropService.GenerateCustomAirdropLoot(request);
|
||||
}
|
||||
|
||||
return this._airdropService.GenerateAirdropLoot();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Core.Models.Eft.Common.Tables;
|
||||
|
||||
@@ -25,4 +25,4 @@ public class Path
|
||||
public string? Destination { get; set; }
|
||||
|
||||
public bool? Event { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Core.Models.Eft.Common.Tables;
|
||||
|
||||
public class LocationsGenerateAllResponse
|
||||
{
|
||||
[JsonPropertyName("locations")]
|
||||
public Locations? Locations { get; set; }
|
||||
public Dictionary<string, LocationBase> Locations { get; set; }
|
||||
|
||||
[JsonPropertyName("paths")]
|
||||
public List<Path>? Paths { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Reflection;
|
||||
using System.Text.Json.Serialization;
|
||||
using Core.Models.Eft.Common.Tables;
|
||||
using Core.Models.Eft.Common;
|
||||
|
||||
@@ -81,4 +82,23 @@ public class Locations
|
||||
.Invoke(this, [value]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Dictionary<string, Eft.Common.Location>? _locationDictionaryCache;
|
||||
|
||||
/// <summary>
|
||||
/// Get map locations as a dictionary, keyed by its name e.g. factory4_day
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Dictionary<string, Eft.Common.Location> GetDictionary()
|
||||
{
|
||||
if (_locationDictionaryCache is null)
|
||||
{
|
||||
var classProps = GetType()
|
||||
.GetProperties();
|
||||
_locationDictionaryCache = classProps
|
||||
.ToDictionary(propertyInfo => propertyInfo.Name, propertyInfo => propertyInfo.GetValue(this, null) as Eft.Common.Location);
|
||||
}
|
||||
|
||||
return _locationDictionaryCache;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user