Пример #1
0
        internal static BenchmarkShell Create(string key, IEnumerable <IShell> shells)
        {
            var benchmark = new BenchmarkShell();

            benchmark.Key = key;

            BenchmarkCommodity.Initialize(benchmark, shells);

            benchmark.Caliber         = shells.Median(s => s.Caliber);
            benchmark.Damage          = new ShellDamage(shells.Average(s => s.Damage.Armor), shells.Average(s => s.Damage.Devices));
            benchmark.ExplosionRadius = shells.Average(s => s.ExplosionRadius);
            benchmark.Gravity         = shells.Average(s => s.Gravity);
            benchmark.MaxDistance     = shells.Average(s => s.MaxDistance);
            benchmark.PiercingPower   = new PiercingPower(shells.Average(s => s.PiercingPower.P100), shells.Average(s => s.PiercingPower.P400));
            benchmark.PiercingPowerLossFactorByDistance = shells.Average(s => s.PiercingPowerLossFactorByDistance);
            benchmark.Speed = shells.Average(s => s.Speed);
            benchmark.Type  = shells.Majority(s => s.Type);

            return(benchmark);
        }
Пример #2
0
        internal static IGun CreateBenchmarkGun(string key, TankObjectKey ownerKey, IEnumerable <IGun> guns)
        {
            var benchmark = new VirtualGun();

            benchmark.Key      = key;
            benchmark.OwnerKey = ownerKey;
            BenchmarkDamageableModule.Initialize(benchmark, guns);
            benchmark.Accuracy   = guns.Average(g => g.Accuracy);
            benchmark.AimingTime = guns.Average(g => g.AimingTime);
            benchmark.GunArmor   = guns.Average(g => g.GunArmor);

            var burstGuns = guns.Where(g => g.Burst != null);

            if (burstGuns.Count() == 0)
            {
                benchmark.Burst = null;
            }
            else
            {
                benchmark.Burst = new Burst((int)burstGuns.Average(g => g.Burst.Count), burstGuns.Average(g => g.Burst.Rate));
            }

            benchmark.CamouflageFactorAfterShot = guns.Average(g => g.CamouflageFactorAfterShot);

            var clipGuns = guns.Where(g => g.Clip != null);

            if (clipGuns.Count() == 0)
            {
                benchmark.Clip = null;
            }
            else
            {
                benchmark.Clip = new Clip((int)clipGuns.Average(g => g.Clip.Count), clipGuns.Average(g => g.Clip.Rate));
            }

            benchmark.HorizontalTraverse = new HorizontalTraverse(guns.Median(g => g.HorizontalTraverse.Left), guns.Median(g => g.HorizontalTraverse.Right));
            benchmark.MaxAmmo            = (int)guns.Average(g => g.MaxAmmo);
            benchmark.ReloadTime         = guns.Average(g => g.ReloadTime);
            benchmark.RotationSpeed      = guns.Average(g => g.RotationSpeed);
            benchmark.ShotDispersion     = new TurretShotDispersion(guns.Average(g => g.ShotDispersion.AfterShot), guns.Average(g => g.ShotDispersion.TurretRotation), guns.Average(g => g.ShotDispersion.GunDamaged));

            var shellGroups = new List <KeyValuePair <IGun, IShell> > [4];

            for (int i = 0; i < 4; ++i)
            {
                shellGroups[i] = new List <KeyValuePair <IGun, IShell> >();
            }

            foreach (var gun in guns)
            {
                foreach (var shell in gun.Shots)
                {
                    var kineticFlag = shell.Type.IsKineticShellType() ? 2 : 0;
                    var premiumFlag = shell.CurrencyType == CurrencyType.Gold ? 1 : 0;
                    shellGroups[kineticFlag | premiumFlag].Add(new KeyValuePair <IGun, IShell>(gun, shell));
                }
            }

            int shellIndex = 0;
            var shots      = new List <IShell>();

            foreach (var shellGroup in shellGroups.Where(g => g.Count > 0))
            {
                var shellKey       = $"{key}Shell{shellIndex++}";
                var benchmarkShell = BenchmarkShell.Create(shellKey, shellGroup.Select(g => g.Value));
                benchmarkShell.DamagePerMinute = shellGroup.Average(g => VirtualGun.CalculateDpm(g.Key, g.Value));
                shots.Add(benchmarkShell);
            }

            benchmark.Shots = shots.ToArray();

            benchmark.VerticalTraverse = new GunVerticalTraverse();
            benchmark.VerticalTraverse.DefaultPitchLimits = new PitchLimits(guns.Average(g => g.VerticalTraverse.Front.Elevation), guns.Average(g => g.VerticalTraverse.Front.Depression));
            return(benchmark);
        }