Beispiel #1
0
    public void SpawnWeapon()
    {
        List <WeaponSpawner> availableSpawners = new List <WeaponSpawner>();

        foreach (WeaponSpawner spwnr in spawners)
        {
            if (spwnr.spawned == 0)
            {
                if (spwnr.lastTimeSpawned)
                {
                    spwnr.lastTimeSpawned = false;
                    continue;
                }
                availableSpawners.Add(spwnr);
            }
        }
        WeaponSpawner spawner = availableSpawners[RollRandom.RollBetween(0, availableSpawners.Count)];


        int[] weights = new int[guns.Length];
        foreach (Gun gun in guns)
        {
            weights.Append(gun.chance);
        }
        Gun g = GetRandomWeightedIndex(guns);

        spawner.SpawnGun(g.gun);
        spawning = false;
    }
Beispiel #2
0
 public List <GameObject> Shuffle(List <GameObject> list)
 {
     for (int i = 0; i < list.Count; i++)
     {
         GameObject temp        = list[i];
         int        randomIndex = RollRandom.RollBetween(i, list.Count);
         list[i]           = list[randomIndex];
         list[randomIndex] = temp;
     }
     return(list);
 }
Beispiel #3
0
    void Die()
    {
        if (!doOnce)
        {
            Debug.Log("Enemy Died");
            doOnce = true;
            if (HealthPickup)
            {
                RaycastHit groundCheck;
                if (Physics.Raycast(transform.position, Vector3.down, out groundCheck, 100, LayerMask.GetMask("Default")))
                {
                    if (RollRandom.RollForProbability(5))
                    {
                        GameObject pickup = Instantiate(HealthPickup, groundCheck.point, Quaternion.identity);
                    }
                }
            }

            GameManager.gameManager.kills++;

            //if (decalHandler != null)
            //{
            //    decalHandler.GetComponent<DecalHandler>().EnemyGib(transform, BloodBurst.ConeTrailsLong);
            //}
            switch (ai.enemyType)
            {
            case EnemyAi.EnemyType.CyberDemon:
                decalHandler.GetComponent <DecalHandler>().EnemyGib(transform, BloodBurst.ConeTrailsLong);
                Destroy(gameObject);
                break;

            case EnemyAi.EnemyType.Mancubus:
                decalHandler.GetComponent <DecalHandler>().EnemyGib(transform, BloodBurst.ConeTrailsLong);
                Destroy(gameObject);
                break;

            case EnemyAi.EnemyType.Fencer:
                decalHandler.GetComponent <DecalHandler>().EnemyGib(transform, BloodBurst.ConeTrailsLong);
                Destroy(gameObject);
                break;

            case EnemyAi.EnemyType.SharkDog:
                decalHandler.GetComponent <DecalHandler>().EnemyGib(transform, BloodBurst.ConeTrailsLong);
                Destroy(gameObject);
                break;

            case EnemyAi.EnemyType.FlyingBlob:
                decalHandler.GetComponent <DecalHandler>().EnemyGib(transform, BloodBurst.SphereTrailsLong);
                Destroy(GetComponent <FlyingEnemyPosition>().parentTransform.gameObject);
                Destroy(this.gameObject);
                break;
            }
        }
    }
Beispiel #4
0
    public void UpdateState()
    {
        hasLineOfSight = enemy.CheckLineOfSight(rangedAttackBuffer);

        if (!hasLineOfSight)
        {
            enemy.chase.EnterState();
            return;
        }


        //Special attack
        if (enemy.hasSpecialAttack && enemy.specialAttackAvailable && (enemy.target.position - enemy.transform.position).magnitude >= enemy.minSpecialAttackRange)
        {
            if (RollRandom.RollForProbability(enemy.specialAttackProbability))
            {
                //Debug.Log("SPECIAL");
                enemy.special.EnterState();
                return;
            }
            else
            {
                enemy.StartSpecialCooldown();
            }
        }

        //Melee attack
        else if (enemy.hasMeleeAttack && enemy.navMeshAgent.hasPath && enemy.navMeshAgent.remainingDistance < enemy.navMeshAgent.stoppingDistance)
        {
            //Debug.Log("MELEE");
            enemy.melee.EnterState();
        }

        //Continue chasing
        else//if (enemy.navMeshAgent.hasPath && (enemy.target.position - enemy.transform.position).magnitude >= enemy.navMeshAgent.stoppingDistance)
        {
            //Debug.Log("CHASING");
            enemy.chase.EnterState();
            return;
        }

        /*if (enemy.grounded && enemy.navMeshAgent.hasPath && enemy.navMeshAgent.remainingDistance <= enemy.minSpecialAttackRange)
         * {
         *  Debug.Log("CHASING");
         *  enemy.chase.EnterState();
         *  return;
         * }*/
    }
Beispiel #5
0
    public Gun GetRandomWeightedIndex(Gun[] guns)
    {
        int totalWeight = 1;

        foreach (Gun g in guns)
        {
            totalWeight += g.chance;
        }
        int randomWeight = RollRandom.RollBetween(0, totalWeight);

        Debug.Log("Random Weight: " + randomWeight);
        int currentWeight = 0;

        foreach (Gun g in guns)
        {
            currentWeight += g.chance;
            if (randomWeight <= currentWeight)
            {
                return(g);
            }
        }
        Debug.Log("Not found");
        return(guns[0]);
    }
    public void UpdateState()
    {
        if (!attacking && enemy.FaceTargetCheck(rangedAttackBuffer) && enemy.specialAttackAvailable)
        {
            /*enemy.specialFrontSwing = false;
             * enemy.specialSwing = false;
             * enemy.specialBackSwing = false;*/
            enemy.specialAttackStart = false;
            enemy.specialAttackEnd   = false;

            attacking          = true;
            projectileLaunched = false;
        }

        /*if (!attacking && enemy.navMeshAgent.remainingDistance <= enemy.navMeshAgent.stoppingDistance)      //Maybe not needed. depends how stiff we want the AI to be. remove if needs to be stiffer
         * {
         *  enemy.chase.EnterState();
         * }*/

        if (attacking)
        {
            timer += Time.deltaTime;

            if (timer <= frontSwing)        //Front swing of the attack animation
            {
                /*if (!enemy.specialFrontSwing)
                 *  enemy.specialFrontSwing = true;*/
                if (!enemy.specialAttackStart)
                {
                    enemy.specialAttackStart = true;
                }

                //if (enemy.IndicatorTemp)
                //enemy.IndicatorTemp.GetComponent<Renderer>().material.color = Color.yellow;

                //Debug.Log("FRONT SWING");
            }
            else if (timer >= frontSwing && timer < frontSwing + attackTime)        //Beginning of the attack after front swing. Performs attack
            {
                /*enemy.specialFrontSwing = false;
                 * if (!enemy.specialSwing)
                 *  enemy.specialSwing = true;*/
                enemy.specialAttacking = true;

                //if (enemy.IndicatorTemp)
                //enemy.IndicatorTemp.GetComponent<Renderer>().material.color = Color.red;

                if (!projectileLaunched)
                {
                    Vector3    temp             = new Vector3(enemy.transform.position.x, enemy.transform.position.y + enemy.transform.lossyScale.y, enemy.transform.position.z);
                    Vector3    tempPos          = new Vector3(enemy.transform.position.x, enemy.transform.position.y + (enemy.transform.lossyScale.y * 0.5f), enemy.transform.position.z) + enemy.transform.forward * 0.5f;
                    GameObject rangedProjectile = enemy.ShootProjectile(enemy.target.GetChild(0).position - tempPos, projectileSpeed);
                    rangedProjectile.GetComponent <EnemyProjectile>().knockback = enemy.specialKnockback;
                    projectileLaunched = true;
                }

                //Debug.Log("ATTACK");
            }
            else if (timer >= frontSwing + attackTime && timer < frontSwing + attackTime + backSwing)       //Back swing of the animation
            {
                enemy.specialRecovering  = true;
                enemy.specialAttackStart = false;

                /*enemy.specialSwing = false;
                 * if (!enemy.specialBackSwing)
                 *  enemy.specialBackSwing = true;*/

                //if (enemy.IndicatorTemp)
                //enemy.IndicatorTemp.GetComponent<Renderer>().material.color = Color.blue;


                //Debug.Log("BACK SWING");
            }
            else if (timer >= frontSwing + attackTime + backSwing)      //End of attack animation.
            {
                //enemy.specialBackSwing = false;
                enemy.specialAttackEnd  = true;
                enemy.specialAttacking  = false;
                enemy.specialRecovering = false;

                //if (enemy.IndicatorTemp)
                //enemy.IndicatorTemp.GetComponent<Renderer>().material.color = Color.gray;
                //Debug.Log("END ATTACK");
                enemy.StartSpecialCooldown();
                if (RollRandom.RollForProbability(enemy.specialAttackContinueProbability) && enemy.navMeshAgent.remainingDistance > enemy.navMeshAgent.stoppingDistance)
                {
                    enemy.special.EnterState();
                }
                else
                {
                    enemy.chase.EnterState();
                }
            }
        }
        else
        {
            Quaternion rotation = Quaternion.LookRotation(new Vector3(enemy.target.position.x, enemy.transform.position.y, enemy.target.position.z) - enemy.transform.position);
            enemy.transform.rotation = Quaternion.Slerp(enemy.transform.rotation, rotation, Time.deltaTime * turnSpeed);
            if (!enemy.CheckLineOfSight(rangedAttackBuffer))
            {
                enemy.chase.EnterState();
            }
        }
    }
Beispiel #7
0
 public void EnterState()
 {
     enemy.currentState           = this;
     enemy.navMeshAgent.isStopped = true;
     RollRandom.RollForProbability(enemy.specialAttackProbability);
 }
Beispiel #8
0
    IEnumerator SpawnWaves(int[] chosenSpawners)
    {
        spawnables = new List <GameObject>();



        //Define the points left to use on "buying" enemies
        pointsLeft = 0;

        if (randomizeOnRound != 0 && randomizeOnRound <= currentRound + 1)
        {
            randomRounds.pointpool += randomRounds.increasePointPool;
            pointsLeft              = randomRounds.pointpool;
            if (gameManager.multiplyPointpool > 0)
            {
                pointsLeft = Mathf.CeilToInt(pointsLeft * gameManager.multiplyPointpool);
            }
        }
        else
        {
            pointsLeft = rounds[currentRound].pointpool;
            if (gameManager.multiplyPointpool > 0)
            {
                pointsLeft = Mathf.CeilToInt(pointsLeft * gameManager.multiplyPointpool);
            }
        }


        while (pointsLeft > 0)
        {
            if (pointsLeft == 1)
            {
                spawnables.Add(enemiesByCost[0].enemyUnits[RollRandom.RollBetween(0, enemiesByCost[0].enemyUnits.Length)]);
                pointsLeft -= 1;
                Debug.Log("Points Left: " + pointsLeft);
                break;
            }
            int pointsCost;
            if (randomizeOnRound != 0 && randomizeOnRound <= currentRound + 1)
            {
                pointsCost = RollRandom.RollBetween(0, enemiesByCost.Length);
                if (pointsLeft < enemiesByCost.Length)
                {
                    pointsCost = RollRandom.RollBetween(0, pointsLeft);
                }
            }
            else
            {
                pointsCost = RollRandom.RollBetween(0, rounds[currentRound].maxCost);
                if (pointsLeft < rounds[currentRound].maxCost)
                {
                    pointsCost = RollRandom.RollBetween(0, pointsLeft);
                }
            }
            if (enemiesByCost[pointsCost].enemyUnits.Count() != 0)
            {
                pointsLeft -= (pointsCost + 1);
                GameObject[] chosenPrice = enemiesByCost[pointsCost].enemyUnits;
                spawnables.Add(chosenPrice[RollRandom.RollBetween(0, chosenPrice.Length)]);
            }
        }
        if (randomizeOnRound != 0 && randomizeOnRound <= currentRound + 1)
        {
            if (randomRounds.everyXRoundBoss != 0 && currentRound % randomRounds.everyXRoundBoss == 0)
            {
                for (int i = 0; i < randomRounds.firstForcedAmount; i++)
                {
                    if (randomRounds.randomForced.Length != 0)
                    {
                        spawnables.Add(randomRounds.randomForced[RollRandom.RollBetween(0, randomRounds.randomForced.Length)]);
                    }
                }
                randomRounds.firstForcedAmount++;
            }
        }
        else
        {
            foreach (GameObject forced in rounds[currentRound].forcedSpawns)
            {
                spawnables.Add(forced);
            }
        }

        spawnables = Shuffle(spawnables);
        //Add all forced spawns to the list

        int spawnsAmount;
        int waves;

        if (randomizeOnRound != 0 && randomizeOnRound <= currentRound + 1)
        {
            do
            {
                randomRounds.waves++;
                spawnsAmount = Mathf.CeilToInt(spawnables.Count / randomRounds.waves / chosenSpawners.Length);
            }while (spawnsAmount / chosenSpawners.Length > randomRounds.maxEnemiesPerWave);
            waves = (int)randomRounds.waves;
        }
        else
        {
            spawnsAmount = Mathf.CeilToInt(spawnables.Count / rounds[currentRound].waves / chosenSpawners.Length);
            waves        = (int)rounds[currentRound].waves;
        }

        for (int i = 0; i < waves; i++)
        {
            foreach (int chosen in chosenSpawners)
            {
                if (spawnables.Count > 0)
                {
                    if (chosen >= 0) // *NEW
                    {
                        spawnables = spawners[chosen].SpawnEnemy(spawnables, spawnsAmount);
                    }
                }
            }
            yield return(new WaitForSeconds(timeBetweenWaves));
        }
    }
Beispiel #9
0
    void StartNewRound()
    {
        if (randomizeOnRound != 0 && randomizeOnRound <= currentRound + 1)
        {
            chosenSpawners = new int[Random.Range(randomRounds.minSpawners, spawners.Length)];
        }
        else
        {
            chosenSpawners = new int[(int)rounds[currentRound].spawnersActive];
        }

        if (chosenSpawners.Length != spawners.Length)
        {
            for (int i = 0; i < chosenSpawners.Length; i++)
            {
                chosenSpawners[i] = -1;
            }

            alreadyChosen = Mathf.CeilToInt(spawnersNearPlayerPct * gameManager.playerCount / 100 * chosenSpawners.Length);
            Debug.Log("AreadyChosen: " + alreadyChosen);
            GameObject[] nearPlayer = new GameObject[alreadyChosen];
            List <float> temp       = new List <float>();
            for (int i = 0; i < spawners.Length; i++)
            {
                if (gameManager.playerOne != null) // *NEW
                {
                    temp.Add((spawners[i].gameObject.transform.position - gameManager.playerOne.transform.position).magnitude);
                }
            }
            temp.Sort();
            foreach (float f in temp)
            {
                Debug.Log("Temp: " + f);
            }

            if (gameManager.playerCount == 2)
            {
                for (int i = 0; i <= alreadyChosen / 2; i++)
                {
                    for (int j = 0; j < spawners.Length; j++)
                    {
                        if (gameManager.playerOne != null) // *NEW
                        {
                            if (temp[i] >= (spawners[j].gameObject.transform.position - gameManager.playerOne.transform.position).magnitude)
                            {
                                if (!chosenSpawners.Contains(j))
                                {
                                    //temp[i] = (spawners[j].gameObject.transform.position - gameManager.playerOne.transform.position).magnitude;
                                    chosenSpawners[i] = j;
                                }
                            }
                        }
                    }
                }
                temp = new List <float>();
                for (int i = 0; i < spawners.Length; i++)
                {
                    if (gameManager.playerTwo != null) // *NEW
                    {
                        temp.Add((spawners[i].gameObject.transform.position - gameManager.playerTwo.transform.position).magnitude);
                    }
                }
                temp.Sort();
                for (int i = 0 + alreadyChosen / 2; i < alreadyChosen; i++)
                {
                    for (int j = 0; j < spawners.Length; j++)
                    {
                        if (gameManager.playerTwo != null) // *NEW
                        {
                            if (temp[i] >= (spawners[j].gameObject.transform.position - gameManager.playerTwo.transform.position).magnitude)
                            {
                                if (!chosenSpawners.Contains(j))
                                {
                                    //temp[i] = (spawners[j].gameObject.transform.position - gameManager.playerTwo.transform.position).magnitude;
                                    chosenSpawners[i] = j;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < alreadyChosen; i++)
                {
                    for (int j = 0; j < spawners.Length; j++)
                    {
                        if (gameManager.playerOne != null) // *NEW
                        {
                            if (temp[i] >= (spawners[j].gameObject.transform.position - gameManager.playerOne.transform.position).magnitude)
                            {
                                if (!chosenSpawners.Contains(j))
                                {
                                    //temp[i] = (spawners[j].gameObject.transform.position - gameManager.playerOne.transform.position).magnitude;
                                    chosenSpawners[i] = j;
                                }
                            }
                        }
                    }
                }
            }
            for (int i = 0 + alreadyChosen; i < chosenSpawners.Length; i++)
            {
                int rand;
                do
                {
                    rand = RollRandom.RollBetween(0, spawners.Length);
                }while (chosenSpawners.Contains(rand));
                chosenSpawners[i] = rand;
            }
        }
        else
        {
            for (int i = 0; i < chosenSpawners.Length; i++)
            {
                chosenSpawners[i] = i;
            }
        }

        //KostinKoodi
        if (megaphoneObject != null)
        {
            megaphone.setParameterByName("RoundVoiceLine", currentRound);
            megaphone.start();
            Debug.Log("MegaphoneSOUND" + currentRound);
        }
        else
        {
            Debug.Log("Megaphone not found");
        }
        if (musicObject != null)
        {
            if (currentRound < 4)
            {
                musicObject.SetParameter("Music Stage", currentRound);
            }
            if (currentRound == 4)
            {
                musicObject.SetParameter("Music Intensity", 1);
            }
        }
        StartCoroutine(SpawnWaves(chosenSpawners));
    }
Beispiel #10
0
    public void UpdateState()
    {
        if (!attacking && enemy.FaceTargetCheck(rangedAttackBuffer) && enemy.specialAttackAvailable)
        {
            /*enemy.specialFrontSwing = false;
             * enemy.specialSwing = false;
             * enemy.specialBackSwing = false;*/
            enemy.specialAttackStart = false;
            enemy.specialAttackEnd   = false;

            attacking   = true;
            lungeDir    = enemy.transform.forward;
            damageDealt = false;
        }
        if (!attacking && enemy.navMeshAgent.remainingDistance <= enemy.navMeshAgent.stoppingDistance)      //Maybe not needed. depends how stiff we want the AI to be. remove if needs to be stiffer
        {
            enemy.chase.EnterState();
        }

        if (attacking)
        {
            timer += Time.deltaTime;

            if (timer <= frontSwing)        //Front swing of the attack animation
            {
                /*if (!enemy.specialFrontSwing)
                 *  enemy.specialFrontSwing = true;*/
                if (!enemy.specialAttackStart)
                {
                    enemy.specialAttackStart = true;
                }

                //if (enemy.IndicatorTemp)
                //enemy.IndicatorTemp.GetComponent<Renderer>().material.color = Color.yellow;
            }
            else if (timer >= frontSwing && timer < frontSwing + attackTime)        //Beginning of the attack after front swing. Performs attack
            {
                /*enemy.specialFrontSwing = false;
                 * if (!enemy.specialSwing)
                 *  enemy.specialSwing = true;*/

                //if (enemy.IndicatorTemp)
                //enemy.IndicatorTemp.GetComponent<Renderer>().material.color = Color.red;
                if (!enemy.GetComponent <Rigidbody>())
                {
                    enemy.gameObject.AddComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation;
                }
                enemy.navMeshAgent.enabled = false;

                enemy.lunging = true;
                enemy.GetComponent <Rigidbody>().velocity = lungeDir * Time.deltaTime * lungeSpeed;
            }
            else if (timer >= frontSwing + attackTime && timer < frontSwing + attackTime + backSwing)       //Back swing of the animation
            {
                /*enemy.specialSwing = false;
                 * if (!enemy.specialBackSwing)
                 *  enemy.specialBackSwing = true;*/
                enemy.specialAttacking   = true;
                enemy.specialRecovering  = true;
                enemy.specialAttackStart = false;

                //if (enemy.IndicatorTemp)
                //enemy.IndicatorTemp.GetComponent<Renderer>().material.color = Color.blue;
                enemy.navMeshAgent.enabled = true;
                enemy.lunging = false;
                //Debug.Log("BACK SWING");
            }
            else if (timer >= frontSwing + attackTime + backSwing)      //End of attack animation.
            {
                //enemy.specialBackSwing = false;
                enemy.specialAttackEnd  = true;
                enemy.specialAttacking  = false;
                enemy.specialRecovering = false;

                //if (enemy.IndicatorTemp)
                //enemy.IndicatorTemp.GetComponent<Renderer>().material.color = Color.gray;
                //Debug.Log("END ATTACK");
                enemy.StartSpecialCooldown();
                if (RollRandom.RollForProbability(enemy.specialAttackContinueProbability) && enemy.navMeshAgent.remainingDistance > enemy.navMeshAgent.stoppingDistance)
                {
                    enemy.special.EnterState();
                }
                else
                {
                    enemy.chase.EnterState();
                }
            }
        }
        else
        {
            enemy.lunging = false;
            Quaternion rotation = Quaternion.LookRotation(new Vector3(enemy.target.position.x, enemy.transform.position.y, enemy.target.position.z) - enemy.transform.position);
            enemy.transform.rotation = Quaternion.Slerp(enemy.transform.rotation, rotation, Time.deltaTime * turnSpeed);
            if (!enemy.CheckLineOfSight(rangedAttackBuffer))
            {
                enemy.chase.EnterState();
            }
        }
    }