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.
This commit is contained in:
Vera Aguilera Puerto
2021-09-30 13:35:35 +02:00
parent ac81b207d7
commit e194df9747
3 changed files with 15 additions and 9 deletions

View File

@@ -193,7 +193,7 @@ namespace Content.Server.GameTicking
foreach (var slot in EquipmentSlotDefines.AllSlots) foreach (var slot in EquipmentSlotDefines.AllSlots)
{ {
var equipmentStr = startingGear.GetGear(slot, profile); var equipmentStr = startingGear.GetGear(slot, profile);
if (equipmentStr != string.Empty) if (!string.IsNullOrEmpty(equipmentStr))
{ {
var equipmentEntity = EntityManager.SpawnEntity(equipmentStr, entity.Transform.Coordinates); var equipmentEntity = EntityManager.SpawnEntity(equipmentStr, entity.Transform.Coordinates);
inventory.Equip(slot, equipmentEntity.GetComponent<ItemComponent>()); inventory.Equip(slot, equipmentEntity.GetComponent<ItemComponent>());

View File

@@ -2,6 +2,7 @@ using System.Collections.Generic;
using Content.Shared.Preferences; using Content.Shared.Preferences;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
using static Content.Shared.Inventory.EquipmentSlotDefines; using static Content.Shared.Inventory.EquipmentSlotDefines;
@@ -10,18 +11,19 @@ namespace Content.Shared.Roles
[Prototype("startingGear")] [Prototype("startingGear")]
public class StartingGearPrototype : IPrototype public class StartingGearPrototype : IPrototype
{ {
// TODO: Custom TypeSerializer for dictionary value prototype IDs
[DataField("equipment")] private Dictionary<Slots, string> _equipment = new(); [DataField("equipment")] private Dictionary<Slots, string> _equipment = new();
/// <summary> /// <summary>
/// if empty, there is no skirt override - instead the uniform provided in equipment is added. /// if empty, there is no skirt override - instead the uniform provided in equipment is added.
/// </summary> /// </summary>
[DataField("innerclothingskirt")] [DataField("innerclothingskirt", customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
private string _innerClothingSkirt = default!; private string _innerClothingSkirt = string.Empty;
[DataField("satchel")] [DataField("satchel", customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
private string _satchel = string.Empty; private string _satchel = string.Empty;
[DataField("duffelbag")] [DataField("duffelbag", customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
private string _duffelbag = string.Empty; private string _duffelbag = string.Empty;
public IReadOnlyDictionary<string, string> Inhand => _inHand; public IReadOnlyDictionary<string, string> Inhand => _inHand;
@@ -33,17 +35,17 @@ namespace Content.Shared.Roles
[ViewVariables] [ViewVariables]
[DataField("id", required: true)] [DataField("id", required: true)]
public string ID { get; } = default!; public string ID { get; } = string.Empty;
public string GetGear(Slots slot, HumanoidCharacterProfile? profile) public string GetGear(Slots slot, HumanoidCharacterProfile? profile)
{ {
if (profile != null) 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; return _innerClothingSkirt;
if ((slot == Slots.BACKPACK) && (profile.Backpack == BackpackPreference.Satchel) && (_satchel != "")) if (slot == Slots.BACKPACK && profile.Backpack == BackpackPreference.Satchel && !string.IsNullOrEmpty(_satchel))
return _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; return _duffelbag;
} }

View File

@@ -0,0 +1,4 @@
author: Zumorica
changes:
- type: Fix
message: Fix bug where you couldn't join as clown under certain circumstances.