Files
wwdpublic/Content.Server/Jobs/AddTraitSpecial.cs
Peptide90 07f5bb8c2b AddTraitSpecial (#1528)
Adds a way to specify traits in the jobs special area.

Hashset so you can specify multiple traits. Tested on Nuclear14 to give
the tribals a specific language in a friendly way.
```
  special:
  - !type:AddTraitSpecial
    traits: [ LanguageTribal, LanguageChinese ]
```

(cherry picked from commit bc0708ab3f602f5f348f2e0a0585effac9f5c3e8)
2025-01-15 00:06:41 +03:00

31 lines
987 B
C#

using Content.Server.Traits;
using Content.Shared.Roles;
using Content.Shared.Traits;
using JetBrains.Annotations;
using Robust.Shared.Prototypes;
namespace Content.Server.Jobs;
[UsedImplicitly]
public sealed partial class AddTraitSpecial : JobSpecial
{
// Datafield for storing multiple trait prototype IDs as strings
[DataField(required: true)]
public HashSet<string> Traits { get; private set; } = new();
public override void AfterEquip(EntityUid mob)
{
// Resolve the necessary systems
var entityManager = IoCManager.Resolve<IEntityManager>();
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
var traitSystem = entityManager.System<TraitSystem>();
// Iterate through each trait and add it to the entity
foreach (var traitId in Traits)
if (prototypeManager.TryIndex<TraitPrototype>(traitId, out var traitPrototype))
traitSystem.AddTrait(mob, traitPrototype);
}
}