From 25dc17e088549c5e223346258a29f4eb055594d8 Mon Sep 17 00:00:00 2001 From: MyAngelKamikaze Date: Thu, 12 Dec 2024 16:09:08 +0900 Subject: [PATCH] fix poi submission --- .../Data/PoiDbSubmission/Extensions.cs | 36 ++++++++++++++- .../PoiDbRouteSubmission/LosValues.cs | 24 +++++----- .../PoiDbRouteSubmissionService.cs | 44 +++++++------------ 3 files changed, 62 insertions(+), 42 deletions(-) diff --git a/ElectronicObserver/Data/PoiDbSubmission/Extensions.cs b/ElectronicObserver/Data/PoiDbSubmission/Extensions.cs index e7a2170e8..57e3b281f 100644 --- a/ElectronicObserver/Data/PoiDbSubmission/Extensions.cs +++ b/ElectronicObserver/Data/PoiDbSubmission/Extensions.cs @@ -1,4 +1,9 @@ -using System.Text.Json.Nodes; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Text.Json; +using System.Text.Json.Nodes; +using ElectronicObserver.Data.PoiDbSubmission.PoiDbRouteSubmission; using ElectronicObserverTypes; namespace ElectronicObserver.Data.PoiDbSubmission; @@ -9,9 +14,36 @@ public static JsonNode MakeShip(this IShipData ship) { string rawData = ship.RawData.ToString(); - return JsonNode.Parse(rawData)!; + List poiSlot = ship.SlotInstance + .Select(MakePoiEquipment) + .ToList(); + PoiDbRouteEquipment? poiSlotEx = ship.ExpansionSlotInstance.MakePoiEquipment(); + + JsonNode shipJson = JsonNode.Parse(rawData)!; + shipJson["poi_slot"] = JsonSerializer.SerializeToNode(poiSlot); + shipJson["poi_slot_ex"] = JsonSerializer.SerializeToNode(poiSlotEx); + + return shipJson; } + [return: NotNullIfNotNull(nameof(equipment))] + public static PoiDbRouteEquipment? MakePoiEquipment(this IEquipmentData? equipment) => equipment switch + { + null => null, + _ => new() + { + ApiId = equipment.MasterID, + ApiSlotitemId = equipment.EquipmentID, + ApiLocked = equipment.IsLocked switch + { + true => 1, + false => 0, + }, + ApiLevel = equipment.Level, + ApiAlv = equipment.AircraftLevel, + }, + }; + public static JsonNode MakeEquipment(this IEquipmentData equipment) { string rawData = equipment.RawData.ToString(); diff --git a/ElectronicObserver/Data/PoiDbSubmission/PoiDbRouteSubmission/LosValues.cs b/ElectronicObserver/Data/PoiDbSubmission/PoiDbRouteSubmission/LosValues.cs index 1b424e1a6..210ba2dde 100644 --- a/ElectronicObserver/Data/PoiDbSubmission/PoiDbRouteSubmission/LosValues.cs +++ b/ElectronicObserver/Data/PoiDbSubmission/PoiDbRouteSubmission/LosValues.cs @@ -5,38 +5,38 @@ namespace ElectronicObserver.Data.PoiDbSubmission.PoiDbRouteSubmission; public class LosValues { [JsonPropertyName("sakuOne25")] - public required double? SakuOne25 { get; set; } + public required string? SakuOne25 { get; set; } [JsonPropertyName("sakuOne25a")] - public required double? SakuOne25a { get; set; } + public required string? SakuOne25a { get; set; } [JsonPropertyName("sakuOne33x1")] - public required double SakuOne33x1 { get; set; } + public required string SakuOne33x1 { get; set; } [JsonPropertyName("sakuOne33x2")] - public required double SakuOne33x2 { get; set; } + public required string SakuOne33x2 { get; set; } [JsonPropertyName("sakuOne33x3")] - public required double SakuOne33x3 { get; set; } + public required string SakuOne33x3 { get; set; } [JsonPropertyName("sakuOne33x4")] - public required double SakuOne33x4 { get; set; } + public required string SakuOne33x4 { get; set; } [JsonPropertyName("sakuTwo25")] - public required double? SakuTwo25 { get; set; } + public required string? SakuTwo25 { get; set; } [JsonPropertyName("sakuTwo25a")] - public required double? SakuTwo25a { get; set; } + public required string? SakuTwo25a { get; set; } [JsonPropertyName("sakuTwo33x1")] - public required double? SakuTwo33x1 { get; set; } + public required string? SakuTwo33x1 { get; set; } [JsonPropertyName("sakuTwo33x2")] - public required double? SakuTwo33x2 { get; set; } + public required string? SakuTwo33x2 { get; set; } [JsonPropertyName("sakuTwo33x3")] - public required double? SakuTwo33x3 { get; set; } + public required string? SakuTwo33x3 { get; set; } [JsonPropertyName("sakuTwo33x4")] - public required double? SakuTwo33x4 { get; set; } + public required string? SakuTwo33x4 { get; set; } } diff --git a/ElectronicObserver/Data/PoiDbSubmission/PoiDbRouteSubmission/PoiDbRouteSubmissionService.cs b/ElectronicObserver/Data/PoiDbSubmission/PoiDbRouteSubmission/PoiDbRouteSubmissionService.cs index faa7d1606..cc353cbb8 100644 --- a/ElectronicObserver/Data/PoiDbSubmission/PoiDbRouteSubmission/PoiDbRouteSubmissionService.cs +++ b/ElectronicObserver/Data/PoiDbSubmission/PoiDbRouteSubmission/PoiDbRouteSubmissionService.cs @@ -7,6 +7,7 @@ using ElectronicObserver.KancolleApi.Types.ApiGetMember.Mapinfo; using ElectronicObserver.KancolleApi.Types.ApiReqMap.Next; using ElectronicObserver.KancolleApi.Types.ApiReqMap.Start; +using ElectronicObserver.Utility.Data; using ElectronicObserverTypes; namespace ElectronicObserver.Data.PoiDbSubmission.PoiDbRouteSubmission; @@ -142,11 +143,7 @@ private void SubmitData() List> slot1 = Fleet1.MembersInstance! .OfType() .Select(s => s.SlotInstance - .Select(e => e switch - { - null => (object)-1, - _ => MakeEquipment(e), - }) + .Select(e => e.MakePoiEquipment() ?? (object)-1) .ToList()) .ToList(); @@ -158,11 +155,7 @@ private void SubmitData() List>? slot2 = Fleet2?.MembersInstance! .OfType() .Select(s => s.SlotInstance - .Select(e => e switch - { - null => (object)-1, - _ => MakeEquipment(e), - }) + .Select(e => e.MakePoiEquipment() ?? (object)-1) .ToList()) .ToList(); @@ -187,16 +180,16 @@ private void SubmitData() { SakuOne25 = null, SakuOne25a = null, - SakuOne33x1 = Fleet1.GetSearchingAbility(1), - SakuOne33x2 = Fleet1.GetSearchingAbility(2), - SakuOne33x3 = Fleet1.GetSearchingAbility(3), - SakuOne33x4 = Fleet1.GetSearchingAbility(4), + SakuOne33x1 = GetSearch(Fleet1, 1), + SakuOne33x2 = GetSearch(Fleet1, 2), + SakuOne33x3 = GetSearch(Fleet1, 3), + SakuOne33x4 = GetSearch(Fleet1, 4), SakuTwo25 = null, SakuTwo25a = null, - SakuTwo33x1 = Fleet2?.GetSearchingAbility(1), - SakuTwo33x2 = Fleet2?.GetSearchingAbility(2), - SakuTwo33x3 = Fleet2?.GetSearchingAbility(3), - SakuTwo33x4 = Fleet2?.GetSearchingAbility(4), + SakuTwo33x1 = GetSearch(Fleet2, 1), + SakuTwo33x2 = GetSearch(Fleet2, 2), + SakuTwo33x3 = GetSearch(Fleet2, 3), + SakuTwo33x4 = GetSearch(Fleet2, 4), }, ApiCellData = cellCount, Version = Version, @@ -235,16 +228,11 @@ private void SubmitData() ApiSlotitemLevel = ship.ExpansionSlotInstance?.Level ?? -1, }; - public static PoiDbRouteEquipment MakeEquipment(IEquipmentData equipment) => new() + [return: NotNullIfNotNull(nameof(fleet))] + private static string? GetSearch(IFleetData? fleet, int weight) => fleet switch { - ApiId = equipment.MasterID, - ApiSlotitemId = equipment.EquipmentID, - ApiLocked = equipment.IsLocked switch - { - true => 1, - false => 0, - }, - ApiLevel = equipment.Level, - ApiAlv = equipment.AircraftLevel, + null => null, + _ => Math.Round(Calculator.GetSearchingAbility_New33(fleet, weight), 2, MidpointRounding.ToNegativeInfinity) + .ToString("F2") }; }