public override bool DoAttack(GameObject target, Pawn user)
    {
        if (Ammo > 0)
        {
            Ammo--;
        }
        else if (Ammo == 0)
        {
            return(false);
        }
        //Else if ammo < 0 then player has "infinite" ammo

        //Just basic hitscan
        if (_anim)
        {
            _anim.SetTrigger("attack");
        }

        RaycastHit hit;

        if (Physics.Raycast(transform.position, transform.forward, out hit, maxRange, hittable, QueryTriggerInteraction.Ignore))
        {
            DamageReciever.DealDamageToTarget(hit.transform.gameObject, ScaleDamageByCharge(Damage), user, hit);
            return(true);
        }

        return(false);
    }
Exemple #2
0
    public override bool DoAttack(GameObject target, Pawn user)
    {
        if (_anim)
        {
            _anim.SetTrigger("attack");
        }

        if (target)
        {
            RaycastHit?hitInfo = null;
            if (user is PlayerPawn)
            {
                PlayerPawn playerUser = user as PlayerPawn;
                hitInfo = playerUser.Raycaster.RaycastInfo.HitInfo;
            }

            DamageReciever.DealDamageToTarget(target, ScaleDamageByCharge(Damage), user, hitInfo);
            ResetAttackCharge();

            if (AttackCharge >= 0.848f)
            {
                Collider[] foundColliders = Physics.OverlapSphere(target.transform.position, SweepAttackRadius, Physics.AllLayers, QueryTriggerInteraction.Ignore);
                foreach (Collider col in foundColliders)
                {
                    Pawn foundPawn = col.GetComponent <Pawn>();
                    if (foundPawn)
                    {
                        bool hitThisPawn = true;

                        if (user)
                        {
                            hitThisPawn = user.MyFaction != foundPawn.MyFaction;
                        }

                        if (hitThisPawn)
                        {
                            DamageReciever.DealDamageToTarget(target, SweepAttackDamage, user, hitInfo);
                        }
                    }
                }
            }

            return(true);
        }

        ResetAttackCharge();
        return(false);
    }
    protected virtual void CollideWith(RaycastHit hitInfo)
    {
        DamageReciever.DealDamageToTarget(hitInfo.transform.gameObject, _damage, _source, hitInfo);
        if (AfterCollisionLifeTime > 0 && !hitInfo.transform.GetComponent <ProjectileNonStick>())
        {
            Destroy(gameObject, AfterCollisionLifeTime);
        }
        else
        {
            Destroy(gameObject);
        }

        FreezePosition   = true;
        transform.parent = hitInfo.transform;
        _trail.enabled   = false;
    }
 public override bool DoAttack(GameObject target, Pawn user)
 {
     if (_anim)
     {
         _anim.SetTrigger("attack");
     }
     if (target)
     {
         DamageReciever.DealDamageToTarget(target, ScaleDamageByCharge(Damage), user);
         ResetAttackCharge();
         return(true);
     }
     ResetAttackCharge();
     //If no target found to take damage, return false.
     return(false);
 }