public override void Telegraph()
    {
        base.Telegraph();

        //Vector3 direction = wielder.currentTarget.transform.position - wielder.LookOrigin;
        Vector3       direction = DetermineEnemyPosition() - wielder.LookOrigin;
        AttackMessage m         = AttackMessage.Ranged(wielder.characterData, wielder.LookOrigin, direction, stats.range, stats.projectilePrefab.diameter, stats.projectileSpread, stats.projectilePrefab.velocity, stats.projectilePrefab.hitDetection);

        EventJunction.Transmit(m);
        //EventObserver.TransmitAttack(m); // Transmits a message of the attack the player is about to perform
    }
Esempio n. 2
0
    void Update()
    {
        // Ensure things don't happen if the game is paused.
        if (Time.timeScale == 0)
        {
            return;
        }


        attackMessageLimitTimer += Time.deltaTime;

        // If the player is not switching weapons or fire modes, and is therefore able to operate the weapon
        if (isSwitchingWeapon == false && isSwitchingFireMode == false && playerHolding.weaponSelector.InSelection == false)
        {
            #region Firing mode controls
            float scrollInput = Input.GetAxis("Mouse ScrollWheel");
            if (scrollInput != 0 && firingModes.Length > 1) // Switch firing modes with the scroll wheel
            {
                int i = firingModeIndex;
                i -= (int)new Vector2(scrollInput, 0).normalized.x;
                i  = (int)Misc.InverseClamp(i, 0, firingModes.Length - 1);
                StartCoroutine(SwitchMode(i));
            }
            #endregion

            #region Fire controls
            fireControls.fireTimer += Time.deltaTime;

            // If player is active
            // If player is pressing fire button
            // If fireTimer has finished
            // If burst count has not exceeded the limit OR there is no burst limit
            // If ammo is available OR not required
            // If magazine is not empty OR null
            if (playerHolding.handler.PlayerState() == GameState.Active &&
                Input.GetButton("Fire") &&
                fireControls.fireTimer >= 60 / fireControls.roundsPerMinute &&
                (fireControls.burstCounter < fireControls.maxBurst || fireControls.maxBurst <= 0) &&
                (general.consumesAmmo == false || (playerHolding.handler.ammo.GetStock(general.ammoType) >= general.ammoPerShot)) &&
                (magazine == null || (magazine.data.current >= general.ammoPerShot && reloading == null)))
            {
                CancelReloadSequence();

                fireControls.fireTimer     = 0; // Reset fire timer to count up to next shot
                fireControls.burstCounter += 1;

                if (general.consumesAmmo == true)
                {
                    playerHolding.handler.ammo.Spend(general.ammoType, general.ammoPerShot);
                }

                if (magazine != null)
                {
                    magazine.data.current -= general.ammoPerShot;
                }

                recoilToApply += general.recoil;

                #region Calculate and fire shot
                Transform head         = playerHolding.handler.movement.head;
                Vector3   aimDirection = head.forward;
                if (optics == null || isAiming == false)
                {
                    float accuracy = playerHolding.standingAccuracy.Calculate();
                    aimDirection = Quaternion.Euler(Random.Range(-accuracy, accuracy), Random.Range(-accuracy, accuracy), Random.Range(-accuracy, accuracy)) * aimDirection;
                }

                general.Shoot(playerHolding.handler, head.position, aimDirection, head.up);
                #endregion

                #region Send attack message if the timer is right
                if (attackMessageLimitTimer >= attackMessageLimitDelay) // Sends attack message
                {
                    AttackMessage am = AttackMessage.Ranged(playerHolding.handler, transform.position, transform.forward, general.range, general.projectilePrefab.diameter, playerHolding.standingAccuracy.Calculate() + general.projectileSpread, general.projectilePrefab.velocity, general.projectilePrefab.hitDetection);
                    EventJunction.Transmit(am);


                    attackMessageLimitTimer = 0;
                }
                #endregion
            }
            else if (!Input.GetButton("Fire"))
            {
                fireControls.burstCounter = 0;
            }
            #endregion

            #region ADS and reload controls
            ADSHandler();

            /*
             * if (optics != null)
             * {
             *  optics.ADSHandler(this, currentMode);
             * }
             */
            ReloadHandler();
            #endregion
        }

        RecoilHandler(general.recoilApplyRate, playerHolding);
    }