Exemplo n.º 1
0
        public void Fire()
        {
            var projectile = _projectileFactory.Create(_cannonEndTransform);

            projectile.Launch();
            ShotFired.Invoke();
        }
Exemplo n.º 2
0
        public void Shoot()
        {
            if (_nextFire >= 0)
            {
                return;
            }

            _nextFire = Settings.FireRate;

            if (Settings.CurrentAmmo > 0 || Settings.AIUseInfiniteAmmo)
            {
                Settings.ShootAudioEvent?.PlayOneShot(_gunEndAudioSource);
                Settings.CurrentAmmo--;

                if (Settings.IsRaycast)
                {
                    ShootRaycast();
                }
                else
                {
                    ShootProjectile();
                }

                ShotFired?.Invoke();
            }
            else
            {
                Settings.EmptyAmmoAudioEvent?.PlayOneShot(_gunEndAudioSource);
            }
        }
Exemplo n.º 3
0
        public void FireShot(ShotInfo shot)
        {
            shot.CreateTimeStamp = GameTime.Now;

            MsgShotBegin shotMessage = new MsgShotBegin();

            if (shot.Owner == null)
            {
                shotMessage.PlayerID = BZFlag.Data.Players.PlayerConstants.ServerPlayerID;
            }
            else
            {
                shotMessage.PlayerID = shot.Owner.PlayerID;
            }

            shotMessage.ShotID   = shot.PlayerShotID;
            shotMessage.Team     = shot.TeamColor;
            shotMessage.TimeSent = (float)shot.FireTimestamp;
            shotMessage.Position = shot.InitalPostion;
            shotMessage.Velocity = shot.InitalVector;
            shotMessage.Lifetime = (float)shot.Lifetime;
            if (shot.SourceFlag != null)
            {
                shotMessage.Flag = shot.SourceFlag.FlagAbbv;
            }

            lock (ShotList)
                ShotList.Add(shot);

            Players.SendToAll(shotMessage, false);

            ShotFired?.Invoke(this, shot);
            shot.Allow = true;
        }
        public async Task Handle(ShotFired message)
        {
            var gameToUpdate = await _read.Get <GameDetails>(message.GameId);

            gameToUpdate.Players[message.AggressorPlayer].Board.AddShotFired(message.Target);
            gameToUpdate.Players[message.TargetPlayer].Board.AddShotReceived(message.Target);
            gameToUpdate.Turn   += 1;
            gameToUpdate.Version = message.Version;
            await _save.Put(gameToUpdate);
        }
Exemplo n.º 5
0
    private void ShootBullet()
    {
        Bullet  bullet    = BulletPooler.Instance.GetPooledObject();
        Vector3 direction = (enemy.Target.position - bulletSpawnPoint.position).normalized;

        bullet.transform.position = bulletSpawnPoint.position;
        bullet.Launch(projectileLayer.MaskToLayer(), direction, config.BulletSpeed, Element.None);

        ShotFired?.Invoke();
    }
Exemplo n.º 6
0
 void InvokeOnShotFired(IProjectile projectile)
 {
     try
     {
         ShotFired?.Invoke(this, projectile);
     }
     catch (Exception e)
     {
         Urho.IO.Log.Write(LogLevel.Debug,
                           $"There was an unexpected exception during the invocation of {nameof(ShotFired)}: {e.Message}");
     }
 }
Exemplo n.º 7
0
        private void FireMissileShot(Vector2 fireAngle)
        {
            ShotFiredEventArgs args = new ShotFiredEventArgs
            {
                Location = _turretSprite.WorldLocation,
                Velocity = fireAngle * WeaponSpeed,
                ShotType = ShotType.Missile
            };

            ShotFired?.Invoke(this, args);

            _missileTimer.Reset();
        }
Exemplo n.º 8
0
        private IEnumerator Shoot()
        {
            rateOfFireHandler = false;
            isShooting        = true;
            PreShootMethod();
            StartCoroutine(ShootMethod());
            ShotFired?.Invoke();
            PostShootMethod();
            yield return(new WaitForSeconds(RateOfFire));

            isShooting        = false;
            rateOfFireHandler = true;
        }
Exemplo n.º 9
0
        public void FireShot()
        {
            ShotFiredEventArgs args = new ShotFiredEventArgs
            {
                Location  = Location + _gunOffset,
                ShotSpeed = ShotSpeed,
                FiredBy   = FiredBy.Enemy,
                Damage    = EnemyShotDamage
                            // Don't know directional velocity because we don't know where the player is
            };

            ShotFired?.Invoke(this, args);
        }
Exemplo n.º 10
0
    private IEnumerator FiringLoop()
    {
        while (health.IsAlive)
        {
            Bullet  bullet    = BulletPooler.Instance.GetPooledObject();
            Vector3 direction = bulletSpawnPoint.forward;

            bullet.transform.position = bulletSpawnPoint.transform.position;
            bullet.Launch(projectileLayer.MaskToLayer(), direction, _playerConfig.BulletSpeed, elementDataObject.Value);
            ShotFired?.Invoke();

            yield return(new WaitForSeconds(_playerConfig.FireRate));
        }
    }
Exemplo n.º 11
0
        private void FireShot()
        {
            if (_shotTimer.Completed)
            {
                ShotFiredEventArgs args = new ShotFiredEventArgs
                {
                    Location  = Location + _gunOffset,
                    Velocity  = new Vector2(0, -1), // player can only fire on one direction
                    ShotSpeed = ShotSpeed,
                    FiredBy   = FiredBy.Player
                                // ShotBy = ShotBy.Player
                };

                ShotFired?.Invoke(this, args);
                _shotTimer.Reset();
            }
        }
Exemplo n.º 12
0
        private void FireTripleShot(Vector2 fireAngle)
        {
            Vector2 baseWeaponVector = fireAngle * WeaponSpeed;
            double  baseAngle        = Math.Atan2(baseWeaponVector.Y, baseWeaponVector.X);
            double  offset           = MathHelper.ToRadians(TripleWeaponSplitAngleDegrees);

            ShotFiredEventArgs shot1 = new ShotFiredEventArgs
            {
                Location = _turretSprite.WorldLocation,
                Velocity = baseWeaponVector,
                ShotType = ShotType.Bullet
            };

            ShotFiredEventArgs shot2 = new ShotFiredEventArgs
            {
                Location = _turretSprite.WorldLocation,
                Velocity = new Vector2(
                    (float)Math.Cos(baseAngle - offset),
                    (float)Math.Sin(baseAngle - offset)
                    ) * baseWeaponVector.Length(),
                ShotType = ShotType.Bullet
            };

            ShotFiredEventArgs shot3 = new ShotFiredEventArgs
            {
                Location = _turretSprite.WorldLocation,
                Velocity = new Vector2(
                    (float)Math.Cos(baseAngle + offset),
                    (float)Math.Sin(baseAngle + offset)
                    ) * baseWeaponVector.Length(),
                ShotType = ShotType.Bullet
            };

            ShotFired?.Invoke(this, shot1);
            ShotFired?.Invoke(this, shot2);
            ShotFired?.Invoke(this, shot3);

            _shotTimer.Reset();
        }
Exemplo n.º 13
0
        /// <summary>
        ///     Triggered regulary with wave input data.
        ///     Here we will analyze the audio data and detect shots.
        ///     When shots are detected the ShotFired() is invoked.
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">WaveInEventArgs. This one has a buffer byte array that represents audio data.</param>
        private void ReadingAvailableAudioData(object sender, WaveInEventArgs e)
        {
            // Transform the byte array to a MemoryStream
            var stream = new MemoryStream();

            stream.Write(e.Buffer, 0, e.BytesRecorded);
            stream.Position = 0;

            // Process the audio to detect shots
            var shotsFound = _shotDetector.ProcessAudio(stream);

            // The stopwatch needs to be running, or we will just discard those shots that occured before the Start
            if (!_stopWatch.IsRunning)
            {
                return;
            }

            // Shots found
            if (shotsFound.Length > 0)
            {
                // Invoke the ShotFired event, that MainWindow will catch
                ShotFired.Invoke(this, new ShotEventArgs(shotsFound));
            }
        }
Exemplo n.º 14
0
 private void EnemyShotFired(object sender, ShotFiredEventArgs e)
 {
     ShotFired?.Invoke(sender, e);
 }
Exemplo n.º 15
0
 internal void Notify(ShotFired e) => Body.FaceToward(e.Target);
Exemplo n.º 16
0
 internal static void InvokeShotFiredSecondary(WeaponScript weapon, int burstCount)
 => ShotFired?.Invoke(null, new WeaponFireEventArgs(weapon.gameObject)
 {
     IsPrimaryFire = false, BurstCount = burstCount
 });
Exemplo n.º 17
0
 private void OnShotFired(ShotFired obj)
 {
     Sound.SoundEffect("SFX/rifle-1.wav", DefaultVolume).Play();
 }
Exemplo n.º 18
0
 private void OnShotFired(ShotFired e) => e.Attacker.Notify(e);