mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-16 13:51:10 +03:00
66 lines
2.2 KiB
C#
66 lines
2.2 KiB
C#
using System.Linq;
|
|
using Content.Server.Fax;
|
|
using Content.Shared.GameTicking;
|
|
using Content.Shared.Paper;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Random;
|
|
|
|
namespace Content.Server.Corvax.StationGoal
|
|
{
|
|
/// <summary>
|
|
/// System to spawn paper with station goal.
|
|
/// </summary>
|
|
public sealed class StationGoalPaperSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
[Dependency] private readonly FaxSystem _faxSystem = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<RoundStartedEvent>(OnRoundStarted);
|
|
}
|
|
|
|
private void OnRoundStarted(RoundStartedEvent ev)
|
|
{
|
|
SendRandomGoal();
|
|
}
|
|
|
|
public bool SendRandomGoal()
|
|
{
|
|
var availableGoals = _prototypeManager.EnumeratePrototypes<StationGoalPrototype>().ToList();
|
|
var goal = _random.Pick(availableGoals);
|
|
return SendStationGoal(goal);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Send a station goal to all faxes which are authorized to receive it.
|
|
/// </summary>
|
|
/// <returns>True if at least one fax received paper</returns>
|
|
public bool SendStationGoal(StationGoalPrototype goal)
|
|
{
|
|
var faxes = EntityManager.EntityQuery<FaxMachineComponent>();
|
|
var wasSent = false;
|
|
foreach (var fax in faxes)
|
|
{
|
|
if (!fax.ReceiveStationGoal) continue;
|
|
|
|
var printout = new FaxPrintout(
|
|
Loc.GetString(goal.Text),
|
|
Loc.GetString("station-goal-fax-paper-name"),
|
|
null,
|
|
"paper_stamp-centcom",
|
|
new List<StampDisplayInfo>
|
|
{
|
|
new() { StampedName = Loc.GetString("stamp-component-stamped-name-centcom"), StampedColor = Color.FromHex("#BB3232") },
|
|
});
|
|
_faxSystem.Receive(fax.Owner, printout, null, fax);
|
|
|
|
wasSent = true;
|
|
}
|
|
|
|
return wasSent;
|
|
}
|
|
}
|
|
}
|