Refactor Game Modes (#5857)
This commit is contained in:
committed by
GitHub
parent
d1a1ee3cbe
commit
f4d8ec1b35
@@ -1,78 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Content.Shared.GameTicking;
|
||||
using Content.Shared.Suspicion;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
|
||||
namespace Content.Server.Suspicion.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class SuspicionEndTimerSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IPlayerManager _playerManager = null!;
|
||||
|
||||
private TimeSpan? _endTime;
|
||||
|
||||
public TimeSpan? EndTime
|
||||
{
|
||||
get => _endTime;
|
||||
set
|
||||
{
|
||||
_endTime = value;
|
||||
SendUpdateToAll();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<RoundRestartCleanupEvent>(Reset);
|
||||
|
||||
_playerManager.PlayerStatusChanged += PlayerManagerOnPlayerStatusChanged;
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
base.Shutdown();
|
||||
|
||||
_playerManager.PlayerStatusChanged -= PlayerManagerOnPlayerStatusChanged;
|
||||
}
|
||||
|
||||
private void PlayerManagerOnPlayerStatusChanged(object? sender, SessionStatusEventArgs e)
|
||||
{
|
||||
if (e.NewStatus == SessionStatus.InGame)
|
||||
{
|
||||
SendUpdateTimerMessage(e.Session);
|
||||
}
|
||||
}
|
||||
|
||||
private void SendUpdateToAll()
|
||||
{
|
||||
foreach (var player in _playerManager.ServerSessions.Where(p => p.Status == SessionStatus.InGame))
|
||||
{
|
||||
SendUpdateTimerMessage(player);
|
||||
}
|
||||
}
|
||||
|
||||
private void SendUpdateTimerMessage(IPlayerSession player)
|
||||
{
|
||||
var msg = new SuspicionMessages.SetSuspicionEndTimerMessage
|
||||
{
|
||||
EndTime = EndTime
|
||||
};
|
||||
|
||||
EntityManager.EntityNetManager?.SendSystemNetworkMessage(msg, player.ConnectedClient);
|
||||
}
|
||||
|
||||
private void Reset(RoundRestartCleanupEvent ev)
|
||||
{
|
||||
EndTime = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Roles;
|
||||
using Content.Server.Suspicion.Roles;
|
||||
using Content.Shared.GameTicking;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Suspicion.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class SuspicionRoleSystem : EntitySystem
|
||||
{
|
||||
private readonly HashSet<SuspicionRoleComponent> _traitors = new();
|
||||
|
||||
public IReadOnlyCollection<SuspicionRoleComponent> Traitors => _traitors;
|
||||
|
||||
#region Overrides of EntitySystem
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<RoundRestartCleanupEvent>(Reset);
|
||||
SubscribeLocalEvent<SuspicionRoleComponent, PlayerAttachedEvent>(OnPlayerAttached);
|
||||
SubscribeLocalEvent<SuspicionRoleComponent, PlayerDetachedEvent>(OnPlayerDetached);
|
||||
SubscribeLocalEvent<SuspicionRoleComponent, RoleAddedEvent>(OnRoleAdded);
|
||||
SubscribeLocalEvent<SuspicionRoleComponent, RoleRemovedEvent>(OnRoleRemoved);
|
||||
}
|
||||
|
||||
private void OnPlayerDetached(EntityUid uid, SuspicionRoleComponent component, PlayerDetachedEvent args)
|
||||
{
|
||||
component.SyncRoles();
|
||||
}
|
||||
|
||||
private void OnPlayerAttached(EntityUid uid, SuspicionRoleComponent component, PlayerAttachedEvent args)
|
||||
{
|
||||
component.SyncRoles();
|
||||
}
|
||||
|
||||
private void OnRoleAdded(EntityUid uid, SuspicionRoleComponent component, RoleAddedEvent args)
|
||||
{
|
||||
if (args.Role is not SuspicionRole role) return;
|
||||
component.Role = role;
|
||||
}
|
||||
|
||||
private void OnRoleRemoved(EntityUid uid, SuspicionRoleComponent component, RoleRemovedEvent args)
|
||||
{
|
||||
if (args.Role is not SuspicionRole) return;
|
||||
component.Role = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void AddTraitor(SuspicionRoleComponent role)
|
||||
{
|
||||
if (!_traitors.Add(role))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var traitor in _traitors)
|
||||
{
|
||||
traitor.AddAlly(role);
|
||||
}
|
||||
|
||||
role.SetAllies(_traitors);
|
||||
}
|
||||
|
||||
public void RemoveTraitor(SuspicionRoleComponent role)
|
||||
{
|
||||
if (!_traitors.Remove(role))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var traitor in _traitors)
|
||||
{
|
||||
traitor.RemoveAlly(role);
|
||||
}
|
||||
|
||||
role.ClearAllies();
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
_traitors.Clear();
|
||||
base.Shutdown();
|
||||
}
|
||||
|
||||
public void Reset(RoundRestartCleanupEvent ev)
|
||||
{
|
||||
_traitors.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.GameTicking.Rules;
|
||||
using Content.Server.Mind.Components;
|
||||
using Content.Server.Roles;
|
||||
using Content.Server.Suspicion.EntitySystems;
|
||||
using Content.Server.Suspicion.Roles;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.MobState.Components;
|
||||
@@ -11,7 +11,6 @@ using Content.Shared.Suspicion;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
@@ -43,17 +42,17 @@ namespace Content.Server.Suspicion
|
||||
|
||||
Dirty();
|
||||
|
||||
var suspicionRoleSystem = EntitySystem.Get<SuspicionRoleSystem>();
|
||||
var sus = EntitySystem.Get<SuspicionRuleSystem>();
|
||||
|
||||
if (value == null || !value.Antagonist)
|
||||
{
|
||||
ClearAllies();
|
||||
suspicionRoleSystem.RemoveTraitor(this);
|
||||
sus.RemoveTraitor(this);
|
||||
}
|
||||
else if (value.Antagonist)
|
||||
{
|
||||
SetAllies(suspicionRoleSystem.Traitors);
|
||||
suspicionRoleSystem.AddTraitor(this);
|
||||
SetAllies(sus.Traitors);
|
||||
sus.AddTraitor(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user