コード例 #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;
            }
        }
コード例 #2
0
        private static TankInstance GetInstance(IRepository repository, IXQueryable tank, TankUnikey unikey)
        {
            var key = unikey.ToString();

            return(s_instances.GetOrCreate(key, () =>
            {
                var storage = TankInstanceManager.GetRepositoryTankConfigInfoStorage(repository);
                TankInstanceConfigurationInfo configInfo;
                storage.TryGetValue(key, out configInfo);
                var instance = new TankInstance(repository, TankEntity.Create(tank), configInfo);
                storage[key] = instance.ConfigurationInfo;
                return instance;
            }));
        }
コード例 #3
0
        internal CrewConfiguration(IRepository repository, TankEntity tank, ScriptHost scriptHost, CrewConfigurationInfo configInfo)
            : base(repository, tank, scriptHost)
        {
            if (configInfo == null)
            {
                _crewConfigurationInfo = new CrewConfigurationInfo();
            }

            _element = new XElement("crews");

            var crewDatum = tank.QueryMany("crews/crew");

            var redundancyCounters = new Dictionary <string, int>();
            var crewList           = new List <CrewInstance>();

            foreach (var data in crewDatum)
            {
                var primaryRole    = data["@role"];
                var secondaryRoles = data.QueryManyValues("secondaryRoles/secondaryRole").ToArray();
                int redundancyIndex;
                if (redundancyCounters.ContainsKey(primaryRole))
                {
                    redundancyIndex = redundancyCounters[primaryRole] = redundancyCounters[primaryRole] + 1;
                }
                else
                {
                    redundancyIndex = redundancyCounters[primaryRole] = 0;
                }

                var crew = new CrewInstance(this, primaryRole, secondaryRoles, redundancyIndex);
                crewList.Add(crew);
                this.Element.Add(crew.Element);

                if (configInfo == null)
                {
                    _crewConfigurationInfo[crew.PrimaryRole] = crew.CrewInstanceInfo;
                }
            }

            _crews = crewList.ToArray();

            if (configInfo != null)
            {
                _crewConfigurationInfo = configInfo;
            }
        }
 private ImageSource GetTankIcon(TankEntity tank)
 {
     return(_client.PackageImages.GetTankSmallIcon(tank.IconKey));
 }
        private void Load()
        {
            this.IsLoading = true;

            const int columns = TankTiers;

            var nodes = new List <NationalTechTreeNodeVM>();

            var nodeTankMap = new Dictionary <TechTreeLayoutNode, TankEntity>();

            var tanksInTechTree = new HashSet <TankEntity>(KeyEqualityComparer <IXQueryable> .Instance);

            var rowMap = new Dictionary <int, int>();

            var definedRows = _layout == null ? 0 : _layout.QueryInt("grid/rows");

            // 1. build a node grid, solve situations where two tanks are occupying one cell

            var occupiedCells = new List <TechTreeLayoutNode[]>();

            for (int row = 0; row < definedRows + 1; ++row)
            {
                occupiedCells.Add(new TechTreeLayoutNode[columns]);
            }

            if (_layout != null)
            {
                var t1TankRow = 0;

                foreach (var node in _layout.QueryMany("nodes/node").Select(n => new TechTreeLayoutNode(n)))
                {
                    var tankData = _client.GetTank(this.NationKey, node.TankKey);
                    if (tankData != null)
                    {
                        var tank = new TankEntity(tankData);
                        var row  = node.Row;
                        int mappedRow;
                        if (rowMap.TryGetValue(row, out mappedRow))
                        {
                            row = mappedRow;
                        }

                        var tankTier = tank.Tier;
                        var column   = tankTier - 1;
                        while (occupiedCells[row][column] != null)
                        {
                            // two tanks are occupying one cell, insert a row
                            ++row;
                            if (row == occupiedCells.Count)
                            {
                                occupiedCells.Insert(row, new TechTreeLayoutNode[columns]);
                            }
                        }

                        rowMap[node.Row] = row;

                        occupiedCells[row][column] = node;
                        nodeTankMap[node]          = tank;
                        tanksInTechTree.Add(tank);

                        if (tankTier == 1 && !tank.IsPremium && !tank.IsObsoleted)
                        {
                            t1TankRow = row;
                        }
                    }
                }

                // remove empty rows
                for (int row = occupiedCells.Count - 1; row >= 0; --row)
                {
                    if (occupiedCells[row].All(node => node == null))
                    {
                        occupiedCells.RemoveAt(row);
                    }
                    else
                    {
                        break;
                    }
                }

                // place T1 tank in vertical center
                var newT1TankRow = (int)Math.Round(occupiedCells.Count / 2.0);
                var sign         = newT1TankRow > t1TankRow ? -1 : 1;
                for (int row = newT1TankRow; row != t1TankRow; row += sign)
                {
                    if (occupiedCells[row][0] == null)
                    {
                        var t1Node    = occupiedCells[t1TankRow][0];
                        var newT1Node = new TechTreeLayoutNode(t1Node.Tank, row, t1Node.Column, t1Node.UnlockTanks);
                        occupiedCells[row][0]       = newT1Node;
                        occupiedCells[t1TankRow][0] = null;
                        nodeTankMap[newT1Node]      = nodeTankMap[t1Node];
                        nodeTankMap.Remove(t1Node);
                        break;
                    }
                }
            }

            // 2. find out tanks which are existed and valid, but not appeared in the techtree
            var techTreeRowCount = occupiedCells.Count;

            foreach (var tankData in _client.TankDatabase.QueryMany("tank[nation/@key='{0}']", this.NationKey))
            {
                var tank = new TankEntity(tankData);
                if (!tanksInTechTree.Contains(tank) /*&& tank.IsValid*/)
                {
                    var row    = techTreeRowCount;
                    var column = tank.QueryInt("level") - 1;
                    while (true)
                    {
                        if (occupiedCells.Count <= row)
                        {
                            occupiedCells.Insert(row, new TechTreeLayoutNode[columns]);
                        }
                        else if (occupiedCells[row][column] != null)
                        {
                            ++row;
                        }
                        else
                        {
                            var node = new TechTreeLayoutNode(tank, row, column, null);
                            occupiedCells[row][column] = node;
                            nodeTankMap[node]          = tank;
                            break;
                        }
                    }
                }
            }

            // 3. create node viewmodels
            for (int row = 1; row < occupiedCells.Count; ++row)
            {
                for (int column = 0; column < columns; ++column)
                {
                    var node = occupiedCells[row][column];
                    if (node != null)
                    {
                        var tank = nodeTankMap[node];
                        nodes.Add(new NationalTechTreeNodeVM(_client, tank, row, column, node.UnlockTanks, this.GetTankIcon(tank)));
                    }
                }
            }


            this.Rows    = occupiedCells.Count;
            this.Columns = columns;
            this.Nodes   = nodes.ToArray();
            // IsLoading will be set by the view, after all controls are populated
            this.IsLoading = false;

            this.IsLoaded = true;
        }
コード例 #6
0
 internal ConfigurationBase(IRepository repository, TankEntity tank, ScriptHost scriptHost)
 {
     this.Tank       = tank;
     this.Repository = repository;
     this.ScriptHost = scriptHost;
 }