예제 #1
0
 public void Load(XElement doableElement)
 {
     Unlocked = XMLUtils.GetBool(doableElement, "Unlocked");
 }
예제 #2
0
        /// <summary>
        /// Saves the forest to an XML file.
        /// </summary>
        public void Save(string filename = null)
        {
            Console.WriteLine("Saving...");
            XElement element = new XElement("Forest");

            // Saves values
            XElement valuesElement = XMLUtils.CreateElement(element, "Values");

            foreach (KeyValuePair <string, double> entry in Values)
            {
                if (entry.Value != 0)
                {
                    XMLUtils.CreateElement(valuesElement, entry.Key, entry.Value);
                }
            }
            // Saves soft values
            foreach (KeyValuePair <string, double> entry in SoftValues)
            {
                if (entry.Value != 0)
                {
                    XMLUtils.CreateElement(valuesElement, entry.Key, entry.Value);
                }
            }

            // Saves skills
            XElement skillsElement = XMLUtils.CreateElement(element, "skills");

            foreach (string skill in Statics.skills)
            {
                XMLUtils.CreateElement(skillsElement, skill, Xp[skill] + ":" + TalentPoints[skill]);
            }

            // Saves growths
            XElement growthsElement = XMLUtils.CreateElement(element, "Growths");

            foreach (Entity g in Entities.Values)
            {
                XElement growthElement = XMLUtils.CreateElement(growthsElement, g.Name);
                g.Save(growthElement);
            }

            // Saves doables
            XElement doablesElement = XMLUtils.CreateElement(element, "Doables");

            foreach (Doable d in Doables.Values)
            {
                XElement doableElement = XMLUtils.CreateElement(doablesElement, d.Name);
                d.Save(doableElement);
            }

            XElement modifiersElement = XMLUtils.CreateElement(element, "Modifiers");

            foreach (Modifier m in Modifiers.Values)
            {
                XElement modifierElement = XMLUtils.CreateElement(modifiersElement, m.Name);
                m.Save(modifierElement);
            }

            XMLUtils.CreateElement(element, "Path", CurPath.Name);
            XMLUtils.CreateElement(element, "PathBoss", CurBoss);
            XMLUtils.CreateElement(element, "Count", Count);
            XMLUtils.CreateElement(element, "OfflineTicks", OfflineTicks);
            element.CreateElement("Hp", Hp);
            element.CreateElement("Mana", Mana);
            element.CreateElement("FightingStyle", FightingStyle);
            element.CreateElement("LifeCount", LifeCount);

            System.IO.Directory.CreateDirectory("saves");
            XDocument xd = new XDocument();

            xd.Add(element);
            if (filename == null)
            {
                if (System.IO.File.Exists("saves/save.xml"))
                {
                    for (int loop = 10; loop > 2; loop--)
                    {
                        if (System.IO.File.Exists("saves/save" + (loop - 1) + ".xml"))
                        {
                            System.IO.File.Copy("saves/save" + (loop - 1) + ".xml", "saves/save" + loop + ".xml", true);
                        }
                    }
                    System.IO.File.Copy("saves/save.xml", "saves/save2.xml", true);
                }
                xd.Save("saves/save.xml");
            }
            else
            {
                xd.Save("saves/" + filename + ".xml");
            }
        }
예제 #3
0
 public void Save(XElement doableElement)
 {
     XMLUtils.CreateElement(doableElement, "Unlocked", Unlocked);
 }
예제 #4
0
        public void Load(string filename = null)
        {
            Console.WriteLine("Loading...");
            XDocument xd = null;

            if (filename == null)
            {
                xd = XDocument.Load(@"saves/save.xml");
            }
            else
            {
                xd = XDocument.Load(@"saves/" + filename + ".xml");
            }
            XElement element = xd.Element("Forest");

            // Loads values and soft values
            XElement valuesElement = XMLUtils.GetElement(element, "Values");

            foreach (XElement valueElement in valuesElement.Elements())
            {
                string name = XMLUtils.GetName(valueElement);
                if (name.StartsWith("sv")) //Soft value
                {
                    SoftValues[name] = double.Parse(valueElement.Value, System.Globalization.NumberFormatInfo.InvariantInfo);
                }
                else
                {
                    Values[XMLUtils.GetName(valueElement)] = double.Parse(valueElement.Value, System.Globalization.NumberFormatInfo.InvariantInfo);
                }
            }

            // Loads skills
            XElement skillsElement = XMLUtils.GetElement(element, "skills");

            foreach (string skill in Statics.skills)
            {
                if (XMLUtils.HasChild(skillsElement, skill))
                {
                    string skillValue = skillsElement.GetString(skill);
                    if (skillValue.Contains(":"))
                    {
                        Xp[skill]           = double.Parse(skillValue.Split(':')[0]);
                        TalentPoints[skill] = int.Parse(skillValue.Split(':')[1]);
                    }
                    else
                    {
                        Xp[skill] = double.Parse(skillValue);
                    }
                }
            }

            // Loads growths
            XElement growthsElement = XMLUtils.GetElement(element, "Growths");

            foreach (Entity g in Entities.Values)
            {
                XElement growthElement = XMLUtils.GetElement(growthsElement, g.Name);
                if (growthElement != null)
                {
                    g.Load(growthElement);
                }
            }

            // Loads doables
            XElement doablesElement = XMLUtils.GetElement(element, "Doables");

            foreach (Doable d in Doables.Values)
            {
                XElement doableElement = XMLUtils.GetElement(doablesElement, d.Name);
                if (doableElement != null)
                {
                    d.Load(doableElement);
                }
            }

            // Loads modifiers TODO: if anything needs modifiers to stay past loads, do something about it then
            Modifiers.Clear();
            XElement modifiersElement = XMLUtils.GetElement(element, "Modifiers");

            foreach (XElement modifierElement in modifiersElement.Elements())
            {
                Modifier m = new Modifier(XMLUtils.GetName(modifierElement));
                m.Load(modifierElement);
                Modifiers[m.Name] = m;
            }

            string path = element.GetString("Path");

            CurBoss = element.GetInt("PathBoss");
            foreach (Path p in Path.paths)
            {
                if (p.Name == path)
                {
                    CurPath = p;
                    Boss    = p.Bosses[CurBoss];
                    break;
                }
            }

            Count = element.GetInt("Count");
            Hp    = element.GetDouble("Hp");
            if (element.HasChild("Mana"))
            {
                Mana = element.GetDouble("Mana");
            }
            OfflineTicks = element.GetInt("OfflineTicks");
            if (element.HasChild("FightingStyle"))
            {
                FightingStyle = element.GetString("FightingStyle");
            }
            if (element.HasChild("LifeCount"))
            {
                LifeCount = element.GetInt("LifeCount");
            }
        }