Beispiel #1
0
        private void cache()
        {
            _cacheItem        = RightItem;
            _cachedComponent  = null;
            _cachedGun        = RightItem == null ? null : RightItem.GetComponent <BaseGun>();
            _cachedRightMelee = RightItem == null ? null : RightItem.GetComponent <BaseMelee>();
            _cachedLeftMelee  = LeftItem == null ? null : LeftItem.GetComponent <BaseMelee>();

            _cachedTool       = RightItem == null ? null : RightItem.GetComponent <Tool>();
            _cachedPhone      = RightItem == null ? null : RightItem.GetComponent <Phone>();
            _cachedRadio      = RightItem == null ? null : RightItem.GetComponent <Radio>();
            _cachedFlashlight = RightItem == null ? null : RightItem.GetComponent <Flashlight>();

            if (_cachedFlashlight == null && RightItem != null)
            {
                _cachedFlashlight = RightItem.GetComponentInChildren <Flashlight>();
            }

            if (_cachedPhone != null)
            {
                _cachedToolType = ToolType.phone;
            }
            else if (_cachedRadio != null)
            {
                _cachedToolType = ToolType.radio;
            }
            else if (_cachedFlashlight != null)
            {
                _cachedToolType = ToolType.flashlight;
            }
            else
            {
                _cachedToolType = ToolType.none;
            }
        }
Beispiel #2
0
 private void Awake()
 {
     _gun = GetComponent<BaseGun>();
 }
Beispiel #3
0
        private void Update()
        {
            if (!_actor.IsAlive)
            {
                return;
            }

            var wantsToAlwaysAim = AlwaysAim && _motor.Cover == null;

            if (wantsToAlwaysAim)
            {
                EquipWeapon(_motor);
            }

            var gun = _motor.EquippedWeapon.Gun;

            if (gun == null)
            {
                return;
            }

            if (_isReloading)
            {
                _isReloading = !_motor.IsGunReady;
            }
            else if (gun != null && gun.LoadedBulletsLeft <= 0)
            {
                _isReloading = true;
                _motor.InputReload();
            }

            var isObstructed = false;

            if (_isFiring && _isAimingAtAPosition)
            {
                var origin = transform.position;

                if (_motor.Cover != null && _motor.Cover.IsTall)
                {
                    if (_motor.CoverDirection > 0 && _motor.IsNearRightCorner)
                    {
                        origin = _motor.Cover.RightCorner(transform.position.y, _motor.CoverSettings.CornerOffset.x);
                    }
                    else if (_motor.CoverDirection < 0 && _motor.IsNearLeftCorner)
                    {
                        origin = _motor.Cover.LeftCorner(transform.position.y, _motor.CoverSettings.CornerOffset.x);
                    }
                }

                var start    = origin + Vector3.up * 2;
                var distance = Vector3.Distance(start, _aim);

                if (distance > 1.5f)
                {
                    isObstructed = AIUtil.IsObstructed(start, _aim);
                }
            }

            if (_motor.Cover == null && (_isAiming || wantsToAlwaysAim) && !_isReloading)
            {
                _motor.InputAim();
            }

            if (_isFiring && !_isReloading && !isObstructed)
            {
                var cycleDuration = _motor.Cover != null ? CoverBursts.CycleDuration : Bursts.CycleDuration;

                if (_fireCycle >= cycleDuration)
                {
                    if (_isFiringABurst)
                    {
                        _gunBurstsWereCalculatedFor = gun;
                        _burstBulletCount           = _bulletCountAtStart - gun.LoadedBulletsLeft;
                    }

                    _isFiringABurst = false;
                    _fireCycle     -= cycleDuration;

                    if (_gunBurstsWereCalculatedFor == gun && gun.LoadedBulletsLeft < _burstBulletCount)
                    {
                        _isReloading = true;
                        _motor.InputReload();
                    }
                }

                if (_motor.Cover != null)
                {
                    if (_fireCycle >= CoverBursts.Wait)
                    {
                        _motor.InputAim();

                        if (_fireCycle >= CoverBursts.Wait + CoverBursts.IntroDuration &&
                            _fireCycle < CoverBursts.CycleDuration - CoverBursts.OutroDuration)
                        {
                            if (!_isFiringABurst)
                            {
                                _bulletCountAtStart = gun.LoadedBulletsLeft;
                                _isFiringABurst     = true;
                            }

                            if (_motor.IsGunReady)
                            {
                                _motor.InputFireOnCondition(_actor.Side);
                            }
                        }
                    }
                }
                else
                {
                    _motor.InputAim();

                    if (_fireCycle >= Bursts.Wait)
                    {
                        if (!_isFiringABurst)
                        {
                            _bulletCountAtStart = gun.LoadedBulletsLeft;
                            _isFiringABurst     = true;
                        }

                        if (_motor.IsGunReady)
                        {
                            _motor.InputFireOnCondition(_actor.Side);
                        }
                    }
                }

                _fireCycle += Time.deltaTime;
            }
            else
            {
                _fireCycle      = 0;
                _isFiringABurst = false;
            }
        }