Пример #1
0
        /// <summary>
        /// Calculate the damage before we apply to the live object.
        /// </summary>
        /// <param name="minDamage"></param>
        /// <param name="maxDamage"></param>
        /// <param name="hit"></param>
        /// <param name="defenseValue"></param>
        /// <returns></returns>
        public int[] PreCalculateSequenceDamage(int minDamage, int maxDamage, int hit, int defenseValue)
        {
            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 (hit <= 0)
            {
                JCS_Debug.LogError("Hit count should not be equal or lower than 0!");
                return(null);
            }


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

            int[] damages = new int[hit];

            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;
                    }
                }
            }


            // return the damages we just create!
            return(damages);
        }
        /// <summary>
        /// Add specific game manager type.
        /// </summary>
        private void SetSpecificGameTypeGameManager()
        {
            JCS_GameSettings gs = JCS_GameSettings.instance;

            switch (gs.GAME_TYPE)
            {
            case JCS_GameType.GAME_2D:
                this.gameObject.AddComponent <JCS_2DGameManager>();
                break;
            }
        }
Пример #3
0
        /* Functions */

        private void OnApplicationQuit()
        {
            APP_QUITTING = true;

            JCS_GameSettings gs = JCS_GameSettings.instance;

            if (gs.SAVE_ON_EXIT_APP &&
                gs.SAVE_GAME_DATA_FUNC != null)
            {
                // save when exit app
                gs.SAVE_GAME_DATA_FUNC.Invoke();
            }
        }
 public void SetJCSGameSettings(JCS_GameSettings gs)
 {
     this.mJCSGameSettings = gs;
 }
Пример #5
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);
        }
Пример #6
0
        /// <summary>
        /// Load scene with self-define fade in time.
        /// </summary>
        /// <param name="sceneName"> scene name to load </param>
        /// <param name="fadeInTime"> time to fade in </param>
        /// <param name="screenColor"> screen color </param>
        /// <param name="keepBGM"> keep background music playing? </param>
        public void LoadScene(
            string sceneName,
            float fadeInTime,
            Color screenColor,
            bool keepBGM)
        {
#if (UNITY_EDITOR)
            // only do this in Editor Mode,
            // this help level designer to do their job.
            if (!ReadSceneNames.CheckSceneAvailable(sceneName))
            {
                JCS_Debug.LogReminder("Scene [" + sceneName + "] you want to load is not in the Build Setting");
                return;
            }
#endif

            // if is loading already, dont load it agian
            if (mSwitchSceneEffect)
            {
                return;
            }

            // set the next scene name
            this.mNextSceneName = sceneName;

            JCS_GameSettings gs = JCS_GameSettings.instance;
            if (gs.SAVE_ON_SWITCH_SCENE &&
                gs.SAVE_GAME_DATA_FUNC != null)
            {
                // do the saving.
                gs.SAVE_GAME_DATA_FUNC.Invoke();
            }

            // preload the scene
            mAsyncOperation = SceneManager.LoadSceneAsync(mNextSceneName);
            mAsyncOperation.allowSceneActivation = false;

            switch (mSwitchSceneType)
            {
            case JCS_SwitchSceneType.BLACK_SCREEN:
            {
                // move to the last child in order
                // to render the black screen in front of
                // any UI's GUI
                mBlackScreen.MoveToTheLastChild();

                // set the screen color.
                // NOTE(jenchieh): always start with opacity the same
                // as previous.
                screenColor.a           = mBlackScreen.LocalColor.a;
                mBlackScreen.LocalColor = screenColor;

                // record down the screen color.
                JCS_SceneSettings.instance.SCREEN_COLOR = screenColor;

                // start fading in (black screen)
                mBlackScreen.FadeIn(fadeInTime);
            }
            break;

            case JCS_SwitchSceneType.SLIDE_SCREEN:
            {
                mBlackSlideScreen.MoveToTheLastChild();

                mBlackSlideScreen.StartSlideIn(mAlign, fadeInTime);
            }
            break;
            }



            JCS_SoundSettings ss = JCS_SoundSettings.instance;

            ss.KEEP_BGM_SWITCH_SCENE = keepBGM;

            if (!keepBGM)
            {
                // start fading sound
                if (ss.SMOOTH_SWITCH_SOUND_BETWEEN_SCENE)
                {
                    // get the component.
                    if (mJCSFadeSound == null)
                    {
                        mJCSFadeSound = this.gameObject.AddComponent <JCS_FadeSound>();
                    }

                    mJCSFadeSound.SetAudioSource(JCS_SoundManager.instance.GetBGMAudioSource());

                    // fade out sound to zero
                    mJCSFadeSound.FadeOut(0, fadeInTime);
                }
            }

            // start check to switch scene or not
            mSwitchSceneEffect = true;

            // Pause the game depends on setting...
            JCS_GameManager.instance.GAME_PAUSE = mPauseGameWhileLoadingScene;
        }