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
{
///
/// System to spawn paper with station goal.
///
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(OnRoundStarted);
}
private void OnRoundStarted(RoundStartedEvent ev)
{
SendRandomGoal();
}
public bool SendRandomGoal()
{
var availableGoals = _prototypeManager.EnumeratePrototypes().ToList();
var goal = _random.Pick(availableGoals);
return SendStationGoal(goal);
}
///
/// Send a station goal to all faxes which are authorized to receive it.
///
/// True if at least one fax received paper
public bool SendStationGoal(StationGoalPrototype goal)
{
var faxes = EntityManager.EntityQuery();
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
{
new() { StampedName = Loc.GetString("stamp-component-stamped-name-centcom"), StampedColor = Color.FromHex("#BB3232") },
});
_faxSystem.Receive(fax.Owner, printout, null, fax);
wasSent = true;
}
return wasSent;
}
}
}