예제 #1
0
파일: UnitAI.cs 프로젝트: phiLyken/RC_1
    IEnumerator Move(Tile t)
    {
        MDebug.Log("^aiMOVE");
        yield return(null);

        //  MDebug.Log(m_unit.GetID()+ "Selecting move");
        UnitAction_Move move = getMove();

        m_Actions.SelectAbility(move);

        if (move == null || !move.HasRequirements(true))
        {
            MDebug.Log("^ai no move, no requirements");
            yield break;
        }

        yield return(new WaitForSeconds(0.5f));

        MDebug.Log("^aihover tile to for move ");

        t.OnHover();
        yield return(new WaitForSeconds(0.5f));

        MDebug.Log("^aiSelect tile to for move ");
        TileSelecter.SelectTile(t);
        t.OnHoverEnd();
        while (move.ActionInProgress)
        {
            yield return(null);
        }
    }
예제 #2
0
    void Awake()
    {
        TileSelector = Instantiate(TileSelectorPrefab);
        TileSelector.SetActive(false);

        UnitAction_Move move = GetComponent <UnitAction_Move>();

        move.OnSetPreviewTile += SetToPosition;
        move.OnUnselectAction += OnUnSelectedMove;
    }
예제 #3
0
파일: UnitAI.cs 프로젝트: phiLyken/RC_1
    IEnumerator MoveRandom()
    {
        MDebug.Log("^ai: random");
        UnitAction_Move move = getMove();

        Tile randomDest = GetRandomWalkableTile(move);

        if (randomDest != null)
        {
            yield return(StartCoroutine(Move(randomDest)));
        }
        else
        {
            yield return(new WaitForSeconds(1f));

            SkipTurn();
        }
    }
예제 #4
0
 void OnMoveStart(UnitAction_Move m)
 {
     UnitAnimator.SetWalking(true);
     m.OnActionComplete += OnMoveEnd;
 }
예제 #5
0
파일: UnitAI.cs 프로젝트: phiLyken/RC_1
    IEnumerator AttackOrMove()
    {
        MDebug.Log("What to do..`?");

        UnitAction_ApplyEffectFromWeapon attack = getAttack();
        UnitAction_Move move = getMove();

        //dictionary of all units and the paths by which they are attackable
        Dictionary <Unit, List <List <Tile> > > attack_map = GetPathMapForTargets();

        MDebug.Log("^aiAttack Map Count:" + attack_map.Count);
        List <Unit> units_attackable = Unit.GetAllUnitsOfOwner(0, false).Where(unit => attack.CanTarget(unit)).ToList();

        MDebug.Log("^aiAttackable " + units_attackable.Count);
        List <Unit> units_move_attackable = attack_map.Where(kvp => CanFinishPathInMoves(1, kvp.Value)).Select(kvp => kvp.Key).ToList();
        List <Unit> units_movable         = attack_map.Where(kvp => !units_move_attackable.Contains(kvp.Key)).Select(kvp => kvp.Key).ToList();


        if (attack_map.Count > 0 && (preferred_target == null || !preferred_target.IsActive))
        {
            preferred_target = M_Math.GetRandomObject(attack_map.Select(kvp => kvp.Key).ToList());
        }

        if (preferred_target == null)
        {
            yield return(StartCoroutine(MoveRandom()));

            yield break;
        }

        if (!units_attackable.Contains(preferred_target) && (!units_attackable.IsNullOrEmpty() && (!attack_map.ContainsKey(preferred_target) || M_Math.Roll(Constants.AI_TARGET_SWITCH_WHEN_OUT_OF_ATTACK_RANGE))))
        {
            MDebug.Log("^ainew Prefferred  from" + units_attackable.Count);
            preferred_target = M_Math.GetRandomObject(units_attackable);
        }

        if (attack.CanTarget(preferred_target) && units_attackable.Contains(preferred_target))
        {
            Tile better_pos = GetReachableAttackPosition(preferred_target);

            if (m_Actions.HasAP(2) && better_pos != null)
            {
                yield return(StartCoroutine(Move(better_pos)));

                yield break;
            }
            else
            {
                yield return(StartCoroutine(Attack(preferred_target)));

                yield break;
            }
        }
        else
        {
            List <Unit> other_move_targets = units_move_attackable.Where(unit => unit != preferred_target && !units_attackable.Contains(unit)).ToList();

            if (!other_move_targets.IsNullOrEmpty() && M_Math.Roll(Constants.AI_TARGET_SWITCH_TO_ATTACK_MOVE_WHEN_OUT_OF_MOVE_ATTACK_RANGE))
            {
                preferred_target = M_Math.GetRandomObject(other_move_targets);
            }
            else
            {
                if (!attack_map.ContainsKey(preferred_target) && !units_movable.IsNullOrEmpty() && M_Math.Roll(Constants.AI_TARGET_SWITCH_TO_CHASE_WHEN_OUT_OF_ATTACK_RANGE))
                {
                    preferred_target = M_Math.GetRandomObject(units_movable);
                }
            }

            if (attack_map.ContainsKey(preferred_target))
            {
                if (units_move_attackable.Contains(preferred_target))
                {
                    Tile attack_pos = GetReachableAttackPosition(preferred_target);

                    if (attack_pos != null)
                    {
                        yield return(StartCoroutine(Move(attack_pos)));
                    }
                    else
                    {
                        yield return(StartCoroutine(MoveRandom()));
                    }

                    yield break;
                }
                else
                {
                    Tile Final_Target_Tile = GetBestAttackPosition(preferred_target, attack_map[preferred_target].Select(path => path[path.Count - 1]).ToList());

                    List <Tile> final_path = TileManager.Instance.FindPath(m_unit.currentTile, Final_Target_Tile, m_unit);

                    Tile target = move.GetFurthestMovibleTileOnPath(final_path);

                    yield return(StartCoroutine(Move(target)));

                    yield break;
                }
            }
            else
            {
                yield return(StartCoroutine(MoveRandom( )));

                yield break;
            }
        }
    }
예제 #6
0
파일: UnitAI.cs 프로젝트: phiLyken/RC_1
 Tile GetRandomWalkableTile(UnitAction_Move m)
 {
     return(FindBestWalkableTile(GetWalkableTiles(m)));
 }
예제 #7
0
파일: UnitAI.cs 프로젝트: phiLyken/RC_1
 List <Tile> GetWalkableTiles(UnitAction_Move m)
 {
     return(m.GetWalkableTiles(m_unit.currentTile));
 }