Exemple #1
0
        private void Initialize()
        {
            KingdomConfigs.Clear();
            // Load mod's config information, this defines what to look for when loading the mods other xmls
            if (File.Exists(configXDocPath))
            {
                try
                {
                    XDocument doc = XDocument.Load(configXDocPath);
                    if (doc.Root != null)
                    {
                        IEnumerable <XElement> kingdomConfigs = doc.Root.Elements();

                        if (kingdomConfigs.Any())
                        {
                            IEnumerator <XElement> elementrator = kingdomConfigs.GetEnumerator();
                            while (elementrator.MoveNext())
                            {
                                XElement current = elementrator.Current;
                                if (current?.Element("KingdomId") != null &&
                                    current.Element("LocationsFileName") != null &&
                                    current.Element("KingdomLordCollection") != null &&
                                    current.Element("KingdomLord") != null &&
                                    current.Element("kingdomLeaderId") != null)
                                {
                                    KingdomConfig kingdomConfig = new KingdomConfig(
                                        current.Element("KingdomId")?.Value,
                                        current.Element("LocationsFileName")?.Value,
                                        current.Element("KingdomLordCollection")?.Value,
                                        current.Element("KingdomLord")?.Value,
                                        current.Element("kingdomLeaderId")?.Value);
                                    KingdomConfigs.Add(kingdomConfig);
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    InformationManager.DisplayMessage(new InformationMessage("KingdomTemplate: Config.xml Data: " + e.Message, Color.FromUint(4278255360U)));
                }
            }
            else
            {
                InformationManager.DisplayMessage(new InformationMessage("KingdomTemplate: Config.xml not found", Color.FromUint(4278255360U)));
            }

            if (KingdomConfigs.Any())
            {
                KingdomConfigs.ForEach(kC =>
                {
                    // if (File.Exists(locationsxDocPath))
                    // {
                    //     try
                    //     {
                    //         XDocument doc = XDocument.Load(locationsxDocPath);
                    //         if (doc.Root != null)
                    //         {
                    //             IEnumerable<XElement> headhunters = doc.Root.Elements("Headhunters").Elements("Headhunter");
                    //             IEnumerable<XElement> elements = headhunters.ToList();
                    //
                    //             if (elements.Any())
                    //             {
                    //                 IEnumerator<XElement> elementrator = elements.GetEnumerator();
                    //                 while (elementrator.MoveNext())
                    //                 {
                    //                     XElement current = elementrator.Current;
                    //                     if (current?.Element("Name") != null &&
                    //                         current.Element("Settlement") != null)
                    //                     {
                    //                         string heroName = current.Element("Name")?.Value;
                    //                         string heroLocation = current.Element("Settlement")?.Value;
                    //                         hunterLocations.Add(heroName, heroLocation);
                    //                     }
                    //                 }
                    //             }
                    //         }
                    //     }
                    //     catch (Exception e)
                    //     {
                    //         InformationManager.DisplayMessage(new InformationMessage("KingdomTemplate: Failed to load Hunter Location Data: " + e.Message, Color.FromUint(4278255360U)));
                    //     }
                    // }
                    // InformationManager.DisplayMessage(new InformationMessage("KingdomTemplate: Initialized.", Color.FromUint(4282569842U)));
                });
            }
        }
Exemple #2
0
        private static Dictionary <string, KingdomLocation> LoadLocationsForKingdomConfiguration(KingdomConfig config)
        {
            string fileLocation = baseXDocPath + config.locationFilename + ".xml";
            Dictionary <string, KingdomLocation> lordLocations = new Dictionary <string, KingdomLocation>();

            if (File.Exists(fileLocation))
            {
                try
                {
                    XDocument doc = XDocument.Load(fileLocation);
                    if (doc.Root != null)
                    {
                        IEnumerable <XElement> lords    = doc.Root.Elements(config.kingdomLordCollectionTag).Elements(config.kingdomLordTag);
                        IEnumerable <XElement> elements = lords.ToList();

                        if (elements.Any())
                        {
                            IEnumerator <XElement> elementrator = elements.GetEnumerator();
                            while (elementrator.MoveNext())
                            {
                                XElement current = elementrator.Current;
                                if (current?.Element("Name") != null &&
                                    current.Element("Settlement") != null &&
                                    current.Element("XOffset") != null &&
                                    current.Element("YOffset") != null)
                                {
                                    string heroName     = current.Element("Name")?.Value;
                                    string heroLocation = current.Element("Settlement")?.Value;
                                    int    xOffset      = 0;
                                    int    yOffset      = 0;

                                    if (Int32.TryParse(current.Element("XOffset")?.Value, out xOffset) &&
                                        Int32.TryParse(current.Element("YOffset")?.Value, out yOffset))
                                    {
                                        lordLocations.Add(heroName, new KingdomLocation(heroLocation, xOffset, yOffset));
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    InformationManager.DisplayMessage(new InformationMessage("KingdomTemplate: Failed to load Lord Location Data: " + e.Message, Color.FromUint(4278255360U)));
                }
            }

            return(lordLocations);
        }