From 5bf8bedffb3e231de89019af2d3ba17fc61f0288 Mon Sep 17 00:00:00 2001 From: Alkheemist Date: Fri, 3 Jan 2025 10:04:04 +1100 Subject: [PATCH 1/6] Add alt verb to toggle accents from clothing --- .../Components/AddAccentClothingComponent.cs | 5 ++ .../EntitySystems/AddAccentClothingSystem.cs | 57 ++++++++++++++++++- Resources/Locale/en-US/_NF/accent/accents.ftl | 5 +- 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/Content.Server/Speech/Components/AddAccentClothingComponent.cs b/Content.Server/Speech/Components/AddAccentClothingComponent.cs index 9d93b55368c..eb3679332e8 100644 --- a/Content.Server/Speech/Components/AddAccentClothingComponent.cs +++ b/Content.Server/Speech/Components/AddAccentClothingComponent.cs @@ -25,4 +25,9 @@ public sealed partial class AddAccentClothingComponent : Component /// Is that clothing is worn and affecting someones accent? /// public bool IsActive = false; + + /// + /// Who is currently wearing the item? + /// + public EntityUid Wearer; // Frontier } diff --git a/Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs b/Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs index 897cd061f42..d24fe3766f2 100644 --- a/Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs +++ b/Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs @@ -1,5 +1,6 @@ using Content.Server.Speech.Components; using Content.Shared.Clothing; +using Content.Shared.Verbs; // Frontier namespace Content.Server.Speech.EntitySystems; @@ -12,6 +13,7 @@ public override void Initialize() base.Initialize(); SubscribeLocalEvent(OnGotEquipped); SubscribeLocalEvent(OnGotUnequipped); + SubscribeLocalEvent>(OnGetAltVerbs); // Frontier } private void OnGotEquipped(EntityUid uid, AddAccentClothingComponent component, ref ClothingGotEquippedEvent args) @@ -22,7 +24,7 @@ private void OnGotEquipped(EntityUid uid, AddAccentClothingComponent component, return; // add accent to the user - var accentComponent = (Component) _componentFactory.GetComponent(componentType); + var accentComponent = (Component)_componentFactory.GetComponent(componentType); AddComp(args.Wearer, accentComponent); // snowflake case for replacement accent @@ -30,10 +32,12 @@ private void OnGotEquipped(EntityUid uid, AddAccentClothingComponent component, rep.Accent = component.ReplacementPrototype!; component.IsActive = true; + component.Wearer = args.Wearer; } private void OnGotUnequipped(EntityUid uid, AddAccentClothingComponent component, ref ClothingGotUnequippedEvent args) { + component.Wearer = new EntityUid(0); // null out the component wearer entry to prevent alt verb interactions when no longer worn. Frontier if (!component.IsActive) return; @@ -46,4 +50,55 @@ private void OnGotUnequipped(EntityUid uid, AddAccentClothingComponent component component.IsActive = false; } + + // Frontier Start + /// + /// Adds an alt verb allowing for the accent to be toggled easily. + /// + private void OnGetAltVerbs(EntityUid uid, AddAccentClothingComponent component, GetVerbsEvent args) + { + if (!args.CanInteract || args.User != component.Wearer) //only the wearer can toggle the effect + return; + + AlternativeVerb verb = new() + { + Text = Loc.GetString("accent-clothing-component-toggle"), + Act = () => ToggleAccent(uid, component) + }; + args.Verbs.Add(verb); + } + + private void ToggleAccent(EntityUid uid, AddAccentClothingComponent component) + { + if (component.IsActive) + { + // try to remove the accent if it's enabled + var componentType = _componentFactory.GetRegistration(component.Accent).Type; + if (EntityManager.HasComponent(component.Wearer, componentType)) + { + EntityManager.RemoveComponent(component.Wearer, componentType); + } + component.IsActive = false; + // we don't wipe out wearer in this case + } + else + { + // try to add the accent as if we are equipping this item again + // does the user already has this accent? + var componentType = _componentFactory.GetRegistration(component.Accent).Type; + if (HasComp(component.Wearer, componentType)) + return; + + // add accent to the user + var accentComponent = (Component)_componentFactory.GetComponent(componentType); + AddComp(component.Wearer, accentComponent); + + // snowflake case for replacement accent + if (accentComponent is ReplacementAccentComponent rep) + rep.Accent = component.ReplacementPrototype!; + + component.IsActive = true; + } + } + // Frontier End } diff --git a/Resources/Locale/en-US/_NF/accent/accents.ftl b/Resources/Locale/en-US/_NF/accent/accents.ftl index 49941b4141a..8383381cc5a 100644 --- a/Resources/Locale/en-US/_NF/accent/accents.ftl +++ b/Resources/Locale/en-US/_NF/accent/accents.ftl @@ -31,4 +31,7 @@ accent-words-fox-2 = Yap! accent-words-fox-3 = Ruff! accent-words-fox-4 = Wraaah! accent-words-fox-5 = Aaaaagh! -accent-words-fox-6 = Screeee! \ No newline at end of file +accent-words-fox-6 = Screeee! + +# Accent Toggle +accent-clothing-component-toggle = Toggle Accent From 39b12bdd899371dd64a89357279d799dbafb6e5a Mon Sep 17 00:00:00 2001 From: Alkheemist Date: Fri, 3 Jan 2025 11:59:46 +1100 Subject: [PATCH 2/6] Update Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs Co-authored-by: Dvir <39403717+dvir001@users.noreply.github.com> --- Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs b/Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs index d24fe3766f2..eb64b77c00e 100644 --- a/Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs +++ b/Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs @@ -24,7 +24,7 @@ private void OnGotEquipped(EntityUid uid, AddAccentClothingComponent component, return; // add accent to the user - var accentComponent = (Component)_componentFactory.GetComponent(componentType); + var accentComponent = (Component) _componentFactory.GetComponent(componentType); AddComp(args.Wearer, accentComponent); // snowflake case for replacement accent From 0c075b03918d88b905c225d776f39d92c9e54d0b Mon Sep 17 00:00:00 2001 From: Alkheemist Date: Fri, 3 Jan 2025 11:59:53 +1100 Subject: [PATCH 3/6] Update Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs Co-authored-by: Dvir <39403717+dvir001@users.noreply.github.com> --- Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs b/Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs index eb64b77c00e..923162c4abf 100644 --- a/Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs +++ b/Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs @@ -32,7 +32,7 @@ private void OnGotEquipped(EntityUid uid, AddAccentClothingComponent component, rep.Accent = component.ReplacementPrototype!; component.IsActive = true; - component.Wearer = args.Wearer; + component.Wearer = args.Wearer; // Frontier } private void OnGotUnequipped(EntityUid uid, AddAccentClothingComponent component, ref ClothingGotUnequippedEvent args) From 4d9ffcd3336566d1b2168e69bc36cf4b79483c7f Mon Sep 17 00:00:00 2001 From: Alkheemist Date: Thu, 9 Jan 2025 13:41:51 +1100 Subject: [PATCH 4/6] Add toggling accents to AccentPickupSystem, and also fixed accent pickup system to trigger correctly --- .../Components/AddAccentPickupComponent.cs | 10 +++- .../EntitySystems/AddAccentPickupSystem.cs | 59 ++++++++++++++++++- .../EntitySystems/SharedHandsSystem.Pickup.cs | 1 + Content.Shared/Item/PickupEvent.cs | 32 ++++++++++ 4 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 Content.Shared/Item/PickupEvent.cs diff --git a/Content.Server/Speech/Components/AddAccentPickupComponent.cs b/Content.Server/Speech/Components/AddAccentPickupComponent.cs index 020deca65b1..4dcd0454a51 100644 --- a/Content.Server/Speech/Components/AddAccentPickupComponent.cs +++ b/Content.Server/Speech/Components/AddAccentPickupComponent.cs @@ -4,7 +4,7 @@ namespace Content.Server._NF.Speech.Components; /// -/// Applies accent to user while they wear entity as a clothing. +/// Applies accent to user while they pick up entity. /// [RegisterComponent] public sealed partial class AddAccentPickupComponent : Component @@ -23,7 +23,13 @@ public sealed partial class AddAccentPickupComponent : Component public string? ReplacementPrototype; /// - /// Is that clothing is worn and affecting someones accent? + /// Is the entity held and affecting someones accent? /// public bool IsActive = false; + + /// + /// Who is currently holding the item? + /// + [DataField("holder")] + public EntityUid Holder = new(0); // Frontier } diff --git a/Content.Server/_NF/Speech/EntitySystems/AddAccentPickupSystem.cs b/Content.Server/_NF/Speech/EntitySystems/AddAccentPickupSystem.cs index fa71e1bfc3f..6cd6d5fc0d9 100644 --- a/Content.Server/_NF/Speech/EntitySystems/AddAccentPickupSystem.cs +++ b/Content.Server/_NF/Speech/EntitySystems/AddAccentPickupSystem.cs @@ -2,6 +2,7 @@ using Content.Server.Speech.Components; using Content.Shared.Interaction.Events; using Content.Shared.Item; +using Content.Shared.Verbs; // Frontier namespace Content.Server._NF.Speech.EntitySystems; @@ -12,11 +13,12 @@ public sealed class AddAccentPickupSystem : EntitySystem public override void Initialize() { base.Initialize(); - SubscribeLocalEvent(OnPickup); + SubscribeLocalEvent(OnPickup); SubscribeLocalEvent(OnDropped); + SubscribeLocalEvent>(OnGetAltVerbs); } - private void OnPickup(EntityUid uid, AddAccentPickupComponent component, ref GettingPickedUpAttemptEvent args) + private void OnPickup(EntityUid uid, AddAccentPickupComponent component, ref GettingPickedUpEvent args) { // does the user already has this accent? var componentType = _componentFactory.GetRegistration(component.Accent).Type; @@ -32,10 +34,12 @@ private void OnPickup(EntityUid uid, AddAccentPickupComponent component, ref Get rep.Accent = component.ReplacementPrototype!; component.IsActive = true; + component.Holder = args.User; // Frontier } private void OnDropped(EntityUid uid, AddAccentPickupComponent component, DroppedEvent args) { + component.Holder = new EntityUid(0); // null out the component wearer entry to prevent alt verb interactions when no longer worn. Frontier if (!component.IsActive) return; @@ -48,4 +52,55 @@ private void OnDropped(EntityUid uid, AddAccentPickupComponent component, Droppe component.IsActive = false; } + + // Frontier Start + /// + /// Adds an alt verb allowing for the accent to be toggled easily. + /// + private void OnGetAltVerbs(EntityUid uid, AddAccentPickupComponent component, GetVerbsEvent args) + { + if (!args.CanInteract || args.User != component.Holder) //only the holder can toggle the effect + return; + + AlternativeVerb verb = new() + { + Text = Loc.GetString("accent-clothing-component-toggle"), + Act = () => ToggleAccent(uid, component) + }; + args.Verbs.Add(verb); + } + + private void ToggleAccent(EntityUid uid, AddAccentPickupComponent component) + { + if (component.IsActive) + { + // try to remove the accent if it's enabled + var componentType = _componentFactory.GetRegistration(component.Accent).Type; + if (EntityManager.HasComponent(component.Holder, componentType)) + { + EntityManager.RemoveComponent(component.Holder, componentType); + } + component.IsActive = false; + // we don't wipe out Holder in this case + } + else + { + // try to add the accent as if we are equipping this item again + // does the user already has this accent? + var componentType = _componentFactory.GetRegistration(component.Accent).Type; + if (HasComp(component.Holder, componentType)) + return; + + // add accent to the user + var accentComponent = (Component)_componentFactory.GetComponent(componentType); + AddComp(component.Holder, accentComponent); + + // snowflake case for replacement accent + if (accentComponent is ReplacementAccentComponent rep) + rep.Accent = component.ReplacementPrototype!; + + component.IsActive = true; + } + } + // Frontier End } diff --git a/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Pickup.cs b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Pickup.cs index dea7081553e..d6a652052c2 100644 --- a/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Pickup.cs +++ b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Pickup.cs @@ -235,6 +235,7 @@ public virtual void DoPickup(EntityUid uid, Hand hand, EntityUid entity, HandsCo Log.Error($"Failed to insert {ToPrettyString(entity)} into users hand container when picking up. User: {ToPrettyString(uid)}. Hand: {hand.Name}."); return; } + RaiseLocalEvent(entity, new GettingPickedUpEvent(uid, entity), false); // Frontier if (log) { diff --git a/Content.Shared/Item/PickupEvent.cs b/Content.Shared/Item/PickupEvent.cs new file mode 100644 index 00000000000..7fd1fcfdc5f --- /dev/null +++ b/Content.Shared/Item/PickupEvent.cs @@ -0,0 +1,32 @@ +// Fronter Start +namespace Content.Shared.Item; + +/// +/// Raised on a *mob* when it picks something up +/// +public sealed class PickupEvent : BasePickupAttemptEvent +{ + public PickupEvent(EntityUid user, EntityUid item) : base(user, item) { } +} + +/// +/// Raised directed at entity being picked up when someone picks it up sucessfully +/// +public sealed class GettingPickedUpEvent : BasePickupEvent +{ + public GettingPickedUpEvent(EntityUid user, EntityUid item) : base(user, item) { } +} + +[Virtual] +public class BasePickupEvent : CancellableEntityEventArgs +{ + public readonly EntityUid User; + public readonly EntityUid Item; + + public BasePickupEvent(EntityUid user, EntityUid item) + { + User = user; + Item = item; + } +} +// Fronter End From a306c1a578622d45e47d5a5a92c91b495a6d2912 Mon Sep 17 00:00:00 2001 From: Alkheemist Date: Thu, 9 Jan 2025 13:45:13 +1100 Subject: [PATCH 5/6] Edit comments --- .../Speech/Components/AddAccentPickupComponent.cs | 2 +- .../_NF/Speech/EntitySystems/AddAccentPickupSystem.cs | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Content.Server/Speech/Components/AddAccentPickupComponent.cs b/Content.Server/Speech/Components/AddAccentPickupComponent.cs index 4dcd0454a51..df4a2cd7956 100644 --- a/Content.Server/Speech/Components/AddAccentPickupComponent.cs +++ b/Content.Server/Speech/Components/AddAccentPickupComponent.cs @@ -4,7 +4,7 @@ namespace Content.Server._NF.Speech.Components; /// -/// Applies accent to user while they pick up entity. +/// Applies accent to user while they hold the entity. /// [RegisterComponent] public sealed partial class AddAccentPickupComponent : Component diff --git a/Content.Server/_NF/Speech/EntitySystems/AddAccentPickupSystem.cs b/Content.Server/_NF/Speech/EntitySystems/AddAccentPickupSystem.cs index 6cd6d5fc0d9..384748df700 100644 --- a/Content.Server/_NF/Speech/EntitySystems/AddAccentPickupSystem.cs +++ b/Content.Server/_NF/Speech/EntitySystems/AddAccentPickupSystem.cs @@ -2,7 +2,7 @@ using Content.Server.Speech.Components; using Content.Shared.Interaction.Events; using Content.Shared.Item; -using Content.Shared.Verbs; // Frontier +using Content.Shared.Verbs; namespace Content.Server._NF.Speech.EntitySystems; @@ -34,12 +34,12 @@ private void OnPickup(EntityUid uid, AddAccentPickupComponent component, ref Get rep.Accent = component.ReplacementPrototype!; component.IsActive = true; - component.Holder = args.User; // Frontier + component.Holder = args.User; } private void OnDropped(EntityUid uid, AddAccentPickupComponent component, DroppedEvent args) { - component.Holder = new EntityUid(0); // null out the component wearer entry to prevent alt verb interactions when no longer worn. Frontier + component.Holder = new EntityUid(0); // null out the component wearer entry to prevent alt verb interactions when no longer worn. if (!component.IsActive) return; @@ -53,7 +53,6 @@ private void OnDropped(EntityUid uid, AddAccentPickupComponent component, Droppe component.IsActive = false; } - // Frontier Start /// /// Adds an alt verb allowing for the accent to be toggled easily. /// @@ -102,5 +101,4 @@ private void ToggleAccent(EntityUid uid, AddAccentPickupComponent component) component.IsActive = true; } } - // Frontier End } From 9b0643b19076316fbc268996787be4abfbe67ae0 Mon Sep 17 00:00:00 2001 From: Alkheemist Date: Wed, 15 Jan 2025 11:04:51 +1100 Subject: [PATCH 6/6] component datafield visibility edit --- Content.Server/Speech/Components/AddAccentPickupComponent.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Content.Server/Speech/Components/AddAccentPickupComponent.cs b/Content.Server/Speech/Components/AddAccentPickupComponent.cs index df4a2cd7956..93a52d6debb 100644 --- a/Content.Server/Speech/Components/AddAccentPickupComponent.cs +++ b/Content.Server/Speech/Components/AddAccentPickupComponent.cs @@ -30,6 +30,5 @@ public sealed partial class AddAccentPickupComponent : Component /// /// Who is currently holding the item? /// - [DataField("holder")] - public EntityUid Holder = new(0); // Frontier + public EntityUid Holder; // Frontier }