1
0
mirror of synced 2024-12-18 01:15:55 +01:00

Implemented shop, adjusted initialDataCheck

This commit is contained in:
S-Sebb?? 2023-09-11 23:07:13 +08:00
parent 505283a003
commit b880ac9663
11 changed files with 145 additions and 16 deletions

View File

@ -0,0 +1,10 @@
using System.Text.Json.Serialization;
namespace SharedProject.Models;
public class ShopFolderData
{
[JsonPropertyName("songNo")] public uint SongNo { get; set; }
[JsonPropertyName("price")] public uint Price { get; set; }
}

View File

@ -126,4 +126,22 @@ public static class FlagCalculator
return result; return result;
} }
public static byte[] GetBitArrayTrue(int bitArraySize)
{
var result = new byte[(bitArraySize / 8) + 1];
var bitSet = new BitArray(bitArraySize, true);
bitSet.CopyTo(result, 0);
return result;
}
public static byte[] GetBitArrayFalse(int bitArraySize)
{
var result = new byte[(bitArraySize / 8) + 1];
var bitSet = new BitArray(bitArraySize, false);
bitSet.CopyTo(result, 0);
return result;
}
} }

View File

@ -17,7 +17,7 @@ public class GetGenericMasterController : BaseController<GetGenericMasterControl
{ {
Result = 1, Result = 1,
VerupNo = 2, VerupNo = 2,
EnableIdBit = Enumerable.Repeat((byte)1, 20).ToArray(), EnableIdBit = FlagCalculator.GetBitArrayTrue(20)
}; };

View File

@ -4,24 +4,31 @@
[ApiController] [ApiController]
public class GetShopFolderController : BaseController<GetShopFolderController> public class GetShopFolderController : BaseController<GetShopFolderController>
{ {
private readonly IGameDataService gameDataService;
public GetShopFolderController(IGameDataService gameDataService)
{
this.gameDataService = gameDataService;
}
[HttpPost] [HttpPost]
[Produces("application/protobuf")] [Produces("application/protobuf")]
public IActionResult GetShopFolder([FromBody] GetShopFolderRequest request) public IActionResult GetShopFolder([FromBody] GetShopFolderRequest request)
{ {
Logger.LogInformation("GetShopFolder request : {Request}", request.Stringify()); Logger.LogInformation("GetShopFolder request : {Request}", request.Stringify());
gameDataService.GetTokenDataDictionary().TryGetValue("shopTokenId", out var shopTokenId);
var shopFolderDictionary = gameDataService.GetShopFolderDictionary();
var response = new GetShopFolderResponse var response = new GetShopFolderResponse
{ {
Result = 1, Result = 1,
TokenId = 1, TokenId = shopTokenId,
VerupNo = 2 VerupNo = 2
}; };
response.AryShopFolderDatas.Add(new GetShopFolderResponse.ShopFolderData foreach (var shopFolder in shopFolderDictionary) response.AryShopFolderDatas.Add(shopFolder.Value);
{
Price = 1,
SongNo = 2
});
return Ok(response); return Ok(response);
} }

View File

@ -24,14 +24,16 @@ public class InitialDataCheckController : BaseController<InitialDataCheckControl
Logger.LogInformation("Initial data check request: {Request}", request.Stringify()); Logger.LogInformation("Initial data check request: {Request}", request.Stringify());
var songIdMax = settings.EnableMoreSongs ? Constants.MUSIC_ID_MAX_EXPANDED : Constants.MUSIC_ID_MAX; var songIdMax = settings.EnableMoreSongs ? Constants.MUSIC_ID_MAX_EXPANDED : Constants.MUSIC_ID_MAX;
var lockedSongsList = gameDataService.GetLockedSongsList();
var enabledMusicList = gameDataService.GetMusicList().Except(lockedSongsList);
var enabledUraMusicList = gameDataService.GetMusicWithUraList().Except(lockedSongsList);
var enabledArray = var enabledArray =
FlagCalculator.GetBitArrayFromIds(gameDataService.GetMusicList(), songIdMax, Logger); FlagCalculator.GetBitArrayFromIds(enabledMusicList, songIdMax, Logger);
var uraReleaseBit = FlagCalculator.GetBitArrayFromIds(enabledUraMusicList, songIdMax, Logger);
var defaultSongWithUraList = gameDataService.GetMusicWithUraList(); var verupNo1 = new uint[] { 104 };
var uraReleaseBit =
FlagCalculator.GetBitArrayFromIds(defaultSongWithUraList, songIdMax, Logger);
var verupNo1 = new uint[] { 2, 3, 4, 5, 6, 7, 8, 13, 15, 24, 25, 26, 27, 28, 29, 30, 31 };
var aryVerUp = verupNo1.Select(i => new InitialdatacheckResponse.VerupNoData1 var aryVerUp = verupNo1.Select(i => new InitialdatacheckResponse.VerupNoData1
{ {
MasterType = i, MasterType = i,
@ -50,7 +52,7 @@ public class InitialDataCheckController : BaseController<InitialDataCheckControl
response.AryVerupNoData1s.AddRange(aryVerUp); response.AryVerupNoData1s.AddRange(aryVerUp);
var danData = new List<InitialdatacheckResponse.VerupNoData2.InformationData>(); var danData = new List<InitialdatacheckResponse.VerupNoData2.InformationData>();
for (var danId = Constants.MIN_DAN_ID; danId <= 1; danId++) for (var danId = Constants.MIN_DAN_ID; danId <= 18; danId++)
{ {
danData.Add(new InitialdatacheckResponse.VerupNoData2.InformationData danData.Add(new InitialdatacheckResponse.VerupNoData2.InformationData
{ {
@ -58,7 +60,7 @@ public class InitialDataCheckController : BaseController<InitialDataCheckControl
VerupNo = 1 VerupNo = 1
}); });
} }
var verupNo2 = new uint[] { 11, 101, 102, 103, 105 }; var verupNo2 = new uint[] { 101 };
foreach (var i in verupNo2) foreach (var i in verupNo2)
{ {
var verUp2 = new InitialdatacheckResponse.VerupNoData2 var verUp2 = new InitialdatacheckResponse.VerupNoData2

View File

@ -27,10 +27,17 @@ public class GameDataService : IGameDataService
private ImmutableDictionary<uint, GetfolderResponse.EventfolderData> folderDictionary = private ImmutableDictionary<uint, GetfolderResponse.EventfolderData> folderDictionary =
ImmutableDictionary<uint, GetfolderResponse.EventfolderData>.Empty; ImmutableDictionary<uint, GetfolderResponse.EventfolderData>.Empty;
private ImmutableDictionary<uint, GetShopFolderResponse.ShopFolderData> shopFolderDictionary =
ImmutableDictionary<uint, GetShopFolderResponse.ShopFolderData>.Empty;
private List<uint> musics = new(); private List<uint> musics = new();
private List<uint> musicsWithUra = new(); private List<uint> musicsWithUra = new();
private List<uint> lockedSongsList = new();
private Dictionary<string, uint> tokenDataDictionary = new();
private readonly DataSettings settings; private readonly DataSettings settings;
public GameDataService(IOptions<DataSettings> settings) public GameDataService(IOptions<DataSettings> settings)
@ -73,6 +80,21 @@ public class GameDataService : IGameDataService
return folderDictionary; return folderDictionary;
} }
public ImmutableDictionary<uint, GetShopFolderResponse.ShopFolderData> GetShopFolderDictionary()
{
return shopFolderDictionary;
}
public Dictionary<string, uint> GetTokenDataDictionary()
{
return tokenDataDictionary;
}
public List<uint> GetLockedSongsList()
{
return lockedSongsList;
}
public async Task InitializeAsync() public async Task InitializeAsync()
{ {
var dataPath = PathHelper.GetDataPath(); var dataPath = PathHelper.GetDataPath();
@ -83,6 +105,9 @@ public class GameDataService : IGameDataService
var danDataPath = Path.Combine(dataPath, settings.DanDataFileName); var danDataPath = Path.Combine(dataPath, settings.DanDataFileName);
var songIntroDataPath = Path.Combine(dataPath, settings.IntroDataFileName); var songIntroDataPath = Path.Combine(dataPath, settings.IntroDataFileName);
var eventFolderDataPath = Path.Combine(dataPath, settings.EventFolderDataFileName); var eventFolderDataPath = Path.Combine(dataPath, settings.EventFolderDataFileName);
var shopFolderDataPath = Path.Combine(dataPath, settings.ShopFolderDataFileName);
var tokenDataPath = Path.Combine(dataPath, settings.TokenDataFileName);
var lockedSongsDataPath = Path.Combine(dataPath, settings.LockedSongsDataFileName);
if (File.Exists(compressedMusicInfoPath)) if (File.Exists(compressedMusicInfoPath))
{ {
@ -97,12 +122,18 @@ public class GameDataService : IGameDataService
await using var danDataFile = File.OpenRead(danDataPath); await using var danDataFile = File.OpenRead(danDataPath);
await using var songIntroDataFile = File.OpenRead(songIntroDataPath); await using var songIntroDataFile = File.OpenRead(songIntroDataPath);
await using var eventFolderDataFile = File.OpenRead(eventFolderDataPath); await using var eventFolderDataFile = File.OpenRead(eventFolderDataPath);
await using var shopFolderDataFile = File.OpenRead(shopFolderDataPath);
await using var tokenDataFile = File.OpenRead(tokenDataPath);
await using var lockedSongsDataFile = File.OpenRead(lockedSongsDataPath);
var infoesData = await JsonSerializer.DeserializeAsync<MusicInfoes>(musicInfoFile); var infoesData = await JsonSerializer.DeserializeAsync<MusicInfoes>(musicInfoFile);
var attributesData = await JsonSerializer.DeserializeAsync<MusicAttributes>(musicAttributeFile); var attributesData = await JsonSerializer.DeserializeAsync<MusicAttributes>(musicAttributeFile);
var danData = await JsonSerializer.DeserializeAsync<List<DanData>>(danDataFile); var danData = await JsonSerializer.DeserializeAsync<List<DanData>>(danDataFile);
var introData = await JsonSerializer.DeserializeAsync<List<SongIntroductionData>>(songIntroDataFile); var introData = await JsonSerializer.DeserializeAsync<List<SongIntroductionData>>(songIntroDataFile);
var eventFolderData = await JsonSerializer.DeserializeAsync<List<EventFolderData>>(eventFolderDataFile); var eventFolderData = await JsonSerializer.DeserializeAsync<List<EventFolderData>>(eventFolderDataFile);
var shopFolderData = await JsonSerializer.DeserializeAsync<List<ShopFolderData>>(shopFolderDataFile);
var tokenData = await JsonSerializer.DeserializeAsync<Dictionary<string, uint>>(tokenDataFile);
var lockedSongsData = await JsonSerializer.DeserializeAsync<Dictionary<string, uint[]>>(lockedSongsDataFile);
InitializeMusicInfoes(infoesData); InitializeMusicInfoes(infoesData);
@ -113,6 +144,12 @@ public class GameDataService : IGameDataService
InitializeIntroData(introData); InitializeIntroData(introData);
InitializeEventFolderData(eventFolderData); InitializeEventFolderData(eventFolderData);
InitializeShopFolderData(shopFolderData);
InitializeTokenData(tokenData);
InitializeLockedSongsData(lockedSongsData);
} }
private static void TryDecompressMusicInfo() private static void TryDecompressMusicInfo()
@ -180,6 +217,24 @@ public class GameDataService : IGameDataService
musics.Sort(); musics.Sort();
} }
private void InitializeShopFolderData(List<ShopFolderData>? shopFolderData)
{
shopFolderData.ThrowIfNull("Shouldn't happen!");
shopFolderDictionary = shopFolderData.ToImmutableDictionary(data => data.SongNo, ToResponseShopFolderData);
}
private void InitializeTokenData(Dictionary<string, uint>? tokenData)
{
tokenData.ThrowIfNull("Shouldn't happen!");
tokenDataDictionary = tokenData;
}
private void InitializeLockedSongsData(Dictionary<string, uint[]>? lockedSongsData)
{
lockedSongsData.ThrowIfNull("Shouldn't happen!");
lockedSongsList = lockedSongsData["songNo"].ToList();
}
private static GetDanOdaiResponse.OdaiData ToResponseOdaiData(DanData data) private static GetDanOdaiResponse.OdaiData ToResponseOdaiData(DanData data)
{ {
var responseOdaiData = new GetDanOdaiResponse.OdaiData var responseOdaiData = new GetDanOdaiResponse.OdaiData
@ -223,4 +278,15 @@ public class GameDataService : IGameDataService
return responseEventFolderData; return responseEventFolderData;
} }
private static GetShopFolderResponse.ShopFolderData ToResponseShopFolderData(ShopFolderData data)
{
var responseShopFolderData = new GetShopFolderResponse.ShopFolderData
{
SongNo = data.SongNo,
Price = data.Price
};
return responseShopFolderData;
}
} }

View File

@ -19,5 +19,11 @@ public interface IGameDataService
public ImmutableDictionary<uint, GetSongIntroductionResponse.SongIntroductionData> GetSongIntroDictionary(); public ImmutableDictionary<uint, GetSongIntroductionResponse.SongIntroductionData> GetSongIntroDictionary();
public ImmutableDictionary<uint, GetfolderResponse.EventfolderData> GetFolderDictionary(); public ImmutableDictionary<uint, GetfolderResponse.EventfolderData> GetFolderDictionary();
public ImmutableDictionary<uint, GetShopFolderResponse.ShopFolderData> GetShopFolderDictionary();
public Dictionary<string, uint> GetTokenDataDictionary();
public List<uint> GetLockedSongsList();
} }

View File

@ -7,4 +7,10 @@ public class DataSettings
public string EventFolderDataFileName { get; set; } = "event_folder_data.json"; public string EventFolderDataFileName { get; set; } = "event_folder_data.json";
public string IntroDataFileName { get; set; } = "intro_data.json"; public string IntroDataFileName { get; set; } = "intro_data.json";
public string ShopFolderDataFileName { get; set; } = "shop_folder_data.json";
public string TokenDataFileName { get; set; } = "token_data.json";
public string LockedSongsDataFileName { get; set; } = "locked_songs_data.json";
} }

View File

@ -0,0 +1,4 @@
{
"songNo": [
]
}

View File

@ -0,0 +1,6 @@
[
{
"songNo": 2,
"price": 0
}
]

View File

@ -0,0 +1,4 @@
{
"shopTokenId": 4,
"kaTokenId": 1000
}