Beispiel #1
0
 public PathCell(Cell cell, CellPartEnum prevDirection, CellPartEnum nextDirection)
 {
     _cell = cell;
     _prevDirection = prevDirection;
     _nextDirection = nextDirection;
     _isAvoidObstracle = false;
 }
Beispiel #2
0
        private bool FindPath_Sub(Cell cell, Cell cellDest, ArrayList path, CellPartEnum direction, ArrayList deadPath, 
            bool ignoreDestCharacter, bool ignoreObstacle, bool useStraightAngle)
        {
            Debug.WriteLine(string.Format("Find cell at {0}", direction));

            Cell cellNext = null;
            if (direction == CellPartEnum.Center)
                cellNext = null;
            else
                cellNext = cell._adjacentCells[direction];

            if (cellNext == null)
            {
                // no more cell found
                Debug.WriteLine(string.Format("No cell"));

                // get new direction
                CellPartEnum direction2 = FindDirection(cell.GetCenterPoint(), cellDest.GetCenterPoint());
                if (direction == direction2)
                {
                    switch (direction2)
                    {
                        case CellPartEnum.LowerRight:
                            direction2 = CellPartEnum.LowerLeft;
                            break;
                        case CellPartEnum.LowerLeft:
                            direction2 = CellPartEnum.LowerRight;
                            break;
                        case CellPartEnum.UpperLeft:
                            direction2 = CellPartEnum.UpperRight;
                            break;
                        case CellPartEnum.UpperRight:
                            direction2 = CellPartEnum.UpperLeft;
                            break;
                    }
                }
                direction = direction2;

                //Debug.WriteLine(string.Format("Find cell on {0}", direction));
                return FindPath_Sub(cell, cellDest, path, direction, deadPath,
                    ignoreDestCharacter, ignoreObstacle, useStraightAngle);
            }

            if (!cellNext.HasPassability() || deadPath.Contains(cellNext))
            {
                // has character or dead cell
                //Debug.WriteLine(string.Format("Obstacle found"));

                if (ignoreDestCharacter)
                {
                    if (cellNext.Equals(cellDest))
                    {
                        path.Add(cellNext);

                        // end
                        return true;
                    }
                }

                if (ignoreObstacle)
                {
                    return FindPath_Good(cellNext, cellDest, direction, path, deadPath,
                        ignoreDestCharacter, ignoreObstacle, useStraightAngle);
                }
                else
                {
                    // change direction
                    Cell cellNextTest = GetPathNextCell(cell, cellDest, direction, deadPath);
                    if (cellNextTest != null)
                    {
                        // if go backward, remove unwanted (dead) cell
                        if (path.Contains(cellNextTest))
                        {
                            int index = path.IndexOf(cellNextTest);
                            while (path.Count - 1 > index)
                            {
                                Cell deadCell = (Cell)path[path.Count - 1];
                                deadPath.Add(deadCell);
                                path.RemoveAt(path.Count - 1);
                            }
                        }

                        //Debug.WriteLine(string.Format("ChangeDir, {0},{1},{2}", direction, cellNextTest._row, cellNextTest._col));
                        cellNext = cellNextTest;
                        path.Add(cellNext);

                        // continue to find next cell
                        cell = cellNext;
                    }
                    else
                    {
                        // cannot move
                        // end
                        Debug.WriteLine(string.Format("No more move"));
                        return false;
                    }

                    return FindPath_Sub(cell, cellDest, path, direction, deadPath,
                        ignoreDestCharacter, ignoreObstacle, useStraightAngle);
                }
            }

            return FindPath_Good(cellNext, cellDest, direction, path, deadPath,
                ignoreDestCharacter, ignoreObstacle, useStraightAngle);
        }
Beispiel #3
0
        private bool FindPath_Good(Cell cellNext, Cell cellDest, CellPartEnum direction, ArrayList path, ArrayList deadPath,
            bool ignoreDestCharacter, bool ignoreObstacle, bool useStraightAngle)
        {
            //Debug.WriteLine(string.Format("Accept cell {0},{1}", cellNext._row, cellNext._col));
            path.Add(cellNext);

            if (cellNext.Equals(cellDest))
            {
                // end
                //Debug.WriteLine("Reach Destination");
                return true;
            }

            if (useStraightAngle)
                direction = CellPartEnum.Center;
            else
            {
                // change direction if has whole/direct angle
                double degree = FindDegree(cellNext.GetCenterPoint(), cellDest.GetCenterPoint());
                if (Math.Abs(degree) <= 0.05)
                    direction = CellPartEnum.CenterRight;
                else if (Math.Abs(degree - DIGONAL_ANGLE) <= 0.05)
                    direction = CellPartEnum.LowerRight;
                else if (Math.Abs(degree - (180 - DIGONAL_ANGLE)) <= 0.05)
                    direction = CellPartEnum.LowerLeft;
                else if (Math.Abs(degree - 180) <= 0.05)
                    direction = CellPartEnum.CenterLeft;
                else if (Math.Abs(degree - (180 + DIGONAL_ANGLE)) <= 0.05)
                    direction = CellPartEnum.UpperLeft;
                else if (Math.Abs(degree - (360 - DIGONAL_ANGLE)) <= 0.05)
                    direction = CellPartEnum.UpperRight;
            }

            return FindPath_Sub(cellNext, cellDest, path, direction, deadPath,
                ignoreDestCharacter, ignoreObstacle, useStraightAngle);
        }
Beispiel #4
0
        private void FindPathAvoid_SubAdj(ArrayList directPath, ArrayList adjCells, ArrayList obsCells,
            List<ArrayList> pathAvoidLst, ArrayList pathAvoid, Cell prevCell)
        {
            ArrayList pathAvoid2 = null;
            foreach (Cell adjCell in prevCell._adjacentCells.Values)
            {
                if (pathAvoid.Contains(adjCell)) continue;
                if (obsCells.Contains(adjCell)) continue;
                if (!directPath.Contains(adjCell) && !adjCells.Contains(adjCell)) continue;

                Debug.WriteLine(string.Format("PA_SubAdj:{0},{1}", adjCell._row, adjCell._col));
                {
                    // clone a new pathAvoid
                    pathAvoid2 = new ArrayList();
                    foreach (Cell cellClone in pathAvoid)
                    {
                        pathAvoid2.Add(cellClone);
                    }

                    pathAvoidLst.Add(pathAvoid2);
                }

                if (directPath.Contains(adjCell))
                {
                    pathAvoid2.Add(adjCell);
                    continue;
                }

                pathAvoid2.Add(adjCell);

                FindPathAvoid_SubAdj(directPath, adjCells, obsCells, pathAvoidLst, pathAvoid2, adjCell);
            }

            pathAvoidLst.Remove(pathAvoid);
        }
Beispiel #5
0
        private void GetAdjCells(ArrayList directPath, ArrayList adjCells, ArrayList obstacles, Cell directCell)
        {
            foreach (Cell adjCell in directCell._adjacentCells.Values)
            {
                if (adjCell == null) continue;
                if (directPath.Contains(adjCell)) continue;
                if (adjCells.Contains(adjCell)) continue;

                if (!adjCell.HasPassability())
                {
                    if (obstacles.Contains(adjCell)) continue;

                    obstacles.Add(adjCell);
                    GetAdjCells(directPath, adjCells, obstacles, adjCell);
                }
                else
                    adjCells.Add(adjCell);
            }
        }
Beispiel #6
0
        public static Action CreateShootAction(StandardCharacter character, CellPartEnum attackDirection,
            ArrayList targets, Cell targetCell)
        {
            Action action = new Action(ActionTypeEnum.RangeAttack);

            SubAction subAction = new SubAction();
            action._subActions.Add(subAction);
            subAction._character = character;

            // add getting hit or death
            ArrayList defendTriggers = new ArrayList();
            ArrayList hitTriggers = new ArrayList();
            foreach (Heroes.Core.Battle.Characters.Armies.Army target in targets)
            {
                SubAction subAction2 = new SubAction();
                action._subActions.Add(subAction2);
                subAction2._character = target;

                AnimationSequence animationSeq = null;
                if (target._isDead)
                    animationSeq = subAction2.AddDeath(attackDirection);
                else if (target._isDefend)
                    animationSeq = subAction2.AddDefend(attackDirection);
                else
                    animationSeq = subAction2.AddGettingHit(attackDirection);

                subAction2._currentAnimationSeq = animationSeq;

                if (target._isDefend)
                    defendTriggers.Add(animationSeq);
                else
                    hitTriggers.Add(animationSeq);
            }

            subAction.AddStartShoot(attackDirection, defendTriggers);
            subAction.AddStopShoot(attackDirection, hitTriggers);

            subAction._currentAnimationSeq = (AnimationSequence)subAction._animationSeqs[0];

            return action;
        }
Beispiel #7
0
 private void SetDestCell(StandardCharacter c, Cell cell)
 {
     c._cell._character = null;
     c._cell = cell;
     c._cell._character = c;
 }
Beispiel #8
0
 public void InitCell(Cell cell)
 {
     _cell = cell;
     Point pt = cell.GetStandingPoint();
     this._currentAnimationPt = pt;
     this._destAnimationPt = new Point(pt.X, pt.Y);
 }
Beispiel #9
0
        private void BuildCells()
        {
            _cells = new Cell[_rowCount, _colCount];
            _rowTops = new int[_rowCount];
            _rowBottoms = new int[_rowCount];
            _colLefts = new int[_rowCount, _colCount];
            _colRights = new int[_rowCount, _colCount];

            int startx = 58;
            int starty = 86;
            int x = startx;
            int y = starty;

            for (int row = 0; row < _rowCount; row++)
            {
                _rowTops[row] = y;

                if (row % 2 == 1)
                    x = startx;
                else
                    x = startx + Cell.WIDTH_MIDDLE - 1;

                for (int col = 0; col < _colCount; col++)
                {
                    _colLefts[row, col] = x;

                    _cells[row, col] = new Cell(row, col, x, y);

                    x += Cell.WIDTH_BODY - 1;
                    _colRights[row, col] = x;
                }

                y += Cell.HEIGHT_HEAD + Cell.HEIGHT_BODY;
                _rowBottoms[row] = y + Cell.HEIGHT_HEAD;
            }

            // build surrounding cell
            for (int row = 0; row < _rowCount; row++)
            {
                for (int col = 0; col < _colCount; col++)
                {
                    Cell cell = _cells[row, col];

                    CellPartEnum direction = CellPartEnum.CenterRight;
                    Cell cell2 = GetNextCell(cell, direction);
                    cell._adjacentCells.Add(direction, cell2);

                    direction = CellPartEnum.CenterLeft;
                    cell2 = GetNextCell(cell, direction);
                    cell._adjacentCells.Add(direction, cell2);

                    direction = CellPartEnum.LowerRight;
                    cell2 = GetNextCell(cell, direction);
                    cell._adjacentCells.Add(direction, cell2);

                    direction = CellPartEnum.LowerLeft;
                    cell2 = GetNextCell(cell, direction);
                    cell._adjacentCells.Add(direction, cell2);

                    direction = CellPartEnum.UpperRight;
                    cell2 = GetNextCell(cell, direction);
                    cell._adjacentCells.Add(direction, cell2);

                    direction = CellPartEnum.UpperLeft;
                    cell2 = GetNextCell(cell, direction);
                    cell._adjacentCells.Add(direction, cell2);
                }
            }
        }
Beispiel #10
0
        public Cell GetNextCell(Cell cell, CellPartEnum direction)
        {
            if (cell == null) return null;

            switch (direction)
            {
                case CellPartEnum.UpperLeft:
                    {
                        return GetCell(cell._row - 1, cell._rect.Left);
                    }
                case CellPartEnum.UpperRight:
                    {
                        return GetCell(cell._row - 1, cell._rect.Right);
                    }
                case CellPartEnum.CenterLeft:
                    {
                        if (cell._col - 1 < 0)
                            return null;
                        else
                        {
                            return _cells[cell._row, cell._col - 1];
                        }
                    }
                case CellPartEnum.CenterRight:
                    {
                        if (cell._col + 1 >= _colCount)
                            return null;
                        else
                        {
                            return _cells[cell._row, cell._col + 1];
                        }
                    }
                case CellPartEnum.LowerRight:
                    {
                        return GetCell(cell._row + 1, cell._rect.Right);
                    }
                case CellPartEnum.LowerLeft:
                    {
                        return GetCell(cell._row + 1, cell._rect.Left);
                    }
                default:
                    return null;
            }
        }
Beispiel #11
0
        public bool FindPathAdjBest(Cell cellSrc, Cell cellDest,
            bool ignoreDestCharacter, bool ignoreObstacle, out ArrayList path)
        {
            path = null;

            ArrayList directions = new ArrayList();
            FindDirection(cellSrc.GetCenterPoint(), cellDest.GetCenterPoint(), out directions);

            // use fine path
            foreach (CellPartEnum direction in directions)
            {
                ArrayList path3 = new ArrayList();

                if (FindPathAdj(cellSrc, cellDest, direction,
                    ignoreDestCharacter, ignoreObstacle, false,
                    out path3))
                {
                    if (path == null || path3.Count < path.Count)
                    {
                        path = path3;
                    }
                }
            }

            //// use straight path
            //ArrayList path2 = null;
            //if (FindPathAdj(cellSrc, cellDest, (CellPartEnum)directions[0],
            //    ignoreDestCharacter, ignoreObstacle, true,
            //    out path2))
            //{
            //    if (path == null || path2.Count < path.Count)
            //    {
            //        path = path2;
            //    }
            //}

            return true;
        }
Beispiel #12
0
        public bool FindPath(Cell cellSrc, Cell cellDest, ArrayList path, CellPartEnum startingDirection,
            bool ignoreDestCharacter, bool ignoreObstacle, bool includeSrcCell, bool useStraightAngle)
        {
            if (includeSrcCell) path.Add(cellSrc);

            if (cellSrc.Equals(cellDest))
            {
                // end
                return true;
            }

            //CellPartEnum direction = FindDirection(cellSrc.GetCenterPoint(), cellDest.GetCenterPoint());
            CellPartEnum direction = startingDirection;
            Debug.WriteLine("--------------------------------------");
            Debug.WriteLine(string.Format("Start to find at {0}", direction));

            // detect unless cell
            ArrayList deadPath = new ArrayList();
            return FindPath_Sub(cellSrc, cellDest, path, direction, deadPath,
                ignoreDestCharacter, ignoreObstacle, useStraightAngle);
        }
Beispiel #13
0
        public bool FindPath(Cell cellSrc, Cell cellDest, ArrayList path,
            bool ignoreDestCharacter, bool ignoreObstacle)
        {
            ArrayList directions = null;
            FindDirection(cellSrc.GetCenterPoint(), cellDest.GetCenterPoint(), out directions);

            return FindPath(cellSrc, cellDest, path, (CellPartEnum)directions[0],
                ignoreDestCharacter, ignoreObstacle, false, false);
        }
Beispiel #14
0
 public CellPartEnum FindCellPart(int x, int y, Cell cell)
 {
     if (y <= cell._rect.Top + Cell.HEIGHT_HEAD)
     {
         // upper
         if (x <= cell._rect.Left + Cell.WIDTH_MIDDLE)
         {
             // left
             return CellPartEnum.UpperLeft;
         }
         else
         {
             // right
             return CellPartEnum.UpperRight;
         }
     }
     else if (y <= cell._rect.Top + Cell.HEIGHT_HEAD + Cell.HEIGHT_BODY)
     {
         // center
         if (x <= cell._rect.Left + Cell.WIDTH_BODY_LEFT)
         {
             // left
             return CellPartEnum.CenterLeft;
         }
         else if (x <= cell._rect.Left + Cell.WIDTH_BODY_LEFT + Cell.WIDTH_BODY_CENTER)
         {
             // center
             return CellPartEnum.Center;
         }
         else
         {
             // right
             return CellPartEnum.CenterRight;
         }
     }
     else
     {
         // lower
         if (x <= cell._rect.Left + Cell.WIDTH_MIDDLE)
         {
             // left
             return CellPartEnum.LowerLeft;
         }
         else
         {
             // right
             return CellPartEnum.LowerRight;
         }
     }
 }
Beispiel #15
0
        private Cell GetPathNextCell(Cell cell, Cell cellDest, CellPartEnum direction, ArrayList deadPath)
        {
            double degree = FindDegree(cell.GetCenterPoint(), cellDest.GetCenterPoint());

            switch (direction)
            {
                case CellPartEnum.CenterRight:
                    {
                        // get preferred directions
                        ArrayList directions = GetPathFavourDirections(degree, direction);
                        foreach (CellPartEnum direction2 in directions)
                        {
                            Cell cellNextTest = GetNextCell(cell, direction2);
                            if (cellNextTest != null && cellNextTest.HasPassability() && !deadPath.Contains(cellNextTest))
                            {
                                //Debug.WriteLine(string.Format("Change direction to {0},{1},{2}", direction2, cellNextTest._row, cellNextTest._col));
                                return cellNextTest;
                            }
                        }
                    }
                    break;
                case CellPartEnum.CenterLeft:
                    {
                        // get preferred directions
                        ArrayList directions = GetPathFavourDirections(degree, direction);
                        foreach (CellPartEnum direction2 in directions)
                        {
                            Cell cellNextTest = GetNextCell(cell, direction2);
                            if (cellNextTest != null && cellNextTest.HasPassability() && !deadPath.Contains(cellNextTest))
                            {
                                //Debug.WriteLine(string.Format("Change direction to {0},{1},{2}", direction2, cellNextTest._row, cellNextTest._col));
                                return cellNextTest;
                            }
                        }
                    }
                    break;
                case CellPartEnum.LowerRight:
                    {
                        // get preferred directions
                        ArrayList directions = GetPathFavourDirections(degree, direction);
                        foreach (CellPartEnum direction2 in directions)
                        {
                            Cell cellNextTest = GetNextCell(cell, direction2);
                            if (cellNextTest != null && cellNextTest.HasPassability() && !deadPath.Contains(cellNextTest))
                            {
                                //Debug.WriteLine(string.Format("Change direction to {0},{1},{2}", direction2, cellNextTest._row, cellNextTest._col));
                                return cellNextTest;
                            }
                        }
                    }
                    break;
                case CellPartEnum.LowerLeft:
                    {
                        // get preferred directions
                        ArrayList directions = GetPathFavourDirections(degree, direction);
                        foreach (CellPartEnum direction2 in directions)
                        {
                            Cell cellNextTest = GetNextCell(cell, direction2);
                            if (cellNextTest != null && cellNextTest.HasPassability() && !deadPath.Contains(cellNextTest))
                            {
                                //Debug.WriteLine(string.Format("Change direction to {0},{1},{2}", direction2, cellNextTest._row, cellNextTest._col));
                                return cellNextTest;
                            }
                        }
                    }
                    break;
                case CellPartEnum.UpperLeft:
                    {
                        // get preferred directions
                        ArrayList directions = GetPathFavourDirections(degree, direction);
                        foreach (CellPartEnum direction2 in directions)
                        {
                            Cell cellNextTest = GetNextCell(cell, direction2);
                            if (cellNextTest != null && cellNextTest.HasPassability() && !deadPath.Contains(cellNextTest))
                                return cellNextTest;
                        }
                    }
                    break;
                case CellPartEnum.UpperRight:
                    {
                        // get preferred directions
                        ArrayList directions = GetPathFavourDirections(degree, direction);
                        foreach (CellPartEnum direction2 in directions)
                        {
                            Cell cellNextTest = cell._adjacentCells[direction2];
                            if (cellNextTest != null && cellNextTest.HasPassability() && !deadPath.Contains(cellNextTest))
                            {
                                //Debug.WriteLine(string.Format("Change direction to {0},{1},{2}", direction2, cellNextTest._row, cellNextTest._col));
                                return cellNextTest;
                            }
                        }
                    }
                    break;
            }

            Debug.WriteLine("Change direction but no cell found.");
            return null;
        }
Beispiel #16
0
 private void SetDestCell(Heroes.Core.Battle.Armies.Army c, Cell cell)
 {
     c._cell._character = null;
     c._cell = cell;
     c._cell._character = c;
 }
Beispiel #17
0
 private int CalDiff(int x, int y, Cell cell)
 {
     if (y <= cell._rect.Top + Cell.HEIGHT_HEAD)
     {
         // upper
         if (x <= cell._rect.Left + Cell.WIDTH_MIDDLE)
         {
             // left
             return Math.Abs(cell._rect.Left + Cell.WIDTH_MIDDLE - x) + Math.Abs(cell._rect.Top + Cell.HEIGHT_HEAD - y);
             //return new Rectangle(cell._rect.Left, cell._rect.Top, 23, 10);
         }
         else
         {
             // right
             return Math.Abs(cell._rect.Left + Cell.WIDTH_MIDDLE + 1 - x) + Math.Abs(cell._rect.Top + Cell.HEIGHT_HEAD - y);
             //return new Rectangle(cell._rect.Left + 24, cell._rect.Top, 22, 10);
         }
     }
     else
     {
         // lower
         if (x <= cell._rect.Left + 23)
         {
             // left
             return Math.Abs(cell._rect.Left + Cell.WIDTH_MIDDLE - x) + Math.Abs(cell._rect.Top + Cell.HEIGHT_HEAD + Cell.HEIGHT_BODY - y);
             //return new Rectangle(cell._rect.Left, cell._rect.Top + 42, 23, 10);
         }
         else
         {
             // right
             return Math.Abs(cell._rect.Left + Cell.WIDTH_MIDDLE + 1 - x) + Math.Abs(cell._rect.Top + Cell.HEIGHT_HEAD + Cell.HEIGHT_BODY - y);
             //return new Rectangle(cell._rect.Left + 24, cell._rect.Top + 42, 22, 10);
         }
     }
 }
Beispiel #18
0
        private bool FindPathAdj(Cell cellSrc, Cell cellDest, CellPartEnum staringDirection,
            bool ignoreDestCharacter, bool ignoreObstacle, bool useStraightAngle, out ArrayList path)
        {
            path = null;
            bool hasObstacle = false;

            List<ArrayList> shortestPathAvoids = null;
            if (!FindPathAdj(cellSrc, cellDest, staringDirection,
                ignoreDestCharacter, ignoreObstacle, useStraightAngle,
                out shortestPathAvoids, out hasObstacle))
                return false;

            if (!hasObstacle)
            {
                if (shortestPathAvoids.Count > 0)
                {
                    path = shortestPathAvoids[0];

                    // remove srcCell
                    if (path.Count > 0) path.RemoveAt(0);
                }

                return true;
            }

            // find shortest path from srcCell to pathAvoid
            foreach (ArrayList shortestPathAvoid in shortestPathAvoids)
            {
                if (shortestPathAvoid.Count < 1) continue;

                int index = 0;
                while (index < shortestPathAvoid.Count)
                {
                    Cell cell = (Cell)shortestPathAvoid[index];

                    List<ArrayList> shortestPathAvoids2 = new List<ArrayList>();
                    bool hasObstacle2 = false;
                    if (!FindPathAdj(cellSrc, cell, staringDirection,
                        false, false, true,
                        out shortestPathAvoids2, out hasObstacle2))
                    {
                        break;
                    }
                    else
                    {
                        foreach (ArrayList shortestPathAvoid2 in shortestPathAvoids2)
                        {
                            if (shortestPathAvoid2.Count - 1 < index)
                            {
                                // shorter found
                                Debug.WriteLine("Shorter found.");

                                // remove previous
                                while (!shortestPathAvoid[0].Equals(cell))
                                {
                                    shortestPathAvoid.RemoveAt(0);
                                }

                                // add cell
                                foreach (Cell cell2 in shortestPathAvoid2)
                                {
                                    shortestPathAvoid.Insert(0, cell2);
                                }
                            }
                        }
                    }
                    index += 1;
                }
            }

            List<ArrayList> shortestPathAvoids3 = null;
            FindShortestPathAvoid(shortestPathAvoids, out shortestPathAvoids3);

            path = shortestPathAvoids3[0];

            // remove srcCell
            if (path.Count > 0) path.RemoveAt(0);

            return true;
        }
Beispiel #19
0
        public void SetCell(Cell cell)
        {
            _cell._character = null;

            _cell = cell;
            _cell._character = this;

            Point pt = cell.GetStandingPoint();
            this._destAnimationPt = pt;
        }
Beispiel #20
0
        private bool FindPathAdj(Cell cellSrc, Cell cellDest, CellPartEnum startingDirection,
            bool ignoreDestCharacter, bool ignoreObstacle, bool useStraightAngle,
            out List<ArrayList> shortestPathAvoids, out bool hasObstacle)
        {
            shortestPathAvoids = new List<ArrayList>();
            hasObstacle = false;

            // source is destination
            if (cellSrc.Equals(cellDest)) return true;

            // destination cannot has character or obstacle
            if (!cellDest.HasPassability())
            {
                if (!ignoreDestCharacter && !ignoreObstacle) return false;
            }

            // find direct path (shortest path)
            ArrayList directPath = new ArrayList();
            if (!FindPath(cellSrc, cellDest, directPath, startingDirection,
                true, true, true, useStraightAngle)) return false;

            // find all adjacent cells for obstacle
            ArrayList adjCells = new ArrayList();
            ArrayList obsCells = new ArrayList();
            GetAdjCells(directPath, cellDest, ignoreDestCharacter, adjCells, obsCells);

            // if no obstacles
            if (obsCells.Count < 1)
            {
                hasObstacle = false;
                shortestPathAvoids.Add(directPath);
                return true;
            }
            else
            {
                hasObstacle = true;
            }

            // find new path
            List<ArrayList> pathAvoids = null;
            FindPathAvoid(directPath, adjCells, obsCells, cellDest, out pathAvoids);

            if (pathAvoids.Count < 1) return false;

            // get shortest avoid path (might be many)
            FindShortestPathAvoid(pathAvoids, out shortestPathAvoids);

            if (shortestPathAvoids.Count < 1) return false;

            return true;
        }
Beispiel #21
0
        private void SetRangeAttackNAnimate(StandardCharacter attacker, StandardCharacter defender,
            CellPartEnum attackDirection, Cell targetCell)
        {
            // reset defend and wait
            Heroes.Core.Battle.Characters.Armies.Army army
                = (Heroes.Core.Battle.Characters.Armies.Army)attacker;
            army._isWait = false;
            army._isDefend = false;

            // attack
            SetAttackDamage(attacker, defender, true);
            attacker._shotRemain -= 1;

            // attack Action
            {
                ArrayList targets = new ArrayList();
                targets.Add(defender);

                Action action = Action.CreateShootAction(attacker, attackDirection, targets, targetCell);
                _actions.Add(action);
            }

            if (!defender._isDead)
            {
                // retaliate
                //if (defender._canRangeRetaliate && defender._retaliateRemain > 0 && defender._shotRemain > 0)
                //{
                //    SetAttackDamage(defender, attacker, true);
                //    defender._retaliateRemain -= 1;

                //    // retaliate action
                //    {
                //        CellPartEnum oppAttackDirection = BattleTerrain.GetOppositeDirection(attackDirection);

                //        ArrayList targets = new ArrayList();
                //        targets.Add(attacker);

                //        Action action = Action.CreateShootAction(defender, oppAttackDirection, targets, attacker._cell);
                //        _actions.Add(action);
                //    }
                //}

                // attack more
                {
                    ArrayList targets = new ArrayList();
                    targets.Add(defender);

                    for (int i = 1; i < attacker._noOfAttack; i++)
                    {
                        SetAttackDamage(attacker, defender, true);
                        attacker._shotRemain -= 1;

                        // attack more action
                        {
                            Action action = Action.CreateShootAction(attacker, attackDirection, targets, targetCell);
                            _actions.Add(action);
                        }
                    }
                }
            }
        }
Beispiel #22
0
        private void FindPathAvoid(ArrayList directPath, ArrayList adjCells, ArrayList obsCells, Cell destCell,
            out List<ArrayList> pathAvoidLst)
        {
            pathAvoidLst = new List<ArrayList>();
            pathAvoidLst.Add(new ArrayList());
            int index = 0;
            ArrayList pathAvoid = null;
            while (index < pathAvoidLst.Count)
            {
                pathAvoid = (ArrayList)pathAvoidLst[index];

                if (pathAvoid.Count > 0 && pathAvoid[pathAvoid.Count - 1].Equals(destCell))
                {
                    index += 1;
                    continue;
                }
                else
                {
                    FindPathAvoid_Sub(directPath, adjCells, obsCells, pathAvoidLst, pathAvoid);
                    index = 0;
                }
            }
        }
Beispiel #23
0
        public static Action CreateCastSpellAction(Heroes.Core.Battle.Characters.Hero hero, 
            Heroes.Core.Battle.Characters.Spells.Spell spell,
            CellPartEnum attackDirection,
            ArrayList targets, Cell targetCell)
        {
            Action action = new Action(ActionTypeEnum.Spell);

            SubAction subAction = new SubAction();
            action._subActions.Add(subAction);
            subAction._character = hero;

            // hero casting animation
            AnimationSequence startCastSpellSeq = subAction.AddStartCasting(attackDirection);

            AnimationSequence stopCastSpellSeq = subAction.AddStopCasting(attackDirection);
            stopCastSpellSeq._waitToTrigger = true;

            // add casting
            AnimationSequence spellSeq = null;
            AnimationSequence spellHitSeq = null;
            AnimationSequence hitSeq = null;
            foreach (Heroes.Core.Battle.Characters.ICharacter target in targets)
            {
                // spell animate
                {
                    SubAction subAction2 = new SubAction();
                    action._subActions.Add(subAction2);
                    subAction2._character = spell;

                    PointF destPoint = spell._destCell.GetStandingPoint();

                    if (spell._isMissile)
                    {
                        // move missile
                        PointF srcPoint = hero._castingPointRight;
                        spell._currentAnimationPt = srcPoint;

                        destPoint.Y -= hero._castingHeight;

                        Character.CalculateFlySpeed(srcPoint, destPoint,
                            spell._defaultMoveSpeed,
                        out spell._moveSpeedX, out spell._moveSpeedY);

                        spellSeq = subAction2.AddMissileSpell(destPoint, attackDirection, AnimationPurposeEnum.Moving);
                        subAction2._currentAnimationSeq = spellSeq;
                    }
                    else
                    {
                        spell._currentAnimationPt = destPoint;

                        spellSeq = subAction2.AddOnArmySpell(destPoint, attackDirection, AnimationPurposeEnum.CastSpell);
                        subAction2._currentAnimationSeq = spellSeq;
                    }

                    // hit
                    if (spell._isHit)
                    {
                        spellHitSeq = subAction2.AddSpellHit(destPoint, attackDirection);
                        subAction2._currentAnimationSeq = spellSeq;
                    }
                }

                // target
                if (spell._isDamage)
                {
                    Heroes.Core.Battle.Characters.Armies.Army army
                        = (Heroes.Core.Battle.Characters.Armies.Army)target;

                    SubAction subAction2 = new SubAction();
                    action._subActions.Add(subAction2);
                    subAction2._character = target;

                    if (army._isDead)
                        hitSeq = subAction2.AddDeath(attackDirection);
                    else if (army._isDefend)
                        hitSeq = subAction2.AddDefend(attackDirection);
                    else
                        hitSeq = subAction2.AddGettingHit(attackDirection);

                    hitSeq._waitToTrigger = true;

                    subAction2._currentAnimationSeq = hitSeq;
                }
            }

            startCastSpellSeq._waitToTrigger = false;
            startCastSpellSeq._triggerWhenEnd = true;
            startCastSpellSeq._triggerAnimationSeqs.Add(spellSeq);

            spellSeq._waitToTrigger = true;
            spellSeq._triggerWhenEnd = true;

            if (spell._isHit)
            {
                spellHitSeq._waitToTrigger = true;
                spellSeq._triggerAnimationSeqs.Add(spellHitSeq);
            }

            if (spell._isDamage)
            {
                hitSeq._waitToTrigger = true;
                spellSeq._triggerAnimationSeqs.Add(hitSeq);
            }

            stopCastSpellSeq._waitToTrigger = true;
            spellSeq._triggerAnimationSeqs.Add(stopCastSpellSeq);

            subAction._currentAnimationSeq = (AnimationSequence)subAction._animationSeqs[0];

            return action;
        }
Beispiel #24
0
        private void GetAdjCells(ArrayList directPath, Cell destCell, bool ignoreDestCharacter,
            ArrayList adjCells, ArrayList obstacles)
        {
            int index = 0;
            foreach (Cell cell in directPath)
            {
                if (cell.Equals(destCell) && ignoreDestCharacter)
                {
                    index += 1;
                    continue;
                }

                // index 0 is srcCell
                if (index > 0 && !cell.HasPassability())
                {
                    obstacles.Add(cell);

                    // get all adjacent cells
                    GetAdjCells(directPath, adjCells, obstacles, cell);
                }

                index += 1;
            }
        }