Ejemplo n.º 1
0
    IEnumerator AISearching()
    {
        int   num       = 0;
        float time      = 1.0f;
        float Limit     = 0.0f;
        bool  prevFight = false;

        //평화
        while (true)
        {
            if (Fight)
            {
                NCommand.StateChange(true);
            }
            else
            {
                NCommand.StateChange(false);
            }

            if (Fight != prevFight)
            {
                Limit = float.MaxValue;
            }
            if (Fight == false)
            {
                while (Peace.Count < 2)
                {
                    num = getRandom(1, 3);
                    Peace.Enqueue(num);
                }
            }
            //전투
            else
            {
                //전투중 AI 조건
                while (Battle.Count < 2)
                {
                    if (Vector3.Distance(Player.position, this.gameObject.transform.position) <= ObjLife.Range)
                    {
                        num = 12;
                    }
                    else
                    {
                        num = 11;
                    }
                    Battle.Enqueue(num);
                }
            }

            if (Limit >= time)
            {
                Limit = 0.0f;
                if (!Fight)
                {
                    num = (int)Peace.Dequeue();                    //동작 처리시에 큐서 빠져나감
                }
                else
                {
                    //num = (int)Battle.Dequeue();//동작 처리시에 큐서 빠져나감

                    if (Vector3.Distance(Player.position, this.gameObject.transform.position) <= ObjLife.Range)
                    {
                        num = getRandom(20, 24);
                    }
                    else
                    {
                        num = 11;
                    }
                }


                //실행할 동작 - 삭제할 부분
                Debug.Log(num);
                string temp;
                AITree.Instance.AIDic.TryGetValue(num, out temp);
                Debug.Log(temp);
                //실행할 동작 - 삭제할 부분

                switch (num)
                {
                case 0:
                {
                    //ani.SetBool("Stop", true);
                    ani.SetBool("IsMove", false);
                    time = Time_Nature_Stop;
                    break;
                }

                case 1:
                {
                    ani.SetBool("Stop", false);
                    ani.SetBool("IsMove", true);
                    time            = Time_Nature_Move;
                    msg.time        = time;
                    msg.destination = Stage5Pos.GetRandomPos();
                    msg.Speed       = ObjLife.Speed;
                    NCommand.NatureMove(msg);
                    break;
                }

                case 2:
                {
                    Fight = true;
                    break;
                }

                case 3:
                {
                    time = Time_Nomal_MoveWay;
                    break;
                }

                case 10:
                {
                    time = Time_Taget_Search;
                    break;
                }

                case 11:
                {
                    ani.SetBool("IsMove", true);
                    ani.SetBool("IsAttack", false);
                    time            = Time_Battle_Move;
                    msg.time        = time;
                    msg.destination = Player.position;
                    msg.Speed       = ObjLife.BattleSpeed;
                    BCommand.BattleMove(msg);
                    break;
                }

                case 12:
                {
                    //ani.SetBool("IsMove", false);
                    //ani.SetBool("IsAttack", true);
                    //time = Time_Normal_Attack;
                    //BCommand.Attack(time);
                    break;
                }

                case 20:
                {
                    ani.SetBool("IsMove", false);
                    ani.SetBool("Skill1", true);
                    time = Time_Skill_1;
                    BCommand.Skill(time, 1);
                    break;
                }

                case 21:
                {
                    ani.SetBool("IsMove", false);
                    ani.SetBool("Skill2", true);
                    time = Time_Skill_2;
                    BCommand.Skill(time, 2);
                    break;
                }

                case 22:
                {
                    ani.SetBool("IsMove", false);
                    ani.SetBool("Skill3", true);
                    time = Time_Skill_3;
                    BCommand.Skill(time, 3);
                    break;
                }

                case 23:
                {
                    ani.SetBool("IsMove", false);
                    ani.SetBool("Skill4", true);
                    time = Time_Skill_4;
                    BCommand.Skill(time, 4);
                    break;
                }

                default:
                    time = 1.0f;
                    break;
                }
                prevFight = Fight;
            }
            Limit += 0.1f;
            yield return(new WaitForSeconds(0.1f));
        }
    }
Ejemplo n.º 2
0
    IEnumerator AISearching()
    {
        int   num       = 0;
        float time      = 1.0f;
        float Limit     = 0.0f;
        bool  prevFight = false;

        //평화
        while (true)
        {
            if (ObjLife.Hp <= 0)
            {
                Targetting T;
                T = FindObjectOfType <Targetting>().GetComponent <Targetting>();
                Debug.Log(T);
                ani.SetBool("Die", true);

                MobSound.PlaySound(3);

                yield return(new WaitForSeconds(Die_Time));

                this.gameObject.SetActive(false);
            }
            {
                if (Fight)
                {
                    NCommand.StateChange(true);
                }
                else
                {
                    NCommand.StateChange(false);
                }

                if (Fight != prevFight)
                {
                    Limit = float.MaxValue;
                }
                if (Fight == false)
                {
                    while (Peace.Count < 2)
                    {
                        num = getRandom(0, 3);
                        Peace.Enqueue(num);
                    }
                }
                //전투
                else
                {
                    //전투중 AI 조건
                    while (Battle.Count < 2)
                    {
                        if (Vector3.Distance(Player.position, this.gameObject.transform.position) <= ObjLife.Range)
                        {
                            num = 12;
                        }
                        else
                        {
                            num = 11;
                        }
                        Battle.Enqueue(num);
                    }
                }

                if (Limit >= time)
                {
                    Limit = 0.0f;
                    if (!Fight)
                    {
                        num = (int)Peace.Dequeue();                        //동작 처리시에 큐서 빠져나감
                    }
                    else
                    {
                        //num = (int)Battle.Dequeue();//동작 처리시에 큐서 빠져나감

                        if (Vector3.Distance(Player.position, this.gameObject.transform.position) <= ObjLife.Range)
                        {
                            num = 12;
                        }
                        else
                        {
                            num = 11;
                        }
                    }

                    //	//
                    //	//실행할 동작 - 삭제할 부분
                    //	Debug.Log(num);
                    //	string temp;
                    //	AITree.Instance.AIDic.TryGetValue(num, out temp);
                    //	Debug.Log(temp);
                    //	//실행할 동작 - 삭제할 부분

                    switch (num)
                    {
                    case 0:
                    {
                        //ani.SetBool("Stop", true);
                        ani.SetBool("IsMove", false);
                        time = Time_Nature_Stop;
                        break;
                    }

                    case 1:
                    {
                        ani.SetBool("Stop", false);
                        ani.SetBool("IsMove", true);
                        time            = Time_Nature_Move;
                        msg.time        = time;
                        msg.destination = Stage5Pos.GetRandomPos();
                        msg.Speed       = ObjLife.Speed;
                        NCommand.NatureMove(msg);
                        break;
                    }

                    case 2:
                    {
                        ani.SetBool("Stop", false);
                        ani.SetBool("IsMove", false);
                        time = Time_Nomal_StopMotion;
                        break;
                    }

                    case 3:
                    {
                        time = Time_Nomal_MoveWay;
                        break;
                    }

                    case 10:
                    {
                        time = Time_Taget_Search;
                        break;
                    }

                    case 11:
                    {
                        ani.SetBool("Stop", false);
                        ani.SetBool("IsMove", true);
                        ani.SetBool("IsAttack", false);
                        time            = Time_Battle_Move;
                        msg.time        = time;
                        msg.destination = Player.position;
                        msg.Speed       = ObjLife.BattleSpeed;
                        BCommand.BattleMove(msg);
                        break;
                    }

                    case 12:
                    {
                        ani.SetBool("Stop", false);
                        ani.SetBool("IsMove", false);
                        ani.SetBool("IsAttack", true);
                        time = Time_Normal_Attack;
                        BCommand.Attack(time, isRange);
                        break;
                    }

                    default:
                        time = 1.0f;
                        break;
                    }
                    prevFight = Fight;
                }
                Limit += 0.1f;
                yield return(new WaitForSeconds(0.1f));
            }
        }
    }