Example #1
0
    void Die()
    {
        //item drop
        //int randomChance = (int)Random.Range(0, itemDropChance);
        //print(randomChance);
        if (/*randomChance == 0*/ LootCounter.ShouldDropLoot(lvl.level))
        {
            Debug.LogWarning("item dropped");
            GameObject myItem = (GameObject)Instantiate(itemDrop, transform.position + Vector3.up, transform.rotation);
            if (myItem.GetComponent <GunDrop>())
            {
                myItem.GetComponent <GunDrop>().MakeGun(lvl.level, lvl.rarity);
            }
        }

        //Debug.LogError("lel");
        //give xp
        int xpToGive = xp + Random.Range(-xpRange, xpRange);

        XpGiver.giveXp(xpToGive);
        ScoreController.myScore.AddScore((int)((float)xpToGive * Random.Range(1f, Mathf.Sqrt((float)lvl.level))));
    }
Example #2
0
    void Explode()
    {
        //explosion
        Vector3 explosionPos = transform.position;

        Collider[] colliders = Physics.OverlapSphere(explosionPos, radious);
        foreach (Collider hit in colliders)
        {
            if (hit != null && hit.GetComponent <Rigidbody>() || hit.GetComponentInParent <Rigidbody>())
            {
                if (hit.GetComponent <ExplosionAffection> ())
                {
                    hit.GetComponent <ExplosionAffection> ().GetEffected();
                }
                else if (hit.GetComponentInParent <ExplosionAffection>())
                {
                    hit.GetComponentInParent <ExplosionAffection> ().GetEffected();
                }


                if (hit.GetComponent <Rigidbody> ())
                {
                    hit.GetComponent <Rigidbody>().AddExplosionForce(power, explosionPos, radious, 3.0f);
                }
                else if (hit.GetComponentInParent <Rigidbody>())
                {
                    hit.GetComponentInParent <Rigidbody>().AddExplosionForce(power, explosionPos, radious, 3.0f);
                }
            }

            //deal damage
            if (distance < maxRange)
            {
                if (hit.GetComponent <Health>())
                {
                    Health dealtarget = hit.gameObject.GetComponent <Health>();
                    dealtarget.Damage((int)((float)damage * (1f - (distance / maxRange))), transform);
                    if (dealtarget.health <= 0 && dealtarget.isAlive)
                    {
                        Instantiate(killerPrefab, transform.position, transform.rotation);
                    }
                }
            }

            //deal damage to other enemies
            Hp leDealTarget = null;

            if (hit.GetComponent <Hp> ())
            {
                leDealTarget = hit.GetComponent <Hp> ();
            }
            else if (hit.GetComponentInChildren <Hp> ())
            {
                leDealTarget = hit.GetComponentInChildren <Hp> ();
            }
            else if (hit.GetComponentInParent <Hp> ())
            {
                leDealTarget = hit.GetComponentInParent <Hp> ();
            }
            if (leDealTarget != null)
            {
                float leDistance = Vector3.Distance(transform.position, hit.gameObject.transform.position);
                leDealTarget.Damage((int)(Mathf.Clamp(((float)damage * friendlyFireMultiplier * (1f - (leDistance / maxRange))), 0, Mathf.Infinity)));
            }
        }

        //other stuff
        Rigidbody  zomIns;
        GameObject myExp = (GameObject)Instantiate(exp, transform.position, transform.rotation);

        myExp.GetComponent <UnityStandardAssets.Effects.ParticleSystemMultiplier> ().multiplier = 0.5f;
        zomIns = (Rigidbody)Instantiate(kafa, transform.position + new Vector3(0, 1, 0), transform.rotation);
        zomIns.AddRelativeForce(0, 500, 0);
        zomIns.AddRelativeTorque(Random.Range(15, 100), Random.Range(15, 100), Random.Range(15, 100));

        //item drop
        //int randomChance = (int)Random.Range(0, itemDropChance);
        //print(randomChance);
        if (/*randomChance == 0*/ LootCounter.ShouldDropLoot(level))
        {
            Debug.LogWarning("item dropped");
            GameObject myItem = (GameObject)Instantiate(itemDrop, transform.position + Vector3.up, transform.rotation);
            myItem.GetComponent <GunDrop>().MakeGun(level, rarity);
        }

        //give xp
        int xpToGive = xp + Random.Range(-xpRange, xpRange);

        XpGiver.giveXp(xpToGive);
        ScoreController.myScore.AddScore((int)((float)xpToGive * Random.Range(1f, Mathf.Sqrt((float)level))));

        Destroy(gameObject);
    }