add online games

This commit is contained in:
2026-09-13 01:02:40 +07:00
parent 3e555c9944
commit 0723644d3f
14 changed files with 170 additions and 12 deletions
+29 -3
View File
@@ -72,8 +72,15 @@ func (s *GameService) AddGame(
description string,
startAt time.Time,
scenarioId int32,
format string,
) (int, error) {
id, err := s.gamesRepo.AddGame(ctx, name, description, startAt, scenarioId)
if format == "" {
format = "online"
}
if format != "online" && format != "offline" {
return 0, errors.New("Формат игры должен быть online или offline")
}
id, err := s.gamesRepo.AddGame(ctx, name, description, startAt, scenarioId, format)
if err != nil {
return 0, err
}
@@ -170,8 +177,19 @@ func (s *GameService) UpdateGame(
description string,
startAt time.Time,
scenarioId int32,
format string,
) error {
return s.gamesRepo.UpdateGame(ctx, id, name, description, startAt, scenarioId)
if format == "" {
game, err := s.gamesRepo.GetGameByID(ctx, id)
if err != nil {
return err
}
format = game.Format
}
if format != "online" && format != "offline" {
return errors.New("Формат игры должен быть online или offline")
}
return s.gamesRepo.UpdateGame(ctx, id, name, description, startAt, scenarioId, format)
}
func (s *GameService) StartGame(ctx context.Context, id int) error {
@@ -255,7 +273,9 @@ func (s *GameService) GetTeamActions(ctx context.Context, teamId int, password s
for i, action := range actions {
codes[i] = action.Code
}
return s.storyteller.GetStory(scenario.Story, codes), mapGame(game, s.domain), actions, nil
story := s.storyteller.GetStory(scenario.Story, codes)
filterTeamStory(story, game.Format)
return story, mapGame(game, s.domain), actions, nil
}
func (s *GameService) AddTeamAction(ctx context.Context, teamId int, password string, actionCode string, viaMCP bool) error {
@@ -394,6 +414,9 @@ func (s *GameService) GetTeamAnswers(ctx context.Context, teamId int, password s
if err != nil {
return nil, err
}
if game.Format == "offline" {
return nil, nil
}
_, byCode, err := s.getScenarioQuestionsByCode(ctx, game.ScenarioId)
if err != nil {
return nil, err
@@ -424,6 +447,9 @@ func (s *GameService) SubmitTeamAnswers(ctx context.Context, teamId int, passwor
if err != nil {
return err
}
if game.Format == "offline" {
return errors.New("В offline-игре ответы через сайт недоступны")
}
switch game.Status {
case "run", "pause":
// игра идёт — можно отвечать