Example #1
0
 public WdGun(string id, JsonDict gun, WdData data, WdCountry country)
 {
     Raw            = gun;
     Id             = id;
     Name           = data.ResolveString(gun["userString"].WdString());
     Shells         = new List <WdShell>();
     PitchUpLimit   = -999;
     PitchDownLimit = -999;
     UpdateFrom(gun, country, initialize: true);
 }
Example #2
0
        /// <remarks>
        ///     This method requires the shell data to already be fully loaded.</remarks>
        /// <param name="initialize">
        ///     Forces all parameters to be loaded, producing an exception if anything important is missing.</param>
        internal void UpdateFrom(JsonDict gun, WdCountry country, bool initialize = false)
        {
            // Not sure if this is the easiest way to correctly load the data on guns... but seems to do the job
            // The idea appears to be that there is a base gun definition, but each specific turret may override certain gun parameters

            if (initialize || gun.ContainsKey("level"))
            {
                Level = gun["level"].WdInt();
            }
            if (initialize || gun.ContainsKey("price"))
            {
                Price = gun["price"].WdInt();
            }
            if (initialize || gun.ContainsKey("mass"))
            {
                Mass = gun["weight"].WdInt();
            }
            if (initialize || gun.ContainsKey("maxHealth"))
            {
                HitPoints = gun["maxHealth"].WdInt();
            }

            if (initialize || gun.ContainsKey("pitchLimits"))
            {
                if (gun["pitchLimits"] is JsonDict)
                {
                    // new-style limits in 0.9.9 and later
                    if (gun["pitchLimits"].ContainsKey("minPitch"))
                    {
                        PitchUpLimit = (gun["pitchLimits"]["minPitch"].WdString() == "") ? 0 : -gun["pitchLimits"]["minPitch"].WdString().Split(' ').Select(x => (x == "") ? 0 : decimal.Parse(x, NumberStyles.Float, CultureInfo.InvariantCulture)).Min();
                    }
                    if (gun["pitchLimits"].ContainsKey("maxPitch"))
                    {
                        PitchDownLimit = (gun["pitchLimits"]["maxPitch"].WdString() == "") ? 0 : -gun["pitchLimits"]["maxPitch"].WdString().Split(' ').Select(x => (x == "") ? 0 : decimal.Parse(x, NumberStyles.Float, CultureInfo.InvariantCulture)).Max();
                    }
                }
                else
                {
                    // old-style limits before 0.9.9
                    var parts = gun["pitchLimits"].WdString().Split(' ').Select(x => decimal.Parse(x, NumberStyles.Float, CultureInfo.InvariantCulture)).ToArray();
                    PitchUpLimit   = -parts[0];
                    PitchDownLimit = -parts[1];
                }
            }
            if (gun.ContainsKey("turretYawLimits")) // earlier game versions have this in the turret data
            {
                var parts = gun["turretYawLimits"].WdString().Split(' ').Select(x => decimal.Parse(x, NumberStyles.Float, CultureInfo.InvariantCulture)).ToArray();
                YawLeftLimit  = parts[0]; // not too sure about which is which
                YawRightLimit = parts[1];
            }

            if (initialize || gun.ContainsKey("rotationSpeed"))
            {
                RotationSpeed = gun["rotationSpeed"].WdDecimal();
            }
            if (initialize || gun.ContainsKey("reloadTime"))
            {
                ReloadTime = gun["reloadTime"].WdDecimal();
            }
            if (initialize || gun.ContainsKey("maxAmmo"))
            {
                MaxAmmo = gun["maxAmmo"].WdInt();
            }
            if (initialize || gun.ContainsKey("aimingTime"))
            {
                AimTime = gun["aimingTime"].WdDecimal();
            }

            if (initialize)
            {
                HasDrum = gun.ContainsKey("clip");
            }
            else if (gun.ContainsKey("clip"))
            {
                HasDrum = true;
            }

            // Load the shell types - not sure how the overrides are supposed to work here, so just clear the entire list in that case
            if (gun.ContainsKey("shots"))
            {
                Shells.Clear();
                foreach (var kvp in gun["shots"].GetDict())
                {
                    var shell = country.Shells[kvp.Key].Clone();
                    shell.AddGunSpecific(kvp.Value.GetDict());
                    Shells.Add(shell);
                }
            }
        }
Example #3
0
        public WdTank(string id, JsonDict json, WdCountry country, WdData data)
        {
            RawId   = id;
            Country = country;
            Raw     = json;

            var tags1 = Raw["tags"].WdString().Split("\r\n").Select(s => s.Trim()).ToHashSet();
            var tags2 = Raw["tags"].WdString().Split(' ').Select(s => s.Trim()).ToHashSet();

            Tags      = tags1.Count > tags2.Count ? tags1 : tags2;
            NotInShop = Raw.ContainsKey("notInShop") && Raw["notInShop"].GetBool();
            Price     = Raw["price"] is JsonDict ? Raw["price"][""].WdInt() : Raw["price"].WdInt();
            Gold      = Raw["price"] is JsonDict && Raw["price"].ContainsKey("gold");

            if (Tags.Contains("lightTank"))
            {
                Class = "lightTank";
            }
            else if (Tags.Contains("mediumTank"))
            {
                Class = "mediumTank";
            }
            else if (Tags.Contains("heavyTank"))
            {
                Class = "heavyTank";
            }
            else if (Tags.Contains("SPG"))
            {
                Class = "SPG";
            }
            else if (Tags.Contains("AT-SPG"))
            {
                Class = "AT-SPG";
            }
            else
            {
                Class = null;
            }

            Tier   = Raw["level"].WdInt();
            Secret = Tags.Contains("secret");
            string scriptsFolder = string.IsNullOrEmpty(data.VersionConfig.PathSourceScripts) ? @"res\scripts" : data.VersionConfig.PathSourceScripts;

            var path = WotFileExporter.CombinePaths(data.Installation.Path, scriptsFolder,
                                                    @"item_defs\vehicles\{0}\{1}.xml".Fmt(Country.Name, id));

            using (var stream = WotFileExporter.GetFileStream(path))
            {
                RawExtra = BxmlReader.ReadFile(stream);
            }

            FullName    = data.ResolveString(Raw["userString"].WdString());
            ShortName   = Raw.ContainsKey("shortUserString") ? data.ResolveString(Raw["shortUserString"].WdString()) : FullName;
            Description = data.ResolveString(Raw["description"].WdString());

            MaxSpeedForward = RawExtra["speedLimits"]["forward"].WdDecimal();
            MaxSpeedReverse = RawExtra["speedLimits"]["backward"].WdDecimal();

            RepairCost = RawExtra["repairCost"].WdDecimal();

            Hull = new WdHull(RawExtra["hull"].GetDict());

            Chassis = new List <WdChassis>();
            Turrets = new List <WdTurret>();
            Engines = new List <WdEngine>();
            Radios  = new List <WdRadio>();
            // these lists are populated once all the tanks are loaded, since some shared modules occur before the non-shared "definition" of the module.

            foreach (var kvp in RawExtra["chassis"].GetDict())
            {
                if (kvp.Value.GetStringLenientSafe() != "shared" && kvp.Value.Safe[""].GetStringSafe() != "shared" && !kvp.Value.ContainsKey("shared"))
                {
                    Country.Chassis.Add(kvp.Key, new WdChassis(kvp.Key, kvp.Value.GetDict(), data));
                }
            }
            foreach (var kvp in RawExtra["turrets0"].GetDict())
            {
                if (kvp.Value.GetStringLenientSafe() != "shared" && kvp.Value.Safe[""].GetStringSafe() != "shared" && !kvp.Value.ContainsKey("shared"))
                {
                    Country.Turrets.Add(kvp.Key, new WdTurret(kvp.Key, kvp.Value.GetDict(), data));
                }
            }
            // RawExtra["engines"] and RawExtra["radios"] only contain information about unlocks; the rest is contained in separate files parsed in WdCountry.
        }