GetCell() public method

public GetCell ( int id ) : MapCell
id int
return MapCell
Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="map"></param>
        /// <param name="beginCell"></param>
        /// <param name="direction"></param>
        /// <param name="endCell"></param>
        /// <returns></returns>
        public static int IsValidLine(AbstractEntity entity, MapInstance map, MovementPath finalPath, int beginCell, int direction, int endCell, int finalCell)
        {
            var length     = -1;
            var actualCell = beginCell;
            var lastCell   = beginCell;

            finalPath.AddCell(actualCell, direction);

            const int MAX_LOOP = 100;
            var       time     = 0;

            do
            {
                time++;
                if (time > MAX_LOOP)
                {
                    return(-1);
                }

                actualCell = Pathfinding.NextCell(map, actualCell, direction);

                // io
                var mapCell = map.GetCell(actualCell);
                if (mapCell != null)
                {
                    if (mapCell.InteractiveObject != null && (!mapCell.InteractiveObject.CanWalkThrough || (entity.Type == EntityTypeEnum.TYPE_CHARACTER && actualCell == finalCell && mapCell.InteractiveObject.IsActive)))
                    {
                        length = -2;
                        break;
                    }
                }

                // impossible de marcher
                if (!mapCell.Walkable)
                {
                    length = -2;
                    break;
                }

                // aggressé par un groupe de mobs
                if (entity.Type == EntityTypeEnum.TYPE_CHARACTER && map.Entities.OfType <MonsterGroupEntity>().Any(monsters => map.CanBeAggro((CharacterEntity)entity, lastCell, monsters)))
                {
                    length = -2;
                    break;
                }

                length++;
                lastCell = actualCell;
                finalPath.MovementLength++;
            } while (actualCell != endCell);

            finalPath.AddCell(lastCell, direction);

            return(length);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Map"></param>
        /// <param name="currentCell"></param>
        /// <param name="encodedPath"></param>
        /// <returns></returns>
        public static MovementPath IsValidPath(AbstractEntity entity, MapInstance map, int currentCell, string encodedPath)
        {
            var decodedPath = DecodePath(map, currentCell, encodedPath);

            if (decodedPath.TransitCells.Count == 0)
            {
                return(null);
            }
            var finalPath       = new MovementPath();
            var index           = 0;
            int transitCell     = 0;
            int nextTransitCell = 0;
            int direction       = 0;

            do
            {
                transitCell     = decodedPath.TransitCells[index];
                nextTransitCell = decodedPath.TransitCells[index + 1];
                direction       = decodedPath.GetDirection(transitCell);
                var length = Pathfinding.IsValidLine(entity, map, finalPath, transitCell, direction, nextTransitCell, decodedPath.EndCell);
                if (length == -1)
                {
                    return(null);
                }
                else if (length == -2)
                {
                    break;
                }
                index++;
            }while (transitCell != decodedPath.LastStep);

            if (entity.Type == EntityTypeEnum.TYPE_CHARACTER)
            {
                var mapCell = map.GetCell(decodedPath.EndCell);
                if (mapCell != null && mapCell.InteractiveObject != null && mapCell.InteractiveObject is Pheonix)
                {
                    var character = (CharacterEntity)entity;
                    character.AutomaticSkillId     = (int)SkillIdEnum.SKILL_USE_PHOENIX;
                    character.AutomaticSkillCellId = decodedPath.EndCell;
                    character.AutomaticSkillMapId  = map.Id;
                }
            }

            return(finalPath);
        }