reposition tanks on map switch, rework map logic
This commit is contained in:
parent
3d65c81b8b
commit
97144ae3b8
13 changed files with 208 additions and 117 deletions
24
tanks-backend/TanksServer/GameLogic/ChangeToRequestedMap.cs
Normal file
24
tanks-backend/TanksServer/GameLogic/ChangeToRequestedMap.cs
Normal file
|
@ -0,0 +1,24 @@
|
|||
namespace TanksServer.GameLogic;
|
||||
|
||||
internal sealed class ChangeToRequestedMap(
|
||||
MapService mapService,
|
||||
MapEntityManager entityManager,
|
||||
EmptyTileFinder emptyTileFinder
|
||||
) : ITickStep
|
||||
{
|
||||
private MapPrototype? _requestedMap;
|
||||
|
||||
public ValueTask TickAsync(TimeSpan delta)
|
||||
{
|
||||
var changeTo = Interlocked.Exchange(ref _requestedMap, null);
|
||||
if (changeTo == null)
|
||||
return ValueTask.CompletedTask;
|
||||
|
||||
mapService.SwitchTo(changeTo);
|
||||
foreach (var t in entityManager.Tanks)
|
||||
t.Position = emptyTileFinder.ChooseEmptyTile().GetCenter().ToFloatPosition();
|
||||
return ValueTask.CompletedTask;
|
||||
}
|
||||
|
||||
public void Request(MapPrototype map) => _requestedMap = map;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue