Esempio 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);
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Map"></param>
        /// <param name="currentCell"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        public static MovementPath DecodePath(MapInstance map, int currentCell, string path)
        {
            MovementPath movementPath = new MovementPath();

            if (path == "")
            {
                return(movementPath);
            }

            movementPath.AddCell(currentCell, GetDirection(map, currentCell, Util.CharToCell(path.Substring(1, 2))));

            for (int i = 0; i < path.Length; i += 3)
            {
                int curCell = Util.CharToCell(path.Substring(i + 1, 2));
                int curDir  = Util.HASH.IndexOf(path[i]);

                movementPath.AddCell(curCell, curDir);
            }

            return(movementPath);
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fight"></param>
        /// <param name="fighter"></param>
        /// <param name="path"></param>
        /// <param name="beginCell"></param>
        /// <param name="direction"></param>
        /// <param name="endCell"></param>
        /// <returns></returns>
        public static int IsValidLine(AbstractFight fight, AbstractFighter fighter, MovementPath path, int beginCell, int direction, int endCell)
        {
            var length     = -1;
            var actualCell = beginCell;

            if (!Pathfinding.InLine(fight.Map, beginCell, endCell))
            {
                return(length);
            }

            length = (int)GoalDistance(fight.Map, beginCell, endCell);

            path.AddCell(actualCell, direction);

            for (int i = 0; i < length; i++)
            {
                actualCell = Pathfinding.NextCell(fight.Map, actualCell, direction);

                if (!fight.Map.IsWalkable(actualCell))
                {
                    return(-2);
                }

                if (fight.GetFighterOnCell(actualCell) != null)
                {
                    return(-2);
                }

                path.AddCell(actualCell, direction);
                path.MovementLength++;

                if (Pathfinding.IsStopCell(fighter.Fight, fighter.Team, actualCell))
                {
                    return(-2);
                }
            }

            return(length);
        }