示例#1
0
 public static string GetTankHyphenKeyEscaped(string nation, string tankKey)
 {
     return(SecurityElement.Escape(RepositoryHelper.GetTankHyphenKey(nation, tankKey)));
 }
示例#2
0
        public XElement BuildTankDatabase()
        {
            var result = new XElement("tanks");

            Parallel.ForEach(_paths.Nations, nation =>
            {
                var chassisFile   = ProcessChassisListFile(nation);
                var enginesFile   = ProcessEngineListFile(nation);
                var fuelTanksFile = ProcessFuelTankListFile(nation);
                var gunsFile      = ProcessGunListFile(nation);
                var radiosFile    = ProcessRadioListFile(nation);
                var turretsFile   = ProcessTurretListFile(nation);
                var shellFile     = ProcessShellListFile(nation);

                var tankListFile = ProcessTankListFile(nation);

                var successorInfo     = new Dictionary <string, string[]>();
                var successorInfoLock = new object();
                var tankElements      = new Dictionary <string, XElement>();
                var tankElementsLock  = new object();

                Parallel.ForEach(tankListFile.Elements(), tank =>
                {
                    var tankElement = new XElement(tank);
                    var tankKey     = tank.Attribute("key").Value;
                    tankElement.SetAttributeValue("fullKey", RepositoryHelper.GetTankFullKeyEscaped(nation, tankKey));
                    tankElement.SetAttributeValue("iconKey", RepositoryHelper.GetTankHyphenKeyEscaped(nation, tankKey));

                    lock (tankElementsLock)
                    {
                        tankElements[tankKey] = tankElement;
                    }

                    var tankFile = ProcessTankFile(nation, tankKey);

                    var mmWeightElement = this.CommonVehicleData.Element("balance")?
                                          .Element("byVehicleModule")?
                                          .Elements()
                                          .FirstOrDefault(e => e.Attribute("key").Value == tankKey);

                    if (mmWeightElement == null)
                    {
                        var tankTier    = int.Parse(tank.ExistedElement("level").Value.Trim(), CultureInfo.InvariantCulture);
                        mmWeightElement = this.CommonVehicleData.Element("balance")?
                                          .Element("byComponentLevels")?
                                          .Elements()
                                          .ElementAt(tankTier - 1);
                    }

                    tankElement.Add(new XElement("mmweight", mmWeightElement?.Value ?? "-1"));        // this value no long exists in (and maybe after) 9.15

                    foreach (var element in tankFile.Elements())
                    {
                        tankElement.Add(new XElement(element));
                    }

                    this.LinkTankModules(tankElement.Element("chassis"), chassisFile);
                    this.LinkTankModules(tankElement.Element("engines"), enginesFile);
                    this.LinkTankModules(tankElement.Element("fuelTanks"), fuelTanksFile);
                    this.LinkTankModules(tankElement.Element("radios"), radiosFile);
                    this.LinkTankModules(tankElement.Element("turrets"), turretsFile);
                    foreach (var turretElement in tankElement.ExistedElement("turrets").Elements())
                    {
                        this.LinkTankModules(turretElement.Element("guns"), gunsFile);
                        foreach (var gunElement in turretElement.ExistedElement("guns").Elements())
                        {
                            this.LinkShell(gunElement.Element("shots"), shellFile);
                        }
                    }

                    lock (successorInfoLock)
                    {
                        successorInfo.Add(tankKey, ((IEnumerable)tankFile.XPathEvaluate("//unlocks/vehicle/@key"))
                                          .Cast <XAttribute>()
                                          .Select(e => e.Value)
                                          .ToArray());
                    }

                    result.Add(tankElement);
                });

                var predecessorInfo = new Dictionary <string, List <string> >();
                foreach (var successorInfoItem in successorInfo)
                {
                    foreach (var successor in successorInfoItem.Value)
                    {
                        var predecessorInfoItem = predecessorInfo.GetOrCreate(successor,
                                                                              () => new List <string>());
                        predecessorInfoItem.Add(successorInfoItem.Key);
                    }
                }

                Parallel.ForEach(tankListFile.Elements(), tank =>
                                 //foreach (var tank in tankListFile.Elements())
                {
                    var tankKey       = tank.Attribute("key").Value;
                    var tankElement   = tankElements[tankKey];
                    var maybeObsolete = tankElement.ExistedElement("price").ExistedAttribute("currency").Value != "gold";

                    var successorsElement = new XElement("successors");
                    string[] successors;
                    if (successorInfo.TryGetValue(tankKey, out successors))
                    {
                        foreach (var successor in successors)
                        {
                            var successorElement = new XElement("successor");
                            successorElement.SetAttributeValue("key", successor);
                            successorsElement.Add(successorElement);
                            maybeObsolete = false;
                        }
                    }
                    tankElement.Add(successorsElement);

                    var predecessorsElement = new XElement("predecessors");
                    List <string> predecessors;
                    if (predecessorInfo.TryGetValue(tankKey, out predecessors))
                    {
                        foreach (var predecessor in predecessors)
                        {
                            var predecessorElement = new XElement("predecessor");
                            predecessorElement.SetAttributeValue("key", predecessor);
                            predecessorsElement.Add(predecessorElement);
                            maybeObsolete = false;
                        }
                    }
                    tankElement.Add(predecessorsElement);

                    if (maybeObsolete)
                    {
                        var secretTags = tankElement.ExistedElement("secretTags");
                        if (!secretTags.Elements().Any())
                        {
                            secretTags.Add(new XElement("tag", "obsolete"));
                        }
                    }
                });
            });

            return(result);
        }
示例#3
0
 public IXQueryable GetTank(string nationKey, string tankKey)
 {
     return(this.TankDatabase
            .Query("tank[@fullKey='{0}']", RepositoryHelper.GetTankFullKeyEscaped(nationKey, tankKey)));
 }