From 73f02aaa0b815fbfe86f172b4fad654762f76f29 Mon Sep 17 00:00:00 2001 From: lzk <124214523+lzk228@users.noreply.github.com> Date: Tue, 2 Jul 2024 15:32:21 +0200 Subject: [PATCH] Add ability to add additional friendly and hostile factions in prototypes (#29636) * Make friendly and hostile factions in NpcFactionMemberComponent datafiels * :trollface: * :trollface: --- .../Nyanotrasen/Psionics/PsionicsSystem.cs | 8 +-- .../Components/NpcFactionMemberComponent.cs | 14 +++-- .../NPC/Systems/NpcFactionSystem.cs | 9 ++++ .../Faction/ClothingAddFactionComponent.cs | 21 -------- .../NPC/Systems/FactionSystem.Core.cs | 40 -------------- .../NPC/Systems/FactionSystem.Items.cs | 52 ------------------- .../Entities/Clothing/Uniforms/jumpsuits.yml | 4 +- RobustToolbox | 2 +- 8 files changed, 25 insertions(+), 125 deletions(-) delete mode 100644 Content.Shared/Nyanotrasen/NPC/Systems/Components/Faction/ClothingAddFactionComponent.cs delete mode 100644 Content.Shared/Nyanotrasen/NPC/Systems/FactionSystem.Core.cs delete mode 100644 Content.Shared/Nyanotrasen/NPC/Systems/FactionSystem.Items.cs diff --git a/Content.Server/Nyanotrasen/Psionics/PsionicsSystem.cs b/Content.Server/Nyanotrasen/Psionics/PsionicsSystem.cs index fbde7271f1..d81e116b0a 100644 --- a/Content.Server/Nyanotrasen/Psionics/PsionicsSystem.cs +++ b/Content.Server/Nyanotrasen/Psionics/PsionicsSystem.cs @@ -30,7 +30,7 @@ namespace Content.Server.Psionics [Dependency] private readonly MindSwapPowerSystem _mindSwapPowerSystem = default!; [Dependency] private readonly GlimmerSystem _glimmerSystem = default!; [Dependency] private readonly ChatSystem _chat = default!; - [Dependency] private readonly NpcFactionSystem _npcFactonSystem = default!; + [Dependency] private readonly NpcFactionSystem _faction = default!; [Dependency] private readonly IConfigurationManager _cfg = default!; [Dependency] private readonly SharedAudioSystem _audio = default!; @@ -98,10 +98,10 @@ namespace Content.Server.Psionics if (!TryComp(uid, out var factions)) return; - if (_npcFactonSystem.ContainsFaction(uid, "GlimmerMonster", factions)) + if (_faction.IsMember((uid, factions), "GlimmerMonster")) return; - _npcFactonSystem.AddFaction(uid, "PsionicInterloper"); + _faction.AddFaction((uid, factions) "PsionicInterloper"); } private void OnRemove(EntityUid uid, PsionicComponent component, ComponentRemove args) @@ -109,7 +109,7 @@ namespace Content.Server.Psionics if (!TryComp(uid, out var factions)) return; - _npcFactonSystem.RemoveFaction(uid, "PsionicInterloper"); + _faction.RemoveFaction((uid, factions), "PsionicInterloper"); } private void OnStamHit(EntityUid uid, AntiPsionicWeaponComponent component, StaminaMeleeHitEvent args) diff --git a/Content.Shared/NPC/Components/NpcFactionMemberComponent.cs b/Content.Shared/NPC/Components/NpcFactionMemberComponent.cs index 188ece81ed..208dfd4681 100644 --- a/Content.Shared/NPC/Components/NpcFactionMemberComponent.cs +++ b/Content.Shared/NPC/Components/NpcFactionMemberComponent.cs @@ -26,11 +26,15 @@ public sealed partial class NpcFactionMemberComponent : Component [ViewVariables] public readonly HashSet> HostileFactions = new(); - // Nyano - Summary - Begin modified code block: support for specific entities to be friendly. /// - /// Permanently friendly specific entities. Our summoner, etc. - /// Would like to separate. Could I do that by extending this method, maybe? + /// Used to add friendly factions in prototypes. /// - public HashSet ExceptionalFriendlies = new(); - // Nyano - End modified code block. + [DataField, ViewVariables] + public HashSet>? AddFriendlyFactions; + + /// + /// Used to add hostile factions in prototypes. + /// + [DataField, ViewVariables] + public HashSet>? AddHostileFactions; } diff --git a/Content.Shared/NPC/Systems/NpcFactionSystem.cs b/Content.Shared/NPC/Systems/NpcFactionSystem.cs index f0bb1945eb..ea762ec113 100644 --- a/Content.Shared/NPC/Systems/NpcFactionSystem.cs +++ b/Content.Shared/NPC/Systems/NpcFactionSystem.cs @@ -60,6 +60,15 @@ public sealed partial class NpcFactionSystem : EntitySystem ent.Comp.FriendlyFactions.UnionWith(factionData.Friendly); ent.Comp.HostileFactions.UnionWith(factionData.Hostile); } + // Add additional factions if it is written in prototype + if (ent.Comp.AddFriendlyFactions != null) + { + ent.Comp.FriendlyFactions.UnionWith(ent.Comp.AddFriendlyFactions); + } + if (ent.Comp.AddHostileFactions != null) + { + ent.Comp.HostileFactions.UnionWith(ent.Comp.AddHostileFactions); + } } /// diff --git a/Content.Shared/Nyanotrasen/NPC/Systems/Components/Faction/ClothingAddFactionComponent.cs b/Content.Shared/Nyanotrasen/NPC/Systems/Components/Faction/ClothingAddFactionComponent.cs deleted file mode 100644 index 3d55cd9a8c..0000000000 --- a/Content.Shared/Nyanotrasen/NPC/Systems/Components/Faction/ClothingAddFactionComponent.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Content.Shared.NPC.Prototypes; -using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; - -namespace Content.Shared.NPC.Components -{ - /// - /// Allows clothing to add a faction to you when you wear it. - /// - [RegisterComponent] - public sealed partial class ClothingAddFactionComponent : Component - { - public bool IsActive = false; - - /// - /// Faction added - /// - [ViewVariables(VVAccess.ReadWrite), - DataField("faction", required: true, customTypeSerializer:typeof(PrototypeIdSerializer))] - public string Faction = ""; - } -} diff --git a/Content.Shared/Nyanotrasen/NPC/Systems/FactionSystem.Core.cs b/Content.Shared/Nyanotrasen/NPC/Systems/FactionSystem.Core.cs deleted file mode 100644 index 385f3a1099..0000000000 --- a/Content.Shared/Nyanotrasen/NPC/Systems/FactionSystem.Core.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Content.Shared.NPC.Components; - -namespace Content.Shared.NPC.Systems; - -public partial class NpcFactionSystem : EntitySystem -{ - public void InitializeCore() - { - SubscribeLocalEvent(OnGetNearbyHostiles); - } - - public bool ContainsFaction(EntityUid uid, string faction, NpcFactionMemberComponent? component = null) - { - if (!Resolve(uid, ref component, false)) - return false; - - return component.Factions.Contains(faction); - } - - public void AddFriendlyEntity(EntityUid uid, EntityUid fEntity, NpcFactionMemberComponent? component = null) - { - if (!Resolve(uid, ref component, false)) - return; - - component.ExceptionalFriendlies.Add(fEntity); - } - - private void OnGetNearbyHostiles(EntityUid uid, NpcFactionMemberComponent component, ref GetNearbyHostilesEvent args) - { - args.ExceptionalFriendlies.UnionWith(component.ExceptionalFriendlies); - } -} - -/// -/// Raised on an entity when it's trying to determine which nearby entities are hostile. -/// -/// Entities that will be counted as hostile regardless of faction. Overriden by friendlies. -/// Entities that will be counted as friendly regardless of faction. Overrides hostiles. -[ByRefEvent] -public readonly record struct GetNearbyHostilesEvent(HashSet ExceptionalHostiles, HashSet ExceptionalFriendlies); diff --git a/Content.Shared/Nyanotrasen/NPC/Systems/FactionSystem.Items.cs b/Content.Shared/Nyanotrasen/NPC/Systems/FactionSystem.Items.cs deleted file mode 100644 index 012b59c6cc..0000000000 --- a/Content.Shared/Nyanotrasen/NPC/Systems/FactionSystem.Items.cs +++ /dev/null @@ -1,52 +0,0 @@ -using Content.Shared.Clothing.Components; -using Content.Shared.Inventory.Events; -using Content.Shared.NPC.Components; - -namespace Content.Shared.NPC.Systems; - -public partial class NpcFactionSystem : EntitySystem -{ - public void InitializeItems() - { - // SubscribeLocalEvent(OnItemPurchased); - - SubscribeLocalEvent(OnClothingEquipped); - SubscribeLocalEvent(OnClothingUnequipped); - } - - /// - /// If we bought something we probably don't want it to start biting us after it's automatically placed in our hands. - /// If you do, consider finding a better solution to grenade penguin CBT. - /// - // private void OnItemPurchased(EntityUid uid, NpcFactionMemberComponent component, ref ItemPurchasedEvent args) - // { - // component.ExceptionalFriendlies.Add(args.Purchaser); - // } - - private void OnClothingEquipped(EntityUid uid, ClothingAddFactionComponent component, GotEquippedEvent args) - { - if (!TryComp(uid, out var clothing)) - return; - - if (!clothing.Slots.HasFlag(args.SlotFlags)) - return; - - if (!TryComp(args.Equipee, out var factionComponent)) - return; - - if (factionComponent.Factions.Contains(component.Faction)) - return; - - component.IsActive = true; - AddFaction(args.Equipee, component.Faction); - } - - private void OnClothingUnequipped(EntityUid uid, ClothingAddFactionComponent component, GotUnequippedEvent args) - { - if (!component.IsActive) - return; - - component.IsActive = false; - RemoveFaction(args.Equipee, component.Faction); - } -} diff --git a/Resources/Prototypes/Nyanotrasen/Entities/Clothing/Uniforms/jumpsuits.yml b/Resources/Prototypes/Nyanotrasen/Entities/Clothing/Uniforms/jumpsuits.yml index 11f6d32b5c..f45e854c2a 100644 --- a/Resources/Prototypes/Nyanotrasen/Entities/Clothing/Uniforms/jumpsuits.yml +++ b/Resources/Prototypes/Nyanotrasen/Entities/Clothing/Uniforms/jumpsuits.yml @@ -8,7 +8,7 @@ sprite: Nyanotrasen/Clothing/Uniforms/Jumpsuit/mailman.rsi - type: Clothing sprite: Nyanotrasen/Clothing/Uniforms/Jumpsuit/mailman.rsi -# - type: ClothingAddFaction +# - type: FactionClothing # faction: Mailman - type: entity @@ -21,7 +21,7 @@ sprite: Nyanotrasen/Clothing/Uniforms/Jumpskirt/mailman.rsi - type: Clothing sprite: Nyanotrasen/Clothing/Uniforms/Jumpskirt/mailman.rsi -# - type: ClothingAddFaction +# - type: FactionClothing # faction: Mailman - type: entity diff --git a/RobustToolbox b/RobustToolbox index a9aea7027f..860c9af2bf 160000 --- a/RobustToolbox +++ b/RobustToolbox @@ -1 +1 @@ -Subproject commit a9aea7027f1840c83bcaf1c973caf099745f9eed +Subproject commit 860c9af2bfbf1477b96519067ef5e62b2525d987