Add some minor setup behavior to DummyGameTicker by giving it a common base with normal GameTicker.

Necessary for the game to, well, function.
This commit is contained in:
Pieter-Jan Briers
2020-08-21 17:41:50 +02:00
parent 1f1e95f535
commit d5c4ed819c
3 changed files with 55 additions and 25 deletions

View File

@@ -0,0 +1,41 @@
using Content.Server.Players;
using Content.Shared;
using Robust.Server.Interfaces.Player;
using Robust.Server.Player;
using Robust.Shared.Enums;
using Robust.Shared.IoC;
using Robust.Shared.Timers;
#nullable enable
namespace Content.Server.GameTicking
{
/// <summary>
/// Handles some low-level GameTicker behavior such as setting up clients when they connect.
/// Does not contain lobby/round handling mechanisms.
/// </summary>
public abstract class GameTickerBase : SharedGameTicker
{
[Dependency] protected readonly IPlayerManager PlayerManager = default!;
public virtual void Initialize()
{
PlayerManager.PlayerStatusChanged += PlayerStatusChanged;
}
protected virtual void PlayerStatusChanged(object sender, SessionStatusEventArgs args)
{
var session = args.Session;
if (args.NewStatus == SessionStatus.Connected)
{
// Always make sure the client has player data. Mind gets assigned on spawn.
if (session.Data.ContentDataUncast == null)
session.Data.ContentDataUncast = new PlayerData(session.SessionId);
// timer time must be > tick length
Timer.Spawn(0, args.Session.JoinGame);
}
}
}
}