Ejemplo n.º 1
0
        public static object GetDivisions(Configuration configuration, DataSource dataSource)
        {
            var           source     = dataSource.GetDataSource <NdfBinary>(configuration.DataMappings["DeckData"]);
            List <object> outputData = new List <object>();
            var           output     = new ExportedDataTable()
            {
                MetaData = new ExportedDataTable.MetaDataModel()
                {
                    DataIdentifier = "Divisions",
                    ExtractedFrom  = new[]
                    {
                        configuration.DataMappings["DeckData"],
                        configuration.DataMappings["LocalizationDeck"]
                    }
                },
                Data = outputData
            };

            var serializer  = source.Classes.First(x => x.Name == "TDeckSerializer");
            var instance    = serializer.Instances.First();
            var divisionMap = instance.PropertyValues.First(x => x.Property.Name == "DivisionIds").Value as NdfMapList;

            for (var i = 0; i < divisionMap.Count; i++)
            {
                var division = new DivisionModel();
                outputData.Add(division);

                var kvMap = divisionMap[i].Value as NdfMap;
                division.Id = (int)(UInt32)((kvMap.Value as MapValueHolder).Value as NdfUInt32).Value;

                var mapValue = kvMap.Key as MapValueHolder;
                var divRef   = mapValue.Value as NdfObjectReference;
                var divInst  = divRef.Instance;

                division.DivisionName = dataSource.GetLocalizedString(divInst.GetInstancePropertyValue <string>("DivisionName") as string,
                                                                      configuration.DataMappings["LocalizationDeck"]);

                division.DivisionNickName = dataSource.GetLocalizedString(divInst.GetInstancePropertyValue <string>("DivisionNickName") as string,
                                                                          configuration.DataMappings["LocalizationDeck"]);

                division.Nationality = (int)divInst.GetInstancePropertyValue <int>("DivisionNationalite");

                var phaseList = divInst.PropertyValues.First(x => x.Property.Name == "PhaseList").Value as NdfCollection;

                List <int> incomes = new List <int>();
                for (var j = 0; j < phaseList.Count; j++)
                {
                    var phaseRef  = phaseList[j].Value as NdfObjectReference;
                    var phaseInst = phaseRef.Instance;
                    var income    = (UInt32)phaseInst.GetInstancePropertyValue <UInt32>("PhaseIncome");
                    incomes.Add((int)income);
                }

                division.PhaseIncome = incomes.ToArray();
            }

            return(output);
        }
Ejemplo n.º 2
0
        public static object GetUnitData(Configuration configuration, DataSource dataSource)
        {
            var source            = dataSource.GetDataSource <NdfBinary>(configuration.DataMappings["DeckData"]);
            var localizationsFile = configuration.DataMappings["LocalizationDeck"];

            List <object> outputData = new List <object>();
            var           output     = new ExportedDataTable()
            {
                MetaData = new ExportedDataTable.MetaDataModel()
                {
                    DataIdentifier = "Units",
                    ExtractedFrom  = new[]
                    {
                        configuration.DataMappings["DeckData"],
                        configuration.DataMappings["LocalizationDeck"]
                    }
                },
                Data = outputData
            };

            var unitDescriptorTable = source.Classes.First(x => x.Name == "TModularUnitDescriptor");

            foreach (var instance in unitDescriptorTable.Instances)
            {
                var unit = new UnitModel();
                outputData.Add(unit);
                unit.Id = (int)instance.Id;

                unit.DescriptorId =
                    (instance.PropertyValues.FirstOrDefault(x => x.Property.Name == "DescriptorId")?.Value as NdfGuid)?.Value
                    .ToString();

                var modules = instance.PropertyValues.First(x => x.Property.Name == "Modules").Value as NdfCollection;
                for (var i = 0; i < modules.Count; i++)
                {
                    var       modRef = modules[i].Value as NdfObjectReference;
                    NdfObject modInst;
                    var       controllerName = (int)(modRef?.Instance?.GetInstancePropertyValue <int>("ControllerName") ?? 0);

                    switch (controllerName)
                    {
                    case 148:
                        modInst = TryGetReference("TTypeUnitModuleDescriptor", modRef)?.Instance;

                        if (modInst != null)
                        {
                            unit.TypeUnitHint = dataSource.GetLocalizedString(
                                (string)modInst.GetInstancePropertyValue <string>("TypeUnitHintToken"),
                                localizationsFile);

                            unit.AliasName  = (string)modInst.GetInstancePropertyValue <string>("AliasName");
                            unit.Category   = (int)modInst.GetInstancePropertyValue <int>("Category");
                            unit.NameInMenu = dataSource.GetLocalizedString(
                                (string)modInst.GetInstancePropertyValue <string>("NameInMenuToken"),
                                localizationsFile);
                            unit.MotherCountry = (string)modInst.GetInstancePropertyValue <string>("MotherCountry");
                        }
                        break;

                    case 103:
                        modInst = TryGetReference("TModernWarfareProductionModuleDescriptor", modRef)?.Instance;

                        if (modInst != null)
                        {
                            unit.Factory         = (int)modInst.GetInstancePropertyValue <int>("Factory");
                            unit.ProductionPrice = (int)modInst.GetInstancePropertyValue <int>("ProductionPrice");
                        }
                        break;

                    case 173:
                        modInst = TryGetReference("TCommandManagerModuleDescriptor", modRef)?.Instance;

                        var isCommand = modInst?.PropertyValues.First(x => x.Property.Name == "GiveMoraleBonusToSurroundingUnits").Value as NdfBoolean;
                        if (isCommand != null && Convert.ToBoolean(isCommand.Value))
                        {
                            unit.ResolvedIsCommand = true;
                        }
                        break;

                    case 108:
                        modInst = TryGetReference("TScannerConfigurationDescriptor", modRef)?.Instance;

                        var opticalStrength = modInst?.PropertyValues.First(x => x.Property.Name == "OpticalStrength").Value as NdfSingle;
                        if (opticalStrength != null && opticalStrength.Value > 120)
                        {
                            unit.ResolvedIsRecon = true;
                        }
                        break;

                    case 32:
                        modInst = TryGetReference("TModernWarfareDamageModuleDescriptor", modRef)?.Instance;

                        if (modInst != null)
                        {
                            var cddRef = modInst.PropertyValues.FirstOrDefault(x => x.Property.Name == "CommonDamageDescriptor")?.Value as
                                         NdfObjectReference;
                            var armorPropsRef = cddRef?.Instance.PropertyValues.FirstOrDefault(
                                x => x.Property.Name == "BlindageProperties")?.Value as NdfObjectReference;
                            var frontArmorRef =
                                armorPropsRef?.Instance.PropertyValues.FirstOrDefault(
                                    x => x.Property.Name == "ArmorDescriptorFront")?.Value as NdfObjectReference;
                            var frontArmorValue =
                                (int)(frontArmorRef?.Instance?.GetInstancePropertyValue <int>("BaseBlindage") ?? 0);

                            unit.FrontalArmor = frontArmorValue;
                        }
                        break;

                    case 157:
                        modInst = TryGetReference("TWeaponManagerModuleDescriptor_Wargame", modRef)?.Instance;

                        if (modInst != null)
                        {
                            var tdl = modInst.PropertyValues.FirstOrDefault(x => x.Property.Name == "TurretDescriptorList")?.Value as
                                      NdfCollection;

                            int                biggestWeaponApValue = 0;
                            int                biggestWeaponHeValue = 0;
                            double             biggestWeaponRange   = 0;
                            bool               hasWeapon            = false;
                            NdfObjectReference mainTurret           = null;
                            NdfObjectReference potentialMainTurret  = null;
                            foreach (var turret in tdl)
                            {
                                var turretDescriptor = turret.Value as NdfObjectReference;
                                if (turretDescriptor == null)
                                {
                                    continue;
                                }

                                if (mainTurret == null)
                                {
                                    mainTurret = turretDescriptor;
                                }

                                var mountedWeaponList =
                                    turretDescriptor.Instance.PropertyValues.FirstOrDefault(
                                        x => x.Property.Name == "MountedWeaponDescriptorList")?.Value as
                                    NdfCollection;

                                if (mountedWeaponList == null)
                                {
                                    continue;
                                }

                                foreach (var weapon in mountedWeaponList)
                                {
                                    var weaponDescriptor = weapon.Value as NdfObjectReference;
                                    if (weaponDescriptor == null)
                                    {
                                        continue;
                                    }

                                    hasWeapon = true;
                                    var ammoRef =
                                        weaponDescriptor.Instance.PropertyValues.FirstOrDefault(
                                            x => x.Property.Name == "Ammunition")?.Value as NdfObjectReference;
                                    var damageValue =
                                        (int)(ammoRef?.Instance.GetInstancePropertyValue <int>("Arme") ?? 0);
                                    var isAp =
                                        (bool)
                                        (ammoRef?.Instance.GetInstancePropertyValue <bool>("PiercingWeapon") ?? false);
                                    var weaponRange =
                                        (double)
                                        (ammoRef?.Instance.GetInstancePropertyValue <double>("PorteeMaximale") ?? 0);

                                    if (isAp && damageValue > biggestWeaponApValue)
                                    {
                                        mainTurret           = turretDescriptor;
                                        biggestWeaponApValue = damageValue;
                                    }
                                    if (!isAp && damageValue > biggestWeaponHeValue)
                                    {
                                        biggestWeaponHeValue = damageValue;
                                        potentialMainTurret  = turretDescriptor;
                                    }
                                    if (weaponRange > biggestWeaponRange)
                                    {
                                        biggestWeaponRange = weaponRange;
                                    }
                                }
                            }

                            unit.MaxApDamage    = biggestWeaponApValue;
                            unit.MaxHeDamage    = biggestWeaponHeValue;
                            unit.HasWeapons     = hasWeapon;
                            unit.WeaponMaxRange = (int)(biggestWeaponRange / 130);     // world units, and divide by 130 gets us game units?

                            if (biggestWeaponApValue == 0 && biggestWeaponHeValue > 0)
                            {
                                mainTurret = potentialMainTurret;
                            }

                            var angleRad =
                                (float)(mainTurret?.Instance.GetInstancePropertyValue <float>("AngleRotationMax") ?? 0.0f);
                            var angleDeg = Math.Round(angleRad * 180.0 / Math.PI, 1);
                            unit.TurretArcAngle = angleDeg;
                        }
                        break;

                    case 129:
                        modInst = TryGetReference("TTagsModuleDescriptor", modRef)?.Instance;

                        if (modInst != null)
                        {
                            var tagsList = modInst.PropertyValues.FirstOrDefault(x => x.Property.Name == "TagSet")?.Value as
                                           NdfCollection;
                            if (tagsList != null)
                            {
                                foreach (var tag in tagsList)
                                {
                                    var tagStr = tag.Value.ToString();
                                    if (tagStr.StartsWith("Observ", StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        unit.ResolvedIsObserver = true;
                                    }
                                }
                            }
                        }
                        break;

                    default:
                        break;
                    }
                }
            }

            return(output);
        }
Ejemplo n.º 3
0
        public static object GetPacks(Configuration configuration, DataSource dataSource)
        {
            var           source     = dataSource.GetDataSource <NdfBinary>(configuration.DataMappings["DeckData"]);
            List <object> outputData = new List <object>();
            var           output     = new ExportedDataTable()
            {
                MetaData = new ExportedDataTable.MetaDataModel()
                {
                    DataIdentifier = "Packs",
                    ExtractedFrom  = new[]
                    {
                        configuration.DataMappings["DeckData"],
                        configuration.DataMappings["LocalizationOutgame"]
                    }
                },
                Data = outputData
            };

            var serializer = source.Classes.First(x => x.Name == "TDeckSerializer");
            var instance   = serializer.Instances.First();
            var packMap    = instance.PropertyValues.First(x => x.Property.Name == "PackIds").Value as NdfMapList;

            for (var i = 0; i < packMap.Count; i++)
            {
                var pack = new PackModel();
                outputData.Add(pack);

                var kvMap = packMap[i].Value as NdfMap;
                pack.Id = (int)(UInt32)((kvMap.Value as MapValueHolder).Value as NdfUInt32).Value;

                var mapValue = kvMap.Key as MapValueHolder;
                var packRef  = mapValue.Value as NdfObjectReference;
                var packInst = packRef.Instance;

                pack.FactoryType        = (int)packInst.GetInstancePropertyValue <int>("FactoryType");
                pack.ExperienceLevel    = (int)packInst.GetInstancePropertyValue <int>("ExperienceLevel");
                pack.AvailableFromPhase = (int)(UInt32)packInst.GetInstancePropertyValue <UInt32>("AvailableFromPhase");

                var tpUnitList = packInst.PropertyValues.FirstOrDefault(x => x.Property.Name == "TransporterAndUnitsList")?.Value as
                                 NdfCollection;

                if (tpUnitList != null)
                {
                    pack.TransportAndUnitCount = tpUnitList.Count;

                    var tpAndUnitsDescriptorRef = tpUnitList.FirstOrDefault()?.Value as NdfObjectReference;
                    var inst = tpAndUnitsDescriptorRef?.Instance;
                    if (inst != null)
                    {
                        var tpRef = inst.PropertyValues.FirstOrDefault(x => x.Property.Name == "TransporterDescriptor")?.Value as
                                    NdfObjectReference;
                        var tpInst = tpRef?.Instance;
                        if (tpInst != null)
                        {
                            pack.TransportDescriptorId =
                                (tpInst.PropertyValues.FirstOrDefault(x => x.Property.Name == "DescriptorId")?.Value as
                                 NdfGuid)?.Value.ToString();
                        }

                        var unitList = inst.PropertyValues.FirstOrDefault(x => x.Property.Name == "UnitDescriptorList")?.Value as NdfCollection;
                        var unitRef  = unitList?.FirstOrDefault()?.Value as NdfObjectReference;
                        var unitInst = unitRef?.Instance;
                        if (unitInst != null)
                        {
                            pack.UnitDescriptorId =
                                (unitInst.PropertyValues.FirstOrDefault(x => x.Property.Name == "DescriptorId")?.Value
                                 as NdfGuid)?.Value.ToString();
                        }
                    }
                }
            }

            return(output);
        }