Skip to content

Commit

Permalink
probably everything
Browse files Browse the repository at this point in the history
  • Loading branch information
DEATHB4DEFEAT committed Feb 12, 2024
1 parent a5ddcec commit 9f3b949
Show file tree
Hide file tree
Showing 32 changed files with 1,208 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Content.Server/Body/Systems/BloodstreamSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Content.Server.Forensics;
using Content.Server.HealthExaminable;
using Content.Server.Popups;
using Content.Server.SimpleStation14.EndOfRoundStats.BloodLost;
using Content.Shared.Alert;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.EntitySystems;
Expand Down Expand Up @@ -92,6 +93,8 @@ public override void Update(float frameTime)
{
base.Update(frameTime);

var totalBloodLost = 0f; // Parkstation-EndOfRoundStats

var query = EntityQueryEnumerator<BloodstreamComponent>();
while (query.MoveNext(out var uid, out var bloodstream))
{
Expand Down Expand Up @@ -119,6 +122,8 @@ public override void Update(float frameTime)
TryModifyBloodLevel(uid, (-bloodstream.BleedAmount), bloodstream);
// Bleed rate is reduced by the bleed reduction amount in the bloodstream component.
TryModifyBleedAmount(uid, -bloodstream.BleedReductionAmount, bloodstream);

totalBloodLost += bloodstream.BleedAmount / 20; // Parkstation-EndOfRoundStats
}

// deal bloodloss damage if their blood level is below a threshold.
Expand Down Expand Up @@ -151,6 +156,8 @@ public override void Update(float frameTime)
bloodstream.StatusTime = 0;
}
}

RaiseLocalEvent(new BloodLostStatEvent(totalBloodLost)); // Parkstation-EndOfRoundStats
}

private void OnComponentInit(Entity<BloodstreamComponent> entity, ref ComponentInit args)
Expand Down
2 changes: 2 additions & 0 deletions Content.Server/Instruments/InstrumentComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public sealed partial class InstrumentComponent : SharedInstrumentComponent
public ICommonSession? InstrumentPlayer =>
_entMan.GetComponentOrNull<ActivatableUIComponent>(Owner)?.CurrentSingleUser
?? _entMan.GetComponentOrNull<ActorComponent>(Owner)?.PlayerSession;

public TimeSpan? TimeStartedPlaying { get; set; } // Parkstation-EndOfRoundStats
}

[RegisterComponent]
Expand Down
16 changes: 16 additions & 0 deletions Content.Server/Instruments/InstrumentSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Content.Server.Administration;
using Content.Server.Interaction;
using Content.Server.Popups;
using Content.Server.SimpleStation14.EndOfRoundStats.Instruments;
using Content.Server.Stunnable;
using Content.Shared.Administration;
using Content.Shared.Instruments;
Expand Down Expand Up @@ -30,6 +31,7 @@ public sealed partial class InstrumentSystem : SharedInstrumentSystem
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly TransformSystem _transform = default!;
[Dependency] private readonly InteractionSystem _interactions = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;

private const float MaxInstrumentBandRange = 10f;

Expand Down Expand Up @@ -116,6 +118,8 @@ private void OnMidiStart(InstrumentStartMidiEvent msg, EntitySessionEventArgs ar

instrument.Playing = true;
Dirty(uid, instrument);

instrument.TimeStartedPlaying = _gameTiming.CurTime; // Parkstation-EndOfRoundStats
}

private void OnMidiStop(InstrumentStopMidiEvent msg, EntitySessionEventArgs args)
Expand Down Expand Up @@ -286,6 +290,18 @@ public void Clean(EntityUid uid, InstrumentComponent? instrument = null)
RaiseNetworkEvent(new InstrumentMidiEventEvent(netUid, new[]{RobustMidiEvent.SystemReset(0)}));

RaiseNetworkEvent(new InstrumentStopMidiEvent(netUid));

// Parkstation-EndOfRoundStats-Start
if (instrument.TimeStartedPlaying != null && instrument.InstrumentPlayer != null)
{
var username = instrument.InstrumentPlayer.Name;
var entity = instrument.InstrumentPlayer.AttachedEntity;
var name = entity != null ? MetaData((EntityUid) entity).EntityName : "Unknown";

RaiseLocalEvent(new InstrumentPlayedStatEvent(name, (TimeSpan) (_gameTiming.CurTime - instrument.TimeStartedPlaying), username));
}
instrument.TimeStartedPlaying = null;
// Parkstation-EndOfRoundStats-End
}

instrument.Playing = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Content.Server.SimpleStation14.EndOfRoundStats.BloodLost;

public sealed class BloodLostStatEvent : EntityEventArgs
{
public float BloodLost;

public BloodLostStatEvent(float bloodLost)
{
BloodLost = bloodLost;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Content.Server.GameTicking;
using Content.Shared.GameTicking;
using Robust.Shared.Configuration;
using Content.Shared.SimpleStation14.CCVar;
using Content.Shared.FixedPoint;

namespace Content.Server.SimpleStation14.EndOfRoundStats.BloodLost;

public sealed class BloodLostStatSystem : EntitySystem
{
[Dependency] private readonly IConfigurationManager _config = default!;

FixedPoint2 totalBloodLost = 0;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<BloodLostStatEvent>(OnBloodLost);

SubscribeLocalEvent<RoundEndTextAppendEvent>(OnRoundEnd);
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundRestart);
}

private void OnBloodLost(BloodLostStatEvent args)
{
totalBloodLost += args.BloodLost;
}

private void OnRoundEnd(RoundEndTextAppendEvent ev)
{
var line = String.Empty;

if (totalBloodLost < _config.GetCVar<float>(SimpleStationCCVars.BloodLostThreshold))
return;

line += $"[color=maroon]{Loc.GetString("eorstats-bloodlost-total", ("bloodLost", totalBloodLost.Int()))}[/color]";

ev.AddLine("\n" + line);
}

private void OnRoundRestart(RoundRestartCleanupEvent ev)
{
totalBloodLost = 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Content.Server.GameTicking;
using Content.Shared.GameTicking;

namespace Content.Server.SimpleStation14.EndOfRoundStats.Command;

public sealed class CommandStatSystem : EntitySystem
{
public List<(string, string)> eorStats = new();

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<RoundEndTextAppendEvent>(OnRoundEnd);
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundRestart);
}

private void OnRoundEnd(RoundEndTextAppendEvent ev)
{
foreach (var (stat, color) in eorStats)
{
ev.AddLine($"[color={color}]{stat}[/color]");
}
}

private void OnRoundRestart(RoundRestartCleanupEvent ev)
{
eorStats.Clear();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System.Linq;
using Content.Server.Administration;
using Content.Shared.Administration;
using Content.Shared.Administration.Logs;
using Content.Shared.Database;
using Robust.Shared.Console;

namespace Content.Server.SimpleStation14.EndOfRoundStats.Command;

[AdminCommand(AdminFlags.Admin)]
public sealed class EORStatsAddCommmand : IConsoleCommand
{
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;

public string Command => "eorstatsadd";
public string Description => "Adds an end of round stat to be displayed.";
public string Help => $"Usage: {Command} <stat> <color?>";

public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var _stats = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<CommandStatSystem>();

if (args.Length < 1 || args.Length > 2)
{
shell.WriteError("Invalid amount of arguments.");
return;
}

if (args.Length == 2 && !Color.TryFromName(args[1], out _))
{
shell.WriteError("Invalid color.");
return;
}

_stats.eorStats.Add((args[0], args.Length == 2 ? args[1] : "Green"));

shell.WriteLine($"Added {args[0]} to end of round stats.");

_adminLogger.Add(LogType.AdminMessage, LogImpact.Low,
$"{shell.Player!.Name} added '{args[0]}' to end of round stats.");
}

public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length == 1)
{
return CompletionResult.FromHint("<Stat>");
}

if (args.Length == 2)
{
var options = Color.GetAllDefaultColors().Select(o => new CompletionOption(o.Key));

return CompletionResult.FromHintOptions(options, "<Color?>");
}

return CompletionResult.Empty;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Content.Server.Administration;
using Content.Shared.Administration;
using Robust.Shared.Console;

namespace Content.Server.SimpleStation14.EndOfRoundStats.Command;

[AdminCommand(AdminFlags.Admin)]
public sealed class EORStatsCommand : IConsoleCommand
{
public string Command => "eorstatslist";
public string Description => "Lists the current command-added end of round stats to be displayed.";
public string Help => $"Usage: {Command}";

public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var _stats = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<CommandStatSystem>();

if (args.Length != 0)
{
shell.WriteError("Invalid amount of arguments.");
return;
}

if (_stats.eorStats.Count == 0)
{
shell.WriteLine("No command-added end of round stats to display.");
return;
}

shell.WriteLine("End of round stats:");

foreach (var (stat, color) in _stats.eorStats)
{
shell.WriteLine($"'{stat}' - {color}");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System.Linq;
using Content.Server.Administration;
using Content.Shared.Administration;
using Robust.Shared.Console;

namespace Content.Server.SimpleStation14.EndOfRoundStats.Command;

[AdminCommand(AdminFlags.Admin)]
public sealed class EORStatsRemoveCommand : IConsoleCommand
{
public string Command => "eorstatsremove";
public string Description => "Removes a previously added end of round stat. Defaults to last added stat.";
public string Help => $"Usage: {Command} <stat index?>";

public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var _stats = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<CommandStatSystem>();

if (args.Length > 1)
{
shell.WriteError("Invalid amount of arguments.");
return;
}

if (_stats.eorStats.Count == 0)
{
shell.WriteError("No stats to remove.");
return;
}

int index = _stats.eorStats.Count;

if (args.Length == 1)
{
if (!int.TryParse(args[0], out index))
{
shell.WriteError("Invalid index.");
return;
}

if (index < 0 || index > _stats.eorStats.Count)
{
shell.WriteError("Index out of range.");
return;
}
}

index--;

shell.WriteLine($"Removed '{_stats.eorStats[index].Item1}' from end of round stats.");

_stats.eorStats.RemoveAt(index);
}

public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
var _stats = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<CommandStatSystem>();

if (args.Length == 1)
{
var options = _stats.eorStats.Select(o => new CompletionOption
((_stats.eorStats.LastIndexOf((o.Item1, o.Item2)) + 1).ToString(), o.Item1));

if (options.Count() == 0)
return CompletionResult.FromHint("No stats to remove.");

return CompletionResult.FromOptions(options);
}

return CompletionResult.Empty;
}
}
Loading

0 comments on commit 9f3b949

Please sign in to comment.