Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        checkPower();
        if (!isPausedCheck.GetIsPaused())
        {
            cooldown = cooldown - Time.deltaTime;
            if (cooldown <= 0)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    //Melee Attack
                    StartCoroutine("animCode");
                    GameObject.FindGameObjectWithTag("MusicHandler").GetComponent <AudioController>().PlaySoundEffect(7); //Case 7 is Melee Attack.
                    cooldown = duplicateCD;
                    if (Physics.Raycast(transform.parent.position, transform.forward, out hit, SWORD_ATTACK_DISTANCE))
                    {
                        Debug.Log("RNG rolled!");
                        if (hit.collider.gameObject.CompareTag("ProjectileEnemy") || hit.collider.gameObject.CompareTag("SwordEnemy") || hit.collider.gameObject.CompareTag("FinalBoss"))
                        {
                            GameObject     obj         = hit.collider.gameObject;
                            Enemy          enemyScript = hit.collider.gameObject.GetComponent <Enemy>();
                            PowerBehaviour powers      = GameObject.FindWithTag("PowerHandler").GetComponent <PowerBehaviour>();
                            var            rand        = new System.Random();
                            Player         player      = GameObject.FindWithTag("MainCamera").GetComponent <Player>();
                            int            RNGRoll     = rand.Next(0, 9999);
                            if (RNGRoll > RAIN_POWER_CHANCE && RNGRoll < RAIN_POWER_CHANCE * 2 && player.GetRainAvailable())
                            {
                                if (powers.powerHandler[11].GetPowerActive() == true)
                                {
                                    RNGRoll = 1;
                                }
                            }
                            if (RNGRoll < RAIN_POWER_CHANCE)
                            {
                                if (powers.powerHandler[12].GetPowerActive() == true)
                                {
                                    isPausedCheck.ShowPowerActivatedMessage(1);
                                    powers.DisableAllFires();
                                    player.SetRainAvailable(false);
                                }
                            }
                            RNGRoll = rand.Next(0, 9999); //Roll another number between 0 and 999.
                            if (RNGRoll > JUSTICE_POWER_CHANCE && RNGRoll < JUSTICE_POWER_CHANCE * 2 && player.GetJusticeAvailable())
                            {
                                if (powers.powerHandler[11].GetPowerActive() == true)
                                {
                                    RNGRoll = 1;
                                }
                            }
                            if (RNGRoll < JUSTICE_POWER_CHANCE && player.GetJusticeAvailable())
                            {
                                //Justice rains from above. 2.5% chance of occuring when damage is dealt.

                                if (powers.powerHandler[13].GetPowerActive() == true)
                                {
                                    GameObject[] projectileEnemies = GameObject.FindGameObjectsWithTag("ProjectileEnemy");
                                    GameObject[] swordEnemies      = GameObject.FindGameObjectsWithTag("SwordEnemy");
                                    foreach (GameObject obj1 in projectileEnemies)
                                    {
                                        JusticeSpawn projectiles = obj1.GetComponentInChildren <JusticeSpawn>();
                                        if (projectiles != null)
                                        {
                                            isPausedCheck.ShowPowerActivatedMessage(2);
                                            projectiles.FirePowerEffect();
                                            player.SetJusticeAvailable(false);
                                        }
                                    }
                                    foreach (GameObject obj1 in swordEnemies)
                                    {
                                        JusticeSpawn projectiles = obj1.GetComponentInChildren <JusticeSpawn>();
                                        if (projectiles != null)
                                        {
                                            projectiles.FirePowerEffect();
                                            player.SetJusticeAvailable(false);
                                        }
                                    }
                                }
                            }
                            double damageCalc;
                            double bonusDamagePower;
                            if (power.powerHandler[8].GetPowerAvailable() == true)
                            {
                                bonusDamagePower = 1.5f;
                            }
                            else
                            {
                                bonusDamagePower = 1f;
                            }
                            damageCalc = damageDealt * bonusDamagePower; //Additional calculation here if in Expert difficulty, to reduce damage.
                            if (hit.collider.gameObject.CompareTag("FinalBoss"))
                            {
                                FinalBoss fbScript = hit.collider.gameObject.GetComponent <FinalBoss>();
                                fbScript.DealDamage((float)damageCalc);
                            }
                            if (enemyScript != null)
                            {
                                enemyScript.takeDamage(damageCalc);
                            }
                        }
                    }
                }
            }
        }
        else
        {
        }
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (!isPaused.GetIsPaused()) //Only increment timer if the game is not paused!
        {
            timer = timer + Time.deltaTime;
            if (timer > TIME_TO_DESTROY)
            {
                Destroy(gameObject);
            }
        }
        Vector3 forward = transform.TransformDirection(Vector3.forward);

        if (Physics.SphereCast(transform.position, 0.25f, forward, out hit, 1.5f))
        {
            if (hit.collider.gameObject.CompareTag("ProjectileEnemy") || hit.collider.gameObject.CompareTag("SwordEnemy") || hit.collider.gameObject.CompareTag("FinalBoss"))
            {
                if (gameObject.tag == "EnemyProjectile")
                {
                    return;
                }

                var rand    = new System.Random();
                int RNGRoll = rand.Next(0, 9999); //Roll a number between 0 and 999.

                Player player = GameObject.FindWithTag("MainCamera").GetComponent <Player>();
                if (RNGRoll > RAIN_INT_CHANCE && RNGRoll < RAIN_INT_CHANCE * 2 && player.GetRainAvailable()) //Mysterious power doubles the chance of the environmental effects occuring.
                {
                    if (GameObject.FindWithTag("PowerHandler").GetComponent <PowerBehaviour>().powerHandler[11].GetPowerActive() == true)
                    {
                        RNGRoll = 1; //change RNG to pass.
                    }
                }

                if (RNGRoll < RAIN_INT_CHANCE && player.GetRainAvailable()) //0 to 24 gives a 2.5% chance when damaging.
                {
                    UIController ui = GameObject.FindWithTag("UIHandler").GetComponent <UIController>();

                    PowerBehaviour powers = GameObject.FindWithTag("PowerHandler").GetComponent <PowerBehaviour>();
                    if (powers.powerHandler[12].GetPowerActive() == true)
                    {
                        ui.ShowPowerActivatedMessage(1);
                        powers.DisableAllFires();
                        player.SetRainAvailable(false); //Start the cooldown.
                    }
                }

                RNGRoll = rand.Next(0, 9999); //Roll 10,000 numbers. Chance is a constant.

                if (RNGRoll > JUSTICE_INT_CHANCE && RNGRoll < JUSTICE_INT_CHANCE * 2 && player.GetJusticeAvailable())
                {
                    if (GameObject.FindWithTag("PowerHandler").GetComponent <PowerBehaviour>().powerHandler[11].GetPowerActive() == true)
                    {
                        RNGRoll = 1; //change RNG to pass.
                    }
                }
                if (RNGRoll < JUSTICE_INT_CHANCE && player.GetJusticeAvailable())
                {
                    //Justice rains from above. 2.5% chance of occuring when damage is dealt.
                    PowerBehaviour powers = GameObject.FindWithTag("PowerHandler").GetComponent <PowerBehaviour>();
                    if (powers.powerHandler[13].GetPowerActive() == true)
                    {
                        UIController ui = GameObject.FindWithTag("UIHandler").GetComponent <UIController>();

                        GameObject[] projectileEnemies = GameObject.FindGameObjectsWithTag("ProjectileEnemy");
                        GameObject[] swordEnemies      = GameObject.FindGameObjectsWithTag("SwordEnemy");
                        GameObject   FB = GameObject.FindGameObjectWithTag("FinalBoss");
                        if (FB != null)
                        {
                            JusticeSpawn projectiles = FB.GetComponentInChildren <JusticeSpawn>();
                            if (projectiles != null)
                            {
                                ui.ShowPowerActivatedMessage(2);
                                projectiles.FirePowerEffect();
                                player.SetJusticeAvailable(false);
                            }
                        }
                        foreach (GameObject obj in projectileEnemies)
                        {
                            JusticeSpawn projectiles = obj.GetComponentInChildren <JusticeSpawn>();
                            if (projectiles != null)
                            {
                                ui.ShowPowerActivatedMessage(2);
                                projectiles.FirePowerEffect();
                                player.SetJusticeAvailable(false);
                            }
                        }
                        foreach (GameObject obj in swordEnemies)
                        {
                            JusticeSpawn projectiles = obj.GetComponentInChildren <JusticeSpawn>();
                            if (projectiles != null)
                            {
                                projectiles.FirePowerEffect();
                                player.SetJusticeAvailable(false);
                            }
                        }
                    }
                }
                double damageCalc;
                Enemy  enemy = hit.collider.gameObject.GetComponent <Enemy>();
                damageCalc = player.GetWeaponPower() * damagePower; //Needs modification to check difficulty.
                Debug.Log("Enemy Damaged!");
                if (hit.collider.gameObject.GetComponent <Enemy>() != null)
                {
                    hit.collider.gameObject.GetComponent <Enemy>().takeDamage(damageCalc);
                }
                if (hit.collider.gameObject.CompareTag("FinalBoss"))
                {
                    hit.collider.gameObject.GetComponent <FinalBoss>().DealDamage((float)damageCalc);
                }
                Destroy(this.gameObject);
            }
            else if (hit.collider.gameObject.CompareTag("MainCamera"))
            {
                Destroy(this.gameObject);
                Player player = hit.collider.gameObject.GetComponent <Player>();
                player.takeDamage(damagePower);
            }
            else if (hit.collider.gameObject.CompareTag("FireDamager"))
            {
                if (gameObject.gameObject.CompareTag("EnemyProjectile"))
                {
                    return;
                }
                else
                {
                    Destroy(this.gameObject);
                    PowerBehaviour power = GameObject.Find("PowerHandler").GetComponent <PowerBehaviour>();
                    //When the trident model is integrated, check if the weapon is the trident, and NOT the other staff.
                    if (power.powerHandler[10].GetPowerActive()) //Check if the power is active
                    {
                        hit.collider.gameObject.GetComponent <FireCollision>().temporarilyDisableFire();
                    }
                }
            }
        }
    }