Skip to content

Commit

Permalink
fix poi route submission
Browse files Browse the repository at this point in the history
  • Loading branch information
myangelkamikaze committed Dec 16, 2024
1 parent 4f8ea21 commit 1697075
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace ElectronicObserver.Data.PoiDbSubmission.PoiDbRouteSubmission;

Expand All @@ -9,4 +10,22 @@ public class NextInfo

[JsonPropertyName("api_mapinfo_no")]
public required string Map { get; init; }

[JsonPropertyName("api_itemget")]
public required List<PoiApiItemget>? 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; }
}
Original file line number Diff line number Diff line change
@@ -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; }
}
Original file line number Diff line number Diff line change
@@ -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; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -23,8 +25,12 @@ public class PoiDbRouteSubmissionService(
private PoiHttpClient PoiHttpClient { get; } = poiHttpClient;
private Action<Exception> LogError { get; } = logError;

private List<ApiMapInfo>? ApiMapInfo { get; set; }
private ApiMapInfo? CurrentMap { get; set; }
private int? CellCount { get; set; }
private List<int>? CellIds { get; set; }
private ApiHappening? ApiHappening { get; set; }
private List<ApiItemget>? ApiItemget { get; set; }
private Dictionary<int, string>? MapLevels { get; set; }
private int? World { get; set; }
private int? Map { get; set; }
Expand All @@ -37,7 +43,8 @@ public void ApiGetMember_MapInfo_ResponseReceived(string apiname, dynamic data)
string json = data.ToString();
ApiGetMemberMapinfoResponse response = JsonSerializer.Deserialize<ApiGetMemberMapinfoResponse>(json)!;

MapLevels = response.ApiMapInfo
ApiMapInfo = response.ApiMapInfo;
MapLevels = ApiMapInfo
.ToDictionary(i => i.ApiId, i => i.ApiEventmap?.ApiSelectedRank.ToString() ?? "0");
}

Expand All @@ -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);

Expand All @@ -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();
}

Expand All @@ -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<List<ApiItemget>>(),

JsonElement i => [i.Deserialize<ApiItemget>()!],

_ => null,
};

SubmitData();
}

Expand All @@ -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;
Expand All @@ -120,6 +140,7 @@ private void ClearState()
[SuppressMessage("Critical Code Smell", "S3776:Cognitive Complexity of methods should not be too high", Justification = "<Pending>")]
private void SubmitData()
{
if (CurrentMap is null) return;
if (Fleet1 is null) return;
if (EscapeList is null) return;
if (CellIds is null) return;
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 1697075

Please sign in to comment.