Beispiel #1
0
    /// <summary>
    /// Creates random units for the wave
    /// </summary>
    /// <param name="wave"></param>
    /// <param name="totalEnemies"></param>
    void CreateRandomWave(int level, int totalEnemies)
    {
        // Keeps track of stats built for a specific unit type so that
        // all units of that types share the same stats
        Dictionary <string, LevelUpMetada> levelData = new Dictionary <string, LevelUpMetada>();

        for (int i = 0; i < totalEnemies; i++)
        {
            // Select a random unit to create
            int       index = UnityEngine.Random.Range(0, m_baseUnits.Count);
            EnemyUnit unit  = BuildUnit(m_baseUnits[index].GetType().Name);

            if (unit != null)
            {
                // Because stats are initialized on unit creation with random base values
                // we want to zero them out so that each unit of the same type has the same values
                unit.Stats.SetStatsToZero();

                if (!levelData.ContainsKey(unit.name))
                {
                    levelData[unit.name] = unit.CreateLevelUp(level);
                }

                LevelUpMetada data = levelData[unit.name];
                unit.LevelUp(data);

                m_waveQueue.Enqueue(unit);
            }
        }
    }
Beispiel #2
0
    /// <summary>
    /// Creates the next unit waiting to be shown for the first time
    /// </summary>
    /// <param name="wave"></param>
    /// <param name="totalEnemies"></param>
    void DequeueBaseUnit(int wave, int level, int totalEnemies)
    {
        Type nextType = m_nextType[wave - 1];

        Dictionary <string, LevelUpMetada> levelData = new Dictionary <string, LevelUpMetada>();

        for (int i = 0; i < totalEnemies; i++)
        {
            EnemyUnit unit = BuildUnit(nextType.Name);

            if (unit != null)
            {
                // Because stats are initialized on unit creation with random base values
                // we want to zero them out so that each unit of the same type has the same values
                unit.Stats.SetStatsToZero();

                if (!levelData.ContainsKey(unit.name))
                {
                    levelData[unit.name] = unit.CreateLevelUp(level);
                }

                LevelUpMetada data = levelData[unit.name];

                unit.LevelUp(data);

                // Ensure we are using the max health from the level up
                // as well as setting the starting HP to the max HP
                unit.Stats[StatsId.HP_Max] = data.stats[StatsId.HP_Max];
                unit.Stats[StatsId.HP_Cur] = unit.Stats[StatsId.HP_Max];

                // Trigger stats change to update the health bars
                unit.Stats = unit.Stats;

                m_waveQueue.Enqueue(unit);
            }
        }
    }