2024-11-06 18:02:37 +03:00
|
|
|
using Content.Server.Actions;
|
2022-09-10 17:40:06 +02:00
|
|
|
using Content.Server.GameTicking;
|
2024-11-06 18:02:37 +03:00
|
|
|
using Content.Shared.Actions;
|
2024-11-19 21:16:49 -08:00
|
|
|
using Content.Shared.GameTicking;
|
2023-05-12 23:11:35 -04:00
|
|
|
using Content.Shared.Hands.Components;
|
|
|
|
|
using Content.Shared.Hands.EntitySystems;
|
2024-09-12 12:36:41 +02:00
|
|
|
using Content.Shared.Roles;
|
2022-09-10 17:40:06 +02:00
|
|
|
using Content.Shared.Traits;
|
2024-06-03 14:40:03 -07:00
|
|
|
using Content.Shared.Whitelist;
|
2022-09-10 17:40:06 +02:00
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Traits;
|
|
|
|
|
|
|
|
|
|
public sealed class TraitSystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
2023-05-12 23:11:35 -04:00
|
|
|
[Dependency] private readonly SharedHandsSystem _sharedHandsSystem = default!;
|
2024-06-03 14:40:03 -07:00
|
|
|
[Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
|
2022-09-10 17:40:06 +02:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<PlayerSpawnCompleteEvent>(OnPlayerSpawnComplete);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// When the player is spawned in, add all trait components selected during character creation
|
|
|
|
|
private void OnPlayerSpawnComplete(PlayerSpawnCompleteEvent args)
|
|
|
|
|
{
|
2024-09-12 12:36:41 +02:00
|
|
|
// Check if player's job allows to apply traits
|
|
|
|
|
if (args.JobId == null ||
|
|
|
|
|
!_prototypeManager.TryIndex<JobPrototype>(args.JobId ?? string.Empty, out var protoJob) ||
|
|
|
|
|
!protoJob.ApplyTraits)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-10 17:40:06 +02:00
|
|
|
foreach (var traitId in args.Profile.TraitPreferences)
|
|
|
|
|
{
|
|
|
|
|
if (!_prototypeManager.TryIndex<TraitPrototype>(traitId, out var traitPrototype))
|
|
|
|
|
{
|
2024-03-10 01:15:13 +01:00
|
|
|
Log.Warning($"No trait found with ID {traitId}!");
|
2022-09-10 17:40:06 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-03 14:40:03 -07:00
|
|
|
if (_whitelistSystem.IsWhitelistFail(traitPrototype.Whitelist, args.Mob) ||
|
|
|
|
|
_whitelistSystem.IsBlacklistPass(traitPrototype.Blacklist, args.Mob))
|
2022-11-03 21:37:17 -04:00
|
|
|
continue;
|
|
|
|
|
|
2022-09-10 17:40:06 +02:00
|
|
|
// Add all components required by the prototype
|
2024-11-06 18:02:37 +03:00
|
|
|
if (traitPrototype.Components.Count > 0) //CP14 added check
|
|
|
|
|
EntityManager.AddComponents(args.Mob, traitPrototype.Components, false);
|
2023-05-12 23:11:35 -04:00
|
|
|
|
|
|
|
|
// Add item required by the trait
|
2024-06-03 21:47:06 +03:00
|
|
|
if (traitPrototype.TraitGear == null)
|
|
|
|
|
continue;
|
2023-05-12 23:11:35 -04:00
|
|
|
|
2024-06-03 21:47:06 +03:00
|
|
|
if (!TryComp(args.Mob, out HandsComponent? handsComponent))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
var coords = Transform(args.Mob).Coordinates;
|
|
|
|
|
var inhandEntity = EntityManager.SpawnEntity(traitPrototype.TraitGear, coords);
|
|
|
|
|
_sharedHandsSystem.TryPickup(args.Mob,
|
|
|
|
|
inhandEntity,
|
|
|
|
|
checkActionBlocker: false,
|
|
|
|
|
handsComp: handsComponent);
|
2022-09-10 17:40:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|