Ejemplo n.º 1
0
        private static void ProcessingRewardPools()
        {
            ConsoleWriteHeadline("Processing Reward Pools");
            var xRewardPools = new XElement("RP");

            //RewardPool and RewardItemPool
            var RewardItemPoolsAssets = Assets.Original
                                        .XPathSelectElements($"//Asset[Template='RewardPool']")
                                        .Concat(Assets.Original.XPathSelectElements($"//Asset[Template='RewardItemPool']"))
                                        .ToList();

            foreach (var RewardPool in RewardItemPoolsAssets)
            {
                var xPool = new XElement("P");
                xRewardPools.Add(xPool);
                xPool.Add(new XAttribute("ID", RewardPool.XPathSelectElement("Values/Standard/GUID").Value));
                xPool.Add(new XAttribute("N", RewardPool.XPathSelectElement("Values/Standard/Name").Value));
                if (RewardPool.XPathSelectElement("Values/RewardPool/ItemsPool")?.HasElements ?? false)
                {
                    var xItems = new XElement("IL");
                    xPool.Add(xItems);
                    foreach (var item in RewardPool.XPathSelectElements("Values/RewardPool/ItemsPool/Item"))
                    {
                        var itemId = item.XPathSelectElement("ItemLink")?.Value ?? item.XPathSelectElement("ItemGroup")?.Value;
                        if (itemId != null)
                        {
                            var xItem = new XElement("I");
                            xItems.Add(xItem);
                            xItem.Add(new XAttribute("ID", itemId));
                            xItem.Add(new XAttribute("W", item.XPathSelectElement("Weight")?.Value ?? "1"));
                        }
                    }
                }
            }

            //ResourcePool
            var ResourcePoolAssets = Assets.Original
                                     .XPathSelectElements($"//Asset[Template='ResourcePool']")
                                     .ToList();

            foreach (var ResourcePool in ResourcePoolAssets)
            {
                var xPool = new XElement("P");
                xRewardPools.Add(xPool);
                xPool.Add(new XAttribute("ID", ResourcePool.XPathSelectElement("Values/Standard/GUID").Value));
                xPool.Add(new XAttribute("N", ResourcePool.XPathSelectElement("Values/Standard/Name").Value));
                if (ResourcePool.XPathSelectElement("Values/ResourceRewardPool/PossibleRewards")?.HasElements ?? false)
                {
                    var xItems = new XElement("I");
                    xPool.Add(xItems);
                    foreach (var item in ResourcePool.XPathSelectElements("Values/ResourceRewardPool/PossibleRewards/Item"))
                    {
                        var itemId = item.XPathSelectElement("Resource")?.Value;
                        if (itemId != null)
                        {
                            var xItem = new XElement("I");
                            xItems.Add(xItem);
                            xItem.Add(new XAttribute("ID", itemId));
                            xItem.Add(new XAttribute("W", item.XPathSelectElement("Weight")?.Value ?? "100"));
                        }
                    }
                }
            }

            //AssetGroups
            var AssetGroups = Assets.Original
                              .Descendants("Groups")
                              .Where(g => g.Element("GUID") != null)
                              .Concat(Assets.Original
                                      .Descendants("Group")
                                      .Where(g => g.Element("GUID") != null))
                              .ToList();

            foreach (var AssetGroup in AssetGroups)
            {
                var childAssets = AssetGroup.Descendants("Asset").Where(a => a.XPathSelectElement("Values/Item") != null || a.XPathSelectElement("Values/Product") != null);
                if (childAssets.Any())
                {
                    var xPool = new XElement("P");
                    xRewardPools.Add(xPool);
                    xPool.Add(new XAttribute("ID", AssetGroup.Element("GUID").Value));
                    var xItems = new XElement("I");
                    xPool.Add(xItems);
                    foreach (var item in childAssets)
                    {
                        var itemId = item.XPathSelectElement("Values/Standard/GUID")?.Value;
                        if (itemId != null)
                        {
                            var xItem = new XElement("I");
                            xItems.Add(xItem);
                            xItem.Add(new XAttribute("ID", itemId));
                            xItem.Add(new XAttribute("W", item.XPathSelectElement("Weight")?.Value ?? "100"));
                        }
                    }
                }
            }

            var document = new XDocument(xRewardPools);

            document.Save($@"{Program.PathRoot}\Modified\Assets_RewardPools.xml");
            document.SaveIndent($@"{Program.PathViewer}\Resources\Assets\RewardPools.xml");
        }