Skip to content

Commit

Permalink
Trait Modify Factions
Browse files Browse the repository at this point in the history
  • Loading branch information
VMSolidus committed Sep 22, 2024
1 parent 900630c commit 300460a
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Content.Server/Traits/TraitSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Content.Shared.Psionics;
using Content.Server.Language;
using Content.Shared.Mood;
using Content.Server.NPC.Systems;

namespace Content.Server.Traits;

Expand All @@ -28,6 +29,7 @@ public sealed class TraitSystem : EntitySystem
[Dependency] private readonly PsionicAbilitiesSystem _psionicAbilities = default!;
[Dependency] private readonly IComponentFactory _componentFactory = default!;
[Dependency] private readonly LanguageSystem _languageSystem = default!;
[Dependency] private readonly NpcFactionSystem _factionSystem = default!;

public override void Initialize()
{
Expand Down Expand Up @@ -71,6 +73,8 @@ public void AddTrait(EntityUid uid, TraitPrototype traitPrototype)
AddTraitLanguage(uid, traitPrototype);
RemoveTraitLanguage(uid, traitPrototype);
AddTraitMoodlets(uid, traitPrototype);
RemoveTraitFactions(uid, traitPrototype);
AddTraitFactions(uid, traitPrototype);
}

/// <summary>
Expand Down Expand Up @@ -225,4 +229,28 @@ public void AddTraitMoodlets(EntityUid uid, TraitPrototype traitPrototype)
if (_prototype.TryIndex(moodProto, out var moodlet))
RaiseLocalEvent(uid, new MoodEffectEvent(moodlet.ID));
}

/// <summary>
/// If a trait includes any faction removals, this removes the faction from the receiving entity.
/// </summary>
public void RemoveTraitFactions(EntityUid uid, TraitPrototype traitPrototype)
{
if (traitPrototype.RemoveFactions is null)
return;

foreach (var faction in traitPrototype.RemoveFactions)
_factionSystem.RemoveFaction(uid, faction);
}

/// <summary>
/// If a trait includes any factions to add, this adds the factions to the receiving entity.
/// </summary>
public void AddTraitFactions(EntityUid uid, TraitPrototype traitPrototype)
{
if (traitPrototype.AddFactions is null)
return;

foreach (var faction in traitPrototype.AddFactions)
_factionSystem.AddFaction(uid, faction);
}
}
18 changes: 18 additions & 0 deletions Content.Shared/Traits/Prototypes/TraitPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,22 @@ public sealed partial class TraitPrototype : IPrototype
/// </summary>
[DataField]
public List<ProtoId<MoodEffectPrototype>>? MoodEffects { get; private set; } = default!;

/// <summary>
/// The list of all Factions that this trait removes.
/// </summary>
/// <remarks>
/// I can't actually Validate these because the proto lives in Shared.
/// </remarks>
[DataField]
public List<string>? RemoveFactions { get; private set; } = default!;

/// <summary>
/// The list of all Factions that this trait adds.
/// </summary>
/// <remarks>
/// I can't actually Validate these because the proto lives in Shared.
/// </remarks>
[DataField]
public List<string>? AddFactions { get; private set; } = default!;
}
4 changes: 4 additions & 0 deletions Resources/Locale/en-US/traits/traits.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,7 @@ trait-description-Spinarette =
trait-name-AddictionNicotine = Nicotine Addiction
trait-description-AddictionNicotine =
You have an addiction to Nicotine, and will require frequent smoke breaks to keep your mood in check.
trait-name-AnimalFriend = Animal Friend
trait-description-AnimalFriend =
You have a way with animals. You will never be attacked by animals, unless you attack them first.
7 changes: 7 additions & 0 deletions Resources/Prototypes/Traits/skills.yml
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,10 @@
- !type:CharacterSpeciesRequirement
species:
- IPC

- type: trait
id: AnimalFriend
category: Mental
points: -4
addFactions:
- AnimalFriend
7 changes: 7 additions & 0 deletions Resources/Prototypes/ai_factions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

- type: npcFaction
id: SimpleHostile
friendly:
- AnimalFriend
hostile:
- NanoTrasen
- Syndicate
Expand Down Expand Up @@ -86,6 +88,8 @@

- type: npcFaction
id: Pibble
friendly:
- AnimalFriend
hostile:
- Cat
- Birb
Expand All @@ -99,3 +103,6 @@

- type: npcFaction
id: Birb

- type: npcFaction
id: AnimalFriend

0 comments on commit 300460a

Please sign in to comment.