public bool Act(MonsterDTO monster, DungeonMapDTO map, PlayerDTO player, CommandSystem commandSystem) { var monsterFov = new FieldOfView(map); if (!monster.TurnsAlerted.HasValue) { monsterFov.ComputeFov(monster.X, monster.Y, monster.Awareness, true); if (monsterFov.IsInFov(player.X, player.Y)) { MessageLog.Add($"{monster.Name} is eager to fight {player.Name}"); monster.TurnsAlerted = 1; } } if (monster.TurnsAlerted.HasValue) { map.SetIsWalkable(monster.X, monster.Y, true); map.SetIsWalkable(player.X, player.Y, true); var pathFinder = new PathFinder(map); Path path = null; try { path = pathFinder.ShortestPath( map.GetCell(monster.X, monster.Y), map.GetCell(player.X, player.Y)); } catch (PathNotFoundException) { MessageLog.Add($"{monster.Name} waits for a turn"); } map.SetIsWalkable(monster.X, monster.Y, false); map.SetIsWalkable(player.X, player.Y, false); if (path != null) { try { commandSystem.MoveMonster(monster, map, player, path.Steps.First()); } catch (NoMoreStepsException) { MessageLog.Add($"{monster.Name} growls in frustration"); } } monster.TurnsAlerted++; if (monster.TurnsAlerted > 15) { monster.TurnsAlerted = null; } } return(true); }
public void MoveMonster(MonsterDTO monsterDto, DungeonMapDTO map, PlayerDTO player, Cell cell) { if (!map.SetCharacterPosition(monsterDto, cell.X, cell.Y)) { if (player.X == cell.X && player.Y == cell.Y) { this.Attack(monsterDto, player, map); } } else { var monster = this.mappingService.GetMonsterByPosition(monsterDto.X, monsterDto.Y); monster.X = cell.X; monster.Y = cell.Y; monsterDto.X = cell.X; monsterDto.Y = cell.Y; this.mappingService.UnitOfWork.Commit(); } }