Esempio n. 1
0
    void FixedUpdate()
    {
        FindPlayer();

        var direction = Vector2.zero;

        if (player != null)
        {
            //Activate the fight when the player gets near
            if ((player.transform.position - this.transform.position).sqrMagnitude < 20 * 20 && !activeFight)
            {
                //print("Activate Broken Golem Fight");
                activeFight = true;
                bgmManager.ChangeBGM(bossMusic);
                GetComponent <Enemy>().healthBar.SetActive(true);
            }


            //Face player
            if (player.transform.position.x < this.transform.position.x + 1.5f)
            {
                if (movingRight)
                {
                    Flip();
                }
            }
            else if (player.transform.position.x + 1.5f > this.transform.position.x)
            {
                if (!movingRight)
                {
                    Flip();
                }
            }

            //what to do when the fight is active
            if (activeFight)
            {
                FightLoop();
            }
            else if (bgmManager == null)
            {
                bgmManager = FindObjectOfType <MusicManager>();
            }
        }
    }
Esempio n. 2
0
    void die()
    {
        GameObject deathObject = Instantiate(deathEffect, transform.position, transform.rotation);

        deathObject.transform.localScale = new Vector2(transform.localScale.x, transform.localScale.y);
        SoundManager.PlaySound("explosion");

        if (changeMusicOnDeath)
        {
            bgmManager.ChangeBGM(newMusic);
        }

        CinemachineShake.Instance.ShakeCamera(15f, 0.5f, 0.2f);

        if (healthBar != null)
        {
            healthBar.gameObject.SetActive(false);
            Destroy(GetComponent <Enemy>().healthBar);
        }

        Destroy(gameObject);
    }
Esempio n. 3
0
    private void FixedUpdate()
    {
        m_wasFalling = m_Falling;
        m_wasJumping = m_Jumping;
        GroundCheck();
        FallCheck();
        JumpCheck();
        FindPlayer();
        speedMult = this.GetComponent <Enemy>().speedMult;

        //Restart attack cooldown when boss hits ground. And stop velocity when landing
        if (m_wasFalling && m_Grounded)
        {
            //OnLandEvent.Invoke();
            //SoundManager.PlaySound("landing");
            StopMove();
            landTime   = Time.time;
            lastAttack = landTime;
        }


        //Make sure it always jumps towards player
        if (player.transform.position.x - this.transform.position.x > 0)
        {
            movingRight = true;
        }
        else
        {
            movingRight = false;
        }



        var direction = Vector2.zero;

        if (player != null)
        {
            //Activate the fight when the player gets near
            if (Mathf.Abs(player.transform.position.x - this.transform.position.x) < 25 && Mathf.Abs(player.transform.position.y - this.transform.position.y) < 10 && !activeFight)
            {
                activeFight = true;
                bgmManager.ChangeBGM(bossMusic);
                GetComponent <Enemy>().healthBar.SetActive(true);
            }


            /*//Face player
             * if (player.transform.position.x < this.transform.position.x + 1.5f)
             * {
             *  if (movingRight)
             *      Flip();
             * }
             * else if (player.transform.position.x + 1.5f > this.transform.position.x)
             * {
             *  if (!movingRight)
             *      Flip();
             * }*/

            //what to do when the fight is active
            if (activeFight)
            {
                FightLoop();
            }
            else if (bgmManager == null)
            {
                bgmManager = FindObjectOfType <MusicManager>();
            }
        }
    }
Esempio n. 4
0
    // 勝利時の結果
    public IEnumerator DisplayVictoryResult(List <GameObject> allCharacterList, List <GameObject> allyCharacterInBattleList)
    {
        yield return(new WaitForSeconds(timeToDisplay));

        won = true;
        resultPanel.SetActive(true);
        // 戦闘で獲得した経験値
        var earnedExperience = 0;
        // 戦闘で獲得したお金
        var earnedMoney = 0;
        // 戦闘で獲得したアイテムとその個数
        Dictionary <Item, int> getItemDictionary = new Dictionary <Item, int>();
        // Floatのランダム値
        float randomFloat;
        // アイテム取得確率
        float probability;
        // キャラクターステータス
        BaseStatus BaseStatus;
        // 敵のアイテムディクショナリー
        ItemDictionary enemyItemDictionary;

        foreach (var character in allCharacterList)
        {
            BaseStatus = character.GetComponent <CharacterBattle>().GetCharacterStatus();
            if (BaseStatus as EnemyStatus != null)
            {
                earnedExperience   += ((EnemyStatus)BaseStatus).GetGettingExperience();
                earnedMoney        += ((EnemyStatus)BaseStatus).GetGettingMoney();
                enemyItemDictionary = ((EnemyStatus)BaseStatus).GetDropItemDictionary();
                // 敵が持っているアイテムの種類の数だけ繰り返し
                foreach (var item in enemyItemDictionary.Keys)
                {
                    // 0~100の間のランダム値を取得
                    randomFloat = Random.Range(0f, 100f);
                    // アイテムの取得確率を取得
                    probability = enemyItemDictionary[item];
                    // ランダム値がアイテム取得確率以下の値であればアイテム取得
                    if (randomFloat <= probability)
                    {
                        if (getItemDictionary.ContainsKey(item))
                        {
                            getItemDictionary[item]++;
                        }
                        else
                        {
                            getItemDictionary.Add(item, 1);
                        }
                    }
                }
            }
        }
        resultText.text  = earnedExperience + "の経験値を獲得した。\n";
        resultText.text += earnedMoney + "のお金を獲得した。\n";

        // パーティーステータスにお金を反映する
        partyStatus.SetMoney(partyStatus.GetMoney() + earnedMoney);

        // intのランダム値
        int        randomInt;
        AllyStatus allyStatus;

        // 取得したアイテムを味方パーティーに分配する
        foreach (var item in getItemDictionary.Keys)
        {
            // パーティーメンバーの誰にアイテムを渡すか決定
            randomInt  = Random.Range(0, allyCharacterInBattleList.Count);
            allyStatus = (AllyStatus)allyCharacterInBattleList[randomInt].GetComponent <CharacterBattle>().GetCharacterStatus();
            // キャラクターが既にアイテムを持っている時
            if (allyStatus.GetItemDictionary().ContainsKey(item))
            {
                allyStatus.SetItemNum(item, allyStatus.GetItemNum(item) + getItemDictionary[item]);
            }
            else
            {
                allyStatus.SetItemDictionary(item, getItemDictionary[item]);
            }
            resultText.text += allyStatus.GetCharacterName() + "は" + item.GetKanjiName() + "を" + getItemDictionary[item] + "個手に入れた。\n";
            resultText.text += "\n";
        }

        // 上がったレベル
        var levelUpCount = 0;
        // 上がったHP
        var raisedHp = 0;
        // 上がったMP
        var raisedMp = 0;
        // 上がった素早さ
        var raisedAgility = 0;
        // 上がった力
        var raisedPower = 0;
        // 上がった打たれ強さ
        var raisedStrikingStrength = 0;
        // 上がった魔法力
        var raisedMagicPower = 0;
        // LevelUpData
        LevelUpData levelUpData;

        // レベルアップ等の計算
        foreach (var characterObj in allyCharacterInBattleList)
        {
            var character = (AllyStatus)characterObj.GetComponent <CharacterBattle>().GetCharacterStatus();
            // 変数を初期化
            levelUpCount           = 0;
            raisedHp               = 0;
            raisedMp               = 0;
            raisedAgility          = 0;
            raisedPower            = 0;
            raisedStrikingStrength = 0;
            raisedMagicPower       = 0;
            levelUpData            = character.GetLevelUpData();

            // キャラクターに経験値を反映
            character.SetEarnedExperience(character.GetEarnedExperience() + earnedExperience);

            // そのキャラクターの経験値で何レベルアップしたかどうか
            for (int i = 1; i < levelUpData.GetLevelUpDictionary().Count; i++)
            {
                // レベルアップに必要な経験値を満たしていたら
                if (character.GetEarnedExperience() >= levelUpData.GetRequiredExperience(character.GetLevel() + i))
                {
                    levelUpCount++;
                }
                else
                {
                    break;
                }
            }
            // レベルを反映
            character.SetLevel(character.GetLevel() + levelUpCount);

            // レベルアップ分のステータスアップを計算し反映する
            for (int i = 0; i < levelUpCount; i++)
            {
                if (Random.Range(0f, 100f) <= levelUpData.GetProbabilityToIncreaseMaxHP())
                {
                    raisedHp += Random.Range(levelUpData.GetMinHPRisingLimit(), levelUpData.GetMaxHPRisingLimit());
                }
                if (Random.Range(0f, 100f) <= levelUpData.GetProbabilityToIncreaseMaxMP())
                {
                    raisedMp += Random.Range(levelUpData.GetMinMPRisingLimit(), levelUpData.GetMaxMPRisingLimit());
                }
                if (Random.Range(0f, 100f) <= levelUpData.GetProbabilityToIncreaseAgility())
                {
                    raisedAgility += Random.Range(levelUpData.GetMinAgilityRisingLimit(), levelUpData.GetMaxAgilityRisingLimit());
                }
                if (Random.Range(0f, 100f) <= levelUpData.GetProbabilityToIncreasePower())
                {
                    raisedPower += Random.Range(levelUpData.GetMinPowerRisingLimit(), levelUpData.GetMaxPowerRisingLimit());
                }
                if (Random.Range(0f, 100f) <= levelUpData.GetProbabilityToIncreaseStrikingStrength())
                {
                    raisedStrikingStrength += Random.Range(levelUpData.GetMinStrikingStrengthRisingLimit(), levelUpData.GetMaxStrikingStrengthRisingLimit());
                }
                if (Random.Range(0f, 100f) <= levelUpData.GetProbabilityToIncreaseMagicPower())
                {
                    raisedMagicPower += Random.Range(levelUpData.GetMinMagicPowerRisingLimit(), levelUpData.GetMaxMagicPowerRisingLimit());
                }
            }
            if (levelUpCount > 0)
            {
                resultText.text += character.GetCharacterName() + "は" + levelUpCount + "レベル上がってLv" + character.GetLevel() + "になった。\n";
                if (raisedHp > 0)
                {
                    resultText.text += "最大HPが" + raisedHp + "上がった。\n";
                    character.SetMaxHp(character.GetMaxHp() + raisedHp);
                }
                if (raisedMp > 0)
                {
                    resultText.text += "最大MPが" + raisedMp + "上がった。\n";
                    character.SetMaxMp(character.GetMaxMp() + raisedMp);
                }
                if (raisedAgility > 0)
                {
                    resultText.text += "素早さが" + raisedAgility + "上がった。\n";
                    character.SetAgility(character.GetAgility() + raisedAgility);
                }
                if (raisedPower > 0)
                {
                    resultText.text += "力が" + raisedPower + "上がった。\n";
                    character.SetPower(character.GetPower() + raisedPower);
                }
                if (raisedStrikingStrength > 0)
                {
                    resultText.text += "打たれ強さが" + raisedStrikingStrength + "上がった。\n";
                    character.SetStrikingStrength(character.GetStrikingStrength() + raisedStrikingStrength);
                }
                if (raisedMagicPower > 0)
                {
                    resultText.text += "魔法力が" + raisedMagicPower + "上がった。\n";
                    character.SetMagicPower(character.GetMagicPower() + raisedMagicPower);
                }
                resultText.text += "\n";
            }
        }
        // 結果を計算し終わった
        isDisplayResult = true;

        // 戦闘終了のBGMに変更する
        musicManager.ChangeBGM();

        // 結果後に数秒待機
        yield return(new WaitForSeconds(timeToDisplay));

        // 戦闘から抜け出す
        resultPanel.transform.Find("FinishText").gameObject.SetActive(true);
        isFinishResult = true;
    }
Esempio n. 5
0
 public void ToggleLoseMenu()
 {
     loseMenuUI.SetActive(true);
     isShown = true;
     mm.ChangeBGM(loseMusic);
 }