private void AnalyseUnlocks()
        {
            var modules = ((IEnumerable <Module>) this.TankInstance.Tank.Turrets)
                          .Union(this.TankInstance.Tank.Guns)
                          .Union(this.TankInstance.Tank.Engines)
                          .Union(this.TankInstance.Tank.Radios)
                          .Union(this.TankInstance.Tank.Chassis);

            var moduleVms       = modules.ToDictionary(m => m, m => new ModuleVM(m));
            var unlockedTankVms = new List <UnlockedTankVM>();

            foreach (var module in modules)
            {
                var unlockVms = new List <UnlockInfoVM>();
                var unlocks   = this.TankInstance.Repository.GetUnlocks(this.TankInstance.Tank, module);
                foreach (var unlockInfo in unlocks)
                {
                    var unlockedModule = unlockInfo.Target as Module;
                    if (unlockedModule != null)
                    {
                        ModuleVM unlockedModuleVm;
                        if (moduleVms.TryGetValue(unlockedModule, out unlockedModuleVm))
                        {
                            unlockVms.Add(new UnlockInfoVM(unlockedModuleVm, unlockInfo.Experience));
                        }
                    }
                    else
                    {
                        var unlockedTank = unlockInfo.Target as Tank;
                        if (unlockedTank != null)
                        {
                            var tankVm = new UnlockedTankVM(unlockedTank, moduleVms[module]);
                            unlockVms.Add(new UnlockInfoVM(tankVm, unlockInfo.Experience));
                            unlockedTankVms.Add(tankVm);
                        }
                    }
                }

                moduleVms[module].Unlocks = unlockVms;
            }

            this.Modules       = moduleVms.Values.ToArray();
            this.UnlockedTanks = unlockedTankVms;

            this.UnlockTargets = ((IEnumerable <IModuleUnlockTargetVM>) this.Modules).Union(this.UnlockedTanks);

            this.Columns = this.LayoutModules() + 1;

            foreach (var unlockedTankVm in unlockedTankVms)
            {
                unlockedTankVm.Row    = unlockedTankVm.UnlockedBy.Row;
                unlockedTankVm.Column = this.Columns - 1;
            }
        }
Beispiel #2
0
        public void SetUnlockedTank(UnlockedTankVM tank)
        {
            this.CheckTerminated();

            if (tank.Row == ModuleUnlockTargetVM.UndefinedRowOrColumn)
            {
                tank.Row = this.Index;
            }

            if (tank.Row != this.Index)
            {
                throw new ArgumentException("tank");
            }

            this.UnlockedTank = tank;
        }