From 1697075c36791915edeac185c99308a935989009 Mon Sep 17 00:00:00 2001 From: MyAngelKamikaze Date: Tue, 17 Dec 2024 01:13:36 +0900 Subject: [PATCH] fix poi route submission --- .../PoiDbRouteSubmission/NextInfo.cs | 21 ++++++- .../PoiDbRouteSubmission/PoiApiHappening.cs | 24 ++++++++ .../PoiDbRouteSubmission/PoiApiItemget.cs | 21 +++++++ .../PoiDbRouteSubmissionService.cs | 60 +++++++++++++++++-- 4 files changed, 119 insertions(+), 7 deletions(-) create mode 100644 ElectronicObserver/Data/PoiDbSubmission/PoiDbRouteSubmission/PoiApiHappening.cs create mode 100644 ElectronicObserver/Data/PoiDbSubmission/PoiDbRouteSubmission/PoiApiItemget.cs diff --git a/ElectronicObserver/Data/PoiDbSubmission/PoiDbRouteSubmission/NextInfo.cs b/ElectronicObserver/Data/PoiDbSubmission/PoiDbRouteSubmission/NextInfo.cs index c47a77195..16c0e940b 100644 --- a/ElectronicObserver/Data/PoiDbSubmission/PoiDbRouteSubmission/NextInfo.cs +++ b/ElectronicObserver/Data/PoiDbSubmission/PoiDbRouteSubmission/NextInfo.cs @@ -1,4 +1,5 @@ -using System.Text.Json.Serialization; +using System.Collections.Generic; +using System.Text.Json.Serialization; namespace ElectronicObserver.Data.PoiDbSubmission.PoiDbRouteSubmission; @@ -9,4 +10,22 @@ public class NextInfo [JsonPropertyName("api_mapinfo_no")] public required string Map { get; init; } + + [JsonPropertyName("api_itemget")] + public required List? ItemGet { get; init; } + + [JsonPropertyName("api_happening")] + public required PoiApiHappening? Happening { get; init; } + + [JsonPropertyName("api_required_defeat_count")] + public required string? RequiredDefeatCount { get; init; } + + [JsonPropertyName("api_defeat_count")] + public required string? DefeatCount { get; init; } + + [JsonPropertyName("api_max_maphp")] + public required string? ApiMaxMaphp { get; init; } + + [JsonPropertyName("api_now_maphp")] + public required string? ApiNowMaphp { get; init; } } diff --git a/ElectronicObserver/Data/PoiDbSubmission/PoiDbRouteSubmission/PoiApiHappening.cs b/ElectronicObserver/Data/PoiDbSubmission/PoiDbRouteSubmission/PoiApiHappening.cs new file mode 100644 index 000000000..7a37c8a5c --- /dev/null +++ b/ElectronicObserver/Data/PoiDbSubmission/PoiDbRouteSubmission/PoiApiHappening.cs @@ -0,0 +1,24 @@ +using System.Text.Json.Serialization; + +namespace ElectronicObserver.Data.PoiDbSubmission.PoiDbRouteSubmission; + +public class PoiApiHappening +{ + [JsonPropertyName("api_count")] + public required string ApiCount { get; set; } + + [JsonPropertyName("api_dentan")] + public required string ApiDentan { get; set; } + + [JsonPropertyName("api_icon_id")] + public required string ApiIconId { get; set; } + + [JsonPropertyName("api_mst_id")] + public required string ApiMstId { get; set; } + + [JsonPropertyName("api_type")] + public required string ApiType { get; set; } + + [JsonPropertyName("api_usemst")] + public required string ApiUsemst { get; set; } +} diff --git a/ElectronicObserver/Data/PoiDbSubmission/PoiDbRouteSubmission/PoiApiItemget.cs b/ElectronicObserver/Data/PoiDbSubmission/PoiDbRouteSubmission/PoiApiItemget.cs new file mode 100644 index 000000000..b5701415f --- /dev/null +++ b/ElectronicObserver/Data/PoiDbSubmission/PoiDbRouteSubmission/PoiApiItemget.cs @@ -0,0 +1,21 @@ +using System.Text.Json.Serialization; + +namespace ElectronicObserver.Data.PoiDbSubmission.PoiDbRouteSubmission; + +public class PoiApiItemget +{ + [JsonPropertyName("api_getcount")] + public required string ApiGetcount { get; set; } + + [JsonPropertyName("api_icon_id")] + public required string ApiIconId { get; set; } + + [JsonPropertyName("api_id")] + public required string ApiId { get; set; } + + [JsonPropertyName("api_name")] + public required string ApiName { get; set; } + + [JsonPropertyName("api_usemst")] + public required string ApiUsemst { get; set; } +} diff --git a/ElectronicObserver/Data/PoiDbSubmission/PoiDbRouteSubmission/PoiDbRouteSubmissionService.cs b/ElectronicObserver/Data/PoiDbSubmission/PoiDbRouteSubmission/PoiDbRouteSubmissionService.cs index de7b5cd5c..fa4ff4403 100644 --- a/ElectronicObserver/Data/PoiDbSubmission/PoiDbRouteSubmission/PoiDbRouteSubmissionService.cs +++ b/ElectronicObserver/Data/PoiDbSubmission/PoiDbRouteSubmission/PoiDbRouteSubmissionService.cs @@ -5,8 +5,10 @@ using System.Text.Json; using System.Threading.Tasks; using ElectronicObserver.KancolleApi.Types.ApiGetMember.Mapinfo; +using ElectronicObserver.KancolleApi.Types.ApiReqMap.Models; using ElectronicObserver.KancolleApi.Types.ApiReqMap.Next; using ElectronicObserver.KancolleApi.Types.ApiReqMap.Start; +using ElectronicObserver.KancolleApi.Types.Models; using ElectronicObserver.Utility.Data; using ElectronicObserverTypes; @@ -23,8 +25,12 @@ public class PoiDbRouteSubmissionService( private PoiHttpClient PoiHttpClient { get; } = poiHttpClient; private Action LogError { get; } = logError; + private List? ApiMapInfo { get; set; } + private ApiMapInfo? CurrentMap { get; set; } private int? CellCount { get; set; } private List? CellIds { get; set; } + private ApiHappening? ApiHappening { get; set; } + private List? ApiItemget { get; set; } private Dictionary? MapLevels { get; set; } private int? World { get; set; } private int? Map { get; set; } @@ -37,7 +43,8 @@ public void ApiGetMember_MapInfo_ResponseReceived(string apiname, dynamic data) string json = data.ToString(); ApiGetMemberMapinfoResponse response = JsonSerializer.Deserialize(json)!; - MapLevels = response.ApiMapInfo + ApiMapInfo = response.ApiMapInfo; + MapLevels = ApiMapInfo .ToDictionary(i => i.ApiId, i => i.ApiEventmap?.ApiSelectedRank.ToString() ?? "0"); } @@ -50,6 +57,9 @@ public void ApiReqMap_Start_ResponseReceived(string apiname, dynamic data) World = response.ApiMapareaId; Map = response.ApiMapinfoNo; CellIds = [response.ApiNo]; + ApiHappening = response.ApiHappening; + + CurrentMap = ApiMapInfo?.FirstOrDefault(m => m.ApiId == 10 * World + Map); FleetData? fleet = KcDatabase.Fleet.Fleets.Values.FirstOrDefault(f => f.IsInSortie); @@ -68,11 +78,6 @@ public void ApiReqMap_Start_ResponseReceived(string apiname, dynamic data) Fleet2 = escortFleet; } - if (!CellIds.Contains(response.ApiNo)) - { - CellIds.Add(response.ApiNo); - } - SubmitData(); } @@ -92,6 +97,17 @@ public void ApiReqMap_NextOnResponseReceived(string apiname, dynamic data) CellIds.Add(response.ApiNo); + ApiHappening = response.ApiHappening; + ApiItemget = response.ApiItemget switch + { + JsonElement { ValueKind: JsonValueKind.Array } i + => i.Deserialize>(), + + JsonElement i => [i.Deserialize()!], + + _ => null, + }; + SubmitData(); } @@ -107,8 +123,12 @@ public void ApiPort_Port_ResponseReceived(string apiname, dynamic data) private void ClearState() { + ApiMapInfo = null; + CurrentMap = null; CellCount = null; CellIds = null; + ApiHappening = null; + ApiItemget = null; MapLevels = null; World = null; Map = null; @@ -120,6 +140,7 @@ private void ClearState() [SuppressMessage("Critical Code Smell", "S3776:Cognitive Complexity of methods should not be too high", Justification = "")] private void SubmitData() { + if (CurrentMap is null) return; if (Fleet1 is null) return; if (EscapeList is null) return; if (CellIds is null) return; @@ -167,6 +188,33 @@ private void SubmitData() { World = world.ToString(), Map = map.ToString(), + ItemGet = ApiItemget + ?.Select(a => new PoiApiItemget + { + ApiGetcount = a.ApiGetcount.ToString(), + ApiIconId = a.ApiIconId.ToString(), + ApiId = a.ApiId.ToString(), + ApiName = a.ApiName, + ApiUsemst = a.ApiUsemst.ToString(), + }) + .ToList(), + Happening = ApiHappening switch + { + null => null, + _ => new() + { + ApiCount = ApiHappening.ApiCount.ToString(), + ApiDentan = ApiHappening.ApiDentan.ToString(), + ApiIconId = ApiHappening.ApiIconId.ToString(), + ApiMstId = ((int)ApiHappening.ApiMstId).ToString(), + ApiType = ApiHappening.ApiType.ToString(), + ApiUsemst = ApiHappening.ApiUsemst.ToString(), + }, + }, + RequiredDefeatCount = CurrentMap.ApiRequiredDefeatCount?.ToString(), + DefeatCount = CurrentMap.ApiDefeatCount?.ToString(), + ApiMaxMaphp = CurrentMap.ApiEventmap?.ApiMaxMaphp?.ToString(), + ApiNowMaphp = CurrentMap.ApiEventmap?.ApiNowMaphp?.ToString(), }, AdmiralLevel = KcDatabase.Admiral.Level, LosValues = new()