Implemented `OpenZoneService
`
This commit is contained in:
@@ -1,10 +1,20 @@
|
||||
using SptCommon.Annotations;
|
||||
using Core.Models.Spt.Config;
|
||||
using Core.Models.Utils;
|
||||
using Core.Servers;
|
||||
using SptCommon.Annotations;
|
||||
|
||||
namespace Core.Services;
|
||||
|
||||
[Injectable(InjectionType.Singleton)]
|
||||
public class OpenZoneService
|
||||
public class OpenZoneService(
|
||||
ISptLogger<OpenZoneService> _logger,
|
||||
DatabaseService _databaseService,
|
||||
LocalisationService _localisationService,
|
||||
ConfigServer _configServer
|
||||
)
|
||||
{
|
||||
protected LocationConfig _locationConfig = _configServer.GetConfig<LocationConfig>();
|
||||
|
||||
/// <summary>
|
||||
/// Add open zone to specified map
|
||||
/// </summary>
|
||||
@@ -12,7 +22,16 @@ public class OpenZoneService
|
||||
/// <param name="zoneToAdd">zone to add</param>
|
||||
public void AddZoneToMap(string locationId, string zoneToAdd)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var location = _locationConfig.OpenZones[locationId];
|
||||
if (location is null)
|
||||
{
|
||||
_locationConfig.OpenZones[locationId] = [];
|
||||
}
|
||||
|
||||
if (!_locationConfig.OpenZones[locationId].Contains(zoneToAdd))
|
||||
{
|
||||
_locationConfig.OpenZones[locationId].Add(zoneToAdd);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -20,6 +39,25 @@ public class OpenZoneService
|
||||
/// </summary>
|
||||
public void ApplyZoneChangesToAllMaps()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var dbLocations = _databaseService.GetLocations().GetDictionary();
|
||||
foreach (var mapKvP in _locationConfig.OpenZones) {
|
||||
if (!dbLocations.ContainsKey(mapKvP.Key))
|
||||
{
|
||||
_logger.Error(_localisationService.GetText("openzone-unable_to_find_map", mapKvP));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
var zonesToAdd = _locationConfig.OpenZones[mapKvP.Key];
|
||||
|
||||
// Convert openzones string into list, easier to work wih
|
||||
var mapOpenZonesArray = dbLocations[mapKvP.Key].Base.OpenZones.Split(",").ToList();
|
||||
foreach (var zoneToAdd in zonesToAdd.Where(zoneToAdd => !mapOpenZonesArray.Contains(zoneToAdd)))
|
||||
{
|
||||
// Add new zone to array and convert array back into comma separated string
|
||||
mapOpenZonesArray.Add(zoneToAdd);
|
||||
dbLocations[mapKvP.Key].Base.OpenZones = string.Join(",", mapOpenZonesArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user