Ejemplo n.º 1
0
    private bool Fire()
    {
        if (RaiseTimer > 0f)
        {
            return(false);
        }
        if (HolsterTimer > 0f)
        {
            return(false);
        }

        if (attackCooldownTimer <= 0f)
        {
            if (UsesAmmo >= 0)
            {
                if (character.ammunition[UsesAmmo] < AmmoUseAmount)
                {
                    Messaging.GUI.ScreenMessage.Invoke("OUT OF AMMO", Color.red);
                    Sounds.CreateSound(EmptySound);
                    attackCooldownTimer = .4f;
                    return(false);
                }

                character.ammunition[UsesAmmo] -= AmmoUseAmount;
            }

            attackCooldownTimer = attackCooldown;

            if (SprayPrefab != null)
            {
                Spray spray = Instantiate(SprayPrefab, LevelLoader.DynamicObjects);
                spray.owner              = character;
                spray.Damage             = SprayDamage;
                spray.damageType         = SprayDamageType;
                spray.LifeTime           = SprayLifeTime;
                spray.Force              = SprayForce;
                spray.Speed              = SpraySpeed;
                spray.BurnTotalDamage    = SprayTotalDamage;
                spray.DamagePerBurn      = DamagePerApplication;
                spray.RadiusOverLifetime = SprayRadius;

                //make a special raycasting move from character to barrel
                spray.transform.position = character.transform.position;
                spray.InitialMove((_weaponPrefab.transform.position + _weaponPrefab.transform.rotation * SprayPosition) - character.transform.position);

                if (AttackDirection == Vector2.zero)
                {
                    spray.transform.rotation = character.LookDirection;
                }
                else
                {
                    spray.transform.rotation = Quaternion.Euler(0, 0, Mathf.Atan2(AttackDirection.x, -AttackDirection.y) * Mathf.Rad2Deg);
                }

                //add spread
                float firstRoll  = Random.Range(-spread, spread);
                float secondRoll = Random.Range(-spread, spread);

                spray.transform.rotation *= Quaternion.Euler(0, 0, Mathf.Abs(firstRoll) < Mathf.Abs(secondRoll) ? firstRoll : secondRoll);

                //inherit speed
                spray.Speed += InheritSpeed * Vector2.Dot(character.physicsBody.velocity, character.LookDirection * Vector3.right);

                spray.GetComponent <SaveGameObject>().SpawnName = SprayDesignation;
            }
        }

        if (UsesAmmo >= 0 && character.ammunition[UsesAmmo] < AmmoUseAmount)
        {
            return(false);
        }

        OnFire.Invoke();

        return(true);
    }