Esempio n. 1
0
        private Build DecodeTemplateInner(string template)
        {
            this.logger.LogInformation("Attempting to decode template");
            var buildMetadata = ParseEncodedTemplate(template);

            this.logger.LogInformation("Decoded template. Beginning parsing");
            if (buildMetadata.VersionNumber != 0)
            {
                this.logger.LogError($"Expected version number to be 0 but found {buildMetadata.VersionNumber}");
                throw new InvalidOperationException($"Failed to parse template");
            }

            var build = new Build()
            {
                BuildMetadata = buildMetadata,
                Skills        = new()
            };

            if (Profession.TryParse(buildMetadata.PrimaryProfessionId, out var primaryProfession) is false)
            {
                this.logger.LogError($"Failed to parse profession with id {buildMetadata.PrimaryProfessionId}");
                throw new InvalidOperationException($"Failed to parse template");
            }

            build.Primary = primaryProfession;
            if (Profession.TryParse(buildMetadata.SecondaryProfessionId, out var secondaryProfession) is false)
            {
                this.logger.LogError($"Failed to parse profession with id {buildMetadata.SecondaryProfessionId}");
                throw new InvalidOperationException($"Failed to parse template");
            }

            build.Secondary = secondaryProfession;
            for (int i = 0; i < buildMetadata.AttributeCount; i++)
            {
                if (Daybreak.Models.Builds.Attribute.TryParse(buildMetadata.AttributesIds[i], out var attribute) is false)
                {
                    this.logger.LogError($"Failed to parse attribute with id {buildMetadata.AttributesIds[i]}");
                    throw new InvalidOperationException($"Failed to parse template");
                }

                build.Attributes.Add(new AttributeEntry {
                    Attribute = attribute, Points = buildMetadata.AttributePoints[i]
                });
            }

            for (int i = 0; i < 8; i++)
            {
                if (Skill.TryParse(buildMetadata.SkillIds[i], out var skill) is false)
                {
                    this.logger.LogError($"Failed to parse skill with id {buildMetadata.SkillIds[i]}");
                    throw new InvalidOperationException($"Failed to parse template");
                }

                build.Skills.Add(skill);
            }

            return(build);
        }