2024-10-10 10:48:56 +02:00
|
|
|
using Content.Shared.Mind;
|
2023-12-24 12:58:28 +03:00
|
|
|
using Content.Shared.Roles;
|
2023-08-28 16:53:24 -07:00
|
|
|
|
|
|
|
|
namespace Content.Server.Roles;
|
|
|
|
|
|
2023-08-30 21:46:11 -07:00
|
|
|
public sealed class RoleSystem : SharedRoleSystem
|
2023-08-28 16:53:24 -07:00
|
|
|
{
|
|
|
|
|
public string? MindGetBriefing(EntityUid? mindId)
|
|
|
|
|
{
|
2023-08-31 22:29:45 +01:00
|
|
|
if (mindId == null)
|
2024-10-10 10:48:56 +02:00
|
|
|
{
|
|
|
|
|
Log.Error($"MingGetBriefing failed for mind {mindId}");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TryComp<MindComponent>(mindId.Value, out var mindComp);
|
|
|
|
|
|
|
|
|
|
if (mindComp is null)
|
|
|
|
|
{
|
|
|
|
|
Log.Error($"MingGetBriefing failed for mind {mindId}");
|
2023-08-31 22:29:45 +01:00
|
|
|
return null;
|
2024-10-10 10:48:56 +02:00
|
|
|
}
|
2023-08-31 22:29:45 +01:00
|
|
|
|
|
|
|
|
var ev = new GetBriefingEvent();
|
2024-10-10 10:48:56 +02:00
|
|
|
|
|
|
|
|
// This is on the event because while this Entity<T> is also present on every Mind Role Entity's MindRoleComp
|
|
|
|
|
// getting to there from a GetBriefing event subscription can be somewhat boilerplate
|
|
|
|
|
// and this needs to be looked up for the event anyway so why calculate it again later
|
|
|
|
|
ev.Mind = (mindId.Value, mindComp);
|
|
|
|
|
|
|
|
|
|
// Briefing is no longer raised on the mind entity itself
|
|
|
|
|
// because all the components that briefings subscribe to should be on Mind Role Entities
|
|
|
|
|
foreach(var role in mindComp.MindRoles)
|
|
|
|
|
{
|
|
|
|
|
RaiseLocalEvent(role, ref ev);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-31 22:29:45 +01:00
|
|
|
return ev.Briefing;
|
2023-08-28 16:53:24 -07:00
|
|
|
}
|
|
|
|
|
}
|
2023-08-31 22:29:45 +01:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Event raised on the mind to get its briefing.
|
|
|
|
|
/// Handlers can either replace or append to the briefing, whichever is more appropriate.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ByRefEvent]
|
2023-10-05 16:05:09 +01:00
|
|
|
public sealed class GetBriefingEvent
|
|
|
|
|
{
|
2024-10-10 10:48:56 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// The text that will be shown on the Character Screen
|
|
|
|
|
/// </summary>
|
2023-10-05 16:05:09 +01:00
|
|
|
public string? Briefing;
|
|
|
|
|
|
2024-10-10 10:48:56 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// The Mind to whose Mind Role Entities the briefing is sent to
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Entity<MindComponent> Mind;
|
|
|
|
|
|
2023-10-05 16:05:09 +01:00
|
|
|
public GetBriefingEvent(string? briefing = null)
|
|
|
|
|
{
|
|
|
|
|
Briefing = briefing;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// If there is no briefing, sets it to the string.
|
|
|
|
|
/// If there is a briefing, adds a new line to separate it from the appended string.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void Append(string text)
|
|
|
|
|
{
|
|
|
|
|
if (Briefing == null)
|
|
|
|
|
{
|
|
|
|
|
Briefing = text;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Briefing += "\n" + text;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|