Having the clear locations endpoint only clear world locations, and adding endpoint to remove all items
This commit is contained in:
@@ -1,10 +1,22 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using GameAuthApi.Models;
|
||||
|
||||
namespace GameAuthApi.Services;
|
||||
|
||||
public class AdminService
|
||||
{
|
||||
private readonly LocationService _locationService;
|
||||
private readonly ItemService _itemService;
|
||||
private readonly PlayerService _playerService;
|
||||
|
||||
public AdminService(LocationService locationService, ItemService itemService, PlayerService playerService)
|
||||
{
|
||||
_locationService = locationService;
|
||||
_itemService = itemService;
|
||||
_playerService = playerService;
|
||||
}
|
||||
|
||||
public virtual Task<Dictionary<string, string>> GetStatusAsync()
|
||||
{
|
||||
var status = new Dictionary<string, string>
|
||||
@@ -13,5 +25,40 @@ public class AdminService
|
||||
};
|
||||
return Task.FromResult(status);
|
||||
}
|
||||
|
||||
public virtual async Task<Location> ResetLocationsAsync()
|
||||
{
|
||||
var worldLocations = await _locationService.GetByTypeAsync("World");
|
||||
foreach (var loc in worldLocations)
|
||||
{
|
||||
await _itemService.DeleteByLocationAsync(loc.Id);
|
||||
}
|
||||
await _locationService.DeleteByTypeAsync("World");
|
||||
|
||||
var origin = new Location
|
||||
{
|
||||
LocationType = "World",
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Z = 0
|
||||
};
|
||||
await _locationService.CreateAsync(origin);
|
||||
|
||||
var players = await _playerService.GetAllAsync();
|
||||
foreach (var player in players)
|
||||
{
|
||||
player.LocationId = origin.Id;
|
||||
await _playerService.UpdateAsync(player);
|
||||
await _locationService.AddPlayerToLocationAsync(origin.Id, player.Id);
|
||||
}
|
||||
|
||||
return origin;
|
||||
}
|
||||
|
||||
public virtual async Task ClearItemsAsync()
|
||||
{
|
||||
await _itemService.DeleteAllAsync();
|
||||
await _locationService.ClearAllItemsAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user