Skip to content

Commit

Permalink
Trait Modify Factions (#955)
Browse files Browse the repository at this point in the history
# Description

Made by request from Nuclear14, while also adding a trait that was
present both in Parkstation, as well as something N14 would like to
have. This PR extends the TraitSystem so that it can now also add or
remove Factions from a character. It also adds in the Animal Friend
trait from Parkstation/Fallout: New Vegas.

# Changelog

:cl:
- add: The Animal Friend trait has been added to the game. Characters
with this trait are not attacked by animals.

---------

Signed-off-by: VMSolidus <[email protected]>
Co-authored-by: DEATHB4DEFEAT <[email protected]>
  • Loading branch information
VMSolidus and DEATHB4DEFEAT authored Oct 27, 2024
1 parent 820cecc commit 8e1a63c
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 5 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 @@ -318,6 +318,10 @@ 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.
trait-name-Liar = Pathological liar
trait-description-Liar = You can hardly bring yourself to tell the truth. Sometimes you lie anyway.
Expand Down
15 changes: 10 additions & 5 deletions Resources/Prototypes/Traits/skills.yml
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,13 @@
componentRemovals:
- PsionicInsulation
requirements:
- !type:CharacterLogicOrRequirement
requirements:
- !type:CharacterSpeciesRequirement
species:
- IPC
- !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 8e1a63c

Please sign in to comment.