Esempio n. 1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="map"></param>
 /// <param name="cellId"></param>
 /// <returns></returns>
 public static IEnumerable <int> GetAdjacentCells(MapInstance map, int cellId)
 {
     for (int i = 1; i < 8; i += 2)
     {
         yield return(Pathfinding.NextCell(map, cellId, i));
     }
 }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cellId"></param>
        /// <returns></returns>
        public int GetNearestMovementCell(int cellId)
        {
            var rand      = Util.Next(0, 101);
            var direction = 1;

            if (rand < 25)
            {
                direction = 3;
            }
            else if (rand < 50)
            {
                direction = 5;
            }
            else if (rand < 75)
            {
                direction = 7;
            }

            var nextCellId = Pathfinding.NextCell(this, cellId, direction);
            var cell       = GetCell(nextCellId);

            if (cell != null && cell.Walkable)
            {
                if (cell.Walkable)
                {
                    return(nextCellId);
                }
            }
            return(-1);
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="map"></param>
        /// <param name="cellId"></param>
        /// <param name="direction"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public static IEnumerable <int> GetLineCells(MapInstance map, int cellId, int direction, int length)
        {
            yield return(cellId);

            for (int i = 1; i < length + 1; i++)
            {
                yield return(Pathfinding.NextCell(map, cellId, direction, i));
            }
        }
Esempio n. 4
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. 5
0
        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="fight"></param>
        ///// <param name="team"></param>
        ///// <param name="cellId"></param>
        ///// <returns></returns>
        public static List <AbstractFighter> GetFightersNear(AbstractFight fight, int cellId)
        {
            List <AbstractFighter> fighters = new List <AbstractFighter>();

            foreach (var direction in Pathfinding.FIGHT_DIRECTIONS)
            {
                var fighter = fight.GetFighterOnCell(Pathfinding.NextCell(fight.Map, cellId, direction));
                if (fighter != null)
                {
                    if (!fighter.IsFighterDead)
                    {
                        fighters.Add(fighter);
                    }
                }
            }
            return(fighters);
        }
Esempio n. 6
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);
        }