Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pathfinding #71

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Interfaces/UI_Mapa.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ private void mapa_Control_Celda_Clic(CeldaMapa celda, MouseButtons botones, bool
switch (cuenta.game.manager.movimientos.get_Mover_A_Celda(celda_destino, mapa.celdas_ocupadas()))
{
case ResultadoMovimientos.EXITO:
cuenta.logger.log_informacion("UI_MAPA", $"Personaje desplazado a la casilla: {celda_destino.cellId}");
cuenta.logger.log_informacion("UI_MAP", $"Personnage se déplace à la cellule : {celda_destino.cellId}");
break;

case ResultadoMovimientos.MISMA_CELDA:
cuenta.logger.log_Error("UI_MAPA", "El jugador está en la misma a la seleccionada");
cuenta.logger.log_Error("UI_MAP", "Le joueur est dans la même cellule que le joueur sélectionné");
break;

default:
cuenta.logger.log_Error("UI_MAPA", $"Error desplazando el personaje a la casilla: {celda_destino.cellId}");
cuenta.logger.log_Error("UI_MAP", $"Erreur de déplacement à la cellule : {celda_destino.cellId}");
break;
}
}
Expand Down
50 changes: 34 additions & 16 deletions Otros/Game/Manejadores/Movimientos/Movimiento.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,26 +89,44 @@ public bool get_Cambiar_Mapa(MapaTeleportCeldas direccion)
celdas_teleport.Remove(celda);
}

cuenta.logger.log_Peligro("MOUVEMENT", "Aucune cellule de destination trouvée, utiliser la méthode : TOP|BOTTOM|RIGHT|LEFT");
cuenta.logger.log_Peligro("MOUVEMENT", "Aucune cellule de destination trouvée, utiliser les cell Id");
return false;
}

public ResultadoMovimientos get_Mover_A_Celda(Cell celda_destino, List<Cell> celdas_no_permitidas, bool detener_delante = false, byte distancia_detener = 0)
{
if (celda_destino.cellId < 0 || celda_destino.cellId > mapa.mapCells.Length)
return ResultadoMovimientos.FALLO;
actual_path = null;

if (cuenta.Is_Busy() || actual_path != null || personaje.inventario.porcentaje_pods >= 100)
return ResultadoMovimientos.FALLO;
if (celda_destino.cellId < 0 || celda_destino.cellId > mapa.mapCells.Length)
{
cuenta.logger.log_Error("ERROR", $"Account is busy {cuenta.Is_Busy()} actual Path : {actual_path != null} pods percentage : {personaje.inventario.porcentaje_pods}");
return ResultadoMovimientos.FALLO;
}

if (cuenta.Is_Busy() || actual_path != null || personaje.inventario.porcentaje_pods >= 100)
{
cuenta.logger.log_Error("ERROR", $"Account is busy {cuenta.Is_Busy()} actual Path : {actual_path != null} pods percentage : {personaje.inventario.porcentaje_pods}");
return ResultadoMovimientos.FALLO;
}

if (celda_destino.cellId == personaje.celda.cellId)
return ResultadoMovimientos.MISMA_CELDA;

if (celda_destino.cellType == CellTypes.NOT_WALKABLE && celda_destino.interactiveObject == null)
return ResultadoMovimientos.FALLO;
if (celdas_no_permitidas.Contains(celda_destino) || celdas_no_permitidas.Contains(personaje.celda))
return ResultadoMovimientos.MONSTER_ON_SUN;

if (celda_destino.cellType == CellTypes.INTERACTIVE_OBJECT && celda_destino.interactiveObject == null)
if (celda_destino.cellType == CellTypes.NOT_WALKABLE && celda_destino.interactiveObject == null)
{
cuenta.logger.log_Error("ERROR", $"Cell is not walkable");
return ResultadoMovimientos.FALLO;
}

if (celda_destino.cellType == CellTypes.INTERACTIVE_OBJECT && celda_destino.interactiveObject == null)
{
cuenta.logger.log_Error("ERROR", $"Cell is interactive object");
return ResultadoMovimientos.FALLO;
}


List<Cell> path_temporal = pathfinder.get_Path(personaje.celda, celda_destino, celdas_no_permitidas, detener_delante, distancia_detener);

Expand All @@ -119,8 +137,8 @@ public ResultadoMovimientos get_Mover_A_Celda(Cell celda_destino, List<Cell> cel
return ResultadoMovimientos.PATHFINDING_ERROR;

if (detener_delante && path_temporal.Count == 1 && path_temporal[0].cellId == personaje.celda.cellId)
return ResultadoMovimientos.MISMA_CELDA;
return ResultadoMovimientos.MISMA_CELDA;
if (detener_delante && path_temporal.Count == 2 && path_temporal[0].cellId == personaje.celda.cellId && path_temporal[1].cellId == celda_destino.cellId)
return ResultadoMovimientos.MISMA_CELDA;

Expand Down Expand Up @@ -152,13 +170,13 @@ private bool get_Mover_Para_Cambiar_mapa(Cell celda)
ResultadoMovimientos resultado = get_Mover_A_Celda(celda, mapa.celdas_ocupadas().Where(c => c.cellType != CellTypes.TELEPORT_CELL).ToList());
switch (resultado)
{
case ResultadoMovimientos.EXITO:
cuenta.logger.log_informacion("MOUVEMENT", $"{mapa.GetCoordinates} changement de map via la cellule {celda.cellId} ");
return true;
case ResultadoMovimientos.EXITO:
cuenta.logger.log_informacion("MOUVEMENT", $"{mapa.GetCoordinates} changement de map via la cellule {celda.cellId} ");
return true;

default:
cuenta.logger.log_Error("MOUVEMENT", $"Chemin vers {celda.cellId} résultat échoué ou bloqué : {resultado}");
return false;
default:
cuenta.logger.log_Error("MOUVEMENT", $"Chemin vers {celda.cellId} résultat échoué ou bloqué : {resultado}");
return false;
}
}

Expand Down
3 changes: 2 additions & 1 deletion Otros/Game/Manejadores/Movimientos/ResultadoMovimientos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public enum ResultadoMovimientos
EXITO,
MISMA_CELDA,
FALLO,
PATHFINDING_ERROR
PATHFINDING_ERROR,
MONSTER_ON_SUN
}
}
2 changes: 1 addition & 1 deletion Otros/Mapas/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void GetRefreshMap(string prmPacket)
public bool get_Puede_Luchar_Contra_Grupo_Monstruos(int monstruos_minimos, int monstruos_maximos, int nivel_minimo, int nivel_maximo, List<int> monstruos_prohibidos, List<int> monstruos_obligatorios) => get_Grupo_Monstruos(monstruos_minimos, monstruos_maximos, nivel_minimo, nivel_maximo, monstruos_prohibidos, monstruos_obligatorios).Count > 0;

// si el destino es una celda teleport, aunque haya un monstruo encima de la celda no causara agresion
public List<Cell> celdas_ocupadas() => entities.Values.Select(c => c.celda).ToList();
public List<Cell> celdas_ocupadas() => entities.Values.Where(c => c is Monstruos).Select(c => c.celda).ToList();
public List<Npcs> lista_npcs() => entities.Values.Where(n => n is Npcs).Select(n => n as Npcs).ToList();
public List<Monstruos> lista_monstruos() => entities.Values.Where(n => n is Monstruos).Select(n => n as Monstruos).ToList();
public List<Personajes> lista_personajes() => entities.Values.Where(n => n is Personajes).Select(n => n as Personajes).ToList();
Expand Down
5 changes: 5 additions & 0 deletions Otros/Scripts/Acciones/Mapas/MoverCeldaAccion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ internal override Task<ResultadosAcciones> proceso(Account cuenta)
case ResultadoMovimientos.MISMA_CELDA:
return resultado_hecho;

case ResultadoMovimientos.MONSTER_ON_SUN:
cuenta.logger.log_normal("MOVE", "Un monstre bloque le passage attente de 5 secondes");
Task.Delay(5000);
return proceso(cuenta);

default:
return resultado_fallado;
}
Expand Down
6 changes: 3 additions & 3 deletions Otros/Scripts/Acciones/PeleasAccion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ internal override Task<ResultadosAcciones> proceso(Account cuenta)
switch (test)
{
case ResultadoMovimientos.EXITO:
cuenta.logger.log_informacion("SCRIPT", $"Mouvent vers un groupes à la cellule : {grupo_monstruo.celda.cellId}, monstres total: {grupo_monstruo.get_Total_Monstruos}, niveaux du groupe: {grupo_monstruo.get_Total_Nivel_Grupo}");
cuenta.logger.log_informacion("SCRIPT", $"Mouvement vers un groupes à la cellule : {grupo_monstruo.celda.cellId}, monstres total: {grupo_monstruo.get_Total_Monstruos}, niveaux du groupe: {grupo_monstruo.get_Total_Nivel_Grupo}");
return resultado_procesado;

case ResultadoMovimientos.PATHFINDING_ERROR:
case ResultadoMovimientos.MISMA_CELDA:
cuenta.logger.log_Peligro("SCRIPT", "Le chemin vers le groupe de monstres est bloqué.");
cuenta.logger.log_Peligro("SCRIPT", "Le chemin vers le groupe de monstres est bloqué. " + test);
continue;

default:
cuenta.script.detener_Script("C'est trompé de groupes" + test);
cuenta.script.detener_Script("C'est trompé de groupes " + test);
return resultado_fallado;
}
}
Expand Down