Ejemplo n.º 1
0
        /// <summary>
        /// 使用於 如果已經計算好公式了!
        /// </summary>
        /// <param name="damages"></param>
        /// <param name="pos"></param>
        /// <param name="cirticalChance"></param>
        /// <param name="algorithm"></param>
        /// <returns></returns>
        public int[] DamageTextSpawnerSimple(
            int[] damages,
            Vector2 pos,
            int cirticalChance,
            JCS_Range algorithm,
            bool isEnemy       = false,
            AudioClip hitSound = null)
        {
            int hit = damages.Length;

            DamageTextType[] types = new DamageTextType[hit];

            for (int index = 0;
                 index < hit;
                 ++index)
            {
                bool isCritical = (algorithm(0, 100) < cirticalChance);

                if (!isEnemy)
                {
                    if (isCritical)
                    {
                        types[index] = DamageTextType.CRITICAL;
                    }
                    else
                    {
                        types[index] = DamageTextType.NORMAL;
                    }
                }
                else
                {
                    types[index] = DamageTextType.GET_DAMAGE;
                }
            }

            SpawnDamageTextsFromPoolByType(damages, pos, types, hitSound);

            // return original damages
            return(damages);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Helper function to spawn the damaget text
        /// so scripter will not have to do all the drug code over and
        /// over agian!
        /// </summary>
        /// <param name="minDamage"> minimum of damage we produce </param>
        /// <param name="maxDamage"> maximum of damage we produce </param>
        /// <param name="pos"> position of damage text we spawn </param>
        /// <param name="hit"> how many damage text we spawn </param>
        /// <param name="percentOfCritical"> how many percentage will be critical instead of normal damage text </param>
        /// <param name="isEnemy">
        /// true: use enemy's specific damage text set,
        /// false: use player's specific damage text set.
        /// </param>
        /// <returns> data we produced </returns>
        public int[] DamageTextSpawnerSimple(
            int minDamage,
            int maxDamage,
            Vector2 pos,
            int hit,
            int percentOfCritical,
            JCS_Range algorithm,
            int defenseValue,
            bool isEnemy       = false,
            AudioClip hitSound = null)
        {
            if (minDamage > maxDamage)
            {
                JCS_Debug.LogError(
                    "min damage cannot be higher or equal to the max damage!");
                return(null);
            }

            if (minDamage < 0 || maxDamage < 0)
            {
                JCS_Debug.LogError(
                    "Min or Max damage cannot be lower than 0!");
                return(null);
            }

            if (percentOfCritical < 0 || percentOfCritical > 100)
            {
                JCS_Debug.LogError(
                    "Percent Of Critical should within range of 0 ~ 100...");
                return(null);
            }

            if (hit <= 0)
            {
                JCS_Debug.LogError(
                    "Hit count should not be equal or lower than 0!");
                return(null);
            }

            int[]            damages = new int[hit];
            DamageTextType[] types   = new DamageTextType[hit];

            // get the game setting first
            JCS_GameSettings jcsGm = JCS_GameSettings.instance;

            for (int index = 0;
                 index < hit;
                 ++index)
            {
                int dm = Random.Range(minDamage, maxDamage);

                // 受到的傷害 = 傷害 - 防禦力
                damages[index] = dm - defenseValue;

                // Check min max
                {
                    // 如果小於最下限得值, 就設定為最下限的值
                    if (damages[index] < jcsGm.MIN_DAMAGE)
                    {
                        damages[index] = jcsGm.MIN_DAMAGE;
                    }

                    // 如果大於最上限得值, 就設定為最上限的值
                    if (damages[index] > jcsGm.MAX_DAMAGE)
                    {
                        damages[index] = jcsGm.MAX_DAMAGE;
                    }
                }

                // see if this damage text a critical damage text?
                bool isCritical = (algorithm(0, 100) < percentOfCritical);

                // Set the type of the damage text
                // base on the tribe!
                if (!isEnemy)
                {
                    if (isCritical)
                    {
                        types[index] = DamageTextType.CRITICAL;
                    }
                    else
                    {
                        types[index] = DamageTextType.NORMAL;
                    }
                }
                else
                {
                    types[index] = DamageTextType.GET_DAMAGE;
                }
            }

            SpawnDamageTextsFromPoolByType(damages, pos, types, hitSound);

            // return the damages we just create!
            return(damages);
        }