Exemplo n.º 1
0
    // 敵の攻撃処理
    public void EnemyAttack(GameObject character)
    {
        CharacterBattle characterBattleScript = character.GetComponent <CharacterBattle>();
        BaseStatus      characterStatus       = characterBattleScript.GetCharacterStatus();

        if (characterStatus.GetSkillList().Count <= 0)
        {
            return;
        }
        // 敵の行動アルゴリズム
        int randomValue = (int)(Random.value * characterStatus.GetSkillList().Count);
        var nowSkill    = characterStatus.GetSkillList()[randomValue];

        // テスト用(特定のスキルで確認)
        //nowSkill = characterStatus.GetSkillList()[0];

        if (nowSkill.GetSkillType() == Skill.Type.DirectAttack)
        {
            var targetNum = (int)(Random.value * allyCharacterInBattleList.Count);
            // 攻撃相手のCharacterBattleScript
            characterBattleScript.ChooseAttackOptions(CharacterBattle.BattleState.DirectAttack, allyCharacterInBattleList[targetNum], nowSkill);
        }
        else if (nowSkill.GetSkillType() == Skill.Type.MagicAttack)
        {
            var targetNum = (int)(Random.value * allyCharacterInBattleList.Count);
            if (characterBattleScript.GetMp() >= ((Magic)nowSkill).GetAmountToUseMagicPoints())
            {
                // 攻撃相手のCharacterBattleScript
                characterBattleScript.ChooseAttackOptions(CharacterBattle.BattleState.MagicAttack, allyCharacterInBattleList[targetNum], nowSkill);
            }
            else
            {
                // MPが足りない場合は直接攻撃を行う
                ShowMessage("MPが足りない!");
                characterBattleScript.ChooseAttackOptions(CharacterBattle.BattleState.DirectAttack, allyCharacterInBattleList[targetNum], characterStatus.GetSkillList().Find(skill => skill.GetSkillType() == Skill.Type.DirectAttack));
            }
        }
        else if (nowSkill.GetSkillType() == Skill.Type.RecoveryMagic)
        {
            if (characterBattleScript.GetMp() >= ((Magic)nowSkill).GetAmountToUseMagicPoints())
            {
                var targetNum = (int)(Random.value * enemyCharacterInBattleList.Count);
                // 回復相手のCharacterBattleScript
                characterBattleScript.ChooseAttackOptions(CharacterBattle.BattleState.Healing, enemyCharacterInBattleList[targetNum], nowSkill);
            }
            else
            {
                ShowMessage("MPが足りない!");
                var targetNum = (int)(Random.value * allyCharacterInBattleList.Count);
                // MPが足りない場合は直接攻撃を行う
                characterBattleScript.ChooseAttackOptions(CharacterBattle.BattleState.DirectAttack, allyCharacterInBattleList[targetNum], characterStatus.GetSkillList().Find(skill => skill.GetSkillType() == Skill.Type.DirectAttack));
            }
        }
    }