示例#1
0
    //最適な行動の確認
    MostAction MostActionCheck(Character caster, int[] pos, List <ActionState> ActionList)
    {
        MostAction MA = new MostAction();

        int[,] Range = AttackRange(pos);

        float MaxPoint = 0;
        float point    = 0;

        foreach (ActionState a in ActionList)
        {
            List <Character> targets = TargetCheck(caster, Range, a);
            //Debug.Log (targets.Count);
            foreach (Character target in targets)
            {
                point = PointRating(a, target);

                if (point > MaxPoint)
                {
                    MaxPoint  = point;
                    MA.action = a.GetAction();
                    MA.target = target;
                }
            }
        }

        return(MA);
    }
示例#2
0
    //AIの開始
    //isMoveOnlyがtrueなら、行動の確認は移動範囲内のみ(範囲外の敵を感知しない)
    public IEnumerator AIStart(Character caster, bool isMoveRangeOnly = true)
    {
        t.setTarget(caster.gameObject);
        //自身の行えるAction確認
        List <ActionState> ActionList = ActionsCheck(caster);

        //移動力のリスト
        int[,] map = MoveRange(caster);
        yield return(null);

        //行動評価点格納用の配列確保
        yield return(StartCoroutine(PointsCheck(map, caster, ActionList, isMoveRangeOnly)));

        CharacterMove CMove = caster.GetComponent <CharacterMove>();

        int[] maxPos = MaxPosCheck(points, CMove.nowPos);//デバッグ中
        //int[] maxPos = new int[2];
        yield return(null);

        Debug.Log(maxPos[0] + ":" + maxPos[1] + "に移動して行動:" + points[maxPos[0], maxPos[1]]);

        t.setTarget(null);

        if (maxPos[0] != CMove.nowPos[0] && maxPos[1] != CMove.nowPos[1])
        {
            //ルーレットを回して移動力決定
            Invoke("RouretteStop", Random.Range(3, 6));
            yield return(StartCoroutine(MapMoveScript.MMS.SetPlayer(caster.gameObject, true)));

            //計算終了まで待機
            do
            {
                yield return(null);
            } while (MapMoveScript.MMS.isCaluculated);

            int[] movePos = MovePosEnter(map, points, CMove.MovePower);
            Debug.Log("移動力は" + CMove.MovePower);
            Debug.Log(movePos[0] + ":" + movePos[1] + "に移動して行動:" + points[movePos[0], movePos[1]]);

            //移動に成功したら
            if (MapMoveScript.MMS.MapChipDragg(movePos[0], movePos[1]))
            {
                MenuScript.MS.MoveEnterButton();
                do
                {
                    yield return(null);

                    Debug.Log("移動待機中");
                } while (MapMoveScript.MMS.isMoveEnd);
                yield return(new WaitForSeconds(0.1f));
            }
        }

        /*行動の実行*/
        MostAction MA = MostActionCheck(caster, new int[2] {
            CMove.nowPos[0], CMove.nowPos[1]
        }, ActionList);

        if (MA.action != null)
        {
            Debug.Log(MA.action.GetName());
            if (MA.action == caster.GetAttackAction().GetComponent <Action>())
            {
                MenuScript.MS.AttackButton();
            }
            else
            {
                MenuScript.MS.SkillButton();
                for (int i = 0; i < caster.skills.GetLength(0); i++)
                {
                    if (MA.action == caster.skills[i].GetComponent <Action>())
                    {
                        MenuScript.MS.SkillEnterButton(i);
                    }
                }
            }
            do
            {
                yield return(null);
            } while (ActionRange.AR.isAttackCaluculated);
            yield return(new WaitForSeconds(0.1f));

            bool isTarget = false;
            //対象の選択
            if (!MA.action.isAoe())
            {
                isTarget = CharacterSelect.CS.CharaSelect(MA.target.gameObject);
            }
            else
            {
            }

            //対象の選択に成功した場合
            if (isTarget)
            {
                //MenuScript.MS.ActionEnterButton();
                StatusOverlay.SO.OkButton();
            }
        }
        else
        {
            Debug.Log("最適な行動がありませんでした");
            MenuScript.MS.BreakButton();
        }

        //yield return null;
    }