Exemplo n.º 1
0
        /// <summary>
        /// Create a ship based on this description.
        /// </summary>
        /// <param name="level">The level that will contain this Ship.</param>
        /// <param name="description">The ship description details.</param>
        public Ship(GamePlay level, ShipDescription description)
            : this(level, description.TexturePath, description.ParticleColor, description.ParticleDuration, description.NormalAmmo, description.SpecialAmmo)
        {
            Mass               = description.Mass;
            MaxSpeed           = description.MaxSpeed;
            RotationStabilizer = description.RotationStabilizer;
            SpecialAttack      = description.SpecialAttack.Special;

            var fuel       = (int)description.FuelDuration.TotalMilliseconds;
            var minReserve = (int)FuelReserve.TotalMilliseconds;

            Fuel = new AutoRegenContainer(fuel, FuelRegenTime)
            {
                Reserve = Math.Max((int)(fuel * 0.5f), minReserve)
            };
        }
Exemplo n.º 2
0
        async Task FireWeapon(AutoRegenContainer container, Func <CancellationToken, Task <bool> > fire, CancellationToken cancellation)
        {
            if (container.IsEmpty)
            {
                return;
            }

            container.Regenerate = false;

            while (!cancellation.IsCancellationRequested)
            {
                if (!await fire(cancellation))
                {
                    break;
                }
            }

            container.Regenerate = true;
        }