1
0
mirror of synced 2025-02-20 20:51:01 +01:00

Try add new logic for recent song selection by add stage number

Try refactor best data update

Try refactor achievement default computation
This commit is contained in:
asesidaa 2022-08-28 00:34:27 +08:00
parent 066b115c84
commit 2c21080e99
6 changed files with 77 additions and 42 deletions

View File

@ -59,23 +59,26 @@ public class BaidController:ControllerBase
userData = context.UserData.First(datum => datum.Baid == baid);
}
var achievementDisplayDifficulty = userData.AchievementDisplayDifficulty == Difficulty.None ?
context.SongPlayData.Where(datum => datum.Crown >= CrownType.Clear).Any() ?
context.SongPlayData.Where(datum => datum.Crown >= CrownType.Clear).Max(datum => datum.Difficulty) :
Difficulty.Easy : userData.AchievementDisplayDifficulty;
var songBestData = context.SongBestData.Where(datum => datum.Baid == baid).ToList();
var achievementDisplayDifficulty = userData.AchievementDisplayDifficulty;
if (userData.AchievementDisplayDifficulty == Difficulty.None)
{
achievementDisplayDifficulty = songBestData.Any(datum => datum.BestCrown >= CrownType.Clear) ?
songBestData.Where(datum => datum.BestCrown >= CrownType.Clear).Max(datum => datum.Difficulty) :
Difficulty.Easy;
}
var songBestData = context.SongBestData
.Where(datum => datum.Baid == baid &&
achievementDisplayDifficulty != Difficulty.UraOni ?
datum.Difficulty == achievementDisplayDifficulty :
datum.Difficulty == Difficulty.Oni || datum.Difficulty == Difficulty.UraOni);
var songCountData = songBestData.Where(datum => achievementDisplayDifficulty != Difficulty.UraOni ?
datum.Difficulty == achievementDisplayDifficulty :
datum.Difficulty is Difficulty.Oni or Difficulty.UraOni).ToList();
var crownCount = new uint[3];
foreach (var crownType in Enum.GetValues<CrownType>())
{
if (crownType != CrownType.None)
{
crownCount[(int)crownType - 1] = (uint)songBestData.Count(datum => datum.BestCrown == crownType);
crownCount[(int)crownType - 1] = (uint)songCountData.Count(datum => datum.BestCrown == crownType);
}
}
@ -84,7 +87,7 @@ public class BaidController:ControllerBase
{
if (scoreRankType != ScoreRank.None)
{
scoreRankCount[(int)scoreRankType - 2] = (uint)songBestData.Count(datum => datum.BestScoreRank == scoreRankType);
scoreRankCount[(int)scoreRankType - 2] = (uint)songCountData.Count(datum => datum.BestScoreRank == scoreRankType);
}
}

View File

@ -60,25 +60,21 @@ public class PlayResultController : ControllerBase
context.UserData.Update(userdata);
var bestData = context.SongBestData.Where(datum => datum.Baid == request.BaidConf).ToList();
foreach (var stageData in playResultData.AryStageInfoes)
for (var songNumber = 0; songNumber < playResultData.AryStageInfoes.Count; songNumber++)
{
var stageData = playResultData.AryStageInfoes[songNumber];
var insert = false;
var bestDatum = bestData
.FirstOrDefault(datum => datum.SongId == stageData.SongNo &&
datum.Difficulty == (Difficulty)stageData.Level);
var crown = CrownType.None;
if (stageData.PlayResult > 0)
// Determine whether it is dondaful crown as this is not reflected by play result
var crown = (CrownType)stageData.PlayResult;
if (crown == CrownType.Gold && stageData.OkCnt == 0)
{
crown = CrownType.Clear;
if (stageData.NgCnt == 0)
{
crown = CrownType.Gold;
if (stageData.OkCnt == 0)
{
crown = CrownType.Dondaful;
}
}
crown = CrownType.Dondaful;
}
if (bestDatum is null)
{
insert = true;
@ -89,22 +85,8 @@ public class PlayResultController : ControllerBase
Difficulty = (Difficulty)stageData.Level
};
}
if (bestDatum.BestCrown < crown)
{
bestDatum.BestCrown = crown;
}
if ((uint)bestDatum.BestScoreRank < stageData.ScoreRank)
{
bestDatum.BestScoreRank = (ScoreRank)stageData.ScoreRank;
}
if (bestDatum.BestScore < stageData.PlayScore)
{
bestDatum.BestScore = stageData.PlayScore;
}
if (bestDatum.BestRate < stageData.ScoreRate)
{
bestDatum.BestRate = stageData.ScoreRate;
}
bestDatum.UpdateBestData(crown, stageData.ScoreRank, stageData.PlayScore, stageData.ScoreRate);
if (insert)
{
@ -114,10 +96,11 @@ public class PlayResultController : ControllerBase
{
context.SongBestData.Update(bestDatum);
}
var playData = new SongPlayDatum
{
Baid = request.BaidConf,
SongNumber = (uint)songNumber,
GoodCount = stageData.GoodCnt,
OkCount = stageData.OkCnt,
MissCount = stageData.NgCnt,

View File

@ -19,6 +19,13 @@ public class UserDataController : ControllerBase
this.context = context;
}
public record PlayTimeOrderTuple(DateTime PlayTime, uint SongNumber)
{
public override string ToString() {
return $"{{ PlayTime = {PlayTime}, SongNumber = {SongNumber} }}";
}
}
[HttpPost]
[Produces("application/protobuf")]
public IActionResult GetUserData([FromBody] UserDataRequest request)
@ -49,7 +56,12 @@ public class UserDataController : ControllerBase
var recentSongs = context.SongPlayData
.Where(datum => datum.Baid == request.Baid)
.AsEnumerable()
.Reverse()
.OrderByDescending(datum => new PlayTimeOrderTuple(datum.PlayTime, datum.SongNumber),
Comparer<PlayTimeOrderTuple>.Create((tuple1, tuple2) =>
{
var timeOrder = tuple1.PlayTime.CompareTo(tuple2.PlayTime);
return timeOrder != 0 ? timeOrder : tuple1.SongNumber.CompareTo(tuple2.SongNumber);
}))
.DistinctBy(datum => datum.SongId)
.Take(10)
.Select(datum => datum.SongId)

View File

@ -0,0 +1,29 @@
using TaikoLocalServer.Common.Enums;
namespace TaikoLocalServer.Entities;
public partial class SongBestDatum
{
public void UpdateBestData(CrownType crown, uint scoreRank, uint playScore, uint scoreRate)
{
if (BestCrown < crown)
{
BestCrown = crown;
}
if ((uint)BestScoreRank < scoreRank)
{
BestScoreRank = (ScoreRank)scoreRank;
}
if (BestScore < playScore)
{
BestScore = playScore;
}
if (BestRate < scoreRate)
{
BestRate = scoreRate;
}
}
}

View File

@ -6,6 +6,9 @@ namespace TaikoLocalServer.Entities
{
public long Id { get; set; }
public uint Baid { get; set; }
public uint SongNumber { get; set; }
public uint SongId { get; set; }
public Difficulty Difficulty { get; set; }
public CrownType Crown { get; set; }

View File

@ -1,4 +1,9 @@
// Global using directives
global using Microsoft.AspNetCore.Mvc;
global using Swan.Formatters;
global using taiko.game;
global using taiko.game;
global using TaikoLocalServer.Common;
global using TaikoLocalServer.Common.Enums;
global using TaikoLocalServer.Context;
global using TaikoLocalServer.Entities;
global using TaikoLocalServer.Utils;