Exemple #1
0
    public override void Refresh()
    {
        Magazine.AmmoLeft = (int)WeaponItem.GetAttributeByName("_LoadedAmmos").Value;

        Magazine.LoadedAmmoID = (string)WeaponItem.GetAttributeByName("_LoadedAmmoID").Value;

        Item ammo = GameManager.Inst.ItemManager.LoadItem(Magazine.LoadedAmmoID);

        _ammoItem           = ammo;
        _projectilesPerShot = (int)ammo.GetAttributeByName("_numberOfProjectiles").Value;

        _isJammed = false;
    }
Exemple #2
0
    public bool TriggerPull()
    {
        //Debug.Log("trigger pull iscooled down " + _isCooledDown + " ammo left " + Magazine.AmmoLeft);
        //only jam gun for player
        if (Attacker.MyAI.ControlType == AIControlType.Player && Magazine.AmmoLeft > 0 && _isCooledDown)
        {
            if (_reloadToUnjam && _isJammed)
            {
                return(false);
            }

            //roll dice for gun jam
            if (UnityEngine.Random.value < _jamRate)
            {
                Magazine.AmmoLeft--;
                WeaponItem.SetAttribute("_LoadedAmmos", Magazine.AmmoLeft);
                GameManager.Inst.UIManager.HUDPanel.OnUpdateMagAmmo();

                if (_reloadToUnjam)
                {
                    _isJammed     = true;
                    _isCooledDown = false;
                }
                _isCooledDown = false;


                AudioSource audio = GetComponent <AudioSource>();
                if (audio != null)
                {
                    string    clipName = "dry_fire" + UnityEngine.Random.Range(1, 3).ToString();
                    AudioClip clip     = GameManager.Inst.SoundManager.GetClip(clipName);
                    audio.PlayOneShot(clip, 0.2f);
                }
                return(false);
            }
        }

        if (_isCooledDown && Magazine.AmmoLeft > 0)
        {
            FlashMuzzle();
            _isCooledDown  = false;
            _isTriggerDown = true;

            this.Attacker.Stealth.SetNoiseLevel(50, 0.8f);
            this.Attacker.Stealth.SetWeaponVisibilityBoost(20);

            Magazine.AmmoLeft--;
            //update weapon item attributes after each shot
            WeaponItem.SetAttribute("_LoadedAmmos", Magazine.AmmoLeft);
            AudioSource audio = GetComponent <AudioSource>();
            if (audio != null)
            {
                string    clipName = GunshotSoundName + "_shot" + UnityEngine.Random.Range(1, 5).ToString();
                AudioClip clip     = GameManager.Inst.SoundManager.GetClip(clipName);
                audio.PlayOneShot(clip, 0.13f);
            }
            //emit brass
            if (Attacker.MyAI.ControlType == AIControlType.Player && BrassEject != null && CurrentFireMode != GunFireModes.Pump)
            {
                BrassEject.Emit(1);
            }

            //handle drain of durability
            WeaponItem.Durability -= GameManager.Inst.Constants.DurabilityDrainRate;
            if (WeaponItem.Durability < 0)
            {
                WeaponItem.Durability = 0;
            }

            float accuMultiplier   = GameManager.Inst.Constants.GunAccuVsDurability.Evaluate(WeaponItem.Durability / WeaponItem.MaxDurability);
            float damageMultiplier = GameManager.Inst.Constants.GunDamageVsDurability.Evaluate(WeaponItem.Durability / WeaponItem.MaxDurability);
            _jamRate        = GameManager.Inst.Constants.GunJamVsDurability.Evaluate(WeaponItem.Durability / WeaponItem.MaxDurability);
            Barrel.Accuracy = (float)WeaponItem.GetAttributeByName("Accuracy").Value *accuMultiplier;
            Barrel.Impact   = (float)WeaponItem.GetAttributeByName("Impact").Value *damageMultiplier;

            _onSuccessfulShot();
            if (Attacker.MyAI.ControlType == AIControlType.Player)
            {
                GameManager.Inst.UIManager.HUDPanel.OnUpdateMagAmmo();
            }
            return(true);
        }


        return(false);
    }