using System.Linq; using Content.Server.GameTicking; using Content.Server.Players.PlayTimeTracking; using Content.Shared.Customization.Systems; using Content.Shared.Players; using Content.Shared.Roles; using Content.Shared.Traits; using Robust.Shared.Configuration; using Robust.Shared.Prototypes; using Robust.Shared.Serialization.Manager; using Robust.Shared.Utility; namespace Content.Server.Traits; public sealed class TraitSystem : 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(OnPlayerSpawnComplete); } // When the player is spawned in, add all trait components selected during character creation private void OnPlayerSpawnComplete(PlayerSpawnCompleteEvent args) { foreach (var traitId in args.Profile.TraitPreferences) { if (!_prototype.TryIndex(traitId, out var traitPrototype)) { DebugTools.Assert($"No trait found with ID {traitId}!"); return; } if (!_characterRequirements.CheckRequirementsValid( traitPrototype.Requirements, _prototype.Index(args.JobId ?? _prototype.EnumeratePrototypes().First().ID), args.Profile, _playTimeTracking.GetTrackerTimes(args.Player), args.Player.ContentData()?.Whitelisted ?? false, traitPrototype, EntityManager, _prototype, _configuration, out _)) continue; AddTrait(args.Mob, traitPrototype); } } /// /// Adds a single Trait Prototype to an Entity. /// public void AddTrait(EntityUid uid, TraitPrototype traitPrototype) { foreach (var function in traitPrototype.Functions) function.OnPlayerSpawn(uid, _componentFactory, EntityManager, _serialization); } }