Exemple #1
0
        public TankInstance(IRepository repository, TankEntity tank, TankInstanceConfigurationInfo configInfo)
            : base(tank.ToElement())
        {
            this._repository = repository;
            this._tank       = tank;

            this.Element.Name = "data";
            this.Element.ExistedElement("crews").Remove();
            this.Element.ExistedElement("chassis").Remove();
            this.Element.ExistedElement("turrets").Remove();
            this.Element.ExistedElement("engines").Remove();
            this.Element.ExistedElement("radios").Remove();
            var fuelTank = new XElement(this.Element.ExistedElement("fuelTanks").ExistedElement("fuelTank"));

            this.Element.ExistedElement("fuelTanks").ReplaceWith(fuelTank);

            _scriptHost            = new ScriptHost();
            this.TankConfiguration = new TankConfiguration(repository,
                                                           tank,
                                                           _scriptHost,
                                                           configInfo == null
                                                               ? null
                                                               : configInfo.TankConfigurationInfo);
            this.CrewConfiguration = new CrewConfiguration(repository,
                                                           tank,
                                                           _scriptHost, configInfo == null
                                                               ? null
                                                               : configInfo.CrewConfigurationInfo);
            this.CustomizationConfiguration = new CustomizationConfiguration(repository,
                                                                             tank,
                                                                             _scriptHost,
                                                                             configInfo == null
                                                                                 ? null
                                                                                 : configInfo.CustomizationConfigurationInfo);

            this.Element.Add(_scriptHost.Element);
            _scriptHost.ElementChanged += OnSubElementChanged;

            if (configInfo == null)
            {
                _tankInstanceConfigurationInfo = new TankInstanceConfigurationInfo
                {
                    TankConfigurationInfo          = this.TankConfiguration.TankConfigurationInfo,
                    CrewConfigurationInfo          = this.CrewConfiguration.CrewConfigurationInfo,
                    CustomizationConfigurationInfo = this.CustomizationConfiguration.CustomizationConfigurationInfo
                };
            }
            else
            {
                _tankInstanceConfigurationInfo = configInfo;
            }
        }
Exemple #2
0
        internal TankConfiguration(IRepository repository, TankEntity tank, ScriptHost scriptHost, TankConfigurationInfo configInfo)
            : base(repository, tank, scriptHost)
        {
            _equipmentsElement  = new XElement("equipments");
            _consumablesElement = new XElement("consumables");

            _equipments  = new Equipment[3];
            _consumables = new Consumable[3];

            if (configInfo == null)
            {
                _tankConfigurationInfo = new TankConfigurationInfo();
                this.LoadStockConfiguration();
            }
            else
            {
                this.TankConfigurationInfo = configInfo;
            }
        }
 internal CustomizationConfiguration(IRepository repository, TankEntity tank, ScriptHost scriptHost, CustomizationConfigurationInfo configInfo)
     : base(repository, tank, scriptHost)
 {
     this.CustomizationConfigurationInfo = configInfo ?? new CustomizationConfigurationInfo();
 }
Exemple #4
0
        public bool CanBeUsedBy(Tank tank)
        {
            var tankNation = tank.NationKey;

            if (this.QueryManyValues("vehicleFilter/exclude/nations/nation").Contains(tankNation))
            {
                return(false);
            }

            var includeNations = this.Query("vehicleFilter/include/nations");

            if (includeNations != null)
            {
                if (!includeNations.QueryManyValues("nation").Contains(tankNation))
                {
                    return(false);
                }
            }

            var tankTags = tank.QueryManyValues("tags/tag").ToArray();

            foreach (var tag in this.QueryManyValues("vehicleFilter/exclude/vehicle/tags"))
            {
                if (tankTags.Contains(tag))
                {
                    return(false);
                }
            }

            var includeVehicleTags = this.Query("vehicleFilter/include/vehicle/tags");

            if (includeVehicleTags != null)
            {
                var matched = false;
                foreach (var tag in includeVehicleTags.QueryManyValues("tag"))
                {
                    if (tankTags.Contains(tag))
                    {
                        matched = true;
                        break;
                    }
                }

                if (!matched)
                {
                    return(false);
                }
            }

            var maxLevelString = this["vehicleFilter/include/vehicle/maxLevel"];

            if (maxLevelString != null)
            {
                var maxLevel = int.Parse(maxLevelString, CultureInfo.InvariantCulture);
                if (tank.Tier > maxLevel)
                {
                    return(false);
                }
            }

            var minLevelString = this["vehicleFilter/include/vehicle/minLevel"];

            if (minLevelString != null)
            {
                var minLevel = int.Parse(minLevelString, CultureInfo.InvariantCulture);
                if (tank.Tier < minLevel)
                {
                    return(false);
                }
            }

            var engineTags = tank.QueryManyValues("engines/engine/tags");

            foreach (var tag in this.QueryManyValues("vehicleFilter/exclude/engine/tags"))
            {
                if (engineTags.Contains(tag))
                {
                    return(false);
                }
            }

            var includeEngineTags = this.Query("vehicleFilter/include/engine/tags");

            if (includeEngineTags != null)
            {
                var matched = false;
                foreach (var tag in includeEngineTags.QueryManyValues("tag"))
                {
                    if (engineTags.Contains(tag))
                    {
                        matched = true;
                        break;
                    }
                }

                if (!matched)
                {
                    return(false);
                }
            }


            return(true);
        }