Exemplo n.º 1
0
        public void AddSpecialization(string name)
        {
            if (!CharacterObject.CanAffordSpecialization)
            {
                return;
            }


            int price = CharacterObject.Options.KarmaSpecialization;

            //If data file contains {4} this crashes but...
            string upgradetext =             //TODO WRONG
                                 $"{LanguageManager.Instance.GetString("String_ExpenseLearnSpecialization")} {DisplayName} ({name})";

            SkillSpecialization nspec = new SkillSpecialization(name, false);

            ExpenseLogEntry entry = new ExpenseLogEntry();

            entry.Create(price * -1, upgradetext, ExpenseType.Karma, DateTime.Now);
            entry.Undo = new ExpenseUndo().CreateKarma(KarmaExpenseType.AddSpecialization, nspec.InternalId);

            CharacterObject.ExpenseEntries.Add(entry);

            Specializations.Add(nspec);
            CharacterObject.Karma -= price;
        }
Exemplo n.º 2
0
        public void AddSpecialization(string name)
        {
            int price = IsKnowledgeSkill ? CharacterObject.Options.KarmaKnowledgeSpecialization : CharacterObject.Options.KarmaSpecialization;

            int     intExtraSpecCost      = 0;
            int     intTotalBaseRating    = TotalBaseRating;
            decimal decSpecCostMultiplier = 1.0m;

            foreach (Improvement objLoopImprovement in CharacterObject.Improvements)
            {
                if (objLoopImprovement.Minimum <= intTotalBaseRating &&
                    (string.IsNullOrEmpty(objLoopImprovement.Condition) || (objLoopImprovement.Condition == "career") == CharacterObject.Created || (objLoopImprovement.Condition == "create") != CharacterObject.Created) && objLoopImprovement.Enabled)
                {
                    if (objLoopImprovement.ImprovedName == SkillCategory)
                    {
                        if (objLoopImprovement.ImproveType == Improvement.ImprovementType.SkillCategorySpecializationKarmaCost)
                        {
                            intExtraSpecCost += objLoopImprovement.Value;
                        }
                        else if (objLoopImprovement.ImproveType == Improvement.ImprovementType.SkillCategorySpecializationKarmaCostMultiplier)
                        {
                            decSpecCostMultiplier *= objLoopImprovement.Value / 100.0m;
                        }
                    }
                }
            }
            if (decSpecCostMultiplier != 1.0m)
            {
                price = decimal.ToInt32(decimal.Ceiling(price * decSpecCostMultiplier));
            }
            price += intExtraSpecCost; //Spec

            if (price > CharacterObject.Karma)
            {
                return;
            }

            //If data file contains {4} this crashes but...
            string upgradetext = //TODO WRONG
                                 $"{LanguageManager.GetString("String_ExpenseLearnSpecialization")} {DisplayName} ({name})";

            SkillSpecialization nspec = new SkillSpecialization(name, false);

            ExpenseLogEntry entry = new ExpenseLogEntry(CharacterObject);

            entry.Create(price * -1, upgradetext, ExpenseType.Karma, DateTime.Now);
            entry.Undo = new ExpenseUndo().CreateKarma(KarmaExpenseType.AddSpecialization, nspec.InternalId);

            CharacterObject.ExpenseEntries.Add(entry);

            Specializations.Add(nspec);
            CharacterObject.Karma -= price;
        }
Exemplo n.º 3
0
 private void btAddSpec_Click(object sender, RoutedEventArgs e)
 {
     if (TbSpecName.Text != "")
     {
         using (var context = new Db1Entities())
         {
             var ss = new SkillSpecialization
             {
                 Name          = TbSpecName.Text,
                 Prerequisites = TbSpecPrereq.Text,
                 SkillId       = int.Parse(TbId.Text),
                 Default       = TbSpecDefault.Text,
                 Discription   = TbSpecDiscription.Text,
                 Modifiers     = TbSpecModifiers.Text,
                 IsOptional    = CbSpecIsOptional.IsChecked
             };
             context.SkillSpecialization.Add(ss);
             context.SaveChanges();
         }
         CleanControls();
     }
     PreparePage1();
 }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        public void AddSpecialization(string name)
        {
            if (!CharacterObject.CanAffordSpecialization) return;

            int price = CharacterObject.Options.KarmaSpecialization;

            //If data file contains {4} this crashes but...
            string upgradetext = //TODO WRONG
                $"{LanguageManager.Instance.GetString("String_ExpenseLearnSpecialization")} {DisplayName} ({name})";

            SkillSpecialization nspec = new SkillSpecialization(name, false);

            ExpenseLogEntry entry = new ExpenseLogEntry();
            entry.Create(price * -1, upgradetext, ExpenseType.Karma, DateTime.Now);
            entry.Undo = new ExpenseUndo().CreateKarma(KarmaExpenseType.AddSpecialization, nspec.InternalId);

            CharacterObject.ExpenseEntries.Add(entry);

            Specializations.Add(nspec);
            CharacterObject.Karma -= price;
        }
Exemplo n.º 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);
        }