Files
wwdpublic/Content.Server/_EE/Contractors/Systems/NationalitySystem.cs
Timfa 60053a10d4 Coat and Scrubs Restricted to Respective Employers (#2134)
<!--
This is a semi-strict format, you can add/remove sections as needed but
the order/format should be kept the same
Remove these comments before submitting
-->

# Description

<!--
Explain this PR in as much detail as applicable

Some example prompts to consider:
How might this affect the game? The codebase?
What might be some alternatives to this?
How/Who does this benefit/hurt [the game/codebase]?
-->

Some coats and scrubs in loadout are branded with specific corporation
logo's.
This PR restricts specifically those items to the employers that they
are from.

Note that we have coats from other companies currently not listed as
available employers too. Perhaps we should consider adding them?

# Updated:
This PR now also includes CCVars that can disable a part, or the
entirety, of Contractors for downstreams that prefer free-form RP over
gameplay.
While I was at it, I made it so that AI and Borgs don't get Passports.

---

# Changelog

<!--
You can add an author after the `🆑` to change the name that appears
in the changelog (ex: `🆑 Death`)
Leaving it blank will default to your GitHub display name
This includes all available types for the changelog
-->

🆑
- tweak: Restricted some corporate jackets and scrubs to that specific
corporation.
- tweak: Downstreams can now disable Contractors entirely or partially
if they prefer freeform-rp over gameplay facilitating RP
- tweak: Station AI and Borg are no longer people and don't get
passports.

(cherry picked from commit 445bdc5c1b04c9f41460fb1cc6986e736732508e)
2025-04-04 15:01:26 +03:00

85 lines
3.3 KiB
C#

using System.Linq;
using Content.Server.Players.PlayTimeTracking;
using Content.Shared._EE.Contractors.Prototypes;
using Content.Shared.CCVar;
using Content.Shared.Customization.Systems;
using Content.Shared.GameTicking;
using Content.Shared.Humanoid;
using Content.Shared.Players;
using Content.Shared.Preferences;
using Content.Shared.Roles;
using Robust.Shared;
using Robust.Shared.Configuration;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager;
using Robust.Shared.Utility;
namespace Content.Server._EE.Contractors.Systems;
public sealed class NationalitySystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly ISerializationManager _serialization = default!;
[Dependency] private readonly CharacterRequirementsSystem _characterRequirements = default!;
[Dependency] private readonly PlayTimeTrackingManager _playTimeTracking = default!;
[Dependency] private readonly IConfigurationManager _configuration = default!;
[Dependency] private readonly IComponentFactory _componentFactory = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<PlayerSpawnCompleteEvent>(OnPlayerSpawnComplete);
}
// When the player is spawned in, add the nationality components selected during character creation
private void OnPlayerSpawnComplete(PlayerSpawnCompleteEvent args) =>
ApplyNationality(args.Mob, args.JobId, args.Profile,
_playTimeTracking.GetTrackerTimes(args.Player), args.Player.ContentData()?.Whitelisted ?? false);
/// <summary>
/// Adds the nationality selected by a player to an entity.
/// </summary>
public void ApplyNationality(EntityUid uid, ProtoId<JobPrototype>? jobId, HumanoidCharacterProfile profile,
Dictionary<string, TimeSpan> playTimes, bool whitelisted)
{
if (jobId == null || !_prototype.TryIndex(jobId, out _))
return;
var jobPrototypeToUse = _prototype.Index(jobId.Value);
ProtoId<NationalityPrototype> nationality = profile.Nationality != string.Empty? profile.Nationality : SharedHumanoidAppearanceSystem.DefaultNationality;
if(!_prototype.TryIndex<NationalityPrototype>(nationality, out var nationalityPrototype))
{
DebugTools.Assert($"Nationality '{nationality}' not found!");
return;
}
if (!_characterRequirements.CheckRequirementsValid(
nationalityPrototype.Requirements,
jobPrototypeToUse,
profile, playTimes, whitelisted, nationalityPrototype,
EntityManager, _prototype, _configuration,
out _))
return;
AddNationality(uid, nationalityPrototype);
}
/// <summary>
/// Adds a single Nationality Prototype to an Entity.
/// </summary>
public void AddNationality(EntityUid uid, NationalityPrototype nationalityPrototype)
{
if (!_configuration.GetCVar(CCVars.ContractorsEnabled) ||
!_configuration.GetCVar(CCVars.ContractorsTraitFunctionsEnabled))
{
return;
}
foreach (var function in nationalityPrototype.Functions)
function.OnPlayerSpawn(uid, _componentFactory, EntityManager, _serialization);
}
}