コード例 #1
0
        private SkillModel CreateSkillFromXML(XElement rootElement)
        {
            SkillModel skill = new SkillModel();

            // Get ID
            uint id = 0;

            if (!uint.TryParse(rootElement.Element("id").Value, out id))
            {
                throw new DeusException("Cannot read the id of the skill");
            }
            skill.Id = id;

            // Get Name
            skill.Name = rootElement.Element("name").Value;

            // Get Shape
            skill.IsCircle = rootElement.Element("shape").Value == "circle";

            // Get Cast time
            uint castTime = 0;

            if (!uint.TryParse(rootElement.Element("casttime").Value, out castTime))
            {
                throw new DeusException("Cannot read the cast time of the skill");
            }
            skill.CastTime = castTime;

            // Get Scope
            ushort scope = 0;

            if (!ushort.TryParse(rootElement.Element("scope").Value, out scope))
            {
                throw new DeusException("Cannot read the scope of the skill");
            }
            skill.MaxScope = scope;

            // Get Scope
            ushort radius = 0;

            if (!ushort.TryParse(rootElement.Element("radius").Value, out radius))
            {
                throw new DeusException("Cannot read the radius of the skill");
            }
            skill.Radius = radius;

            // Get Level
            ushort level = 0;

            if (!ushort.TryParse(rootElement.Element("level").Value, out level))
            {
                throw new DeusException("Cannot read the level of the skill");
            }
            skill.Level = level;

            // Get Mana cost
            ushort manaCost = 0;

            if (!ushort.TryParse(rootElement.Element("manacost").Value, out level))
            {
                throw new DeusException("Cannot read the manacost of the skill");
            }
            skill.ManaCost = manaCost;

            // Get Effects
            skill.Effects = new List <SkillEffect>();
            XElement rootEffect = rootElement.Element("effects");

            for (XElement effectElement = rootEffect.Element("effect"); effectElement != null; effectElement = effectElement.ElementsAfterSelf().FirstOrDefault(elem => elem.Name == "effect"))
            {
                skill.Effects.Add(CreateSkillEffectFromXML(effectElement));
            }

            ////////////////////////////////////////////////////////
            Console.WriteLine($"Skill loaded : {skill.ToString()}");
            return(skill);
        }