Exemplo n.º 1
0
        protected virtual void Start()
        {
            FireMode          = m_GunData.PrimaryFireMode;
            m_FireInterval    = m_GunData.PrimaryRateOfFire;
            RoundsPerMagazine = m_GunData.RoundsPerMagazine;

            if (CurrentRounds == 0 && Magazines == 0)
            {
                SetAmmo(m_GunData.HasChamber ? RoundsPerMagazine + 1 : RoundsPerMagazine, (m_GunData.HasChamber ? RoundsPerMagazine + 1 : RoundsPerMagazine) * m_GunData.InitialMagazines);
            }

            if (m_MotionAnimation.Lean)
            {
                m_MotionAnimation.LeanAmount = 0;
            }

            switch (m_GunData.ReloadType)
            {
            case GunData.ReloadMode.Magazines:
                m_ReloadDuration         = new WaitForSeconds(m_GunAnimator.ReloadAnimationLength);
                m_CompleteReloadDuration = new WaitForSeconds(m_GunAnimator.FullReloadAnimationLength);
                break;

            case GunData.ReloadMode.BulletByBullet:
                m_StartReloadDuration     = new WaitForSeconds(m_GunAnimator.StartReloadAnimationLength);
                m_InsertInChamberDuration = new WaitForSeconds(m_GunAnimator.InsertInChamberAnimationLength / 2);
                m_InsertDuration          = new WaitForSeconds(m_GunAnimator.InsertAnimationLength / 2);
                m_StopReloadDuration      = new WaitForSeconds(m_GunAnimator.StopReloadAnimationLength);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            InitSwing(transform);
            DisableShadowCasting();

            m_FireButton   = InputManager.FindButton("Fire");
            m_AimButton    = InputManager.FindButton("Aim");
            m_ReloadButton = InputManager.FindButton("Reload");
            m_Melee        = InputManager.FindButton("Melee");
            m_FireMode     = InputManager.FindButton("Fire Mode");

            m_FPController.PreJumpEvent   += WeaponJump;
            m_FPController.LandingEvent   += WeaponLanding;
            m_FPController.VaultEvent     += Vault;
            m_FPController.GettingUpEvent += GettingUp;
        }
Exemplo n.º 2
0
        protected virtual void HandleInput()
        {
            // Restrictions:
            // Is firing = m_NextFireTime > Time.time
            // Is reloading = m_IsReloading || m_NextReloadTime > Time.time
            // Is empty = CurrentRounds == 0
            // Is running = m_FPController.State == MotionState.Running
            // Is attacking = m_Attacking
            // Is switching mode = m_NextSwitchModeTime > Time.time
            // Is interacting = m_NextInteractTime > Time.time
            // Can reload = Magazines > 0

            bool canShoot = !m_IsReloading && m_NextReloadTime < Time.time && m_NextFireTime < Time.time && CurrentRounds >= 0 &&
                            (m_FPController.State != MotionState.Running || m_FPController.IsSliding) && !m_Attacking &&
                            m_NextSwitchModeTime < Time.time && m_NextInteractTime < Time.time;

            if (canShoot)
            {
                if (FireMode == GunData.FireMode.FullAuto || FireMode == GunData.FireMode.ShotgunAuto)
                {
                    if (InputManager.GetButton(m_FireButton))
                    {
                        if (CurrentRounds == 0 && Magazines > 0)
                        {
                            Reload();
                        }
                        else
                        {
                            PullTheTrigger();
                        }
                    }
                }
                else if (FireMode == GunData.FireMode.Single || FireMode == GunData.FireMode.ShotgunSingle || FireMode == GunData.FireMode.Burst)
                {
                    if (InputManager.GetButtonDown(m_FireButton))
                    {
                        if (CurrentRounds == 0 && Magazines > 0)
                        {
                            Reload();
                        }
                        else
                        {
                            PullTheTrigger();
                        }
                    }
                }
            }

            if (m_GunData.ReloadType == GunData.ReloadMode.BulletByBullet && m_IsReloading && m_NextReloadTime < Time.time && CurrentRounds > (m_GunData.HasChamber ? 1 : 0))
            {
                if (InputManager.GetButtonDown(m_FireButton))
                {
                    m_IsReloading = false;
                    StartCoroutine(StopReload());
                }
            }

            bool canAim = !m_IsReloading && m_NextReloadTime < Time.time && m_FPController.State != MotionState.Running && !m_Attacking && m_NextInteractTime < Time.time;

            if (canAim)
            {
                if (GameplayManager.Instance.AimStyle == ActionMode.Toggle)
                {
                    if (InputManager.GetButtonDown(m_AimButton) && !m_Aiming)
                    {
                        m_Aiming = !m_Aiming;
                    }
                    else if (InputManager.GetButtonDown(m_AimButton) && m_Aiming && m_GunAnimator.IsAiming)
                    {
                        m_Aiming = !m_Aiming;
                    }
                }
                else
                {
                    m_Aiming = InputManager.GetButton(m_AimButton);
                }
            }
            else
            {
                m_Aiming = false;
            }

            bool canReload = !m_IsReloading && m_NextReloadTime < Time.time && CurrentRounds < (m_GunData.HasChamber ? RoundsPerMagazine + 1 : RoundsPerMagazine) && Magazines > 0 &&
                             !m_Attacking && m_NextSwitchModeTime < Time.time && m_NextInteractTime < Time.time && m_NextFireTime < Time.time;

            if (canReload)
            {
                if (InputManager.GetButtonDown(m_ReloadButton))
                {
                    Reload();
                }
            }

            bool canAttack = !m_Attacking && !m_IsReloading && m_NextReloadTime < Time.time && m_FPController.State != MotionState.Running && !IsAiming &&
                             m_NextFireTime < Time.time && m_GunAnimator.CanMeleeAttack && m_NextSwitchModeTime < Time.time && m_NextInteractTime < Time.time;

            if (canAttack)
            {
                if (InputManager.GetButtonDown(m_Melee))
                {
                    StartCoroutine(MeleeAttack());
                }
            }

            bool canChangeFireMode = HasSecondaryMode && !m_Attacking && !m_IsReloading &&
                                     m_NextReloadTime < Time.time && m_FPController.State != MotionState.Running && m_NextSwitchModeTime < Time.time &&
                                     m_NextInteractTime < Time.time;

            if (canChangeFireMode)
            {
                if (InputManager.GetButtonDown(m_FireMode))
                {
                    if (FireMode == m_GunData.PrimaryFireMode)
                    {
                        m_NextSwitchModeTime = Time.time + m_GunAnimator.SwitchModeAnimationLength;
                        m_GunAnimator.SwitchMode();

                        FireMode       = m_GunData.SecondaryFireMode;
                        m_FireInterval = m_GunData.SecondaryRateOfFire;
                    }
                    else
                    {
                        m_NextSwitchModeTime = Time.time + m_GunAnimator.SwitchModeAnimationLength;
                        m_GunAnimator.SwitchMode();

                        FireMode       = m_GunData.PrimaryFireMode;
                        m_FireInterval = m_GunData.PrimaryRateOfFire;
                    }
                }
            }
        }