public async Task SaveCharacterSlotAsync(string username, ICharacterProfile profile, int slot)
        {
            if (slot < 0 || slot >= _maxCharacterSlots)
            {
                return;
            }

            await _prefsSemaphore.WaitAsync();

            try
            {
                if (profile is null)
                {
                    await DeleteCharacterSlotAsync(username, slot);

                    return;
                }

                if (!(profile is HumanoidCharacterProfile humanoid))
                {
                    // TODO: Handle other ICharacterProfile implementations properly
                    throw new NotImplementedException();
                }
                var appearance = (HumanoidCharacterAppearance)humanoid.CharacterAppearance;
                var entity     = new HumanoidProfile
                {
                    SlotName              = humanoid.Name,
                    CharacterName         = humanoid.Name,
                    Age                   = humanoid.Age,
                    Sex                   = humanoid.Sex.ToString(),
                    HairName              = appearance.HairStyleName,
                    HairColor             = appearance.HairColor.ToHex(),
                    FacialHairName        = appearance.FacialHairStyleName,
                    FacialHairColor       = appearance.FacialHairColor.ToHex(),
                    EyeColor              = appearance.EyeColor.ToHex(),
                    SkinColor             = appearance.SkinColor.ToHex(),
                    Slot                  = slot,
                    PreferenceUnavailable = (DbPreferenceUnavailableMode)humanoid.PreferenceUnavailable
                };
                entity.Jobs.AddRange(
                    humanoid.JobPriorities
                    .Where(j => j.Value != JobPriority.Never)
                    .Select(j => new Job {
                    JobName = j.Key, Priority = (DbJobPriority)j.Value
                })
                    );
                entity.Antags.AddRange(
                    humanoid.AntagPreferences
                    .Select(a => new Antag {
                    AntagName = a
                })
                    );
                await _prefsDb.SaveCharacterSlotAsync(username, entity);
            }
            finally
            {
                _prefsSemaphore.Release();
            }
        }
        private static HumanoidCharacterProfile ConvertProfiles(HumanoidProfile profile)
        {
            var jobs = profile.Jobs.ToDictionary(j => j.JobName, j => (JobPriority)j.Priority);

            return(new HumanoidCharacterProfile(
                       profile.CharacterName,
                       profile.Age,
                       profile.Sex == "Male" ? Male : Female,
                       new HumanoidCharacterAppearance
                       (
                           profile.HairName,
                           Color.FromHex(profile.HairColor),
                           profile.FacialHairName,
                           Color.FromHex(profile.FacialHairColor),
                           Color.FromHex(profile.EyeColor),
                           Color.FromHex(profile.SkinColor)
                       ),
                       jobs,
                       (PreferenceUnavailableMode)profile.PreferenceUnavailable
                       ));
        }