From e194df9747b6e36fdc14e94d57977e24c8573802 Mon Sep 17 00:00:00 2001 From: Vera Aguilera Puerto Date: Thu, 30 Sep 2021 13:35:35 +0200 Subject: [PATCH] Fix GameTicker and StartingGear performing bad string checks. - This prevented people from spawning as clown, etc if they had set the skirt option. - Adds some custom type serializers to StartingGear for YAML linter support. --- .../GameTicking/GameTicker.Spawning.cs | 2 +- Content.Shared/Roles/StartingGearPrototype.cs | 18 ++++++++++-------- Resources/Changelog/Parts/clown.yml | 4 ++++ 3 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 Resources/Changelog/Parts/clown.yml diff --git a/Content.Server/GameTicking/GameTicker.Spawning.cs b/Content.Server/GameTicking/GameTicker.Spawning.cs index 5357bd6bfc..5d696d81ea 100644 --- a/Content.Server/GameTicking/GameTicker.Spawning.cs +++ b/Content.Server/GameTicking/GameTicker.Spawning.cs @@ -193,7 +193,7 @@ namespace Content.Server.GameTicking foreach (var slot in EquipmentSlotDefines.AllSlots) { var equipmentStr = startingGear.GetGear(slot, profile); - if (equipmentStr != string.Empty) + if (!string.IsNullOrEmpty(equipmentStr)) { var equipmentEntity = EntityManager.SpawnEntity(equipmentStr, entity.Transform.Coordinates); inventory.Equip(slot, equipmentEntity.GetComponent()); diff --git a/Content.Shared/Roles/StartingGearPrototype.cs b/Content.Shared/Roles/StartingGearPrototype.cs index 02bdf1331c..edd5f9669a 100644 --- a/Content.Shared/Roles/StartingGearPrototype.cs +++ b/Content.Shared/Roles/StartingGearPrototype.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using Content.Shared.Preferences; using Robust.Shared.Prototypes; using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; using Robust.Shared.ViewVariables; using static Content.Shared.Inventory.EquipmentSlotDefines; @@ -10,18 +11,19 @@ namespace Content.Shared.Roles [Prototype("startingGear")] public class StartingGearPrototype : IPrototype { + // TODO: Custom TypeSerializer for dictionary value prototype IDs [DataField("equipment")] private Dictionary _equipment = new(); /// /// if empty, there is no skirt override - instead the uniform provided in equipment is added. /// - [DataField("innerclothingskirt")] - private string _innerClothingSkirt = default!; + [DataField("innerclothingskirt", customTypeSerializer:typeof(PrototypeIdSerializer))] + private string _innerClothingSkirt = string.Empty; - [DataField("satchel")] + [DataField("satchel", customTypeSerializer:typeof(PrototypeIdSerializer))] private string _satchel = string.Empty; - [DataField("duffelbag")] + [DataField("duffelbag", customTypeSerializer:typeof(PrototypeIdSerializer))] private string _duffelbag = string.Empty; public IReadOnlyDictionary Inhand => _inHand; @@ -33,17 +35,17 @@ namespace Content.Shared.Roles [ViewVariables] [DataField("id", required: true)] - public string ID { get; } = default!; + public string ID { get; } = string.Empty; public string GetGear(Slots slot, HumanoidCharacterProfile? profile) { if (profile != null) { - if ((slot == Slots.INNERCLOTHING) && (profile.Clothing == ClothingPreference.Jumpskirt) && (_innerClothingSkirt != "")) + if (slot == Slots.INNERCLOTHING && profile.Clothing == ClothingPreference.Jumpskirt && !string.IsNullOrEmpty(_innerClothingSkirt)) return _innerClothingSkirt; - if ((slot == Slots.BACKPACK) && (profile.Backpack == BackpackPreference.Satchel) && (_satchel != "")) + if (slot == Slots.BACKPACK && profile.Backpack == BackpackPreference.Satchel && !string.IsNullOrEmpty(_satchel)) return _satchel; - if ((slot == Slots.BACKPACK) && (profile.Backpack == BackpackPreference.Duffelbag) && (_duffelbag != "")) + if (slot == Slots.BACKPACK && profile.Backpack == BackpackPreference.Duffelbag && !string.IsNullOrEmpty(_duffelbag)) return _duffelbag; } diff --git a/Resources/Changelog/Parts/clown.yml b/Resources/Changelog/Parts/clown.yml new file mode 100644 index 0000000000..233438013e --- /dev/null +++ b/Resources/Changelog/Parts/clown.yml @@ -0,0 +1,4 @@ +author: Zumorica +changes: + - type: Fix + message: Fix bug where you couldn't join as clown under certain circumstances.