Kill switch
Deploy Promiscuity Auth API / deploy (push) Successful in 47s
Deploy Promiscuity Crafting API / deploy (push) Has been cancelled
Deploy Promiscuity Inventory API / deploy (push) Has been cancelled
Deploy Promiscuity Locations API / deploy (push) Has been cancelled
Deploy Promiscuity Mail API / deploy (push) Has been cancelled
Deploy Promiscuity World API / deploy (push) Has been cancelled
Deploy Promiscuity Character API / deploy (push) Has been cancelled
k8s smoke test / test (push) Has been cancelled
Deploy Promiscuity Auth API / deploy (push) Successful in 47s
Deploy Promiscuity Crafting API / deploy (push) Has been cancelled
Deploy Promiscuity Inventory API / deploy (push) Has been cancelled
Deploy Promiscuity Locations API / deploy (push) Has been cancelled
Deploy Promiscuity Mail API / deploy (push) Has been cancelled
Deploy Promiscuity World API / deploy (push) Has been cancelled
Deploy Promiscuity Character API / deploy (push) Has been cancelled
k8s smoke test / test (push) Has been cancelled
This commit is contained in:
@@ -11,6 +11,9 @@ public class LocationStore
|
||||
private readonly IMongoCollection<CharacterDocument> _characters;
|
||||
private readonly IMongoCollection<BiomeDefinition> _biomeDefinitions;
|
||||
private const string CoordIndexName = "coord_x_1_coord_y_1";
|
||||
private const string LimboLocationName = "World Limbo";
|
||||
private const int LimboCoordX = -2000000000;
|
||||
private const int LimboCoordY = -2000000000;
|
||||
|
||||
public LocationStore(IConfiguration cfg)
|
||||
{
|
||||
@@ -339,6 +342,60 @@ public class LocationStore
|
||||
return hasUpper || (hasLower && !(keyDoc.Contains("coord.x") && keyDoc.Contains("coord.y")));
|
||||
}
|
||||
|
||||
public async Task<Location> EnsureLimboLocationAsync()
|
||||
{
|
||||
var filter = Builders<Location>.Filter.And(
|
||||
Builders<Location>.Filter.Eq(location => location.Coord.X, LimboCoordX),
|
||||
Builders<Location>.Filter.Eq(location => location.Coord.Y, LimboCoordY));
|
||||
var existing = await _col.Find(filter).FirstOrDefaultAsync();
|
||||
if (existing is not null)
|
||||
return existing;
|
||||
|
||||
var biomeDefinitions = await LoadBiomeDefinitionsAsync();
|
||||
var limbo = BuildLimboLocation(biomeDefinitions);
|
||||
try
|
||||
{
|
||||
await _col.InsertOneAsync(limbo);
|
||||
return limbo;
|
||||
}
|
||||
catch (MongoWriteException ex) when (ex.WriteError.Category == ServerErrorCategory.DuplicateKey)
|
||||
{
|
||||
return await _col.Find(filter).FirstOrDefaultAsync()
|
||||
?? throw new InvalidOperationException("Limbo location was created concurrently but could not be reloaded.");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<string>> GetLocationIdsForWorldResetAsync(string preservedLocationId)
|
||||
{
|
||||
var filter = Builders<Location>.Filter.Ne(location => location.Id, preservedLocationId);
|
||||
var locations = await _col.Find(filter).ToListAsync();
|
||||
return locations
|
||||
.Where(location => !string.IsNullOrWhiteSpace(location.Id))
|
||||
.Select(location => location.Id!)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public async Task<ResetWorldResponse> ResetWorldToOriginAsync(string preservedLocationId)
|
||||
{
|
||||
var biomeDefinitions = await LoadBiomeDefinitionsAsync();
|
||||
var deleteFilter = Builders<Location>.Filter.Ne(location => location.Id, preservedLocationId);
|
||||
var deleteResult = await _col.DeleteManyAsync(deleteFilter);
|
||||
|
||||
var origin = BuildOriginLocation(biomeDefinitions);
|
||||
await _col.InsertOneAsync(origin);
|
||||
var limbo = await _col.Find(location => location.Id == preservedLocationId).FirstOrDefaultAsync()
|
||||
?? throw new InvalidOperationException("Limbo location missing after world reset.");
|
||||
var remainingLocationCount = await _col.CountDocumentsAsync(Builders<Location>.Filter.Empty);
|
||||
|
||||
return new ResetWorldResponse
|
||||
{
|
||||
DeletedLocationCount = (int)deleteResult.DeletedCount,
|
||||
RemainingLocationCount = (int)remainingLocationCount,
|
||||
Origin = origin,
|
||||
Limbo = limbo
|
||||
};
|
||||
}
|
||||
|
||||
private void EnsureOriginLocation()
|
||||
{
|
||||
var biomeDefinitions = LoadBiomeDefinitions();
|
||||
@@ -356,21 +413,12 @@ public class LocationStore
|
||||
if (existing is not null)
|
||||
return;
|
||||
|
||||
var origin = new Location
|
||||
var origin = BuildOriginLocation(biomeDefinitions, originBiomeKey);
|
||||
|
||||
try
|
||||
{
|
||||
Name = "Origin",
|
||||
Coord = new Coord { X = 0, Y = 0 },
|
||||
BiomeKey = originBiomeKey,
|
||||
Elevation = 0,
|
||||
LocationObject = CreateLocationObjectForBiome(biomeDefinitions, originBiomeKey, 0, 0),
|
||||
LocationObjectResolved = true,
|
||||
CreatedUtc = DateTime.UtcNow
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
_col.InsertOne(origin);
|
||||
}
|
||||
_col.InsertOne(origin);
|
||||
}
|
||||
catch (MongoWriteException ex) when (ex.WriteError.Category == ServerErrorCategory.DuplicateKey)
|
||||
{
|
||||
// Another instance seeded it first.
|
||||
@@ -461,6 +509,44 @@ public class LocationStore
|
||||
}
|
||||
}
|
||||
|
||||
private static Location BuildOriginLocation(IReadOnlyList<BiomeDefinition> biomeDefinitions, string? originBiomeKey = null)
|
||||
{
|
||||
var resolvedOriginBiomeKey = string.IsNullOrWhiteSpace(originBiomeKey)
|
||||
? biomeDefinitions.Any(definition => definition.BiomeKey == "plains")
|
||||
? "plains"
|
||||
: biomeDefinitions[0].BiomeKey
|
||||
: originBiomeKey;
|
||||
|
||||
return new Location
|
||||
{
|
||||
Name = "Origin",
|
||||
Coord = new Coord { X = 0, Y = 0 },
|
||||
BiomeKey = resolvedOriginBiomeKey,
|
||||
Elevation = 0,
|
||||
LocationObject = CreateLocationObjectForBiome(biomeDefinitions, resolvedOriginBiomeKey, 0, 0),
|
||||
LocationObjectResolved = true,
|
||||
CreatedUtc = DateTime.UtcNow
|
||||
};
|
||||
}
|
||||
|
||||
private static Location BuildLimboLocation(IReadOnlyList<BiomeDefinition> biomeDefinitions)
|
||||
{
|
||||
var limboBiomeKey = biomeDefinitions.Any(definition => definition.BiomeKey == "plains")
|
||||
? "plains"
|
||||
: biomeDefinitions[0].BiomeKey;
|
||||
|
||||
return new Location
|
||||
{
|
||||
Name = LimboLocationName,
|
||||
Coord = new Coord { X = LimboCoordX, Y = LimboCoordY },
|
||||
BiomeKey = limboBiomeKey,
|
||||
Elevation = 0,
|
||||
LocationObject = null,
|
||||
LocationObjectResolved = true,
|
||||
CreatedUtc = DateTime.UtcNow
|
||||
};
|
||||
}
|
||||
|
||||
private async Task<Location> EnsureLocationMetadataAsync(Location location)
|
||||
{
|
||||
var locationId = location.Id ?? string.Empty;
|
||||
|
||||
Reference in New Issue
Block a user