/// <summary> /// /// </summary> /// <param name="fight"></param> /// <param name="fighter"></param> /// <param name="currentCell"></param> /// <param name="encodedPath"></param> /// <returns></returns> public static MovementPath IsValidPath(AbstractFight fight, AbstractFighter fighter, int currentCell, string encodedPath) { if (encodedPath == "") { return(null); } var decodedPath = DecodePath(fight.Map, currentCell, encodedPath); var finalPath = new MovementPath(); var index = 0; int transitCell = 0; do { transitCell = decodedPath.TransitCells[index]; var length = Pathfinding.IsValidLine(fight, fighter, finalPath, transitCell, decodedPath.GetDirection(transitCell), decodedPath.TransitCells[index + 1]); if (length == -1) { return(null); } else if (length == -2) { break; } index++; }while (transitCell != decodedPath.LastStep); return(finalPath); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <summary> /// /// </summary> /// <param name="entity"></param> /// <param name="path"></param> /// <param name="cellId"></param> public void MovementFinish(AbstractEntity entity, MovementPath path, int cellId) { if (entity.Type == EntityTypeEnum.TYPE_CHARACTER) { var character = (CharacterEntity)entity; if (character.CanGameAction(GameActionTypeEnum.FIGHT)) { foreach (var monsterGroup in m_entityById.Values.OfType <MonsterGroupEntity>()) { if (CanBeAggro(character, cellId, monsterGroup)) { entity.CellId = cellId; if (monsterGroup.AlignmentId == -1) { if (FightManager.StartMonsterFight(character, monsterGroup)) { return; } } else { if (FightManager.StartAggression(monsterGroup, character)) { return; } } } } } } if (entity.CellId == cellId) { return; } entity.Orientation = path.GetDirection(path.LastStep); if (entity.Type == EntityTypeEnum.TYPE_CHARACTER) { var character = (CharacterEntity)entity; var cell = GetCell(cellId); if (cell != null) { if (cell.Trigger != null) { if (!cell.SatisfyConditions(character)) { entity.Dispatch(WorldMessage.IM_ERROR_MESSAGE(InformationEnum.ERROR_CONDITIONS_UNSATISFIED)); return; } entity.CellId = cellId; cell.ApplyActions(character); return; } } } entity.CellId = cellId; }