示例#1
0
        private void SetFiringMode()
        {
            if (gameController.score >= firingModeSteps[FiringMode.Single])
            {
                firingMode = FiringMode.Single;
                guns.First(x => x.name == "Main").isActive      = true;
                guns.First(x => x.name == "Port").isActive      = false;
                guns.First(x => x.name == "Starboard").isActive = false;
            }

            if (gameController.score >= firingModeSteps[FiringMode.Double])
            {
                firingMode = FiringMode.Double;
                guns.First(x => x.name == "Main").isActive      = false;
                guns.First(x => x.name == "Port").isActive      = true;
                guns.First(x => x.name == "Starboard").isActive = true;
            }

            if (gameController.score >= firingModeSteps[FiringMode.Triple])
            {
                firingMode = FiringMode.Triple;

                guns.First(x => x.name == "Main").isActive      = true;
                guns.First(x => x.name == "Port").isActive      = true;
                guns.First(x => x.name == "Starboard").isActive = true;
            }
        }
示例#2
0
        void Start()
        {
            fireRate   = 0.3f;
            speed      = 10;
            tilt       = 4;
            firingMode = FiringMode.Single;

            firingModeSteps = new Dictionary <FiringMode, float>
            {
                { FiringMode.Single, 0 },
                { FiringMode.Double, 250 },
                { FiringMode.Triple, 750 }
            };

            firingRateSteps = new Dictionary <float, float>
            {
                { 0.3f, 0 },
                { 0.25f, 500 },
                { 0.20f, 1000 }
            };

            // TODO: use singleton pattern to reference game controller
            var gameControllerObject = GameObject.FindWithTag("GameController");

            if (gameControllerObject != null)
            {
                gameController = gameControllerObject.GetComponent <GameController>();
            }

            if (gameController == null)
            {
                Debug.Log("Cannot find 'GameController' script");
            }
        }
示例#3
0
        /// <summary>
        /// Construct a state machine with external state storage.
        /// </summary>
        /// <param name="stateAccessor">A function that will be called to read the current state value.</param>
        /// <param name="stateMutator">An action that will be called to write new state values.</param>
        /// <param name="firingMode">Optional specification of fireing mode.</param>
        public StateMachine(Func <TState> stateAccessor, Action <TState> stateMutator, FiringMode firingMode) : this()
        {
            _stateAccessor = stateAccessor ?? throw new ArgumentNullException(nameof(stateAccessor));
            _stateMutator  = stateMutator ?? throw new ArgumentNullException(nameof(stateMutator));

            _firingMode = firingMode;
        }
    protected void LateUpdate()
    {
        if (interactable.attachedToHand)
        {
            if (firearm_fire.GetStateDown(interactable.attachedToHand.handType))
            {
                if (firingRoutine == null)
                {
                    firingRoutine = StartCoroutine(DoTrigger(interactable.attachedToHand));
                }
            }

            if (firearm_zoom.GetStateDown(interactable.attachedToHand.handType))
            {
                onScopeZoomLevelChanged.Invoke();
            }

            if (firearm_mode.GetStateDown(interactable.attachedToHand.handType))
            {
                var cnt = System.Enum.GetValues(typeof(FiringMode)).Length;
                mode = (FiringMode)mod((int)mode + 1, cnt);

                PlayOneshotAudio(changeModeClip);
            }
        }
    }
示例#5
0
    protected override void Start()
    {
        base.Start();

        if (!profile)
        {
            profile = new GunProfile();
        }

        m_fireForce      = profile.firingForce;
        m_fireRate       = profile.firingRate;
        m_fireMode       = profile.firingMode;
        m_burstSize      = profile.burstSize;
        m_magazineSize   = profile.magazineSize;
        m_reloadClipSize = profile.reloadClipSize;
        m_warmUpTime     = profile.warmUpTime;
        m_overheatTime   = profile.overheatTime;
        m_cooldownTime   = profile.cooldownTime;

        shotsRemaining = m_magazineSize;
        burstCount     = 0;
        FiredCount     = 0;

        warmUpTimer   = 0;
        overheatTimer = 0;
        cooldownTimer = 0;

        if (OnBulletFired == null)
        {
            OnBulletFired = new UnityEvent();
        }

        if (OnMagazineEmpty == null)
        {
            OnMagazineEmpty = new UnityEvent();
        }

        if (OnReload == null)
        {
            OnReload = new UnityEvent();
        }

        if (OnBurstStart == null)
        {
            OnBurstStart = new UnityEvent();
        }

        if (OnBurstDone == null)
        {
            OnBurstDone = new UnityEvent();
        }

        OnProjectileSpawned.AddListener(FireBullet);
        OnProjectileRaycast.AddListener(RaycastBullet);
    }
示例#6
0
 public Weapon(Mesh mesh, Material material, float zoomModifier, int magSize, Projectile projectile, float reloadTime, FiringMode firingMode, float fireRate)
 {
     this.mesh         = mesh;
     this.material     = material;
     this.zoomModifier = zoomModifier;
     this.magSize      = magSize;
     this.projectile   = projectile;
     this.reloadTime   = reloadTime;
     this.firingMode   = firingMode;
     this.fireRate     = fireRate;
 }
示例#7
0
        /// <summary>
        /// Construct a state machine.
        /// </summary>
        /// <param name="initialState">The initial state.</param>
        /// <param name="firingMode">Optional specification of fireing mode.</param>
        public StateMachine(TState initialState, FiringMode firingMode) : this()
        {
            var reference = new StateReference {
                State = initialState
            };

            _stateAccessor = () => reference.State;
            _stateMutator  = s => reference.State = s;

            _firingMode = firingMode;
        }
示例#8
0
    private void SwichFiringMode()
    {
        //dohvatiti length od enuma i spremiti ga u int
        int firingModeLength = System.Enum.GetValues(typeof(FiringMode)).Length;

        FiringMode++;

        //provjeriti da li je broj veci od enuma
        if ((int)FiringMode >= firingModeLength)
        {
            FiringMode = FiringMode.Semi;
        }

        GameManger.Instance.ChangeFireMode(FiringMode);
    }
示例#9
0
        public ProjectileWeapon(double projectilePain, double projectileRadius, double projectileMass, double projectileSpeed, bool produceKick, bool ignoreOtherProjectiles, RadarBlipQual projectileQual, bool enforceFiringModeOuterTime, SimpleMap map, MyVector boundryLower, MyVector boundryUpper)
        {
            _projectileSettings         = new ProjectileSettings(projectileSpeed, projectileRadius, projectileMass, projectilePain, ignoreOtherProjectiles, projectileQual);
            _enforceFiringModeOuterTime = enforceFiringModeOuterTime;
            _map         = map;
            _produceKick = produceKick;

            if (boundryLower != null && boundryUpper != null)
            {
                _useBoundry   = true;
                _boundryLower = boundryLower;
                _boundryUpper = boundryUpper;
            }

            _elapsedTime = new FiringMode(0, 0, 0);
        }
        public ProjectileWeapon(double projectilePain, double projectileRadius, double projectileMass, double projectileSpeed, bool produceKick, bool ignoreOtherProjectiles, RadarBlipQual projectileQual, bool enforceFiringModeOuterTime, SimpleMap map, MyVector boundryLower, MyVector boundryUpper)
        {
            _projectileSettings = new ProjectileSettings(projectileSpeed, projectileRadius, projectileMass, projectilePain, ignoreOtherProjectiles, projectileQual);
            _enforceFiringModeOuterTime = enforceFiringModeOuterTime;
            _map = map;
            _produceKick = produceKick;

            if (boundryLower != null && boundryUpper != null)
            {
                _useBoundry = true;
                _boundryLower = boundryLower;
                _boundryUpper = boundryUpper;
            }

            _elapsedTime = new FiringMode(0, 0, 0);
        }
示例#11
0
 protected virtual void Start()
 {
     myAudio = GetComponent<AudioSource>();
     fireMode = FiringMode.Single;
 }
示例#12
0
 public void ShowRangeItemInfo(string name, string description, float value, float weight, float amount, float usage,
                               projectileType projectile, FiringMode firingMode, int magazineSize)
 {
     //show range item panel with info in arguments in position of cursor
 }
示例#13
0
    public virtual void Update()
    {
        if (!isClient)
        {
            return; // Standalone server does not animate.
        }
        // Animation speeds.
        if (animation.Animator != null)
        {
            animation.Animator.SetFloat("ReloadMultiplier", ReloadSpeedMultiplier);
            animation.Animator.SetFloat("ShootMultiplier", ShootSpeedMultiplier);
        }

        // Shooting...
        if (!hasAuthority || gun.Item == null || !gun.Item.IsEquipped())
        {
            return; // Owner only...
        }
        // Change firing mode...
        if (InputManager.InputDown("Firing Mode"))
        {
            NextFiringMode();
        }

        if (bulletsInMagazine > Capacity.MagazineCapacity)
        {
            bulletsInMagazine = Capacity.MagazineCapacity;
            Debug.Log("Reduced bullet amount");
        }

        FiringMode = AllowedModes[firingModeIndex];

        bool requestingShoot = ShootNow();
        bool ready           = animation.IsAiming && BulletInChamber && !animation.IsDropped && !animation.IsChambering && !animation.IsReloading;

        if (requestingShoot && bulletsInMagazine == 0 && !BulletInChamber)
        {
            if (!ErrorMessageUI.Instance.IsDisplaying)
            {
                ErrorMessageUI.Instance.DisplayMessage = "Reload [" + InputManager.GetInput("Reload").ToString() + "]";
            }
        }

        // Problem: We tell server to shoot more than once, beucase:
        // 1. We request one shot, one frame.
        // 2. Shoot bool reaches server.
        // 3. Shoot bool reaches client again...
        // 4. The user is not longer requesting a shot - but the server doesn't know that yet!
        // 5. The client is not updated in time, and shoots too many times.

        // Solution:
        // If in single or burst fire modes, CMD and RPC are used?

        //animation.AnimShoot(requestingShoot && ready); // Pew pew!
        if ((this.FiringMode == FiringMode.SEMI || this.FiringMode == FiringMode.BURST) && requestingShoot && ready && !animation.IsBlocked)
        {
            animation.CmdAnimShootOnce(this.FiringMode == FiringMode.SEMI);
        }
        else if (requestingShoot && ready)
        {
            animation.AnimShoot(true);
        }
        else
        {
            animation.AnimShoot(false);
        }

        bool requestingChamber = !BulletInChamber && CanChamber();

        ready = !animation.IsChambering && !animation.IsEquipping && !animation.IsAiming && !ReloadAutoChambers;
        if (requestingChamber && ready)
        {
            // Chamber new bullet!
            animation.AnimChamber();
        }

        bool requestingReload = InputManager.InputDown("Reload");

        ready = !animation.IsReloading && !animation.IsAiming && !animation.IsChambering && !animation.IsDropped && CanReload();

        if (requestingReload && ready)
        {
            if (ReloadEjectsChambered)
            {
                BulletInChamber = false;
            }

            // Reload!
            animation.AnimReload();
        }

        UpdateInaccuracy();
    }
示例#14
0
 public FiringPatternStep(float duration, FiringMode firingMode)
 {
     this.duration   = duration;
     this.firingMode = firingMode;
 }
示例#15
0
 private void ToggleFiringMode()
 {
     firingMode = firingMode == FiringMode.Single ? FiringMode.Dual : FiringMode.Single;
 }
示例#16
0
 public void ChangeFireMode(FiringMode newFireMode)
 {
     FireModeText.text = newFireMode.ToString();
 }
示例#17
0
 protected virtual void Start()
 {
     myAudio  = GetComponent <AudioSource>();
     fireMode = FiringMode.Single;
 }
示例#18
0
 void Start()
 {
     firingMode = new NormalFiringMode();
     StartCoroutine(Shoot());
 }