Exemplo n.º 1
0
        void PlayBattle()
        {
            var battle = MasterLoader.GetBattle(user.NextBattleId);
            var player = MasterLoader.GetCharacter(user.CharacterId);

            if (battle == null)
            {
                battle = MasterLoader.GetBattle(10001);
            }

            var enemy = MasterLoader.GetCharacter(battle.CharacterId);

            battlePlayerImage.sprite = characterImage.sprite;
            battleEnemyImage.sprite  = battleModalEnemyImage.sprite;

            battlePlayerImage.SetNativeSize();
            battleEnemyImage.SetNativeSize();

            battleModalEnemyImage.sprite = null;

            var playerPower = user.Power + player.Power;
            var enemyPower  = enemy.Power;

            var randMax = 1.2f;
            var randMin = 0.8f;

            // 乱数
            var playerRand = Random.Range(randMin, randMax);
            var enemyRand  = Random.Range(randMin, randMax);

            // クリティカル
            var playerCritical = player.GetCritical(enemy);
            var enemyCritical  = enemy.GetCritical(player);

            // 最終計算
            playerPower = (long)(playerPower * (double)playerRand * playerCritical);
            enemyPower  = (long)(enemyPower * (double)enemyRand * enemyCritical);

            // セーブ
            var userRepository = new UserRepository();

            userRepository.Save(user);

            // パワー
            battlePlayerDescription.text = $"最終P: {playerPower}";
            battleEnemyDescription.text  = $"最終P: {enemyPower}";

            if (playerPower > enemyPower)
            {
                user.SetNextBattleId(battle.NextBattleId);
                battleResultDescription.text = "勝利!";
            }
            else
            {
                user.SubPower(enemyPower);
                battleResultDescription.text = "敗北…";
            }
        }
Exemplo n.º 2
0
        void Start()
        {
            MasterLoader.Load();

            var userRepository = new UserRepository();
            var user           = userRepository.Load();

            if (user == null)
            {
                user = userRepository.Create();
                userRepository.Save(user);
            }
            var character = MasterLoader.GetCharacter(user.CharacterId);

            characterImage.sprite = Resources.Load <Sprite>($"Illust/{character.ImagePath}");

            touchStart.onClick.AddListener(TouchStart);
        }
Exemplo n.º 3
0
        void Start()
        {
            // ワンモーダル
            commonOneModalYesButton.onClick.AddListener(() =>
            {
                commonOneModal.SetActive(false);
                commonModal.SetActive(false);
                battleModal.SetActive(false);
                gachaModal.SetActive(false);

                isPowerUp       = false;
                isMemberPowerUp = true;
            });

            // モーダルのYes/No
            commonModalYesButton.onClick.AddListener(() =>
            {
                onClickCommonModalYesButton?.Invoke();
            });

            commonModalNoButton.onClick.AddListener(() =>
            {
                onClickCommonModalNoButton?.Invoke();
            });

            // ガチャ
            powerUpLvButton.onClick.AddListener(() =>
            {
                commonOneModalDescription.text = $"アップデートをお待ち下さい。";
                commonOneModal.SetActive(true);
                return;
            });

            // バトル
            battleEndButton.onClick.AddListener(() =>
            {
                battlePlayerImage.sprite = null;
                battleEnemyImage.sprite  = null;
                Resources.UnloadUnusedAssets();

                commonOneModal.SetActive(false);
                commonModal.SetActive(false);
                battleModal.SetActive(false);
                battle.SetActive(false);

                isPowerUp       = false;
                isMemberPowerUp = true;
            });

            // バトル
            battleButton.onClick.AddListener(() =>
            {
                isPowerUp       = false;
                isMemberPowerUp = false;

                var battle = MasterLoader.GetBattle(user.NextBattleId);
                if (battle == null)
                {
                    battle = MasterLoader.GetBattle(10001);
                }
                if (battle == null)
                {
                    commonOneModalDescription.text = $"挑めるバトルがありません。\nアップデートをお待ち下さい。";
                    commonOneModal.SetActive(true);
                    return;
                }
                battleModal.SetActive(true);
                var character = MasterLoader.GetCharacter(battle.CharacterId);
                battleModalPlayerImage.sprite = characterImage.sprite;
                battleModalEnemyImage.sprite  = Resources.Load <Sprite>($"Illust/{character.ImagePath}");

                battleModalPlayerImage.SetNativeSize();
                battleModalEnemyImage.SetNativeSize();
            });

            battleModalYesButton.onClick.AddListener(() => {
                battle.SetActive(true);
                battleModal.SetActive(false);
                PlayBattle();
            });

            battleModalNoButton.onClick.AddListener(() => {
                var sprite = battleModalEnemyImage.sprite;
                battleModalEnemyImage.sprite = null;
                battleModal.SetActive(false);
                Resources.UnloadUnusedAssets();
                isPowerUp       = false;
                isMemberPowerUp = true;
            });

            // おやすみボタン
            sleepButton.onClick.AddListener(() =>
            {
                isPowerUp       = false;
                isMemberPowerUp = false;

                commonModalDescription.text = "アプリを終了しますか?";

                onClickCommonModalYesButton = () =>
                {
                    // メソッドグループにはしない。
                    Application.Quit();
                };

                onClickCommonModalNoButton = () =>
                {
                    commonModal.SetActive(false);
                    isPowerUp       = false;
                    isMemberPowerUp = true;
                };
            });

            // パワーアップボタン
            gachaButton.onClick.AddListener(() =>
            {
                isPowerUp       = false;
                isMemberPowerUp = false;

                commonModal.SetActive(true);
                commonModalDescription.text = "パワー獲得値が増加します\n" +
                                              $"必要パワー: {user.UsePowerUpLevel()}\n" +
                                              $"現在レベル: {user.PowerUpLevel}";

                commonOneModalDescription.text = $"パワーが足りません\n 不足: { (user.UsePowerUpLevel() - user.Power) }";

                onClickCommonModalYesButton = () =>
                {
                    commonModal.SetActive(false);
                    if (user.Power < user.UsePowerUpLevel())
                    {
                        commonOneModal.SetActive(true);
                        return;
                    }

                    user.SubPower(user.UsePowerUpLevel());
                    user.AddPowerUpLevel(1);
                    var userRepository = new UserRepository();
                    userRepository.Save(user);
                    UpdatePowerLabel();
                    UpdatePowerUpLvLabel();

                    isPowerUp       = false;
                    isMemberPowerUp = true;
                };

                onClickCommonModalNoButton = () =>
                {
                    commonModal.SetActive(false);
                    isPowerUp       = false;
                    isMemberPowerUp = true;
                };
            });

            // メンバーボタン
            memberLvButton.onClick.AddListener(() =>
            {
                isPowerUp       = false;
                isMemberPowerUp = false;

                commonModal.SetActive(true);
                commonModalDescription.text = "構成員もパワー稼ぎをします\n" +
                                              $"必要パワー: {user.UseMemberUpLevel()}\n" +
                                              $"現在レベル: {user.MemberLevel}";

                commonOneModalDescription.text = $"パワーが足りません\n 不足: { (user.UseMemberUpLevel() - user.Power) }";

                onClickCommonModalYesButton = () =>
                {
                    commonModal.SetActive(false);
                    if (user.Power < user.UseMemberUpLevel())
                    {
                        commonOneModal.SetActive(true);
                        return;
                    }

                    user.SubPower(user.UseMemberUpLevel());
                    user.AddMemberLevel(1);
                    var userRepository = new UserRepository();
                    userRepository.Save(user);
                    UpdatePowerLabel();
                    UpdateMemberLvLabel();

                    isPowerUp       = false;
                    isMemberPowerUp = true;
                };

                onClickCommonModalNoButton = () =>
                {
                    commonModal.SetActive(false);
                    isPowerUp       = false;
                    isMemberPowerUp = true;
                };
            });
        }