From c7c380fa0aabc2922ce250e4ef827d6cdd171ba2 Mon Sep 17 00:00:00 2001 From: S-Sebb?? Date: Sun, 17 Sep 2023 01:17:44 +0800 Subject: [PATCH] Implemented turning off shopToken and kaToken, default token_data.json to both tokens turned off --- .../Game/GetShopFolderController.cs | 2 +- .../Game/GetTokenCountController.cs | 41 +++++++++++-------- .../Controllers/Game/UserDataController.cs | 3 +- TaikoLocalServer/Services/GameDataService.cs | 8 ++-- .../Services/Interfaces/IGameDataService.cs | 2 +- TaikoLocalServer/wwwroot/data/token_data.json | 4 +- 6 files changed, 32 insertions(+), 28 deletions(-) diff --git a/TaikoLocalServer/Controllers/Game/GetShopFolderController.cs b/TaikoLocalServer/Controllers/Game/GetShopFolderController.cs index fc76e57..e11486d 100644 --- a/TaikoLocalServer/Controllers/Game/GetShopFolderController.cs +++ b/TaikoLocalServer/Controllers/Game/GetShopFolderController.cs @@ -24,7 +24,7 @@ public class GetShopFolderController : BaseController var response = new GetShopFolderResponse { Result = 1, - TokenId = shopTokenId, + TokenId = shopTokenId > 0 ? (uint)shopTokenId : 1, VerupNo = 2 }; diff --git a/TaikoLocalServer/Controllers/Game/GetTokenCountController.cs b/TaikoLocalServer/Controllers/Game/GetTokenCountController.cs index a85b739..7993e79 100644 --- a/TaikoLocalServer/Controllers/Game/GetTokenCountController.cs +++ b/TaikoLocalServer/Controllers/Game/GetTokenCountController.cs @@ -41,32 +41,37 @@ public class GetTokenCountController : BaseController } tokenCountDict.ThrowIfNull("TokenCountDict should never be null"); - - if (tokenCountDict.Count == 0) tokenCountDict.Add(shopTokenId, 0); - - tokenCountDict.TryAdd(shopTokenId, 0); - - tokenCountDict.TryAdd(kaTokenId, 0); - - user.TokenCountDict = JsonSerializer.Serialize(tokenCountDict); - await userDatumService.UpdateUserDatum(user); - + var response = new GetTokenCountResponse { Result = 1 }; - response.AryTokenCountDatas.Add(new GetTokenCountResponse.TokenCountData + if (tokenCountDict.Count == 0) tokenCountDict.Add(1, 0); + if (shopTokenId > 0) { - TokenCount = tokenCountDict[shopTokenId], - TokenId = shopTokenId - }); + var castedShopTokenId = (uint)shopTokenId; + tokenCountDict.TryAdd(castedShopTokenId, 0); + response.AryTokenCountDatas.Add(new GetTokenCountResponse.TokenCountData + { + TokenCount = tokenCountDict[castedShopTokenId], + TokenId = castedShopTokenId + }); + } - response.AryTokenCountDatas.Add(new GetTokenCountResponse.TokenCountData + if (kaTokenId > 0) { - TokenCount = tokenCountDict[kaTokenId], - TokenId = kaTokenId - }); + var castedKaTokenId = (uint)kaTokenId; + tokenCountDict.TryAdd(castedKaTokenId, 0); + response.AryTokenCountDatas.Add(new GetTokenCountResponse.TokenCountData + { + TokenCount = tokenCountDict[castedKaTokenId], + TokenId = castedKaTokenId + }); + } + + user.TokenCountDict = JsonSerializer.Serialize(tokenCountDict); + await userDatumService.UpdateUserDatum(user); return Ok(response); } diff --git a/TaikoLocalServer/Controllers/Game/UserDataController.cs b/TaikoLocalServer/Controllers/Game/UserDataController.cs index 1df52b9..582e680 100644 --- a/TaikoLocalServer/Controllers/Game/UserDataController.cs +++ b/TaikoLocalServer/Controllers/Game/UserDataController.cs @@ -125,8 +125,7 @@ public class UserDataController : BaseController IsVoiceOn = userData.IsVoiceOn, IsSkipOn = userData.IsSkipOn, IsChallengecompe = false, - SongRecentCnt = (uint)recentSongs.Length, - TotalCreditCnt = 0 + SongRecentCnt = (uint)recentSongs.Length }; return Ok(response); diff --git a/TaikoLocalServer/Services/GameDataService.cs b/TaikoLocalServer/Services/GameDataService.cs index 62c0e7a..7c411f4 100644 --- a/TaikoLocalServer/Services/GameDataService.cs +++ b/TaikoLocalServer/Services/GameDataService.cs @@ -39,7 +39,7 @@ public class GameDataService : IGameDataService private List lockedSongsList = new(); - private Dictionary tokenDataDictionary = new(); + private Dictionary tokenDataDictionary = new(); private readonly DataSettings settings; @@ -93,7 +93,7 @@ public class GameDataService : IGameDataService return shopFolderDictionary; } - public Dictionary GetTokenDataDictionary() + public Dictionary GetTokenDataDictionary() { return tokenDataDictionary; } @@ -143,7 +143,7 @@ public class GameDataService : IGameDataService var movieData = await JsonSerializer.DeserializeAsync>(movieDataFile); var eventFolderData = await JsonSerializer.DeserializeAsync>(eventFolderDataFile); var shopFolderData = await JsonSerializer.DeserializeAsync>(shopFolderDataFile); - var tokenData = await JsonSerializer.DeserializeAsync>(tokenDataFile); + var tokenData = await JsonSerializer.DeserializeAsync>(tokenDataFile); var lockedSongsData = await JsonSerializer.DeserializeAsync>(lockedSongsDataFile); InitializeMusicInfoes(infoesData); @@ -242,7 +242,7 @@ public class GameDataService : IGameDataService shopFolderDictionary = shopFolderData.ToImmutableDictionary(data => data.SongNo, ToResponseShopFolderData); } - private void InitializeTokenData(Dictionary? tokenData) + private void InitializeTokenData(Dictionary? tokenData) { tokenData.ThrowIfNull("Shouldn't happen!"); tokenDataDictionary = tokenData; diff --git a/TaikoLocalServer/Services/Interfaces/IGameDataService.cs b/TaikoLocalServer/Services/Interfaces/IGameDataService.cs index 5c97fd5..1b6035c 100644 --- a/TaikoLocalServer/Services/Interfaces/IGameDataService.cs +++ b/TaikoLocalServer/Services/Interfaces/IGameDataService.cs @@ -24,7 +24,7 @@ public interface IGameDataService public ImmutableDictionary GetShopFolderDictionary(); - public Dictionary GetTokenDataDictionary(); + public Dictionary GetTokenDataDictionary(); public List GetLockedSongsList(); } diff --git a/TaikoLocalServer/wwwroot/data/token_data.json b/TaikoLocalServer/wwwroot/data/token_data.json index a590dbb..837057c 100644 --- a/TaikoLocalServer/wwwroot/data/token_data.json +++ b/TaikoLocalServer/wwwroot/data/token_data.json @@ -1,4 +1,4 @@ { - "shopTokenId": 4, - "kaTokenId": 1000 + "shopTokenId": -1, + "kaTokenId": -1 } \ No newline at end of file