Skip to content
Draft
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Content.Client/_Scp/Scp914/Scp914System.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Content.Shared._Scp.Scp914;

namespace Content.Client._Scp.Scp914;

public sealed class Scp914System : SharedScp914System
{

}
74 changes: 74 additions & 0 deletions Content.Client/_Scp/Scp914/Ui/Scp914BoundUserInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using Content.Client.Anomaly.Ui;
using Content.Shared._Scp.Scp914;
using Robust.Shared.Timing;

namespace Content.Client._Scp.Scp914.Ui;

public sealed class Scp914BoundUserInterface : BoundUserInterface
{
private Scp914Window? _window;
private IGameTiming _gameTiming;

public Scp914BoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{

_gameTiming = IoCManager.Resolve<IGameTiming>();
}

protected override void Open()
{
base.Open();

_window = new Scp914Window(_gameTiming);
_window.OnClose += Close;
_window.OnNewModeSelected += OnNewModeSelected;
_window.OnStartCycle += OnStartCycle;

if (State != null)
{
UpdateState(State);
}

_window.OpenCentered();
}

private void OnStartCycle()
{
var startCycleMessage = new Scp914StartCycleMessage();
SendPredictedMessage(startCycleMessage);
}

private void OnNewModeSelected(Scp914CycleDirection direction)
{
var changeModeMessage = new Scp914ChangeModeRequestMessage(direction);
SendPredictedMessage(changeModeMessage);
}

protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);

if (state is not Scp914BuiState newState)
{
return;
}

_window?.UpdateState(newState);
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);

if (_window == null)
{
return;
}

_window.OnClose -= Close;
_window.OnNewModeSelected -= OnNewModeSelected;

_window.Dispose();
_window = null;
}
}
14 changes: 14 additions & 0 deletions Content.Client/_Scp/Scp914/Ui/Scp914Window.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<ui:FancyWindow xmlns="https://spacestation14.io"
xmlns:x="http://schemas.microsoft.com/winfx/2007/xaml"
xmlns:ui="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
MinSize="200 150" Resizable="False" Title="SCP 914">
<BoxContainer Align="Center" Orientation="Vertical" HorizontalExpand="True" VerticalExpand="True">
<BoxContainer Orientation="Horizontal" HorizontalAlignment="Center" HorizontalExpand="True">
<Button HorizontalAlignment="Left" Name="TurnLeftButton" TextAlign="Center" Text="{Loc scp914-cycle-left-button}" SetSize="35 35"/>
<Label HorizontalAlignment="Stretch" Name="CurrentModeLabel" Align="Center" HorizontalExpand="True" SetSize="100 25"/>
<Button HorizontalAlignment="Right" Name="TurnRightButton" TextAlign="Center" Text="{Loc scp914-cycle-right-button}" SetSize="35 35"/>
</BoxContainer>
<Button Name="StartCycleBytton" TextAlign="Center" SetHeight="35" HorizontalExpand="True" Text="{Loc scp914-start-cycle}"></Button>
</BoxContainer>
</ui:FancyWindow>
70 changes: 70 additions & 0 deletions Content.Client/_Scp/Scp914/Ui/Scp914Window.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using Content.Client.UserInterface.Controls;
using Content.Shared._Scp.Scp914;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Timing;

namespace Content.Client._Scp.Scp914.Ui;

[GenerateTypedNameReferences]
public sealed partial class Scp914Window : FancyWindow
{
public Action<Scp914CycleDirection>? OnNewModeSelected;
public Action? OnStartCycle;

private IGameTiming _gameTiming;

private TimeSpan _nextTimeUse;
private bool _active;

public Scp914Window(IGameTiming gameTiming)
{
RobustXamlLoader.Load(this);

_gameTiming = gameTiming;

TurnLeftButton.OnPressed += _ => OnTurnLeftPressed();
TurnRightButton.OnPressed += _ => OnTurnRightPressed();
StartCycleBytton.OnPressed += _ => OnStartCyclePressed();
}

protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);

var disabled = _active || _gameTiming.CurTime < _nextTimeUse;

TurnLeftButton.Disabled = disabled;
TurnRightButton.Disabled = disabled;
StartCycleBytton.Disabled = disabled;
}

public void UpdateState(Scp914BuiState newState)
{
CurrentModeLabel.Text = newState.NewMode.ToString();
_active = newState.Active;
}

private void OnStartCyclePressed()
{
OnStartCycle?.Invoke();
SetNextTimeUse();
}

private void OnTurnRightPressed()
{
OnNewModeSelected?.Invoke(Scp914CycleDirection.Right);
SetNextTimeUse();
}

private void OnTurnLeftPressed()
{
OnNewModeSelected?.Invoke(Scp914CycleDirection.Left);
SetNextTimeUse();
}

private void SetNextTimeUse()
{
_nextTimeUse = _gameTiming.CurTime + TimeSpan.FromSeconds(1);
}
}
138 changes: 138 additions & 0 deletions Content.IntegrationTests/Tests/GameRules/ScpSlGameRuleTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
using System.Linq;
using Content.Server._Scp.GameRules.ScpSl;
using Content.Server._Sunrise.StationCentComm;
using Content.Server.GameTicking;
using Content.Server.GameTicking.Presets;
using Content.Server.GameTicking.Rules.Components;
using Content.Server.RoundEnd;
using Content.Shared._Scp.GameRule.Sl;
using Content.Shared.GameTicking;
using Content.Shared.Pinpointer;
using Content.Shared.Station.Components;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Map.Components;

namespace Content.IntegrationTests.Tests.GameRules;

[TestFixture]
public sealed class ScpSlGameRuleTest
{
[Test]
public async Task TryStartGameRuleTestWithSufficientPlayers()
{
await using var pair = await PoolManager.GetServerClient(new PoolSettings
{
Dirty = true,
DummyTicker = false,
Connected = true,
InLobby = true,
});

var server = pair.Server;
var client = pair.Client;

var entMan = server.EntMan;

var ticker = server.System<GameTicker>();
var xformSystem = server.System<TransformSystem>();
var physicsSystem = server.System<PhysicsSystem>();

Assert.That(ticker.DummyTicker, Is.False);

Assert.That(ticker.RunLevel, Is.EqualTo(GameRunLevel.PreRoundLobby));
Assert.That(client.AttachedEntity, Is.Null);
Assert.That(ticker.PlayerGameStatuses[client.User!.Value], Is.EqualTo(PlayerGameStatus.NotReadyToPlay));

var dummies = await pair.Server.AddDummySessions(30);

await pair.RunTicksSync(5);

// Initially, the players have no attached entities
Assert.That(pair.Player?.AttachedEntity, Is.Null);
Assert.That(dummies.All(x => x.AttachedEntity == null));

Assert.That(entMan.Count<MapComponent>(), Is.Zero);
Assert.That(entMan.Count<MapGridComponent>(), Is.Zero);
Assert.That(entMan.Count<StationMapComponent>(), Is.Zero);
Assert.That(entMan.Count<StationMemberComponent>(), Is.Zero);
Assert.That(entMan.Count<StationCentCommComponent>(), Is.Zero); // Sunrise-Edit

// And no sl related components
Assert.That(entMan.Count<ScpSlGameRuleComponent>(), Is.Zero);
Assert.That(entMan.Count<ScpSlHumanoidMarkerComponent>(), Is.Zero);
Assert.That(entMan.Count<ScpSlScpMarkerComponent>(), Is.Zero);

ticker.ToggleReadyAll(true);
Assert.That(ticker.PlayerGameStatuses.Values.All(x => x == PlayerGameStatus.ReadyToPlay));

await pair.WaitCommand("forcepreset ScpSl");
await pair.RunTicksSync(10);

Assert.That(ticker.RunLevel, Is.EqualTo(GameRunLevel.InRound));
Assert.That(ticker.PlayerGameStatuses.Values.All(x => x == PlayerGameStatus.JoinedGame));
Assert.That(client.EntMan.EntityExists(client.AttachedEntity));

Assert.That(entMan.Count<ScpSlGameRuleComponent>(), Is.EqualTo(1));
Assert.That(entMan.Count<ScpSlHumanoidMarkerComponent>, Is.AtLeast(1));
Assert.That(entMan.Count<ScpSlScpMarkerComponent>, Is.AtLeast(1));


//Try escape

var (escapeZoneXform, _) = entMan.EntityQuery<TransformComponent, ScpSlEscapeZoneComponent>().First();

var chaosBefore = dummies.Count(x =>
entMan.TryGetComponent<ScpSlHumanoidMarkerComponent>(x.AttachedEntity!.Value!, out var marker) &&
marker.HumanoidType == ScpSlHumanoidType.Chaos);

var dBefore = dummies.Count(x =>
entMan.TryGetComponent<ScpSlHumanoidMarkerComponent>(x.AttachedEntity!.Value!, out var marker) &&
marker.HumanoidType == ScpSlHumanoidType.ClassD);

var dummyD = dummies
.First(x => entMan.TryGetComponent<ScpSlHumanoidMarkerComponent>(x.AttachedEntity!.Value!, out var marker) &&
marker.HumanoidType == ScpSlHumanoidType.ClassD)
.AttachedEntity!.Value!;

physicsSystem.WakeBody(escapeZoneXform.Owner);
physicsSystem.WakeBody(dummyD);

await pair.RunTicksSync(5);

xformSystem.SetCoordinates(dummyD, escapeZoneXform.Coordinates);

await pair.RunTicksSync(5);

var dAfter = dummies.Count(x =>
entMan.TryGetComponent<ScpSlHumanoidMarkerComponent>(x.AttachedEntity!.Value!, out var marker) &&
marker.HumanoidType == ScpSlHumanoidType.ClassD);

var chaosAfter = dummies.Count(x =>
entMan.TryGetComponent<ScpSlHumanoidMarkerComponent>(x.AttachedEntity!.Value!, out var marker) &&
marker.HumanoidType == ScpSlHumanoidType.Chaos);


Assert.That(dBefore > dAfter, Is.True);
Assert.That(chaosBefore < chaosAfter, Is.True);

// Try end round
var player = pair.Player!.AttachedEntity!.Value;

var dummyEntity = dummies.Select(x => x.AttachedEntity ?? default).Append(player).Where(x=> entMan.HasComponent<ScpSlHumanoidMarkerComponent>(x)).ToList();

await server.WaitAssertion(() =>
{
foreach (var entityUid in dummyEntity)
{
entMan.DeleteEntity(entityUid);
}

});

Assert.That(ticker.RunLevel == GameRunLevel.PostRound, Is.True, "All humanoids are dead, but round doesn't end!");

ticker.SetGamePreset((GamePresetPrototype?) null);
await pair.CleanReturnAsync();
}
}
14 changes: 14 additions & 0 deletions Content.Server/_Scp/GameRules/ScpSl/ScpSLGameRuleSystem.Subs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Content.Server._Scp.GameRules.ScpSl;

public sealed partial class ScpSlGameRuleSystem
{
private int _maxChaosSpawnCount;
private int _maxMogSpawnCount;
private float _chaosSpawnChance;
private void InitializeSubs()
{
_cfg.OnValueChanged(SlCvars.MaxChaosSpawnCount, newValue => _maxChaosSpawnCount = newValue);
_cfg.OnValueChanged(SlCvars.MaxMogSpawnCount, newValue => _maxMogSpawnCount = newValue);
_cfg.OnValueChanged(SlCvars.ChaosSpawnChance, newValue => _chaosSpawnChance = newValue);
}
}
25 changes: 25 additions & 0 deletions Content.Server/_Scp/GameRules/ScpSl/ScpSlEscapeZoneComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Content.Shared._Scp.GameRule.Sl;
using Robust.Shared.Prototypes;

namespace Content.Server._Scp.GameRules.ScpSl;

[RegisterComponent]
public sealed partial class ScpSlEscapeZoneComponent : Component;

[RegisterComponent]
public sealed partial class SlHumanoidSpawnPointComponent : Component
{
[DataField(required: true)]
public ScpSlHumanoidType SpawnPointType { get; private set; }
}

[RegisterComponent]
public sealed partial class SlScpSpawnPointComponent : Component
{
[DataField(required: true)]
public EntProtoId ScpProtoId { get; private set; }

[DataField]
public bool Playable { get; private set; } = true;
}

46 changes: 46 additions & 0 deletions Content.Server/_Scp/GameRules/ScpSl/ScpSlGameRuleComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Content.Shared._Scp.GameRule.Sl;
using Content.Shared.Humanoid.Prototypes;
using Robust.Shared.Map.Components;
using Robust.Shared.Prototypes;

namespace Content.Server._Scp.GameRules.ScpSl;

[RegisterComponent]
public sealed partial class ScpSlGameRuleComponent : Component
{

[DataField(required: true)]
public Dictionary<ScpSlHumanoidType, List<ProtoId<RandomHumanoidSettingsPrototype>>> HumanoidPresets { get; private set; } = new();

public Dictionary<SlZoneType, Entity<MapGridComponent>> Zones { get; private set; } = new();

[DataField(required: true)]
public ProtoId<RandomHumanoidSettingsPrototype> MogCaptainPrototype { get; set; }

[DataField, ViewVariables(VVAccess.ReadWrite)]
public TimeSpan WaveSpawnCooldown { get; set; } = TimeSpan.FromSeconds(300);

public TimeSpan NextWaveSpawnTime { get; set; }

public int EscapedScientists = 0;
public int EscapedDClass = 0;

public int ContainedScps = 0;

public SlWinType WinType = SlWinType.Tie;
}

public enum SlWinType : byte
{
FondWin = 0,
Tie = 1,
ScpWin = 2,
ChaosWin = 3
}

public enum SlZoneType
{
Light,
Hard,
Office
}
Loading