Example #1
0
        /// <summary>
        /// Pick an attack from the list.
        /// </summary>
        /// <param name="attacks">The list of attacks to choose from.</param>
        /// <param name="previousAttack">The last attack that was chosen.</param>
        /// <param name="sumFrequency">The sum of all attack frequencies.</param>
        /// <returns>The next attack that should be performed.</returns>
        public BossAttack GetNextAttack(List <BossAttack> attacks, BossAttack previousAttack = null, float sumFrequency = 0)
        {
            if (sumFrequency == 0)
            {
                foreach (BossAttack attack in attacks)
                {
                    sumFrequency += attack.Frequency;
                }
            }

            if (attacks.Count > 1)
            {
                float roll = Random.Range(0, sumFrequency);

                foreach (BossAttack attack in attacks)
                {
                    if (roll < attack.Frequency)
                    {
                        if (attack != previousAttack)
                        {
                            return(attack);
                        }
                        else
                        {
                            int index = attacks.IndexOf(attack);
                            index = PreventDuplicate(index, attacks.Count);
                            return(attacks[index]);
                        }
                    }

                    roll -= attack.Frequency;
                }

                return(attacks[attacks.Count - 1]);
            }
            else if (attacks.Count == 1)
            {
                return(attacks[0]);
            }

            return(null);
        }
Example #2
0
 /// <summary>
 /// Plan out what and when the next attack will be.
 /// </summary>
 public void PlanNextAttack()
 {
     performingAttack    = false;
     nextAttackCountdown = PickTiming(currentPhase.AttackInterval, currentPhase.AttackIntervalVariance);
     nextAttack          = GetNextAttack(currentPhase.Attacks, nextAttack, totalFrequency);
 }