1
0
mirror of synced 2024-11-28 00:20:53 +01:00

Inital working refactor

This commit is contained in:
asesidaa 2024-03-16 22:21:28 +08:00
parent 6f177ee2ff
commit 7f6462d088
12 changed files with 41 additions and 40 deletions

View File

@ -27,7 +27,6 @@ public class BaidController : BaseController<BaidController>
}
response = Mappers.BaidResponseMapper.Map3906WithPostProcess(commonResponse);
response.Result = 1;
response.PlayerType = 0;
response.IsDispAchievementTypeSet = true;
response.IsDispSouuchiOn = true;
@ -58,7 +57,6 @@ public class BaidController : BaseController<BaidController>
}
response = Mappers.BaidResponseMapper.Map3209WithPostProcess(commonResponse);
response.Result = 1;
response.PlayerType = 0;
response.IsDispAchievementTypeSet = true;
response.IsDispSouuchiOn = true;

View File

@ -5,13 +5,6 @@ namespace TaikoLocalServer.Controllers.Game;
[ApiController]
public class GetAiDataController : BaseController<GetAiDataController>
{
private readonly IUserDatumService userDatumService;
public GetAiDataController(IUserDatumService userDatumService)
{
this.userDatumService = userDatumService;
}
[HttpPost("/v12r08_ww/chassis/getaidata_6x30b9nr.php")]
[Produces("application/protobuf")]
public async Task<IActionResult> GetAiData([FromBody] GetAiDataRequest request)
@ -20,7 +13,6 @@ public class GetAiDataController : BaseController<GetAiDataController>
var commonResponse = await Mediator.Send(new GetAiDataQuery(request.Baid));
var response = Mappers.AiDataResponseMapper.MapTo3906(commonResponse);
response.Result = 1;
return Ok(response);
}
@ -32,7 +24,6 @@ public class GetAiDataController : BaseController<GetAiDataController>
var commonResponse = await Mediator.Send(new GetAiDataQuery((uint)request.Baid));
var response = Mappers.AiDataResponseMapper.MapTo3209(commonResponse);
response.Result = 1;
return Ok(response);
}
}

View File

@ -6,13 +6,6 @@ namespace TaikoLocalServer.Controllers.Game;
[ApiController]
public class GetAiScoreController : BaseController<GetAiScoreController>
{
private readonly IAiDatumService aiDatumService;
public GetAiScoreController(IAiDatumService aiDatumService)
{
this.aiDatumService = aiDatumService;
}
[HttpPost("/v12r08_ww/chassis/getaiscore_lp38po4w.php")]
[Produces("application/protobuf")]
public async Task<IActionResult> GetAiScore([FromBody] GetAiScoreRequest request)
@ -21,7 +14,6 @@ public class GetAiScoreController : BaseController<GetAiScoreController>
var commonResponse = await Mediator.Send(new GetAiScoreQuery(request.Baid, request.SongNo, request.Level));
var response = AiScoreMappers.MapTo3906(commonResponse);
response.Result = 1;
return Ok(response);
}
@ -35,7 +27,6 @@ public class GetAiScoreController : BaseController<GetAiScoreController>
var commonResponse =
await Mediator.Send(new GetAiScoreQuery((uint)request.Baid, request.SongNo, request.Level));
var response = AiScoreMappers.MapTo3209(commonResponse);
response.Result = 1;
return Ok(response);
}

View File

@ -20,6 +20,7 @@ public class BaidQueryHandler(
logger.LogInformation("New user with access code {AccessCode}", request.AccessCode);
return new CommonBaidResponse
{
Result = 1,
IsNewUser = true,
Baid = context.Cards.Any() ? context.Cards.AsEnumerable().Max(c => c.Baid) + 1 : 1
};
@ -108,6 +109,7 @@ public class BaidQueryHandler(
return new CommonBaidResponse
{
Result = 1,
IsNewUser = false,
Baid = baid,
MyDonName = userData.MyDonName,

View File

@ -25,6 +25,7 @@ public class GetAiDataQueryHandler : IRequestHandler<GetAiDataQuery, CommonAiDat
user.ThrowIfNull($"User with baid {request.Baid} does not exist!");
var response = new CommonAiDataResponse
{
Result = 1,
TotalWinnings = (uint)user.AiWinCount,
InputMedian = "1",
InputVariance = "0"

View File

@ -7,18 +7,9 @@ namespace TaikoLocalServer.Handlers;
public record GetAiScoreQuery(uint Baid, uint SongId, uint Level) : IRequest<CommonAiScoreResponse>;
public class GetAiScoreQueryHandler : IRequestHandler<GetAiScoreQuery, CommonAiScoreResponse>
public class GetAiScoreQueryHandler(TaikoDbContext context, ILogger<GetAiScoreQueryHandler> logger)
: IRequestHandler<GetAiScoreQuery, CommonAiScoreResponse>
{
private readonly TaikoDbContext context;
private readonly ILogger<GetAiScoreQueryHandler> logger;
public GetAiScoreQueryHandler(TaikoDbContext context, ILogger<GetAiScoreQueryHandler> logger)
{
this.context = context;
this.logger = logger;
}
public async Task<CommonAiScoreResponse> Handle(GetAiScoreQuery request, CancellationToken cancellationToken)
{
var difficulty = (Difficulty)request.Level;
@ -29,6 +20,14 @@ public class GetAiScoreQueryHandler : IRequestHandler<GetAiScoreQuery, CommonAiS
datum.Difficulty == difficulty)
.Include(datum => datum.AiSectionScoreData)
.FirstOrDefaultAsync(cancellationToken);
return aiData is null ? new CommonAiScoreResponse() : AiScoreMappers.MapToCommonAiScoreResponse(aiData);
if (aiData is null)
{
return new CommonAiScoreResponse
{
Result = 1
};
}
aiData.AiSectionScoreData.Sort((a, b) => a.SectionIndex.CompareTo(b.SectionIndex));
return AiScoreMappers.MapAsSuccess(aiData);
}
}

View File

@ -30,19 +30,26 @@ public class GetSelfBestQueryHandler(IGameDataService gameDataService, TaikoDbCo
(datum.Difficulty == Difficulty.UraOni && requestDifficulty == Difficulty.Oni)))
.OrderBy(datum => datum.SongId)
.ToListAsync(cancellationToken);
var selfBestList = selfbestScores.ConvertAll(datum => new CommonSelfBestResponse.SelfBestData
{
SongNo = datum.SongId,
SelfBestScore = datum.BestScore,
UraBestScore = datum.Difficulty == Difficulty.UraOni ? datum.BestScore : 0,
SelfBestScoreRate = datum.BestRate,
UraBestScoreRate = datum.Difficulty == Difficulty.UraOni ? datum.BestRate : 0
});
// For songs that don't have a score, add them to the response with 0s
var missingSongs = requestSet.Except(selfBestList.Select(datum => datum.SongNo));
selfBestList.AddRange(missingSongs.Select(songNo => new CommonSelfBestResponse.SelfBestData
{
SongNo = songNo
}));
var response = new CommonSelfBestResponse
{
Result = 1,
Level = request.Difficulty,
ArySelfbestScores = selfbestScores.ConvertAll(datum => new CommonSelfBestResponse.SelfBestData
{
SongNo = datum.SongId,
SelfBestScore = datum.BestScore,
UraBestScore = datum.Difficulty == Difficulty.UraOni ? datum.BestScore : 0,
SelfBestScoreRate = datum.BestRate,
UraBestScoreRate = datum.Difficulty == Difficulty.UraOni ? datum.BestRate : 0
})
ArySelfbestScores = selfBestList
};
return response;

View File

@ -54,6 +54,8 @@ public class UpdatePlayResultCommandHandler(TaikoDbContext context, ILogger<Upda
UpdateDanPlayData(danPlayData, playResultData);
context.DanScoreData.Update(danPlayData);
}
await context.SaveChangesAsync(cancellationToken);
return 1;
}

View File

@ -10,6 +10,13 @@ public static partial class AiScoreMappers
[MapProperty(nameof(AiScoreDatum.AiSectionScoreData), nameof(CommonAiScoreResponse.AryBestSectionDatas))]
public static partial CommonAiScoreResponse MapToCommonAiScoreResponse(AiScoreDatum datum);
public static CommonAiScoreResponse MapAsSuccess(AiScoreDatum datum)
{
var response= MapToCommonAiScoreResponse(datum);
response.Result = 1;
return response;
}
public static partial GetAiScoreResponse MapTo3906(CommonAiScoreResponse response);
public static partial Models.v3209.GetAiScoreResponse MapTo3209(CommonAiScoreResponse response);

View File

@ -2,6 +2,7 @@
public class CommonAiDataResponse
{
public uint Result { get; set; }
public uint TotalWinnings { get; set; }
public string InputMedian { get; set; } = "1";
public string InputVariance { get; set; } = "0";

View File

@ -2,6 +2,7 @@
public class CommonAiScoreResponse
{
public uint Result { get; set; }
public List<CommonAiBestSectionData> AryBestSectionDatas { get; set; } = new();
}

View File

@ -2,6 +2,7 @@
public class CommonBaidResponse
{
public uint Result { get; set; }
public bool IsNewUser { get; set; }
public uint Baid { get; set; }
public string MyDonName { get; set; } = string.Empty;