THE RETURN OF THE KING

This reverts commit c18d07538a.
This commit is contained in:
DrSmugleaf
2021-11-22 19:08:27 +01:00
parent 14e342663e
commit c3fe5909ad
65 changed files with 7021 additions and 236 deletions

View File

@@ -0,0 +1,10 @@
using Robust.Shared.GameObjects;
namespace Content.Server.GameTicking.Events;
/// <summary>
/// Raised at the start of <see cref="GameTicker.StartRound"/>
/// </summary>
public class RoundStartingEvent : EntityEventArgs
{
}

View File

@@ -1,3 +1,4 @@
using System;
using Content.Server.Players;
using Content.Shared.GameTicking;
using Content.Shared.GameWindow;
@@ -35,6 +36,8 @@ namespace Content.Server.GameTicking
case SessionStatus.Connected:
{
AddPlayerToDb(args.Session.UserId.UserId);
// Always make sure the client has player data. Mind gets assigned on spawn.
if (session.Data.ContentDataUncast == null)
session.Data.ContentDataUncast = new PlayerData(session.UserId, args.Session.Name);
@@ -106,6 +109,14 @@ namespace Content.Server.GameTicking
await _prefsManager.WaitPreferencesLoaded(session);
SpawnPlayer(session);
}
async void AddPlayerToDb(Guid id)
{
if (RoundId != 0 && _runLevel != GameRunLevel.PreRoundLobby)
{
await _db.AddRoundPlayers(RoundId, id);
}
}
}
private HumanoidCharacterProfile GetPlayerProfile(IPlayerSession p)

View File

@@ -1,6 +1,9 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Content.Server.Database;
using Content.Server.GameTicking.Events;
using Content.Server.Players;
using Content.Server.Mind;
using Content.Server.Ghost;
@@ -33,6 +36,8 @@ namespace Content.Server.GameTicking
"ss14_round_length",
"Round length in seconds.");
[Dependency] private readonly IServerDbManager _db = default!;
[ViewVariables]
private TimeSpan _roundStartTimeSpan;
@@ -54,6 +59,9 @@ namespace Content.Server.GameTicking
}
}
[ViewVariables]
public int RoundId { get; private set; }
private void PreRoundSetup()
{
DefaultMap = _mapManager.CreateMap();
@@ -88,7 +96,7 @@ namespace Content.Server.GameTicking
Logger.InfoS("ticker", $"Loaded map in {timeSpan.TotalMilliseconds:N2}ms.");
}
public void StartRound(bool force = false)
public async void StartRound(bool force = false)
{
// If this game ticker is a dummy, do nothing!
if (DummyTicker)
@@ -97,6 +105,12 @@ namespace Content.Server.GameTicking
DebugTools.Assert(RunLevel == GameRunLevel.PreRoundLobby);
Logger.InfoS("ticker", "Starting round!");
var playerIds = _playersInLobby.Keys.Select(player => player.UserId.UserId).ToArray();
RoundId = await _db.AddNewRound(playerIds);
var startingEvent = new RoundStartingEvent();
RaiseLocalEvent(startingEvent);
SendServerMessage(Loc.GetString("game-ticker-start-round"));
List<IPlayerSession> readyPlayers;