Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (MatchSystem.instance.GetActivePlayer() == _creatureStat && MatchSystem.instance.CanAction)
        {
            List <CreatureStats> enemies = MatchSystem.instance.GetAllPlayers()
                                           .Where(x => x != _creatureStat)
                                           .Where(x => x.team != _creatureStat.team).ToList();
            //Debug.LogFormat("AI нашел {0} врагов", enemies.Count);

            if (enemies.Count > 0)
            {
                AIPriority enemy = checkPrority(enemies);
                if (enemy == null)
                {
                    return;
                }

                if (enemy.isAttack)
                {
                    //AttackAction action = new AttackAction(_creatureStat, enemy.enemy);
                    AttackAction action = GetComponent <AttackAction>();
                    action.Init(enemy.enemy);
                    MatchSystem.instance.RunAction(action);
                }
                else
                {
                    //MoveAction action = new MoveAction(_creatureStat, enemy.tail);
                    MoveAction action = GetComponent <MoveAction>();
                    action.Init(enemy.tail);
                    MatchSystem.instance.RunAction(action);
                }
            }
        }
    }
Ejemplo n.º 2
0
 private void Start()
 {
     unitShop = GameObject.Find("UnitShop").GetComponent <ShopManager>();
     action   = new AIAction(this);
     priority = new AIPriority(this);
 }
Ejemplo n.º 3
0
    AIPriority checkPrority(List <CreatureStats> enemies)
    {
        List <AIPriority> priorityList = new List <AIPriority>();

        foreach (CreatureStats enemy in enemies)
        {
            Tail       tailEnemy = getTail(enemy.transform.position);
            AIPriority aip       = new AIPriority();

            //Проверяем на возможность атаковать
            if (GameHelper.instance.CheckAttack(_creatureStat, enemy))
            {
                aip.enemy    = enemy;
                aip.distance = 1;
                aip.tail     = tailEnemy;
                aip.isAttack = true;
                priorityList.Add(aip);
                continue;
            }

            //Логика приоритета для дальних персов
            if (_creatureStat.rangeAttack > 0)
            {
                //Ищем ближайшую точку, с которой сможем попасть по врагу
                Collider[] cols = Physics.OverlapSphere(enemy.transform.position, ((float)_creatureStat.rangeAttack) - 0.4f, 1 << 8);

                Collider minCol = cols.OrderBy(x => Vector3.Distance(x.transform.position, gameObject.transform.position)).FirstOrDefault();

                List <Vector3> path = PathFinder.instance.GetPath(getTail(_creatureStat.transform.position).transform.position, minCol.transform.position, _creatureStat.SPD);

                if (path.Count > 0)
                {
                    aip.path     = path;
                    aip.enemy    = enemy;
                    aip.distance = path.Count;
                    aip.tail     = getTail(path.Last());
                    priorityList.Add(aip);
                    continue;
                }
            }
            //Логика для ближнего бойца
            List <Vector3> pathToEnemy = PathFinder.instance.GetPath(getTail(_creatureStat.transform.position).transform.position, tailEnemy.transform.position, _creatureStat.SPD);

            if (pathToEnemy.Count == 0)
            {
                continue;
            }

            List <Vector3> allPath = PathFinder.instance.GetPath(getTail(_creatureStat.transform.position).transform.position, tailEnemy.transform.position);

            if (allPath.Count == pathToEnemy.Count)
            {
                pathToEnemy.RemoveAt(pathToEnemy.Count - 1);
            }

            aip.path         = pathToEnemy;
            aip.enemy        = enemy;
            aip.distance     = pathToEnemy.Count;
            aip.fullDistance = allPath.Count;
            aip.tail         = getTail(pathToEnemy.Last());

            priorityList.Add(aip);
        }

        AIPriority first = priorityList.OrderBy(x => x.distance - (x.isAttack?1:0) + x.fullDistance).FirstOrDefault();

        return(first);
    }
Ejemplo n.º 4
0
    /// <summary>
    /// 우선순위 체크 0.25초마다.
    /// </summary>
    /// <returns></returns>
    protected IEnumerator AI_Priority_Check()
    {
        if (GetComponent <MinionBehavior>() != null)
        {
            while (!isDead)
            {   //bool. CC기에 맞았는가
                yield return(new WaitForSeconds(0.2f));

                if (CC_hit)
                {
                    AI = AIPriority.CC;
                    //행동 못하게 고정, CC기 해제 코루틴
                }
                else if (!isLane)
                {
                    //길 벗어났을때.
                }
                else if (CurTarget != null && CurTarget.gameObject.activeInHierarchy == false)
                {
                    CurTarget = null;
                }
                //현재 설정된 타겟이 있거나, bool. help_signal true일때
                else if (CurTarget != null || Help_Signal)
                {
                    AI = AIPriority.KeepAttack;

                    if (Help_Signal)
                    {
                        //아군 챔프는 레이어로 판단?
                        //헬프시그널, 유효한 범위에 아군이 있고 그 아군이 적챔프한테 맞았을때,
                        //타겟을 적 챔프로 바꾼다 .
                        //각각의 챔피언은 챔피언을 타격하고있는지에 대한 bool 값을 가지고 있다.
                        //curtarget = Attacked_Champion
                    }
                    //챔피언이 부쉬 속으로 도망갔다면.
                    //if(ChampInBush)
                    //{
                    //  CurTarget = null;
                    //  break;
                    //}
                    var dist = Vector3.Distance(CurTarget.transform.position, this.transform.position);
                    if (dist > 6)
                    {
                        CurTarget = null;
                    }
                    if (CurTarget != null)
                    {   //공격함수
                        Attack();
                    }
                }
                //타겟리스트 속의 우선순위 설정
                // 타겟에 리스트가 0보다 크다면
                //else if (CurTarget == null)
                //{
                //    AI = AIPriority.FindNewTarget;
                //    //TargetPriority();
                //    ////공격 우선순위 따라.......
                //    //// 우선순위 1 챔피언 공격 하는자.
                //    //// 가장 가까운 미니언

                //}
                else if (CurTarget == null)
                {
                    AI = AIPriority.GoWaypoint;
                    //한번만 실행하게.
                    Minionspeed = 5;
                    animator.SetTrigger("Walk");
                    if (!iswalk)
                    {
                        iswalk = true;
                        //StartCoroutine(FollowPath(waypoints));
                    }
                }
                // 아무것도 하지않음
            }
        }
    }