Skip to content

Commit

Permalink
Добавлен кот в мешке и исправление финала
Browse files Browse the repository at this point in the history
  • Loading branch information
Fooxboy committed Nov 4, 2023
1 parent 90ce020 commit ad86a66
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 2 deletions.
32 changes: 32 additions & 0 deletions MyOwnGame.Backend/BackgroundTasks/PackageCleaner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace MyOwnGame.Backend.BackgroundTasks;

public class PackageCleaner : IBackgroundTask
{
private readonly IConfiguration _configuration;
private readonly ILogger<PackageCleaner> _logger;

public PackageCleaner(IConfiguration configuration, ILogger<PackageCleaner> logger)
{
_configuration = configuration;
_logger = logger;
}

public int Timeout => 54000;

public Task Invoke()
{
_logger.LogWarning("Начало удаления пакетов");

var pathToPackages = _configuration.GetValue<string>("packagesPath");

var packageFiles = Directory.GetFiles(pathToPackages);

foreach (var packageFile in packageFiles)
{
_logger.LogWarning($"Удален пакет '{Path.GetFileName(packageFile)}'");
File.Delete(packageFile);
}

return Task.CompletedTask;
}
}
5 changes: 5 additions & 0 deletions MyOwnGame.Backend/Domain/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ public void ChangeStateToTable()
ResetRespondingPlayer();
}

public void ChangeStateToForwardQuestion()
{
State = SessionState.ForwardQuestion;
}

public void AddReadyToAnswerPlayer(Player player, DateTime time)
{
_playersReadyToAnswer.Add((player, time));
Expand Down
10 changes: 10 additions & 0 deletions MyOwnGame.Backend/Helpers/SessionEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,14 @@ public enum SessionEvents
/// Пользователь устанавливает цену вопроса
/// </summary>
PlayerInstallingQuestionPrice,

/// <summary>
/// Нужно передать вопрос
/// </summary>
NeedForwardQuestion,

/// <summary>
/// Пользователь выбирает кому передать вопрос
/// </summary>
PlayerChoosesQuestionPlayer
}
13 changes: 13 additions & 0 deletions MyOwnGame.Backend/Hubs/SessionHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,19 @@ public async Task SetQuestionPrice(int price)
}
}

public async Task ForwardQuestion()
{
try
{

}
catch (Exception ex)
{
_logger.LogError(ex, ex.Message);
throw new HubException(ex.Message, ex);
}
}

public override async Task OnDisconnectedAsync(Exception? exception)
{
try
Expand Down
2 changes: 2 additions & 0 deletions MyOwnGame.Backend/Models/SessionState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ public enum SessionState

Table,

ForwardQuestion,

Pause
}
1 change: 1 addition & 0 deletions MyOwnGame.Backend/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public static void Main(string[] args)

//Регистрация фоновых задач
builder.Services.AddSingleton<IBackgroundTask, SessionCleaner>();
builder.Services.AddSingleton<IBackgroundTask, PackageCleaner>();
builder.Services.AddSingleton<BackgroundTaskRunner>();


Expand Down
8 changes: 7 additions & 1 deletion MyOwnGame.Backend/Services/SessionCallbackService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,16 @@ await _hubContext.Clients.Client(player.ConnectionId).SendAsync(SessionEvents.Ne

await _hubContext.Clients.Group(player.SessionId.ToString()).SendAsync(SessionEvents.PlayerInstallingQuestionPrice.ToString(), PlayerDto.Create(player));
}

public async Task QuestionPriceInstalled(long sessionId, Player player, int? score)
{
await _hubContext.Clients.Group(sessionId.ToString())
.SendAsync(SessionEvents.QuestionPriceInstalled.ToString(), PlayerDto.Create(player), score);
}

public async Task NeedForwardQuestion(string connectionId, long sessionId)
{
await _hubContext.Clients.Client(connectionId).SendAsync(SessionEvents.NeedForwardQuestion.ToString());
await _hubContext.Clients.Group(sessionId.ToString()).SendAsync(SessionEvents.PlayerChoosesQuestionPlayer.ToString());
}
}
46 changes: 45 additions & 1 deletion MyOwnGame.Backend/Services/SessionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,21 @@ public async Task GetQuestionInfo(int themeNumber, int priceNumber, string conne

return;
}

//Если это кот в мешке, кидаем инфу что надо передать
if (questionInfo.QuestionPackInfo.Type == QuestionPackType.Cat || questionInfo.QuestionPackInfo.Type == QuestionPackType.SuperCat)
{
await _callbackService.QuestionSelectedAdmin(adminConnectionId, questionInfo.Answer);

await _callbackService.QuestionSelected(currentPlayer.SessionId, new List<QuestionBase>(),
questionInfo.QuestionPackInfo, -1, themeNumber, priceNumber);

await _callbackService.NeedForwardQuestion(currentPlayer.ConnectionId, currentPlayer.SessionId);

session.ChangeStateToForwardQuestion();

return;
}
}

//simple
Expand Down Expand Up @@ -679,7 +694,7 @@ public async Task RemoveFinalTheme(int position, string connectionId)
indexPlayer = 0;
}

var nextPlayer = session.Players[indexPlayer];
var nextPlayer = onlinePlayers[indexPlayer];

session.SetSelectQuestionPlayer(nextPlayer);

Expand Down Expand Up @@ -803,6 +818,35 @@ await _callbackService.QuestionSelected(questionPlayer.SessionId, questionInfo.Q
await _callbackService.NeedSetQuestionPrice(nextPlayer.SessionId, nextPlayer, 0, nextPlayer.Score, 1);
}

public async Task ForwardQuestion(string connectionId, int playerId)
{
var player = GetPlayer(connectionId);

if (player is null)
{
throw new Exception("Бляяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяя");
}

var session = _sessionsManager.GetSessionById(player.SessionId);

if (session is null)
{
throw new Exception("Сессия не найдена((((");
}

var forwardPlayer = GetPlayer(player.SessionId, playerId);

if (forwardPlayer is null)
{
throw new Exception("Не найден игрок, которому передают вопрос");
}


session.ChangeStateToAnswer();

await _callbackService.PlayerAnswer(forwardPlayer.SessionId, player);
}

private (Player Player, QuestionInfo QuestionInfo, Session Session) ValidateAnswerData(string connectionId)
{
var sessionInfo = _sessionsManager.GetSessionInfoByConnection(connectionId);
Expand Down

0 comments on commit ad86a66

Please sign in to comment.