Files
crystall-punk-14/Content.Server/_CP14/RoundStatistic/CP14RoundStatTrackerSystem.cs
Ed 8e1d310a8e Guildmaster YML implementation + Clothing pack (#832)
* banker clothing resprite

* dinazewwr

* commandant cape resprite

* guildmaster cloak

* Guildmaster loadout

* guildmaster job icon

* key locks work

* map update

* guildmaster keys

* guildmaster stamp

* update guildmaster house

* track demiplanes

* player death track

* localization

* guildmaster objective

* Update empire_orders.yml

* fix

* fix map
2025-02-01 17:52:01 +03:00

72 lines
2.0 KiB
C#

using System.Text;
using Content.Server.GameTicking;
using Content.Shared._CP14.RoundStatistic;
using Content.Shared.GameTicking;
using Robust.Shared.Prototypes;
namespace Content.Server._CP14.RoundStatistic;
public sealed partial class CP14RoundStatTrackerSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _proto = default!;
private readonly Dictionary<ProtoId<CP14RoundStatTrackerPrototype>, int> _tracking = new();
public override void Initialize()
{
base.Initialize();
InitializeDemiplaneDeath();
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundReset);
SubscribeLocalEvent<RoundEndTextAppendEvent>(OnRoundEndTextAppend);
ClearStatistic();
}
private void OnRoundReset(RoundRestartCleanupEvent ev)
{
ClearStatistic();
}
private void OnRoundEndTextAppend(RoundEndTextAppendEvent ev)
{
//TODO: Move to separate UI Text block
var sb = new StringBuilder();
sb.Append($"[head=3]{Loc.GetString("cp14-tracker-header")}[/head] \n");
foreach (var pair in _tracking)
{
if (!_proto.TryIndex(pair.Key, out var indexedTracker))
continue;
sb.Append($"- {Loc.GetString(indexedTracker.Text)}: {pair.Value}\n");
}
ev.AddLine(sb.ToString());
}
private void ClearStatistic()
{
_tracking.Clear();
foreach (var statTracker in _proto.EnumeratePrototypes<CP14RoundStatTrackerPrototype>())
{
_tracking.Add(statTracker.ID, 0);
}
}
public void TrackAdd(ProtoId<CP14RoundStatTrackerPrototype> proto, int dif)
{
_tracking[proto] += Math.Max(dif, 0);
}
public int? GetTrack(ProtoId<CP14RoundStatTrackerPrototype> proto)
{
if (!_tracking.TryGetValue(proto, out var stat))
{
Log.Error($"Failed to get round statistic: {proto}");
return null;
}
return stat;
}
}