From 16a532137d9b1fefd1c5c6b0efde581721d8a88f Mon Sep 17 00:00:00 2001 From: Alex Evgrashin Date: Wed, 19 Jan 2022 01:18:22 +0300 Subject: [PATCH] Muzzle (#6194) Co-authored-by: mirrorcult --- Content.Client/Entry/IgnoredComponents.cs | 1 + Content.Server/Chat/Managers/ChatManager.cs | 16 ++--- .../Components/AddAccentClothingComponent.cs | 32 ++++++++++ .../EntitySystems/AddAccentClothingSystem.cs | 60 ++++++++++++++++++ .../Catalog/Fills/Lockers/wardrobe_job.yml | 10 +-- .../Entities/Clothing/Masks/masks.yml | 15 +++++ Resources/Prototypes/accents.yml | 7 ++ .../Mask/muzzle.rsi/equipped-MASK.png | Bin 0 -> 350 bytes .../Clothing/Mask/muzzle.rsi/icon.png | Bin 0 -> 166 bytes .../Clothing/Mask/muzzle.rsi/inhand-left.png | Bin 0 -> 221 bytes .../Clothing/Mask/muzzle.rsi/inhand-right.png | Bin 0 -> 216 bytes .../Clothing/Mask/muzzle.rsi/meta.json | 26 ++++++++ 12 files changed, 155 insertions(+), 12 deletions(-) create mode 100644 Content.Server/Speech/Components/AddAccentClothingComponent.cs create mode 100644 Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs create mode 100644 Resources/Textures/Clothing/Mask/muzzle.rsi/equipped-MASK.png create mode 100644 Resources/Textures/Clothing/Mask/muzzle.rsi/icon.png create mode 100644 Resources/Textures/Clothing/Mask/muzzle.rsi/inhand-left.png create mode 100644 Resources/Textures/Clothing/Mask/muzzle.rsi/inhand-right.png create mode 100644 Resources/Textures/Clothing/Mask/muzzle.rsi/meta.json diff --git a/Content.Client/Entry/IgnoredComponents.cs b/Content.Client/Entry/IgnoredComponents.cs index 2ee9e2f2e6..96669d2bb5 100644 --- a/Content.Client/Entry/IgnoredComponents.cs +++ b/Content.Client/Entry/IgnoredComponents.cs @@ -144,6 +144,7 @@ namespace Content.Client.Entry "MovedByPressure", "Spray", "Vapor", + "AddAccentClothing", "DamageOnHighSpeedImpact", "SolutionContainerManager", "RefillableSolution", diff --git a/Content.Server/Chat/Managers/ChatManager.cs b/Content.Server/Chat/Managers/ChatManager.cs index 299709bc48..09aeb75338 100644 --- a/Content.Server/Chat/Managers/ChatManager.cs +++ b/Content.Server/Chat/Managers/ChatManager.cs @@ -173,16 +173,16 @@ namespace Content.Server.Chat.Managers return; } + message = message.Trim(); + + message = SanitizeMessageCapital(source, message); + foreach (var handler in _chatTransformHandlers) { //TODO: rather return a bool and use a out var? message = handler(source, message); } - message = message.Trim(); - - message = SanitizeMessageCapital(source, message); - var listeners = EntitySystem.Get(); listeners.PingListeners(source, message); @@ -211,16 +211,16 @@ namespace Content.Server.Chat.Managers return; } + message = message.Trim(); + + message = SanitizeMessageCapital(source, message); + foreach (var handler in _chatTransformHandlers) { //TODO: rather return a bool and use a out var? message = handler(source, message); } - message = message.Trim(); - - message = SanitizeMessageCapital(source, message); - var listeners = EntitySystem.Get(); listeners.PingListeners(source, message); diff --git a/Content.Server/Speech/Components/AddAccentClothingComponent.cs b/Content.Server/Speech/Components/AddAccentClothingComponent.cs new file mode 100644 index 0000000000..280ee16273 --- /dev/null +++ b/Content.Server/Speech/Components/AddAccentClothingComponent.cs @@ -0,0 +1,32 @@ +using Robust.Shared.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; + +namespace Content.Server.Speech.Components; + +/// +/// Applies accent to user while they wear entity as a clothing. +/// +[RegisterComponent] +public class AddAccentClothingComponent : Component +{ + public override string Name => "AddAccentClothing"; + + /// + /// Component name for accent that will be applied. + /// + [DataField("accent", required: true)] + public string Accent = default!; + + /// + /// What to use. + /// Will be applied only with . + /// + [DataField("replacement", customTypeSerializer: typeof(PrototypeIdSerializer))] + public string? ReplacementPrototype; + + /// + /// Is that clothing is worn and affecting someones accent? + /// + public bool IsActive = false; +} diff --git a/Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs b/Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs new file mode 100644 index 0000000000..263752f82b --- /dev/null +++ b/Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs @@ -0,0 +1,60 @@ +using Content.Server.Clothing.Components; +using Content.Server.Speech.Components; +using Content.Shared.Inventory.Events; +using Robust.Shared.GameObjects; +using Robust.Shared.IoC; + +namespace Content.Server.Speech.EntitySystems; + +public class AddAccentClothingSystem : EntitySystem +{ + [Dependency] private readonly IComponentFactory _componentFactory = default!; + + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(OnGotEquipped); + SubscribeLocalEvent(OnGotUnequipped); + } + + private void OnGotEquipped(EntityUid uid, AddAccentClothingComponent component, GotEquippedEvent args) + { + if (!TryComp(uid, out ClothingComponent? clothing)) + return; + + // check if entity was actually used as clothing + // not just taken in pockets or something + var isCorrectSlot = clothing.SlotFlags.HasFlag(args.SlotFlags); + if (!isCorrectSlot) return; + + // does the user already has this accent? + var componentType = _componentFactory.GetRegistration(component.Accent).Type; + if (EntityManager.HasComponent(args.Equipee, componentType)) return; + + // add accent to the user + var accentComponent = (Component) _componentFactory.GetComponent(componentType); + accentComponent.Owner = args.Equipee; + EntityManager.AddComponent(args.Equipee, accentComponent); + + // snowflake case for replacement accent + if (accentComponent is ReplacementAccentComponent rep) + rep.Accent = component.ReplacementPrototype!; + + component.IsActive = true; + } + + private void OnGotUnequipped(EntityUid uid, AddAccentClothingComponent component, GotUnequippedEvent args) + { + if (!component.IsActive) + return; + + // try to remove accent + var componentType = _componentFactory.GetRegistration(component.Accent).Type; + if (EntityManager.HasComponent(args.Equipee, componentType)) + { + EntityManager.RemoveComponent(args.Equipee, componentType); + } + + component.IsActive = false; + } +} diff --git a/Resources/Prototypes/Catalog/Fills/Lockers/wardrobe_job.yml b/Resources/Prototypes/Catalog/Fills/Lockers/wardrobe_job.yml index 2691af310c..e517a4c8f0 100644 --- a/Resources/Prototypes/Catalog/Fills/Lockers/wardrobe_job.yml +++ b/Resources/Prototypes/Catalog/Fills/Lockers/wardrobe_job.yml @@ -12,6 +12,8 @@ amount: 2 - id: ClothingShoesColorBlack amount: 2 + - id: ClothingMaskMuzzle + amount: 1 #- type: entity # id: WardrobePajamaFilled @@ -75,8 +77,8 @@ prob: 0.5 - id: CrowbarRed #The jojoke - hit video game Half-Life prob: 0.1 - - + + - type: entity id: WardrobeBotanistFilled suffix: Filled @@ -139,7 +141,7 @@ amount: 1 - id: ClothingUniformJumpskirtChaplain amount: 1 - + - type: entity id: WardrobeSecurityFilled @@ -182,7 +184,7 @@ amount: 1 - id: ClothingUniformJumpskirtCargo amount: 1 - + # - type: entity # id: WardrobeAtmosphericsFilled diff --git a/Resources/Prototypes/Entities/Clothing/Masks/masks.yml b/Resources/Prototypes/Entities/Clothing/Masks/masks.yml index 9112452d8e..a932f5d072 100644 --- a/Resources/Prototypes/Entities/Clothing/Masks/masks.yml +++ b/Resources/Prototypes/Entities/Clothing/Masks/masks.yml @@ -72,3 +72,18 @@ sprite: Clothing/Mask/sterile.rsi - type: BreathMask - type: IngestionBlocker + +- type: entity + parent: ClothingMaskBase + id: ClothingMaskMuzzle + name: muzzle + description: To stop that awful noise. + components: + - type: Sprite + sprite: Clothing/Mask/muzzle.rsi + - type: Clothing + sprite: Clothing/Mask/muzzle.rsi + - type: IngestionBlocker + - type: AddAccentClothing + accent: ReplacementAccent + replacement: mumble diff --git a/Resources/Prototypes/accents.yml b/Resources/Prototypes/accents.yml index 9a95284724..decc7210b7 100644 --- a/Resources/Prototypes/accents.yml +++ b/Resources/Prototypes/accents.yml @@ -23,3 +23,10 @@ - Piep! - Chuu! - Eeee! + +- type: accent + id: mumble + words: + - Mmfph! + - Mmmf mrrfff! + - Mmmf mnnf! diff --git a/Resources/Textures/Clothing/Mask/muzzle.rsi/equipped-MASK.png b/Resources/Textures/Clothing/Mask/muzzle.rsi/equipped-MASK.png new file mode 100644 index 0000000000000000000000000000000000000000..117476873b213cc91de325a921b31c4611c534ec GIT binary patch literal 350 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7T#lEU{v*VaSW-L^Y)f~)?ovQ_J{Ec z0-E^*cC}QU)VQ!tm;FO#4cC0Pa)Sz!iZ3CXrpP#KHrisQc~an}g>&WnqY*~G{w;XB znT6rNUwSGK+N{an^LB{Ts5(YKm! literal 0 HcmV?d00001 diff --git a/Resources/Textures/Clothing/Mask/muzzle.rsi/icon.png b/Resources/Textures/Clothing/Mask/muzzle.rsi/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..9f1b19ecdf48a781f315a3aa9e7f929dce1b476b GIT binary patch literal 166 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=ffJTu&Frkcv5PCpq#RP~c$M?mPd4 z@z2F^s}w_5_)1m1IOiKs=E1_D*fPOVRXgK6mzAWL^**k1A{h^F2RA;l>H2rvL}kTq z-kxWy3@$86OrdYZZ{NJ~CMJJkbmM9d{?8kNR$FQ_Exf?}8EC|xIb7@N#09wAE?EIB OX7F_Nb6Mw<&;$St_c}`e literal 0 HcmV?d00001 diff --git a/Resources/Textures/Clothing/Mask/muzzle.rsi/inhand-left.png b/Resources/Textures/Clothing/Mask/muzzle.rsi/inhand-left.png new file mode 100644 index 0000000000000000000000000000000000000000..99abbac3a729544a522f3efd0a0e581180fb701f GIT binary patch literal 221 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=OFUg1Ln`LHy=BOE$bg6S0{-sf5_el6IbX zbI-2Mnz!ubryqNlE-S9}e9WS9QoGUm_5Q5&mwz7-*&-SHXW?P}d%T6OK2%?=pIQ$# zieba{i`C87Za?&wtn4nR@P1MHL3j2Cap4Ive{>J7xZL~K*i2FVKFdSKdj;&vUb`>+ S`)2E8kVa2eKbLh*2~7ZN{$Wx8 literal 0 HcmV?d00001 diff --git a/Resources/Textures/Clothing/Mask/muzzle.rsi/inhand-right.png b/Resources/Textures/Clothing/Mask/muzzle.rsi/inhand-right.png new file mode 100644 index 0000000000000000000000000000000000000000..a3c20a67a48046856d19cf933c08db0d8ea69186 GIT binary patch literal 216 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=^F3W0Ln`LHy=BOC*no%i!j><7 z`~J@e-a7ff4$lKeE}W{%Kb7<`b&Bf6ZHz$G3~Pf<{k|?)_2o(JJkbuNo3r>!|E-pb zb7%ivTYtrMQ&x57^IH#DS{5_U