From 300460a0c75497cf14ed66a9a8a3d95b178eb50b Mon Sep 17 00:00:00 2001 From: VMSolidus Date: Sun, 22 Sep 2024 19:16:16 -0400 Subject: [PATCH 1/2] Trait Modify Factions --- Content.Server/Traits/TraitSystem.cs | 28 +++++++++++++++++++ .../Traits/Prototypes/TraitPrototype.cs | 18 ++++++++++++ Resources/Locale/en-US/traits/traits.ftl | 4 +++ Resources/Prototypes/Traits/skills.yml | 7 +++++ Resources/Prototypes/ai_factions.yml | 7 +++++ 5 files changed, 64 insertions(+) diff --git a/Content.Server/Traits/TraitSystem.cs b/Content.Server/Traits/TraitSystem.cs index bd36b4ecefb..afdf01524de 100644 --- a/Content.Server/Traits/TraitSystem.cs +++ b/Content.Server/Traits/TraitSystem.cs @@ -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; @@ -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() { @@ -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); } /// @@ -225,4 +229,28 @@ public void AddTraitMoodlets(EntityUid uid, TraitPrototype traitPrototype) if (_prototype.TryIndex(moodProto, out var moodlet)) RaiseLocalEvent(uid, new MoodEffectEvent(moodlet.ID)); } + + /// + /// If a trait includes any faction removals, this removes the faction from the receiving entity. + /// + public void RemoveTraitFactions(EntityUid uid, TraitPrototype traitPrototype) + { + if (traitPrototype.RemoveFactions is null) + return; + + foreach (var faction in traitPrototype.RemoveFactions) + _factionSystem.RemoveFaction(uid, faction); + } + + /// + /// If a trait includes any factions to add, this adds the factions to the receiving entity. + /// + public void AddTraitFactions(EntityUid uid, TraitPrototype traitPrototype) + { + if (traitPrototype.AddFactions is null) + return; + + foreach (var faction in traitPrototype.AddFactions) + _factionSystem.AddFaction(uid, faction); + } } diff --git a/Content.Shared/Traits/Prototypes/TraitPrototype.cs b/Content.Shared/Traits/Prototypes/TraitPrototype.cs index 7c0e429a691..fb8ccf54640 100644 --- a/Content.Shared/Traits/Prototypes/TraitPrototype.cs +++ b/Content.Shared/Traits/Prototypes/TraitPrototype.cs @@ -87,4 +87,22 @@ public sealed partial class TraitPrototype : IPrototype /// [DataField] public List>? MoodEffects { get; private set; } = default!; + + /// + /// The list of all Factions that this trait removes. + /// + /// + /// I can't actually Validate these because the proto lives in Shared. + /// + [DataField] + public List? RemoveFactions { get; private set; } = default!; + + /// + /// The list of all Factions that this trait adds. + /// + /// + /// I can't actually Validate these because the proto lives in Shared. + /// + [DataField] + public List? AddFactions { get; private set; } = default!; } diff --git a/Resources/Locale/en-US/traits/traits.ftl b/Resources/Locale/en-US/traits/traits.ftl index 4db6055e46b..edca71af333 100644 --- a/Resources/Locale/en-US/traits/traits.ftl +++ b/Resources/Locale/en-US/traits/traits.ftl @@ -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. \ No newline at end of file diff --git a/Resources/Prototypes/Traits/skills.yml b/Resources/Prototypes/Traits/skills.yml index 0e4868f19bc..6cae08438e2 100644 --- a/Resources/Prototypes/Traits/skills.yml +++ b/Resources/Prototypes/Traits/skills.yml @@ -282,3 +282,10 @@ - !type:CharacterSpeciesRequirement species: - IPC + +- type: trait + id: AnimalFriend + category: Mental + points: -4 + addFactions: + - AnimalFriend \ No newline at end of file diff --git a/Resources/Prototypes/ai_factions.yml b/Resources/Prototypes/ai_factions.yml index 02a2ac168d3..cdbbf868662 100644 --- a/Resources/Prototypes/ai_factions.yml +++ b/Resources/Prototypes/ai_factions.yml @@ -35,6 +35,8 @@ - type: npcFaction id: SimpleHostile + friendly: + - AnimalFriend hostile: - NanoTrasen - Syndicate @@ -86,6 +88,8 @@ - type: npcFaction id: Pibble + friendly: + - AnimalFriend hostile: - Cat - Birb @@ -99,3 +103,6 @@ - type: npcFaction id: Birb + +- type: npcFaction + id: AnimalFriend From d7a84201291f9877b480a7e544e00036eb52db25 Mon Sep 17 00:00:00 2001 From: VMSolidus Date: Sun, 22 Sep 2024 19:30:38 -0400 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: DEATHB4DEFEAT <77995199+DEATHB4DEFEAT@users.noreply.github.com> Signed-off-by: VMSolidus --- Resources/Locale/en-US/traits/traits.ftl | 2 +- Resources/Prototypes/Traits/skills.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Resources/Locale/en-US/traits/traits.ftl b/Resources/Locale/en-US/traits/traits.ftl index edca71af333..9409576c817 100644 --- a/Resources/Locale/en-US/traits/traits.ftl +++ b/Resources/Locale/en-US/traits/traits.ftl @@ -317,4 +317,4 @@ trait-description-AddictionNicotine = 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. \ No newline at end of file + You have a way with animals. You will never be attacked by animals, unless you attack them first. diff --git a/Resources/Prototypes/Traits/skills.yml b/Resources/Prototypes/Traits/skills.yml index 6cae08438e2..e68d72ee92a 100644 --- a/Resources/Prototypes/Traits/skills.yml +++ b/Resources/Prototypes/Traits/skills.yml @@ -288,4 +288,4 @@ category: Mental points: -4 addFactions: - - AnimalFriend \ No newline at end of file + - AnimalFriend