Beispiel #1
0
        //TODO CACHE INVALIDATE

        /// <summary>
        /// Load a skill from a data file describing said skill
        /// </summary>
        /// <param name="n">The XML node describing the skill</param>
        /// <param name="character">The character the skill belongs to</param>
        /// <returns></returns>
        public static Skill FromData(XmlNode n, Character character)
        {
            if (n == null)
            {
                return(null);
            }
            Skill s;

            if (n["exotic"]?.InnerText == "Yes")
            {
                //load exotic skill
                ExoticSkill s2 = new ExoticSkill(character, n);
                s = s2;
            }
            else
            {
                XmlDocument document = XmlManager.Instance.Load("skills.xml");
                XmlNode     knoNode  = null;
                string      category = n["category"]?.InnerText;
                if (string.IsNullOrEmpty(category))
                {
                    return(null);
                }
                bool knoSkill;
                if (SkillTypeCache == null || !SkillTypeCache.TryGetValue(category, out knoSkill))
                {
                    knoNode  = document.SelectSingleNode($"/chummer/categories/category[. = '{category}']");
                    knoSkill = knoNode?.Attributes?["type"]?.InnerText != "active";
                    if (SkillTypeCache != null)
                    {
                        SkillTypeCache[category] = knoSkill;
                    }
                }


                if (knoSkill)
                {
                    //TODO INIT SKILL
                    if (Debugger.IsAttached)
                    {
                        Debugger.Break();
                    }

                    s = new KnowledgeSkill(character);
                }
                else
                {
                    //TODO INIT SKILL

                    s = new Skill(character, n);
                }
                if (knoNode?.Attributes?["translate"] != null)
                {
                    s.DisplayCategory = knoNode.Attributes["translate"].InnerText;
                }
            }


            return(s);
        }
Beispiel #2
0
        //TODO CACHE INVALIDATE

        /// <summary>
        /// Load a skill from a data file describing said skill
        /// </summary>
        /// <param name="n">The XML node describing the skill</param>
        /// <param name="character">The character the skill belongs to</param>
        /// <returns></returns>
        public static Skill FromData(XmlNode n, Character character)
        {
            Skill s;

            if (n["exotic"] != null && n["exotic"].InnerText == "Yes")
            {
                //load exotic skill
                ExoticSkill s2 = new ExoticSkill(character, n);
                s = s2;
            }
            else
            {
                XmlDocument document = XmlManager.Instance.Load("skills.xml");
                XmlNode     knoNode  = null;
                string      category = n["category"].InnerText;            //if missing we have bigger problems, and a nullref is probably prefered
                bool        knoSkill;

                if (SkillTypeCache != null && SkillTypeCache.ContainsKey(category))
                {
                    knoSkill = SkillTypeCache[category];                     //Simple cache, no need to be sloppy
                }
                else
                {
                    knoNode  = document.SelectSingleNode($"/chummer/categories/category[. = '{category}']");
                    knoSkill = knoNode.Attributes["type"].InnerText != "active";
                    SkillTypeCache[category] = knoSkill;
                }


                if (knoSkill)
                {
                    //TODO INIT SKILL
                    if (Debugger.IsAttached)
                    {
                        Debugger.Break();
                    }

                    KnowledgeSkill s2 = new KnowledgeSkill(character);

                    s = s2;
                }
                else
                {
                    Skill s2 = new Skill(character, n);
                    //TODO INIT SKILL

                    s = s2;
                }
                if (knoNode != null)
                {
                    if (knoNode.Attributes["translate"] != null)
                    {
                        s.DisplayCategory = knoNode.Attributes["translate"].InnerText;
                    }
                }
            }


            return(s);
        }
Beispiel #3
0
        public static int CompareSkills(Skill rhs, Skill lhs)
        {
            ExoticSkill rhsExoticSkill = (rhs.IsExoticSkill ? rhs : null) as ExoticSkill;
            ExoticSkill lhsExoticSkill = (lhs.IsExoticSkill ? lhs : null) as ExoticSkill;

            if (rhsExoticSkill != null)
            {
                if (lhsExoticSkill != null)
                {
                    return(string.Compare(rhsExoticSkill.Specific ?? string.Empty, lhsExoticSkill.Specific ?? string.Empty, StringComparison.Ordinal));
                }
                else
                {
                    return(1);
                }
            }
            else if (lhsExoticSkill != null)
            {
                return(-1);
            }

            return(string.Compare(rhs.DisplayName, lhs.DisplayName, StringComparison.Ordinal));
        }
        private void btnExotic_Click(object sender, EventArgs e)
        {
            if (_character.Options.KarmaNewActiveSkill > _character.Karma && _character.Created)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_NotEnoughKarma"));
                return;
            }

            XmlDocument document = XmlManager.Instance.Load("skills.xml");
            frmSelectExoticSkill frmPickExoticSkill = new frmSelectExoticSkill();
            frmPickExoticSkill.ShowDialog(this);

            if (frmPickExoticSkill.DialogResult == DialogResult.Cancel)
                return;

            XmlNode node =
                document.SelectSingleNode("/chummer/skills/skill[name = \"" + frmPickExoticSkill.SelectedExoticSkill + "\"]");

            ExoticSkill skill = new ExoticSkill(ObjCharacter, node);
            skill.Specific = frmPickExoticSkill.SelectedExoticSkillSpecialisation;
            skill.Upgrade();
            ObjCharacter.SkillsSection.Skills.Add(skill);
        }
Beispiel #5
0
        /// <summary>
        /// Loads skill saved in legacy format
        /// </summary>
        /// <param name="character"></param>
        /// <param name="n"></param>
        /// <returns></returns>
        public static Skill LegacyLoad(Character character, XmlNode n)
        {
            Guid  suid;
            Skill skill;

            n.TryGetField("id", Guid.TryParse, out suid, Guid.NewGuid());

            int baseRating  = int.Parse(n["base"].InnerText);
            int fullRating  = int.Parse(n["rating"].InnerText);
            int karmaRating = fullRating - baseRating;              //Not reading karma directly as career only increases rating

            if (n.TryCheckValue("knowledge", "True"))
            {
                Skills.KnowledgeSkill kno = new KnowledgeSkill(character);
                kno.WriteableName = n["name"].InnerText;
                kno.Base          = baseRating;
                kno.Karma         = karmaRating;

                kno.Type = n["skillcategory"].InnerText;

                skill = kno;
            }
            else
            {
                XmlNode data =
                    XmlManager.Instance.Load("skills.xml").SelectSingleNode($"/chummer/skills/skill[id = '{suid}']");

                //Some stuff apparently have a guid of 0000-000... (only exotic?)
                if (data == null)
                {
                    data = XmlManager.Instance.Load("skills.xml")
                           .SelectSingleNode($"/chummer/skills/skill[name = '{n["name"].InnerText}']");
                }


                skill        = Skill.FromData(data, character);
                skill._base  = baseRating;
                skill._karma = karmaRating;

                ExoticSkill exoticSkill = skill as ExoticSkill;
                if (exoticSkill != null)
                {
                    string name = n.SelectSingleNode("skillspecializations/skillspecialization/name")?.InnerText ?? "";
                    //don't need to do more load then.

                    exoticSkill.Specific = name;
                    return(skill);
                }

                skill._buyWithKarma = n.TryCheckValue("buywithkarma", "True");
            }

            var v = from XmlNode node
                    in n.SelectNodes("skillspecializations/skillspecialization")
                    select SkillSpecialization.Load(node);

            var q = v.ToList();

            if (q.Count != 0)
            {
                skill.Specializations.AddRange(q);
            }

            return(skill);
        }
Beispiel #6
0
        /// <summary>
        /// Load a skill from a xml node from a saved .chum5 file
        /// </summary>
        /// <param name="n">The XML node describing the skill</param>
        /// <param name="character">The character this skill belongs to</param>
        /// <returns></returns>
        public static Skill Load(Character character, XmlNode n)
        {
            if (n["suid"] == null)
            {
                return(null);
            }

            Guid suid;

            if (!Guid.TryParse(n["suid"].InnerText, out suid))
            {
                return(null);
            }
            Skill skill;

            if (suid != Guid.Empty)
            {
                XmlDocument skills = XmlManager.Instance.Load("skills.xml");
                XmlNode     node   = skills.SelectSingleNode($"/chummer/skills/skill[id = '{n["suid"].InnerText}']");

                if (node == null)
                {
                    return(null);
                }

                if (node["exotic"]?.InnerText == "Yes")
                {
                    ExoticSkill exotic = new ExoticSkill(character, node);
                    exotic.Load(n);
                    skill = exotic;
                }
                else
                {
                    skill = new Skill(character, node);
                }
            }
            else             //This is ugly but i'm not sure how to make it pretty
            {
                if (n["forced"] != null)
                {
                    skill = new KnowledgeSkill(character, n["name"].InnerText);
                }
                else
                {
                    KnowledgeSkill knoSkill = new KnowledgeSkill(character);
                    knoSkill.Load(n);
                    skill = knoSkill;
                }
            }

            XmlElement element = n["guid"];

            if (element != null)
            {
                skill.Id = Guid.Parse(element.InnerText);
            }

            n.TryGetField("karma", out skill._karma);
            n.TryGetField("base", out skill._base);
            n.TryGetField("buywithkarma", out skill._buyWithKarma);
            n.TryGetField("notes", out skill._strNotes);

            foreach (XmlNode spec in n.SelectNodes("specs/spec"))
            {
                skill.Specializations.Add(SkillSpecialization.Load(spec));
            }

            return(skill);
        }
Beispiel #7
0
        /// <summary>
        /// Load a skill from a xml node from a saved .chum5 file
        /// </summary>
        /// <param name="n">The XML node describing the skill</param>
        /// <param name="character">The character this skill belongs to</param>
        /// <returns></returns>
        public static Skill Load(Character character, XmlNode n)
        {
            if (n?["suid"] == null)
            {
                return(null);
            }

            Guid suid;

            if (!Guid.TryParse(n["suid"].InnerText, out suid))
            {
                return(null);
            }
            XmlDocument skills = XmlManager.Instance.Load("skills.xml");
            Skill       skill  = null;
            bool        blnIsKnowledgeSkill = false;

            if (n.TryGetBoolFieldQuickly("isknowledge", ref blnIsKnowledgeSkill) && blnIsKnowledgeSkill)
            {
                KnowledgeSkill knoSkill = new KnowledgeSkill(character);
                knoSkill.Load(n);
                skill = knoSkill;
            }
            else if (suid != Guid.Empty)
            {
                XmlNode node = skills.SelectSingleNode($"/chummer/skills/skill[id = '{n["suid"].InnerText}']");

                if (node == null)
                {
                    return(null);
                }

                if (node["exotic"]?.InnerText == "Yes")
                {
                    ExoticSkill exotic = new ExoticSkill(character, node);
                    exotic.Load(n);
                    skill = exotic;
                }
                else
                {
                    skill = new Skill(character, node);
                }
            }

            /*
             * else //This is ugly but i'm not sure how to make it pretty
             * {
             *  if (n["forced"] != null && n["name"] != null)
             *  {
             *      skill = new KnowledgeSkill(character, n["name"].InnerText);
             *  }
             *  else
             *  {
             *      KnowledgeSkill knoSkill = new KnowledgeSkill(character);
             *      knoSkill.Load(n);
             *      skill = knoSkill;
             *  }
             * }
             */

            if (skill == null)
            {
                skill = new KnowledgeSkill(character, n["name"]?.InnerText ?? string.Empty);
            }
            XmlElement element = n["guid"];

            if (element != null)
            {
                skill.Id = Guid.Parse(element.InnerText);
            }

            n.TryGetInt32FieldQuickly("karma", ref skill._karma);
            n.TryGetInt32FieldQuickly("base", ref skill._base);
            n.TryGetBoolFieldQuickly("buywithkarma", ref skill._buyWithKarma);
            n.TryGetStringFieldQuickly("notes", ref skill._strNotes);

            foreach (XmlNode spec in n.SelectNodes("specs/spec"))
            {
                skill.Specializations.Add(SkillSpecialization.Load(spec));
            }
            XmlNode objCategoryNode = skills.SelectSingleNode($"/chummer/categories/category[. = '{skill.SkillCategory}']");

            skill.DisplayCategory = objCategoryNode?.Attributes?["translate"]?.InnerText ?? skill.SkillCategory;

            return(skill);
        }