private void BoostPlayer(string boostType)
    {
        if (!shield)
        {
            if (boostType == "Shield")
            {
                shield    = true;
                shielding = Instantiate(shieldPrefab, transform.position, Quaternion.identity);
            }
        }

        if (boostType == "Health")
        {
            if (health < healthBar.GetMaxHealthSlider())
            {
                if (health < healthBar.GetMaxHealthSlider() - 100)
                {
                    health += 100;
                }
                else
                {
                    health = healthBar.GetMaxHealthSlider();
                }

                healthBar.SetHealthSlider(health);
            }
        }

        if (boostType == "Energy")
        {
            DamageDealer playerDamage = laserPrefab.GetComponent <DamageDealer>();
            playerDamage.SetDamage(playerDamage.GetDamage() * 1.2f);
            FindObjectOfType <BoostStats>().AddEnergyStat();
        }
    }
Example #2
0
    private void FireWeaponAtTarget()
    {
        timeSinceLastShot -= Time.deltaTime;
        if (!target)
        {
            return;
        }
        Vector3 dir  = target.transform.position - transform.position;
        float   diff = dir.magnitude;

        //Debug.Log("distance: " + diff + ". AtkRng: " + attackRange);
        if (diff <= attackRange && timeSinceLastShot <= 0)
        {
            sh.SpikeLoudnessDueToAttack();
            AudioSource.PlayClipAtPoint(selectedFiringSound, transform.position);
            selectedFiringSound = SelectSoundFromArray(firingSounds);
            float      zAng   = Vector3.SignedAngle(Vector2.up, dir, Vector3.forward);
            Quaternion rot    = Quaternion.Euler(0, 0, zAng);
            GameObject bullet = Instantiate(weaponPrefab, transform.position + (dir * bulletOffset), rot) as GameObject;
            bullet.GetComponent <Rigidbody2D>().velocity = weaponSpeed * bullet.transform.up;
            DamageDealer dd = bullet.GetComponent <DamageDealer>();
            dd.SetDamage(weaponDamage);
            dd.SetAttackSource(gameObject);
            Destroy(bullet, weaponLifetime);
            timeSinceLastShot = timeBetweenShots;
        }
    }
    public override void OnInit()
    {
        base.OnInit();
        DamageDealer dd = GetComponentInChildren <DamageDealer>();

        GetComponentInChildren <DamageTaker>().Init(OnTakeDamage);
        dd.Init(OnGiveDamage);
        dd.SetDamage(999);
        dd.AddTargetLayer(8);
        dd.AddTargetLayer(10);
    }
    public override void OnStart()
    {
        base.OnStart();
        animator = GetComponent <Animator>();
        DamageDealer dd = GetComponentInChildren <DamageDealer>();

        GetComponentInChildren <DamageTaker>().Init(OnTakeDamage);
        dd.Init(null);
        dd.SetDamage(999);
        dd.AddTargetLayer(8);
        dd.AddTargetLayer(10);
    }
Example #5
0
    private void RpcDisplaySimAttackOnClients(Vector3 pos, Quaternion rot)
    {
        GameObject bullet = Instantiate(weaponPrefab, pos, rot) as GameObject;

        bullet.GetComponent <Rigidbody2D>().velocity = bullet.transform.up * weaponSpeed;
        DamageDealer dd = bullet.GetComponent <DamageDealer>();

        dd.Simulated = true;
        dd.SetDamage(0);
        dd.SetAttackSource(gameObject);
        Destroy(bullet, weaponLifetime);
    }
Example #6
0
    public override void AttackCommence()
    {
        if (timeSinceLastAttack < 0 && energy.GetCurrentEnergy() >= energyCost)
        {
            sh.SpikeLoudnessDueToAttack();
            AudioSource.PlayClipAtPoint(selectedFiringSound, transform.position);
            GameObject shell = Instantiate(projectilePrefab, transform.position + (transform.up * offset), transform.rotation) as GameObject;
            shell.GetComponent <Rigidbody2D>().velocity = shell.transform.up * weaponSpeed;
            DamageDealer dd = shell.GetComponent <DamageDealer>();
            dd.SetAttackSource(transform.root.gameObject);
            dd.SetDamage(weaponDamage);

            Destroy(shell, weaponLifetime);

            timeSinceLastAttack = timeBetweenAttacks;
            energy.ModifyCurrentEnergy(-1 * energyCost);
        }
    }
 public virtual Missile InitMissile(Vector3 position, int[] layers, string[] tags, AttackingUnitI owner)
 {
     isActive           = true;
     dieTimer           = 2.5f;
     transform.position = position;
     dDealer            = GetComponentInChildren <DamageDealer>();
     foreach (var layer in layers)
     {
         dDealer.AddTargetLayer(layer);
     }
     foreach (var tag in tags)
     {
         dDealer.AddTargetTag(tag);
     }
     this.owner = owner;
     dDealer.SetDamage(1);
     dDealer.enabled = false;
     return(this);
 }
Example #8
0
    protected override void ExecuteAttackOnServer()
    {
        // Server-side validation of shot. Sufficient time between shots? Enough energy? Perhaps take in client's believed position and allow it
        // to be the source of the shot as long as its within a certain range of server-true position.
        if (timeSinceLastAttack < 0)
        {
            Debug.Log("execute attack on server");
            GameObject bullet = Instantiate(projectilePrefab, weaponSource.position + (weaponSource.up * offset), weaponSource.rotation) as GameObject;
            bullet.GetComponent <Rigidbody2D>().velocity = bullet.transform.up * weaponSpeed;
            DamageDealer dd = bullet.GetComponent <DamageDealer>();
            dd.Simulated = false;
            dd.SetDamage(weaponDamage);
            Destroy(bullet, weaponLifetime);
            timeSinceLastAttack = timeBetweenAttacks;

            sh.SpikeLoudnessDueToAttack();


            RpcDisplaySimAttackOnClients();
        }
    }
Example #9
0
 private void IncreaseDamage()
 {
     newDamage     = currentDamage * damageMultiplier;
     currentDamage = newDamage;
     damage.SetDamage(newDamage);
 }