fish-station/Content.Server/Roles/Jobs/JobSystem.cs
Vigers Ray 5d2cdd3f44 Merge remote-tracking branch 'space-wizards/master'
# Conflicts:
#	Content.Client/Humanoid/HumanoidAppearanceSystem.cs
#	Content.Server/Fluids/EntitySystems/PuddleSystem.cs
#	Content.Server/Roles/Jobs/JobSystem.cs
#	Content.Shared/Humanoid/HumanoidAppearanceComponent.cs
#	Resources/Prototypes/Entities/Clothing/Head/hardsuit-helmets.yml
#	Resources/Prototypes/Entities/Mobs/Species/vox.yml
#	Resources/Prototypes/Entities/Objects/Misc/paper.yml
#	Resources/Prototypes/Entities/Objects/Tools/lighters.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/SMGs/smgs.yml
#	Resources/Prototypes/Recipes/Lathes/categories.yml
#	Resources/Prototypes/Recipes/Lathes/machine_boards.yml
#	Resources/Prototypes/Species/vox.yml
2025-04-21 08:56:50 +03:00

101 lines
3.2 KiB
C#

using System.Globalization;
using Content.Server.Chat.Managers;
using Content.Server.Jobs;
using Content.Server.Mind;
using Content.Server.Revolutionary.Components;
using Content.Shared.Mind;
using Content.Shared.Players;
using Content.Shared.Roles;
using Content.Shared.Roles.Jobs;
using Robust.Shared.Player;
namespace Content.Server.Roles.Jobs;
/// <summary>
/// Handles the job data on mind entities.
/// </summary>
public sealed class JobSystem : SharedJobSystem
{
[Dependency] private readonly IChatManager _chat = default!;
[Dependency] private readonly ISharedPlayerManager _player = default!;
[Dependency] private readonly RoleSystem _roles = default!;
[Dependency] private readonly SharedPlayerSystem _playerSystem = default!;
[Dependency] private readonly IComponentFactory _componentFactory = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<RoleAddedEvent>(OnRoleAddedEvent);
SubscribeLocalEvent<RoleRemovedEvent>(OnRoleRemovedEvent);
}
private void OnRoleAddedEvent(RoleAddedEvent args)
{
MindOnDoGreeting(args.MindId, args.Mind, args);
if (args.RoleTypeUpdate)
_roles.RoleUpdateMessage(args.Mind);
}
private void OnRoleRemovedEvent(RoleRemovedEvent args)
{
if (args.RoleTypeUpdate)
_roles.RoleUpdateMessage(args.Mind);
}
private void MindOnDoGreeting(EntityUid mindId, MindComponent component, RoleAddedEvent args)
{
if (args.Silent)
return;
if (!_player.TryGetSessionById(component.UserId, out var session))
return;
if (!MindTryGetJob(mindId, out var prototype))
return;
_chat.DispatchServerMessage(session, Loc.GetString("job-greet-introduce-job-name",
("jobName", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(prototype.LocalizedName))));
if (prototype.RequireAdminNotify)
_chat.DispatchServerMessage(session, Loc.GetString("job-greet-important-disconnect-admin-notify"));
_chat.DispatchServerMessage(session, Loc.GetString("job-greet-supervisors-warning", ("jobName", prototype.LocalizedName), ("supervisors", Loc.GetString(prototype.Supervisors))));
}
public void MindAddJob(EntityUid mindId, string jobPrototypeId)
{
if (MindHasJobWithId(mindId, jobPrototypeId))
return;
_roles.MindAddJobRole(mindId, null, false, jobPrototypeId);
}
// Sunrise-Start
public bool IsCommandStaff(ICommonSession session)
{
if (_playerSystem.ContentData(session) is not { Mind: { } mindId })
return false;
if (!MindTryGetJob(mindId, out var jobPrototype))
return false;
foreach (var special in jobPrototype.Special)
{
if (special is not AddComponentSpecial componentSpecial)
continue;
foreach (var componentSpecialComponent in componentSpecial.Components)
{
var copy = _componentFactory.GetComponent(componentSpecialComponent.Value);
if (copy is CommandStaffComponent)
{
return true;
}
}
}
return false;
}
// Sunrise-End
}