コード例 #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);
            }
        }
    }
コード例 #2
0
    /// <summary>
    /// Applies the level and stats changes presented in the level up metadata
    /// Increases the total experience points required to level up for the next level
    /// The increment of the current experience point happens prior to this call
    /// </summary>
    /// <param name="data"></param>
    public void LevelUp(LevelUpMetada data)
    {
        Stats.Level       += data.level;
        Stats.Exp          = Stats.NextLevelExp;
        Stats.NextLevelExp = EXPManager.instance.NextLevelEXP(Stats.Level, BaseExperience);

        foreach (KeyValuePair <StatsId, int> item in data.stats)
        {
            StatsId id    = item.Key;
            int     value = item.Value;
            Stats[id] += value;
        }

        OnStatsChanged();
    }
コード例 #3
0
    /// <summary>
    /// Returns the information that represents the stats changes for adding
    /// the given level number to the current level.
    /// </summary>
    /// <param name="level">How many levels to increase the unit by</param>
    /// <returns></returns>
    public LevelUpMetada CreateLevelUp(int level)
    {
        StatData stats = new StatData();

        // Increase the stats for each level
        for (int i = 0; i < level; i++)
        {
            foreach (KeyValuePair <StatsId, Dice> growth in Stats.Growths)
            {
                StatsId id   = growth.Key;
                Dice    dice = growth.Value;
                stats[id] = dice.Roll();
            }
        }

        LevelUpMetada data = new LevelUpMetada(level, stats);

        return(data);
    }
コード例 #4
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);
            }
        }
    }
コード例 #5
0
    /// <summary>
    /// Increases the current level by a single level
    /// </summary>
    public void TriggerLevelUp()
    {
        LevelUpMetada data = CreateLevelUp(1);

        LevelUp(data);
    }