Exemple #1
0
    //用来排序
    public int CompareTo(object obj)
    {
        CellInfo target = obj as CellInfo;

        if (target == null)
        {
            throw new NotImplementedException();
        }

        int thisValue;

        if (this.IsHump())
        {
            thisValue = this.posX * SORT_FLAG - this.posY * 200 + 100;
        }
        else
        {
            thisValue = this.posX * SORT_FLAG - this.posY * 200;
        }

        int targetValue;

        if (target.IsHump())
        {
            targetValue = target.posX * SORT_FLAG - target.posY * 200 + 100;
        }
        else
        {
            targetValue = target.posX * SORT_FLAG - target.posY * 200;
        }

        return(thisValue.CompareTo(targetValue));
    }
Exemple #2
0
    public WallInfo GetNeighborWallByDir(CellInfo cellInfo, CellDirType dirType)
    {
        bool isHump = cellInfo.IsHump();

        switch (dirType)
        {
        case CellDirType.left_up:
        case CellDirType.up:
        case CellDirType.right_up:
            return(GetWallByPos(cellInfo.posY, cellInfo.posX, (int)dirType));

        case CellDirType.left_down:
            if (cellInfo.posX > 0)
            {
                if (isHump)
                {
                    return(GetWallByPos(cellInfo.posY, cellInfo.posX - 1, 2));
                }
                else
                {
                    if (cellInfo.posY < (BattleModel.Instance.crtBattle.battle_height - 1))
                    {
                        return(GetWallByPos(cellInfo.posY + 1, cellInfo.posX - 1, 2));
                    }
                }
            }
            break;

        case CellDirType.down:
            if (cellInfo.posY < (BattleModel.Instance.crtBattle.battle_height - 1))
            {
                return(GetWallByPos(cellInfo.posY + 1, cellInfo.posX, 1));
            }
            break;

        case CellDirType.right_down:
            if (cellInfo.posX < (BattleModel.Instance.crtBattle.battle_width - 1))
            {
                if (isHump)
                {
                    return(GetWallByPos(cellInfo.posY, cellInfo.posX + 1, 0));
                }
                else
                {
                    if (cellInfo.posY < (BattleModel.Instance.crtBattle.battle_height - 1))
                    {
                        return(GetWallByPos(cellInfo.posY + 1, cellInfo.posX + 1, 0));
                    }
                }
            }
            break;
        }
        return(null);
    }
Exemple #3
0
    private static CellInfo FindSlider(CellInfo blank)
    {
        CellInfo findCell = null;

        int humpOff = blank.IsHump() ? -1 : 0;
        int slidOff = CellInfo.SORT_FLAG;

        findCell = CellModel.Instance.GetCellByPos(blank.posX + slidOff, blank.posY + humpOff);
        WallInfo slidWall = WallModel.Instance.GetWallByPos(blank.posY, blank.posX, 1 + slidOff);

        if (findCell == null || !findCell.CanMove() || !slidWall.CanPass())
        {
            findCell = CellModel.Instance.GetCellByPos(blank.posX - slidOff, blank.posY + humpOff);
            return(findCell);
        }
        return(findCell);
    }
Exemple #4
0
    private static CellInfo FindBlank(CellInfo mover)
    {
        CellInfo findCell = null;

        int humpOff = mover.IsHump() ? 0 : 1;

        int random  = Random.Range(0, 2);
        int slidOff = random > 0 ? 1 : -1;

        findCell = GetCellByPos(mover.posX + slidOff, mover.posY + humpOff);
        if (findCell == null || !findCell.isBlank)
        {
            findCell = GetCellByPos(mover.posX - slidOff, mover.posY + humpOff);
            return(findCell);
        }
        return(findCell);
    }
Exemple #5
0
    public WallInfo GetWall(CellInfo fromCell, CellInfo toCell)
    {
        if (fromCell.posX == toCell.posX && fromCell.posY == toCell.posY)
        {//xiang tong
            return(null);
        }
        if (Mathf.Abs(fromCell.posX - toCell.posX) > 1 || Mathf.Abs(fromCell.posY - toCell.posY) > 1)
        {// tai yuan
            return(null);
        }
        CellInfo targetCell;
        int      targetN = 1;

        if (fromCell.posX == toCell.posX)//up dowm
        {
            targetCell = fromCell.posY > toCell.posY ? fromCell : toCell;
        }
        else
        {
            bool isLeft = fromCell.posX > toCell.posX;
            bool isUp   = fromCell.posY > toCell.posY;

            if (fromCell.posY == toCell.posY)
            {
                if (toCell.IsHump())
                {
                    isUp = true;
                }
            }
            targetN    = (isLeft ? 1 : -1) * ((isLeft ? 1 : -1) + (isUp ? -1 : 1));
            targetCell = isUp ? fromCell : toCell;
        }

        WallInfo wall = GetWallByPos(targetCell.posY, targetCell.posX, targetN);

        return(wall);
    }
Exemple #6
0
    private static bool HasBlindBarrier(CellInfo blankCell, CellDirType dir)
    {
        int cellX, cellY, wallX, wallY, wallN;

        bool isHump = blankCell.IsHump();

        switch (dir)
        {
        case CellDirType.left_up:
            cellX = blankCell.posX - 1;
            if (isHump)
            {
                cellY = blankCell.posY - 1;
            }
            else
            {
                cellY = blankCell.posY;
            }
            break;

        case CellDirType.right_up:
            cellX = blankCell.posX + 1;
            if (isHump)
            {
                cellY = blankCell.posY - 1;
            }
            else
            {
                cellY = blankCell.posY;
            }
            break;

        default:
            cellX = blankCell.posX;
            cellY = blankCell.posY - 1;
            break;
        }

        wallX = blankCell.posX;
        wallY = blankCell.posY;
        wallN = (int)dir;

        CellInfo cellInfo = CellModel.Instance.GetCellByPos(cellX, cellY);
        WallInfo wallInfo = WallModel.Instance.GetWallByPos(wallY, wallX, wallN);

        if (cellY < 0 && wallInfo.CanPass())
        {
            return(false);
        }

        if (cellX < 0 || cellX >= BattleModel.Instance.crtBattle.battle_width)
        {
            return(true);
        }

        if (cellInfo == null)
        {
            return(true);
        }

        if (cellInfo.isBlindBlank)
        {
            return(true);
        }

        if (cellInfo.isMonsterHold)
        {
            return(true);
        }

        bool isCoverOpen = CoverModel.Instance.IsOpen(cellInfo.posX, cellInfo.posY);

        if (!isCoverOpen)
        {
            return(true);
        }

        if (cellInfo.isBlank == false && !cellInfo.CanMove())
        {
            return(true);
        }

        if (!wallInfo.CanPass())
        {
            return(true);
        }

        return(false);
    }
Exemple #7
0
    private static void SingleMove(bool single = false, bool isDeductStep = false)
    {
        bool change = false;

        CellModel.Instance.lineCells.Sort();
        //fill
        int n = CellModel.Instance.lineCells.Count - 1;

        for (; n >= 0; n--)
        {
            CellInfo blankTopCell = CellModel.Instance.lineCells[n];
            bool     isCoverOpen  = CoverModel.Instance.IsOpen(blankTopCell.posX, blankTopCell.posY);
            if (blankTopCell.isMonsterHold == false && blankTopCell.posY == 0 && isCoverOpen)
            {
                WallInfo topWall = WallModel.Instance.GetWallByPos(blankTopCell.posY, blankTopCell.posX, (int)CellDirType.up);
                if (topWall.CanPass())
                {
                    CellInfo addCell = CellModel.Instance.FillNewItem(blankTopCell, n, isDeductStep);
                    CellModel.Instance.AddMoveAnim(addCell, false);
                }
            }
        }

        int i;

        for (i = 0; i < CellModel.Instance.lineCells.Count; i++)
        {
            CellInfo blankCell   = CellModel.Instance.lineCells[i];
            bool     isCoverOpen = CoverModel.Instance.CanMoveIn(blankCell.posX, blankCell.posY);
            bool     hasFall     = false;
            if (blankCell.isMonsterHold == false && isCoverOpen)
            {
                if (blankCell.posY > 0 || (blankCell.posY == 0 && blankCell.IsHump() == false))
                {
                    //fall
                    WallInfo topWall = WallModel.Instance.GetWallByPos(blankCell.posY, blankCell.posX, (int)CellDirType.up);

                    CellInfo topCell = CellModel.Instance.GetCellByPos(blankCell.posX, blankCell.posY - 1);
                    if (topWall.CanPass())
                    {
                        if (topCell != null && topCell.CanMove())
                        {
                            CellModel.Instance.SwitchPos(blankCell, topCell);
                            blankCell.SwitchPos(topCell);
                            CellModel.Instance.AddMoveAnim(topCell, false);
                            hasFall = true;
                            change  = true;
                            break;
                        }
                    }
                    //Slid
                    if (hasFall == false)
                    {
                        if (topCell == null && blankCell.posY != 0)
                        {
                            continue;
                        }
                        if (topCell != null && topCell.isBlank)
                        {
                            //isCoverOpen = CoverModel.Instance.IsOpen(topCell.posX, topCell.posY);
                            if (topCell.isBlindBlank == false && topCell.isMonsterHold == false)
                            {
                                continue;
                            }
                        }

                        CellInfo slidCell = FindSlider(blankCell);
                        if (slidCell != null && slidCell.CanMove())
                        {
                            int posn = (int)CellDirType.left_up;
                            if (slidCell.posX > blankCell.posX)
                            {
                                posn = (int)CellDirType.right_up;
                            }
                            WallInfo slidWall = WallModel.Instance.GetWallByPos(blankCell.posY, blankCell.posX, posn);
                            if (slidWall.CanPass())
                            {
                                CellModel.Instance.SwitchPos(slidCell, blankCell);
                                slidCell.SwitchPos(blankCell);
                                CellModel.Instance.AddMoveAnim(slidCell, true);
                                change = true;
                                break;
                            }
                        }
                    }
                }
            }
        }
        if (change && single == false)
        {
            SingleMove(false, isDeductStep);
        }
    }
Exemple #8
0
    private void PlayPutAutoSkill()
    {
        rootAction = new OrderAction();

        WaitActor waitActor = new WaitActor(200);

        rootAction.AddNode(waitActor);

        List <SkillEntityInfo> skillEntitys = SkillModel.Instance.GetNewSkillEntitys();

        fightUI.ShowSkill();


        if (lastTouchCell != null && skillEntitys.Count > 0)
        {
            ParallelAction parallelAction = new ParallelAction();
            int            holdIndex      = 0;
            bool           lastIsHump     = lastTouchCell.IsHump();
            for (int i = 0; i < skillEntitys.Count; i++)
            {
                OrderAction skillOrder = new OrderAction();

                SkillEntityInfo skillEntity = skillEntitys[i];

                Vector2 addPos = new Vector2();

                for (int h = holdIndex; h < 19; h++)
                {
                    Vector2 holePos = FightConst.GetHoleByLevel(h, lastIsHump);

                    Vector2 checkPos = new Vector2(lastTouchCell.posX + holePos.x, lastTouchCell.posY - holePos.y);

                    CellInfo checkCell = CellModel.Instance.GetCellByPos((int)checkPos.x, (int)checkPos.y);

                    if (checkCell != null && checkCell.isBlank)
                    {
                        addPos    = checkPos;
                        holdIndex = h + 1;
                        break;
                    }
                }

                CellInfo addItem = CellModel.Instance.AddItem(skillEntity.seed.config_cell_item.id, (int)addPos.x, (int)addPos.y);

                SkillModel.Instance.ThrowSkillEntity(skillEntity, addItem);

                GameObject itemObj = CreateCellItem(addItem);
                itemObj.transform.SetParent(effectLayer.transform, false);
                Vector2 toPos = PosUtil.GetFightCellPos(addItem.posX, addItem.posY);
                PosUtil.SetCellPos(itemObj.transform, skillEntity.seed.seed_x, skillEntity.seed.seed_y, 1.0f);

                rootAction.AddNode(new PlaySoundActor("Useskill"));

                rootAction.AddNode(new ShowEffectActor(itemObj.transform, "effect_skill_fly"));

                rootAction.AddNode(new MoveActor((RectTransform)itemObj.transform, new Vector3(toPos.x, toPos.y, 0), 1200));

                skillOrder.AddNode(new SetLayerActor(itemObj.transform, transform));
                skillOrder.AddNode(new PlaySoundActor("PutAutoSkill"));
                skillOrder.AddNode(new ClearEffectActor(itemObj.transform, "effect_skill_fly"));
                skillOrder.AddNode(new ScaleActor((RectTransform)itemObj.transform, new Vector3(1.2f, 1.2f, 0), 0.2f));
                skillOrder.AddNode(new ScaleActor((RectTransform)itemObj.transform, new Vector3(1, 1, 0), 0.1f));

                parallelAction.AddNode(skillOrder);
            }
            rootAction.AddNode(parallelAction);
        }

        waitActor = new WaitActor(200);
        rootAction.AddNode(waitActor);
        ExecuteAction(FightStadus.auto_skill);
    }
Exemple #9
0
    private void CreatBrushs(CellInfo centerCell)
    {
        selectDepth = 1;

        list.ClearList();

        List <int> posIndexs = new List <int>()
        {
            5, 6, 2, 3
        };

        if (centerCell.posX < 1)
        {
            posIndexs = new List <int>()
            {
                1, 2, 3, 4
            };
            if (centerCell.posY < 1)
            {
                posIndexs = new List <int>()
                {
                    3, 4, 12, 13
                };
            }
            if (centerCell.posY >= (BattleModel.Instance.crtBattle.ShowHeight() - 1))
            {
                posIndexs = new List <int>()
                {
                    1, 2, 7, 8
                };
            }
        }
        else if (centerCell.posX >= (BattleModel.Instance.crtBattle.ShowWidth() - 1))
        {
            posIndexs = new List <int>()
            {
                1, 6, 5, 4
            };
            if (centerCell.posY < 1)
            {
                posIndexs = new List <int>()
                {
                    14, 13, 5, 4
                };
            }
            if (centerCell.posY >= (BattleModel.Instance.crtBattle.ShowHeight() - 1))
            {
                posIndexs = new List <int>()
                {
                    1, 6, 7, 18
                };
            }
        }
        else
        {
            if (centerCell.posY < 1)
            {
                posIndexs = new List <int>()
                {
                    14, 12, 5, 3
                };
            }
            if (centerCell.posY >= (BattleModel.Instance.crtBattle.ShowHeight() - 1))
            {
                posIndexs = new List <int>()
                {
                    2, 6, 8, 18
                };
            }
        }

        List <int> controlIds = new List <int>()
        {
            10101, 10102, 10103, 10104, 10105
        };
        List <Vector2> brushPoss = new List <Vector2> ();

        for (int i = 0; i < posIndexs.Count; i++)
        {
            int posIndex = posIndexs[i];

            Vector2 offsetPos;
            if (centerCell.IsHump())
            {
                if (posIndex >= FightConst.RING_HUMP[0].Count)
                {
                    offsetPos = FightConst.RING_HUMP[1][posIndex - FightConst.RING_HUMP[0].Count];
                }
                else
                {
                    offsetPos = FightConst.RING_HUMP[0][posIndex];
                }
            }
            else
            {
                if (posIndex >= FightConst.RING_VALLEY[0].Count)
                {
                    offsetPos = FightConst.RING_VALLEY[1][posIndex - FightConst.RING_VALLEY[0].Count];
                }
                else
                {
                    offsetPos = FightConst.RING_VALLEY[0][posIndex];
                }
            }

            int controlId = 0;
            for (int j = 0; j < controlIds.Count; j++)
            {
                int tempId = controlIds[j];

                if (tempId != centerCell.configId)
                {
                    controlId = tempId;
                    controlIds.RemoveAt(j);
                    break;
                }
            }

            brushPoss.Add(CreateBrushItem(centerCell.posX, centerCell.posY, (int)offsetPos.x, (int)offsetPos.y, controlId));
        }

        for (int i = 0; i < CellModel.Instance.allCells.Count; i++)
        {
            List <CellInfo> cellXs = CellModel.Instance.allCells[i];
            for (int j = 0; j < cellXs.Count; j++)
            {
                bool     has      = false;
                CellInfo cellInfo = cellXs[j];
                for (int n = 0; n < brushPoss.Count; n++)
                {
                    Vector2 brushPos = brushPoss[n];
                    if ((int)brushPos.x == cellInfo.posX && cellInfo.posY == (int)brushPos.y)
                    {
                        has = true;
                        break;
                    }
                }
                if (has == false)
                {
                    PropTouchItem itemCtr = CreateSelectItem(j, i, false);

                    if (j == centerCell.posX && i == centerCell.posY)
                    {
                        itemCtr.Select();
                    }
                }
            }
        }
    }
Exemple #10
0
    private static bool RadiateCheck(List <List <CellInfo> > allCells, CellInfo radiateCell)
    {
        CellInfo checkCenterInfo = radiateCell;
        //一轮查找
        List <CellInfo> firstRingCells = new List <CellInfo>();
        int             i;

        for (i = 0; i < checkList.Count; i++)
        {
            Vector2 indexPos;

            indexPos = FightConst.GetHoleByLevel(checkList[i], checkCenterInfo.IsHump());

            Vector2 offsetPos = new Vector2(checkCenterInfo.posX + indexPos.x, checkCenterInfo.posY - indexPos.y);

            CellInfo checkCell = GetCellByPos(allCells, (int)offsetPos.x, (int)offsetPos.y);

            if (checkCell != null && checkCell.isBlank == false && checkCell.isMonsterHold == false &&
                (checkCell.config.line_type > 0 || checkCell.config.cell_type == (int)CellType.radiate))
            {
                CoverInfo coverInfo = CoverModel.Instance.GetCoverByPos(checkCell.posY, checkCell.posX);
                if (coverInfo.CanLine())
                {
                    if (WallModel.Instance.CanLine(checkCenterInfo, checkCell))
                    {
                        firstRingCells.Add(checkCell);
                    }
                }
            }
            if (firstRingCells.Count > 1)
            {
                for (int j = 0; j < (firstRingCells.Count - 1); j++)
                {
                    CellInfo checkA = firstRingCells [j];
                    for (int n = (j + 1); n < firstRingCells.Count; n++)
                    {
                        CellInfo checkB = firstRingCells [n];
                        if (checkA.IsNeighbor(checkB))
                        {
                            if (WallModel.Instance.CanLine(checkA, checkB))
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
        }

        if (firstRingCells.Count == 0)
        {
            return(true);
        }
        else
        {
            for (int b = 0; b < firstRingCells.Count; b++)
            {
                CellInfo checkCenterInfo2 = firstRingCells[b];
                //二轮查找
                List <CellInfo> secondRingCells = new List <CellInfo>();
                for (i = 0; i < checkList.Count; i++)
                {
                    Vector2 indexPos = FightConst.GetHoleByLevel(checkList[i], checkCenterInfo2.IsHump());

                    Vector2 offsetPos = new Vector2(checkCenterInfo2.posX + indexPos.x, checkCenterInfo2.posY - indexPos.y);

                    CellInfo checkCell = GetCellByPos(allCells, (int)offsetPos.x, (int)offsetPos.y);

                    if (checkCell != null && checkCell.isBlank == false && checkCell.isMonsterHold == false &&
                        checkCenterInfo != checkCell && checkCell.config.line_type == checkCenterInfo.config.line_type)
                    {
                        CoverInfo coverInfo = CoverModel.Instance.GetCoverByPos(checkCell.posY, checkCell.posX);
                        if (coverInfo.CanLine())
                        {
                            if (WallModel.Instance.CanLine(checkCenterInfo2, checkCell))
                            {
                                secondRingCells.Add(checkCell);
                            }
                        }
                    }
                    if (secondRingCells.Count > 1)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
    }
Exemple #11
0
    private static bool RecursiveCheck(List <List <CellInfo> > tempAllCells)
    {
        CellInfo checkCenterInfo = null;
        int      i;

        for (i = 0; i < tempAllCells.Count; i++)
        {
            List <CellInfo> xCells = tempAllCells[i];
            for (int j = 0; j < xCells.Count; j++)
            {
                CellInfo cellInfo = xCells[j];
                if (cellInfo != null && checkCenterInfo == null)
                {
                    checkCenterInfo = cellInfo;
                    ClearCellByPos(tempAllCells, checkCenterInfo.posX, checkCenterInfo.posY);
                    break;
                }
            }
        }

        if (checkCenterInfo == null)
        {
            return(true);
        }
        else
        {
            //一轮查找
            List <CellInfo> firstRingCells = new List <CellInfo>();
            for (i = 0; i < checkList.Count; i++)
            {
                Vector2 indexPos;

                indexPos = FightConst.GetHoleByLevel(checkList[i], checkCenterInfo.IsHump());

                Vector2 offsetPos = new Vector2(checkCenterInfo.posX + indexPos.x, checkCenterInfo.posY - indexPos.y);

                CellInfo checkCell = GetCellByPos(tempAllCells, (int)offsetPos.x, (int)offsetPos.y);

                if (checkCell != null && checkCell.config.line_type == checkCenterInfo.config.line_type)
                {
                    if (WallModel.Instance.CanLine(checkCenterInfo, checkCell))
                    {
                        ClearCellByPos(tempAllCells, checkCell.posX, checkCell.posY);
                        firstRingCells.Add(checkCell);
                    }
                }
                if (firstRingCells.Count > 1)
                {
                    return(false);
                }
            }

            if (firstRingCells.Count == 0)
            {
                return(RecursiveCheck(tempAllCells));
            }
            else
            {
                checkCenterInfo = firstRingCells[0];
                //二轮查找
                for (i = 0; i < checkList.Count; i++)
                {
                    Vector2 indexPos = FightConst.GetHoleByLevel(checkList[i], checkCenterInfo.IsHump());

                    Vector2 offsetPos = new Vector2(checkCenterInfo.posX + indexPos.x, checkCenterInfo.posY - indexPos.y);

                    CellInfo checkCell = GetCellByPos(tempAllCells, (int)offsetPos.x, (int)offsetPos.y);

                    if (checkCell != null && checkCell.config.line_type == checkCenterInfo.config.line_type)
                    {
                        if (WallModel.Instance.CanLine(checkCenterInfo, checkCell))
                        {
                            return(false);
                        }
                    }
                }
                return(RecursiveCheck(tempAllCells));
            }
        }
    }