protected void DoKnockback(WeaponAttackParams parameters)
    {
        GameObject      player = GameObject.FindGameObjectWithTag("Player");
        PlayerBehaviour pc     = player.GetComponent <PlayerBehaviour>();

        pc.DoKnockback(-parameters.direction.normalized * knockback);
    }
Beispiel #2
0
    public override void DoAttack(WeaponAttackParams parameters)
    {
        if (!CanAttack())
        {
            return;
        }
        base.DoAttack(parameters);

        //TODO play animation
        RaycastHit2D[] hits = Physics2D.CircleCastAll(flame.position, radius, parameters.direction, length);
        Debug.DrawRay(flame.position, parameters.direction.normalized * length, Color.red);
        foreach (RaycastHit2D hit in hits)
        {
            GameObject hitGo = hit.collider.gameObject;
            if (hitGo.tag == "Enemy" && hitGo.GetComponent <OngoingDamageEffect>() == null)
            {
                OngoingDamageEffect sc = hitGo.AddComponent <OngoingDamageEffect>() as OngoingDamageEffect;
            }
        }

        if (!isAttacking)
        {
            flameAnimator.SetTrigger("startFire");
        }

        isAttacking = true;
    }
    protected void SpawnPojectile(WeaponAttackParams parameters)
    {
        Projectile p = Instantiate(projectilePrefab, projectileSpawnPoint.position, Quaternion.identity).GetComponent <Projectile>();

        p.SetVariables(this, parameters.direction);
        OnProjectileSpawn(parameters, p);
    }
Beispiel #4
0
 private void CheckUserInput()
 {
     if (Input.GetKey(KeyCode.Mouse0))
     {
         WeaponAttackParams parameters = new WeaponAttackParams();
         DoAttack(parameters);
     }
 }
Beispiel #5
0
 private void CheckContinuousUserInput()
 {
     if (Input.GetKeyDown(KeyCode.Mouse0))
     {
         WeaponAttackParams parameters = new WeaponAttackParams();
         DoAttack(parameters);
     }
     if (Input.GetKeyUp(KeyCode.Mouse0))
     {
         ((FlamethrowerWeapon)currentWeaponHand.GetWeapon()).StopAttack();
     }
 }
    public override void DoAttack(WeaponAttackParams parameters)
    {
        if (!CanAttack())
        {
            return;
        }
        base.DoAttack(parameters);

        SimulateRecoil();
        SpawnPojectile(parameters);
        DoKnockback(parameters);
    }
Beispiel #7
0
    private void DoAttack(WeaponAttackParams parameters)
    {
        Vector3 mousePosition = GetMousePosition();

        MoveMeleeWeapon(mousePosition);

        Vector3 direction = mousePosition - transform.position;

        parameters.parent    = gameObject;
        parameters.direction = direction;

        currentWeaponHand.GetWeapon().DoAttack(parameters);
    }
Beispiel #8
0
 private void CheckChargedUserInput()
 {
     if (Input.GetKeyDown(KeyCode.Mouse0))
     {
         currentChargeTime = Time.time;
     }
     if (Input.GetKeyUp(KeyCode.Mouse0))
     {
         float chargeTime = Time.time - currentChargeTime;
         WeaponAttackParams parameters = new WeaponAttackParams();
         parameters.chargeTime = chargeTime;
         DoAttack(parameters);
     }
 }
Beispiel #9
0
 public static bool TryFire(Ped ped, WeaponAttackParams weaponAttackParams)
 {
     if (ped.CurrentWeapon != null)
     {
         if (Net.NetStatus.IsServer)
         {
             if (ped.IsControlledByLocalPlayer || null == ped.PlayerOwner)
             {
                 return(TryFire(ped, ped.FirePosition, ped.FireDirection, weaponAttackParams));
             }
             else                        // this ped is owned by remote client
             {
                 return(TryFire(ped, ped.NetFirePos, ped.NetFireDir, weaponAttackParams));
             }
         }
     }
     return(false);
 }
Beispiel #10
0
    public override void DoAttack(WeaponAttackParams parameters)
    {
        if (!CanAttack())
        {
            return;
        }
        base.DoAttack(parameters);

        Debug.Log("Player melee attack");
        DoSwing();
        RaycastHit2D[] targets = Physics2D.CircleCastAll(parameters.parent.transform.position, swingRadius, parameters.direction, swingLength);
        foreach (RaycastHit2D target in targets)
        {
            if (target.transform.CompareTag("Enemy"))
            {
                //Debug.Log("Hit: " + target.transform.gameObject.name);
                target.transform.gameObject.GetComponent <EnemySimpleBehaviour>().TakeDamage(damage);
            }
        }
    }
Beispiel #11
0
 protected override void OnProjectileSpawn(WeaponAttackParams parameters, Projectile projectile)
 {
     projectile.ApplySpeedMultiplier(GetSpeedMultiplier(parameters.chargeTime));
 }
Beispiel #12
0
        public static Vector3 GetFireDirection(Ped ped, System.Func <bool> isAimingBackFunc, WeaponAttackParams weaponAttackParams)
        {
            if (null == ped.CurrentWeapon)
            {
                return(ped.AimDirection);
            }

            if (isAimingBackFunc())
            {
                return(ped.transform.up);
            }

            if (ped.IsControlledByLocalPlayer && ped.Camera != null)
            {
                // find ray going into the world
                Ray ray = ped.Camera.GetRayFromCenter();

                // raycast
                RaycastHit hit;
                if (ped.CurrentWeapon.ProjectileRaycast(ray.origin, ray.direction, out hit, weaponAttackParams))
                {
                    return((hit.point - ped.FirePosition).normalized);
                }

                // if any object is hit, direction will be from fire position to hit point

                // if not, direction will be same as aim direction
            }

            return(ped.AimDirection);
        }
Beispiel #13
0
        public static bool TryFire(Ped ped, Vector3 firePos, Vector3 fireDir, WeaponAttackParams weaponAttackParams)
        {
            bool isServer = Net.NetStatus.IsServer;
            var  weapon   = ped.CurrentWeapon;


            if (!isServer)              // for now, do this only on server
            {
                return(false);
            }

            if (Net.NetStatus.IsClientOnly && !ped.IsControlledByLocalPlayer)
            {
                return(false);
            }

            if (null == weapon)
            {
                return(false);
            }

            if (ped.IsFiring)                   // already firing
            {
                return(false);
            }

            // check if there is ammo in clip
            if (weapon.AmmoInClip < 1)
            {
                return(false);
            }

            if (isServer)
            {
                ped.StartFiring();

                if (!ped.IsFiring)                      // failed to start firing
                {
                    return(false);
                }
            }

            // reduce ammo
            weapon.AmmoInClip--;

            // update gun flash
            //	this.EnableOrDisableGunFlash (ped);
            if (weapon.GunFlash != null)
            {
                weapon.GunFlash.gameObject.SetActive(true);
            }
            weapon.UpdateGunFlashRotation();

            // fire projectile
            if (isServer)
            {
                F.RunExceptionSafe(() => weapon.FireProjectile(firePos, fireDir, weaponAttackParams));
            }

            // send fire event to server
            if (Net.NetStatus.IsClientOnly && ped.IsControlledByLocalPlayer)
            {
            }

            // play firing sound
            F.RunExceptionSafe(() => weapon.PlayFireSound());

            // notify clients
            if (isServer)
            {
                Net.PedSync.OnWeaponFired(ped, weapon, firePos);
            }


            return(true);
        }
Beispiel #14
0
 public virtual void DoAttack(WeaponAttackParams parameters)
 {
     //Debug.Log("weapon attack");
     lastAttack = Time.time;
     PlayAnimation();
 }
 protected virtual void OnProjectileSpawn(WeaponAttackParams parameters, Projectile projectile)
 {
     //NOOP
 }