public GameBattleUnit canAttack(int x, int y, GameItem item, GameUnitCampType camp)
    {
        list.Clear();

        int width  = GameBattleManager.instance.Width;
        int height = GameBattleManager.instance.Height;

        int min = 1;
        int max = 1;

        GameAttackRangeType type = GameAttackRangeType.Circle;

        if (item != null)
        {
            min  = (item.AttackRangeMin == GameDefine.INVALID_ID ? 1 : item.AttackRangeMin + 1);
            max  = item.AttackRangeMax;
            type = item.AttackRangeType;
        }

        if (type == GameAttackRangeType.Line)
        {
            for (int i = min; i <= max; i++)
            {
                Cell cell = new Cell();
                cell.x = x + i;
                cell.y = y;
                list.Add(cell);

                cell   = new Cell();
                cell.x = x - i;
                cell.y = y;
                list.Add(cell);

                cell   = new Cell();
                cell.x = x;
                cell.y = y - i;
                list.Add(cell);

                cell   = new Cell();
                cell.x = x;
                cell.y = y + i;
                list.Add(cell);
            }
        }
        else
        {
            for (int i = -max; i <= max; i++)
            {
                for (int j = -max; j <= max; j++)
                {
                    int xx = Mathf.Abs(j);
                    int yy = Mathf.Abs(i);

                    if (xx + yy <= max && xx + yy >= min)
                    {
                        Cell cell = new Cell();
                        cell.x = x + j;
                        cell.y = y + i;
                        list.Add(cell);
                    }
                }
            }
        }


        for (int i = 0; i < list.Count; i++)
        {
            if (list[i].x < 0 || list[i].y < 0 ||
                list[i].x >= width || list[i].y >= height)
            {
                continue;
            }

            GameBattleUnit unit = GameBattleUnitManager.instance.getUnit(list[i].x, list[i].y);

            if (unit != null &&
                unit.UnitCampType != camp)
            {
                return(unit);
            }
        }

        return(null);
    }
    public void show(int x, int y, GameItem item, GameUnitCampType camp, bool fade)
    {
        gameObject.SetActive(true);

        clear();

        list.Clear();

        int width  = GameBattleManager.instance.Width;
        int height = GameBattleManager.instance.Height;

        int min = 1;
        int max = 1;

        GameAttackRangeType type = GameAttackRangeType.Circle;

        if (item != null)
        {
            min  = (item.AttackRangeMin == GameDefine.INVALID_ID ? 1 : item.AttackRangeMin + 1);
            max  = item.AttackRangeMax;
            type = item.AttackRangeType;
        }

        if (type == GameAttackRangeType.Line)
        {
            for (int i = min; i <= max; i++)
            {
                Cell cell = new Cell();
                cell.x = x + i;
                cell.y = y;
                list.Add(cell);

                cell   = new Cell();
                cell.x = x - i;
                cell.y = y;
                list.Add(cell);

                cell   = new Cell();
                cell.x = x;
                cell.y = y - i;
                list.Add(cell);

                cell   = new Cell();
                cell.x = x;
                cell.y = y + i;
                list.Add(cell);
            }
        }
        else
        {
            for (int i = -max; i <= max; i++)
            {
                for (int j = -max; j <= max; j++)
                {
                    int xx = Mathf.Abs(j);
                    int yy = Mathf.Abs(i);

                    if (xx + yy <= max && xx + yy >= min)
                    {
                        Cell cell = new Cell();
                        cell.x = x + j;
                        cell.y = y + i;
                        list.Add(cell);
                    }
                }
            }
        }

        for (int i = 0; i < list.Count;)
        {
            if (list[i].x < 0 || list[i].y < 0 ||
                list[i].x >= width || list[i].y >= height)
            {
                list.RemoveAt(i);
            }
            else
            {
                i++;
            }
        }

        int dis = 99;

        attackCell.x = x;
        attackCell.y = y;


        for (int i = 0; i < list.Count; i++)
        {
            addCell(list[i].x, list[i].y, camp);

            int d = Mathf.Abs(x - list[i].x) + Mathf.Abs(y - list[i].y);

            if (dis > d)
            {
                GameBattleUnit unit = GameBattleUnitManager.instance.getUnit(list[i].x, list[i].y);

                if (unit != null &&
                    unit.UnitCampType != camp)
                {
                    dis          = d;
                    attackCell.x = list[i].x;
                    attackCell.y = list[i].y;
                }
            }
        }



        fadeCell(fade);

        isShow = true;

        GameBattleCursor.instance.show(0);
    }
    public bool canAttack(GameBattleUnit u, GameBattleUnit t)
    {
        if (u.BattleAIType == GameBattleAIType.AIStay)
        {
            return(false);
        }

        if (u.MoveBurst > 1)
        {
            return(false);
        }

        list.Clear();

        int width  = GameBattleManager.instance.Width;
        int height = GameBattleManager.instance.Height;

        int min = 1;
        int max = 1;

        GameAttackRangeType type = GameAttackRangeType.Circle;

        if (u.Weapon != null)
        {
            min  = (u.Weapon.AttackRangeMin == GameDefine.INVALID_ID ? 1 : u.Weapon.AttackRangeMin + 1);
            max  = u.Weapon.AttackRangeMax;
            type = u.Weapon.AttackRangeType;

            if (min > max)
            {
                min = max;
            }
        }
        else
        {
            return(false);
        }

        int x = u.PosX;
        int y = u.PosY;

        if (type == GameAttackRangeType.Line)
        {
            for (int i = min; i <= max; i++)
            {
                Cell cell = new Cell();
                cell.x = x + i;
                cell.y = y;
                list.Add(cell);

                cell   = new Cell();
                cell.x = x - i;
                cell.y = y;
                list.Add(cell);

                cell   = new Cell();
                cell.x = x;
                cell.y = y - i;
                list.Add(cell);

                cell   = new Cell();
                cell.x = x;
                cell.y = y + i;
                list.Add(cell);
            }
        }
        else
        {
            for (int i = -max; i <= max; i++)
            {
                for (int j = -max; j <= max; j++)
                {
                    int xx = Mathf.Abs(j);
                    int yy = Mathf.Abs(i);

                    if (xx + yy <= max && xx + yy >= min)
                    {
                        Cell cell = new Cell();
                        cell.x = x + j;
                        cell.y = y + i;
                        list.Add(cell);
                    }
                }
            }
        }


        for (int i = 0; i < list.Count; i++)
        {
            if (list[i].x < 0 || list[i].y < 0 ||
                list[i].x >= width || list[i].y >= height)
            {
                continue;
            }

            GameBattleUnit unit = GameBattleUnitManager.instance.getUnit(list[i].x, list[i].y);

            if (unit == t)
            {
                return(true);
            }
        }

        return(false);
    }
示例#4
0
    public void canAttack(int x, int y, GameItem m, GameUnitCampType camp)
    {
        attackUnits.Clear();
        list.Clear();

        int width  = GameBattleManager.instance.Width;
        int height = GameBattleManager.instance.Height;

        int min = (m.AttackRangeMin == GameDefine.INVALID_ID ? 1 : m.AttackRangeMin + 1);
        int max = m.AttackRangeMax;

        if (min > max)
        {
            min = max;
        }

        rangeType = m.AttackRangeType;
        posX      = x;
        posY      = y;

        switch (rangeType)
        {
        case GameAttackRangeType.Circle:
        {
            for (int i = -max; i <= max; i++)
            {
                for (int j = -max; j <= max; j++)
                {
                    int xx = Mathf.Abs(j);
                    int yy = Mathf.Abs(i);

                    if (xx + yy <= max && xx + yy >= min)
                    {
                        Cell cell = new Cell();
                        cell.x = x + j;
                        cell.y = y + i;
                        list.Add(cell);
                    }
                }
            }

            if (m.AttackRangeMin == 0)
            {
                Cell cell = new Cell();
                cell.x = x;
                cell.y = y;
                list.Add(cell);
            }

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].x < 0 || list[i].y < 0 ||
                    list[i].x >= width || list[i].y >= height)
                {
                    continue;
                }

                getUnitsCircle(x, y, list[i].x, list[i].y, m, camp);
            }
        }
        break;

        case GameAttackRangeType.Line:
        {
            getUnitsLine(x, y, m, camp);
        }
        break;
        }
    }
示例#5
0
    public void showUse(int x, int y, GameItem item, GameUnitCampType camp, bool fade)
    {
        gameObject.SetActive(true);

        clear();

        list.Clear();

        int width  = GameBattleManager.instance.Width;
        int height = GameBattleManager.instance.Height;

        int min = (item.UseRangeMin == GameDefine.INVALID_ID ? 1 : item.UseRangeMin + 1);
        int max = item.UseRangeMax;

        if (min > max)
        {
            min = max;
        }

        rangeType = item.UseRangeType;
        posX      = x;
        posY      = y;

        switch (rangeType)
        {
        case GameAttackRangeType.Circle:
        {
            for (int i = -max; i <= max; i++)
            {
                for (int j = -max; j <= max; j++)
                {
                    int xx = Mathf.Abs(j);
                    int yy = Mathf.Abs(i);

                    if (xx + yy <= max && xx + yy >= min)
                    {
                        Cell cell = new Cell();
                        cell.x = x + j;
                        cell.y = y + i;
                        list.Add(cell);
                    }
                }
            }

            if (item.UseRangeMin == 0)
            {
                Cell cell = new Cell();
                cell.x = x;
                cell.y = y;
                list.Add(cell);
            }
        }
        break;

        case GameAttackRangeType.Line:
        {
            for (int i = min; i <= max; i++)
            {
                Cell cell = new Cell();
                cell.x = x + i;
                cell.y = y;
                list.Add(cell);

                cell   = new Cell();
                cell.x = x - i;
                cell.y = y;
                list.Add(cell);

                cell   = new Cell();
                cell.x = x;
                cell.y = y - i;
                list.Add(cell);

                cell   = new Cell();
                cell.x = x;
                cell.y = y + i;
                list.Add(cell);
            }
        }
        break;
        }


        bool b   = false;
        int  dis = 99;

        attackCell.x = x;
        attackCell.y = y;

        int size = item.UseRange;

        for (int i = 0; i < list.Count;)
        {
            if (list[i].x < 0 || list[i].y < 0 ||
                list[i].x >= width || list[i].y >= height)
            {
                list.RemoveAt(i);
                continue;
            }

            if (item.UseTargetType == GameTargetType.Summon &&
                GameBattlePathFinder.instance.isBlockPos(list[i].x, list[i].y, GameBattlePathFinder.BLOCK_EVENT))
            {
                list.RemoveAt(i);
                continue;
            }

            i++;
        }

        for (int i = 0; i < list.Count; i++)
        {
            addCell(list[i].x, list[i].y, camp);

            int d = Mathf.Abs(x - list[i].x) + Mathf.Abs(y - list[i].y);

            if (dis > d)
            {
                GameBattleUnit unit = GameBattleUnitManager.instance.getUnit(list[i].x, list[i].y);

                if (unit != null)
                {
                    switch (item.UseTargetType)
                    {
                    case GameTargetType.User:
                    {
                        if (unit.UnitCampType == camp)
                        {
                            dis          = d;
                            b            = true;
                            attackCell.x = list[i].x;
                            attackCell.y = list[i].y;
                        }
                    }
                    break;

                    case GameTargetType.Enemy:
                    {
                        if (unit.UnitCampType != camp)
                        {
                            dis          = d;
                            b            = true;
                            attackCell.x = list[i].x;
                            attackCell.y = list[i].y;
                        }
                    }
                    break;
                    }
                }
                else
                {
                    switch (item.UseTargetType)
                    {
                    case GameTargetType.Summon:
                    {
                        dis          = d;
                        b            = true;
                        attackCell.x = list[i].x;
                        attackCell.y = list[i].y;
                    }
                    break;
                    }
                }
            }
        }


        if (!b)
        {
            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].x < 0 || list[i].y < 0 ||
                    list[i].x >= width || list[i].y >= height)
                {
                    continue;
                }

                int d = Mathf.Abs(x - list[i].x) + Mathf.Abs(y - list[i].y);

                if (dis > d)
                {
                    for (int i0 = -size; i0 <= size; i0++)
                    {
                        for (int j0 = -size; j0 <= size; j0++)
                        {
                            int xx = Mathf.Abs(j0);
                            int yy = Mathf.Abs(i0);

                            if (xx + yy <= size)
                            {
                                GameBattleUnit unit = GameBattleUnitManager.instance.getUnit(list[i].x + j0, list[i].y + i0);

                                if (unit != null)
                                {
                                    switch (item.UseTargetType)
                                    {
                                    case GameTargetType.User:
                                    {
                                        if (unit.UnitCampType == camp)
                                        {
                                            dis          = d;
                                            attackCell.x = list[i].x;
                                            attackCell.y = list[i].y;
                                        }
                                    }
                                    break;

                                    case GameTargetType.Enemy:
                                    {
                                        if (unit.UnitCampType != camp)
                                        {
                                            dis          = d;
                                            attackCell.x = list[i].x;
                                            attackCell.y = list[i].y;
                                        }
                                    }
                                    break;
                                    }
                                }
                                else
                                {
                                    switch (item.UseTargetType)
                                    {
                                    case GameTargetType.Summon:
                                    {
                                        dis          = d;
                                        attackCell.x = list[i].x;
                                        attackCell.y = list[i].y;
                                    }
                                    break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }



        fadeCell(fade);

        isShow = true;

        GameBattleCursor.instance.show(item.UseRange);
    }
示例#6
0
    public void showGive(int x, int y, int rmin, int rmax, GameAttackRangeType type, int range, GameUnitCampType camp, bool fade)
    {
        gameObject.SetActive(true);

        clear();

        list.Clear();

        int width  = GameBattleManager.instance.Width;
        int height = GameBattleManager.instance.Height;

        int min = (rmin == GameDefine.INVALID_ID ? 1 : rmin + 1);
        int max = rmax;

        if (min > max)
        {
            min = max;
        }

        rangeType = type;
        posX      = x;
        posY      = y;


        switch (rangeType)
        {
        case GameAttackRangeType.Circle:
        {
            for (int i = -max; i <= max; i++)
            {
                for (int j = -max; j <= max; j++)
                {
                    int xx = Mathf.Abs(j);
                    int yy = Mathf.Abs(i);

                    if (xx + yy <= max && xx + yy >= min)
                    {
                        Cell cell = new Cell();
                        cell.x = x + j;
                        cell.y = y + i;
                        list.Add(cell);
                    }
                }
            }

            if (rmin == 0)
            {
                Cell cell = new Cell();
                cell.x = x;
                cell.y = y;
                list.Add(cell);
            }
        }
        break;

        case GameAttackRangeType.Line:
        {
            for (int i = min; i <= max; i++)
            {
                Cell cell = new Cell();
                cell.x = x + i;
                cell.y = y;
                list.Add(cell);

                cell   = new Cell();
                cell.x = x - i;
                cell.y = y;
                list.Add(cell);

                cell   = new Cell();
                cell.x = x;
                cell.y = y - i;
                list.Add(cell);

                cell   = new Cell();
                cell.x = x;
                cell.y = y + i;
                list.Add(cell);
            }
        }
        break;
        }

        for (int i = 0; i < list.Count;)
        {
            if (list[i].x < 0 || list[i].y < 0 ||
                list[i].x >= width || list[i].y >= height)
            {
                list.RemoveAt(i);
            }
            else
            {
                addCell(list[i].x, list[i].y, camp);
                i++;
            }
        }

        fadeCell(fade);

        isShow = true;

        GameBattleCursor.instance.show(range);
    }
    public void canAttackAI(GameBattleUnit unit1, int ux, int uy, int x, int y, GameSkill sk, GameUnitCampType camp, int id)
    {
        targetID = id;

        IsAttackUnits = false;
        checkUnitAI   = false;

        list.Clear();

        int width  = GameBattleManager.instance.Width;
        int height = GameBattleManager.instance.Height;

        int min = (sk.AttackRangeMin == GameDefine.INVALID_ID ? 1 : sk.AttackRangeMin + 1);
        int max = sk.AttackRangeMax;

        if (min > max)
        {
            min = max;
        }

        rangeType = sk.AttackRangeType;
        posX      = x;
        posY      = y;

        switch (rangeType)
        {
        case GameAttackRangeType.Circle:
        {
            for (int i = -max; i <= max; i++)
            {
                for (int j = -max; j <= max; j++)
                {
                    int xx = Mathf.Abs(j);
                    int yy = Mathf.Abs(i);

                    if (xx + yy <= max && xx + yy >= min)
                    {
                        Cell cell = new Cell();
                        cell.x = x + j;
                        cell.y = y + i;
                        list.Add(cell);
                    }
                }
            }

            if (sk.AttackRangeMin == 0)
            {
                Cell cell = new Cell();
                cell.x = x;
                cell.y = y;
                list.Add(cell);
            }

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].x < 0 || list[i].y < 0 ||
                    list[i].x >= width || list[i].y >= height)
                {
                    continue;
                }

                getUnitsCircleAI(unit1, ux, uy, x, y, list[i].x, list[i].y, sk, camp);
            }
        }
        break;

        case GameAttackRangeType.Line:
        {
            getUnitsLineAI(unit1, ux, uy, sk, camp);
        }
        break;
        }

        if (checkUnitAI)
        {
            for (int i = 0; i < attackUnits.Count; i++)
            {
                GameBattleUnit unit = attackUnits[i];

                GameUnitMove unitMove = GameUnitMoveTypeData.instance.getData(unit.MoveType);
                bool         fly      = unit.checkEffect(GameSkillResutlEffect.Under) ? true : unitMove.fly;

                List <GameBattleUnitMovement.Cell> cells = GameBattleUnitMovement.instance.getMoveList(
                    unit.PosX, unit.PosY, unit.Move, unit.MoveType, fly, unit.UnitCampType);

                for (int j = 0; j < cells.Count; j++)
                {
                    GameBattleUnit u = GameBattleUnitAttackSelection.instance.canAttack(
                        cells[j].x, cells[j].y, unit.Weapon, unit.UnitCampType);

                    if (u != null)
                    {
                        return;
                    }
                }
            }

            list.Clear();
            attackUnits.Clear();
        }
    }