Exemplo n.º 1
0
        public ClassTemplate FromJson(JObject json)
        {
            ClassTemplate result = new ClassTemplate();

            result.LoadBase(json);

            AddBaseValueVector(GcConstants.Classes.BASE_VALUES, json, result, result.BasicValues);
            foreach (string baseV in result.BasicValues.Keys)
            {
                if (!Engine.GetPropertyManager().HasBaseValue(baseV))
                {
                    throw new MeException($"Class {result.Name} references unknown base value {baseV}.");
                }
            }

            foreach (BaseObject baseValue in Engine.GetPropertyManager().BaseValues.Values)
            {
                if (!result.BasicValues.ContainsKey(baseValue.Key))
                {
                    result.BasicValues.Add(baseValue.Key, 0);
                }
            }



            AddBaseValueVector(GcConstants.Classes.BASIC_ATTRIBUTES, json, result, result.Attributes);
            foreach (string baseV in result.Attributes.Keys)
            {
                if (!Engine.GetPropertyManager().HasAttribute(baseV))
                {
                    throw new MeException($"Class {result.Name} references unknown attribute {baseV}.");
                }
            }
            foreach (BaseObject attribute in Engine.GetPropertyManager().Attributes.Values)
            {
                if (!result.Attributes.ContainsKey(attribute.Key))
                {
                    result.Attributes.Add(attribute.Key, 0);
                }
            }

            JToken[] skills = JsonUtils.GetValueOrDefault <JToken[]>(json, GcConstants.Classes.SKILLS, null);
            if (skills != null)
            {
                foreach (JToken value in skills)
                {
                    SkillTemplate skill = SkillFromJson(value, result);
                    result.Skills.Add(skill.Key, skill);
                }
            }

            JToken        baseAttack = JsonUtils.ValidateJsonEntry(GcConstants.Classes.BASE_ATTACK, json, JTokenType.String, $"Class {result.Name} does not contain a {GcConstants.Classes.BASE_ATTACK} entry.");
            SkillTemplate baseSkill  = SkillFromJson(baseAttack, result);

            result.BaseAttack = baseSkill;

            JToken[] resources = JsonUtils.GetValueOrDefault <JToken[]>(json, GcConstants.Classes.RESOURCES, null);
            if (resources != null)
            {
                foreach (JToken value in resources)
                {
                    ResourceTemplate res = ResourceFromJson(value, result);
                    result.Resources.Add(res.Key, res);
                }
            }
            return(result);
        }