示例#1
0
文件: UnitAI.cs 项目: phiLyken/RC_1
    IEnumerator Attack(Unit target)
    {
        // MDebug.Log("ai: attack");

        yield return(null);

        //   MDebug.Log(m_unit.GetID() + " Selecting atk");
        UnitAction_ApplyEffectFromWeapon Attack = getAttack();

        // MDebug.Log(target);
        if (Attack == null || !Attack.HasRequirements(true))
        {
            yield break;
        }

        m_Actions.SelectAbility(Attack);
        yield return(new WaitForSeconds(0.25f));

        target.OnHover();
        yield return(new WaitForSeconds(0.25f));

        target.UnitSelected();
        yield return(null);

        target.OnHoverEnd();
    }
示例#2
0
文件: UnitAI.cs 项目: phiLyken/RC_1
    List <Tile> GetTilesFromWhichUnitCanAttack(Unit target)
    {
        UnitAction_ApplyEffectFromWeapon atk = getAttack();

        List <Tile> tiles      = TileManager.Instance.GetTilesInRange(target.currentTile, atk.GetRange());
        List <Tile> can_attack = tiles.Where(tile => atk.CanTarget(target, tile)).ToList();

        return(can_attack);
    }
示例#3
0
文件: UnitAI.cs 项目: phiLyken/RC_1
    List <Tile> GetTilesForAttack(Unit target, List <Tile> tiles_to_check)
    {
        UnitAction_ApplyEffectFromWeapon atk = getAttack();
        List <Tile> tiles = new List <Tile>();


        foreach (Tile t in tiles)
        {
            if (atk.CanTarget(target, t))
            {
                tiles.Add(t);
            }
        }

        return(tiles);
    }
示例#4
0
    public override void SetAbility(UnitActionBase ability)
    {
        UnitAction_ApplyEffectFromWeapon ae = ability as UnitAction_ApplyEffectFromWeapon;


        RegularList.SetEffects(ae.GetRegularEffects());

        if (ae.WeaponBehaviorIndex == 0)
        {
            UI_ToolTip_AdrenalineRush adr_ui = (Instantiate(Resources.Load("UI/ui_adrenaline_rush")) as GameObject).GetComponent <UI_ToolTip_AdrenalineRush>();
            adr_ui.transform.SetParent(AdrenalineBonus, false);
            adr_ui.Init(ability.GetOwner().Stats);
        }
        else
        {
            Divider.SetActive(false);
        }

        base.SetAbility(ability);
    }
示例#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;
            }
        }
    }