Exemple #1
0
        public void SaveCharacterSlot(string username, ICharacterProfile profile, int slot)
        {
            if (slot < 0 || slot >= _maxCharacterSlots)
            {
                return;
            }
            if (profile is null)
            {
                DeleteCharacterSlot(username, slot);
                return;
            }

            if (!(profile is HumanoidCharacterProfile humanoid))
            {
                // TODO: Handle other ICharacterProfile implementations properly
                throw new NotImplementedException();
            }

            var appearance = (HumanoidCharacterAppearance)humanoid.CharacterAppearance;

            _prefsDb.SaveCharacterSlot(username, new HumanoidProfile
            {
                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
            });
        }
        public void SaveCharacterSlot(string username, ICharacterProfile profile, int slot)
        {
            if (slot < 0 || slot >= _maxCharacterSlots)
            {
                return;
            }
            if (profile is null)
            {
                DeleteCharacterSlot(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
            })
                );
            _prefsDb.SaveCharacterSlot(username, entity);
        }