Esempio n. 1
0
    /// <summary>
    /// Called through an event in the TurnBased manager, when the cycle of agents is complete, and the player is given control again
    /// This determines whether an enemy should spawn, using a random chance to determine whether it should actually spawn
    /// If an enemy should spawn, it then uses another random to determine which Ai should spawn from the list of enemies in the dungeon theme scriptable object
    /// </summary>
    public void SpawnNewEnemy()
    {
        if (AIManager.Instance.m_currentAiOnScene < AIManager.Instance.m_maxAiOnScene)
        {
            float randomAi = Random.Range(0f, 1f);
            if (randomAi < m_dungeonTheme.m_chanceOfEnemySpawn)
            {
                AIManager.Instance.m_currentAiOnScene++;

                DungeonGridCell spawnRoom   = m_allRooms[Random.Range(0, m_allRooms.Count)];
                List <Vector2>  possiblePos = new List <Vector2>();
                foreach (Vector2 possibleSpot in spawnRoom.m_floorTiles)
                {
                    if (!Physics2D.Raycast(possibleSpot, Vector3.forward, 100, m_spawnMask))
                    {
                        possiblePos.Add(possibleSpot);
                    }
                }
                Vector2 spawnPos = possiblePos[Random.Range(0, possiblePos.Count)];
                spawnPos += new Vector2(.5f, .5f);

                randomAi = Random.Range(0f, 1f);

                foreach (AiStruct ai in m_currentEnemyTypesInDungeon)
                {
                    if (randomAi < ai.m_aiRarity)
                    {
                        AIController newAi = m_pooler.NewObject(m_aiShell, spawnPos, Quaternion.identity).GetComponent <AIController>();
                        newAi.InitializeAi(ai.m_entityType);
                        m_turnSystem.NewAgent(newAi.GetComponent <TurnBasedAgent>());
                        AIManager.Instance.AddAiEntity(newAi.gameObject);
                        return;
                    }
                }
            }
        }
    }